Spaces:
Running
Running
Commit ·
3da0476
1
Parent(s): aa5f38f
feat(claim): remove scroll/sword game UI and make claim direct, instant, and automatic on visit
Browse files- src/pages/ClaimPage.jsx +62 -166
src/pages/ClaimPage.jsx
CHANGED
|
@@ -2,33 +2,19 @@ import React, { useState, useEffect } from 'react';
|
|
| 2 |
import { useLocation, useNavigate, Link } from 'react-router-dom';
|
| 3 |
import axios from 'axios';
|
| 4 |
import { useAuth } from '../context/AuthContext';
|
| 5 |
-
import {
|
| 6 |
-
Scroll,
|
| 7 |
-
ShieldAlert,
|
| 8 |
-
CheckCircle2,
|
| 9 |
-
Sparkles,
|
| 10 |
-
Loader2,
|
| 11 |
-
Sword,
|
| 12 |
-
Lock,
|
| 13 |
-
ArrowRight,
|
| 14 |
-
Map
|
| 15 |
-
} from 'lucide-react';
|
| 16 |
|
| 17 |
function ClaimPage() {
|
| 18 |
const location = useLocation();
|
| 19 |
const navigate = useNavigate();
|
| 20 |
const { user } = useAuth();
|
| 21 |
|
| 22 |
-
const [token, setToken] = useState('');
|
| 23 |
const [loading, setLoading] = useState(true);
|
| 24 |
-
const [claiming, setClaiming] = useState(false);
|
| 25 |
const [error, setError] = useState('');
|
| 26 |
const [success, setSuccess] = useState(false);
|
| 27 |
-
const [graphInfo, setGraphInfo] = useState(null);
|
| 28 |
|
| 29 |
const API_URL = import.meta.env.VITE_API_URL;
|
| 30 |
|
| 31 |
-
// 1. Extract and verify token on load
|
| 32 |
useEffect(() => {
|
| 33 |
const params = new URLSearchParams(location.search);
|
| 34 |
const claimToken = params.get('token');
|
|
@@ -38,112 +24,97 @@ function ClaimPage() {
|
|
| 38 |
setLoading(false);
|
| 39 |
return;
|
| 40 |
}
|
| 41 |
-
|
| 42 |
-
setToken(claimToken);
|
| 43 |
-
|
| 44 |
-
// Check token status anonymously
|
| 45 |
-
const checkToken = async () => {
|
| 46 |
-
try {
|
| 47 |
-
const response = await axios.post(`${API_URL}/agents/canvas/claim/check`, { token: claimToken });
|
| 48 |
-
if (response.data.success) {
|
| 49 |
-
setGraphInfo(response.data);
|
| 50 |
-
if (response.data.isClaimed) {
|
| 51 |
-
setError('Этот свиток с планом уже был забран другим искателем приключений! 🍂');
|
| 52 |
-
}
|
| 53 |
-
}
|
| 54 |
-
} catch (err) {
|
| 55 |
-
console.error('Failed to verify claim token:', err);
|
| 56 |
-
setError(err.response?.data?.message || 'Свиток пуст, поврежден или срок его действия истек.');
|
| 57 |
-
} finally {
|
| 58 |
-
setLoading(false);
|
| 59 |
-
}
|
| 60 |
-
};
|
| 61 |
-
|
| 62 |
-
checkToken();
|
| 63 |
-
}, [location, API_URL]);
|
| 64 |
|
| 65 |
-
// 2. Claim handler
|
| 66 |
-
const handleClaim = async () => {
|
| 67 |
if (!user) {
|
| 68 |
-
// Redirect to
|
| 69 |
navigate(`/auth?redirect=${encodeURIComponent(location.pathname + location.search)}`);
|
| 70 |
return;
|
| 71 |
}
|
| 72 |
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
navigate(`/canvas/${response.data.graphId}`);
|
| 83 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
}
|
| 85 |
-
}
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
setClaiming(false);
|
| 90 |
-
}
|
| 91 |
-
};
|
| 92 |
|
| 93 |
return (
|
| 94 |
<div className="min-h-screen bg-[#0B0F19] text-white flex flex-col items-center justify-center p-4 relative overflow-hidden select-none font-sans">
|
| 95 |
{/* Background Glows */}
|
| 96 |
-
<div className="absolute top-1/
|
| 97 |
-
<div className="absolute bottom-10 right-10 w-[300px] h-[300px] bg-
|
| 98 |
|
| 99 |
<div className="max-w-md w-full relative z-10">
|
| 100 |
|
| 101 |
{/* Brand Header */}
|
| 102 |
-
<div className="flex items-center justify-center gap-2 mb-8
|
| 103 |
<Map size={32} className="text-primary animate-pulse" />
|
| 104 |
<span className="text-2xl font-extrabold tracking-wider bg-clip-text text-transparent bg-gradient-to-r from-white via-slate-200 to-primary">
|
| 105 |
QuestboardAI
|
| 106 |
</span>
|
| 107 |
</div>
|
| 108 |
|
| 109 |
-
{/*
|
| 110 |
-
<div className="bg-[#151B2C]/90 border
|
| 111 |
|
| 112 |
-
{loading
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
<Loader2 size={48} className="text-primary animate-spin" />
|
| 116 |
<p className="text-sm font-bold text-slate-400 animate-pulse">
|
| 117 |
-
|
| 118 |
</p>
|
| 119 |
</div>
|
| 120 |
-
)
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
|
|
|
| 125 |
</div>
|
| 126 |
-
<h2 className="text-
|
| 127 |
-
|
| 128 |
</h2>
|
| 129 |
-
<p className="text-sm text-slate-
|
| 130 |
-
Пр
|
| 131 |
</p>
|
| 132 |
-
<div className="w-full bg-slate-800/40 rounded-xl p-3 border border-slate-700/50 mt-2">
|
| 133 |
-
<p className="text-xs text-slate-400 font-bold uppercase tracking-widest mb-1">Загрузка холста</p>
|
| 134 |
-
<div className="w-full bg-slate-700 h-1.5 rounded-full overflow-hidden">
|
| 135 |
-
<div className="bg-emerald-500 h-full w-full animate-[progress_2s_ease-in-out_infinite]" />
|
| 136 |
-
</div>
|
| 137 |
-
</div>
|
| 138 |
</div>
|
| 139 |
-
)
|
| 140 |
-
|
|
|
|
| 141 |
<div className="flex flex-col items-center text-center gap-4 py-6">
|
| 142 |
-
<div className="w-
|
| 143 |
-
<ShieldAlert size={
|
| 144 |
</div>
|
| 145 |
-
<h2 className="text-
|
| 146 |
-
|
| 147 |
</h2>
|
| 148 |
<p className="text-sm text-slate-300 font-semibold leading-relaxed">
|
| 149 |
{error}
|
|
@@ -151,86 +122,11 @@ function ClaimPage() {
|
|
| 151 |
|
| 152 |
<Link
|
| 153 |
to="/dashboard"
|
| 154 |
-
className="w-full mt-6 py-3
|
| 155 |
>
|
| 156 |
-
Вернутьс
|
| 157 |
</Link>
|
| 158 |
</div>
|
| 159 |
-
) : (
|
| 160 |
-
/* Active Unclaimed State */
|
| 161 |
-
<div className="flex flex-col gap-5">
|
| 162 |
-
|
| 163 |
-
{/* Floating Scroll Icon */}
|
| 164 |
-
<div className="flex justify-center relative">
|
| 165 |
-
<div className="absolute inset-0 bg-yellow-500/20 rounded-full blur-xl animate-pulse" />
|
| 166 |
-
<div className="w-20 h-20 bg-yellow-500/10 border-2 border-yellow-500 rounded-full flex items-center justify-center text-yellow-500 relative z-10 animate-[float_4s_ease-in-out_infinite]">
|
| 167 |
-
<Scroll size={40} />
|
| 168 |
-
</div>
|
| 169 |
-
</div>
|
| 170 |
-
|
| 171 |
-
{/* Title & Badge */}
|
| 172 |
-
<div className="text-center">
|
| 173 |
-
<span className="inline-flex items-center gap-1.5 px-3 py-1 bg-yellow-500/10 border border-yellow-500/30 rounded-full text-xs font-black text-yellow-500 uppercase tracking-widest mb-3">
|
| 174 |
-
<Sparkles size={12} /> Находка: ИИ-План
|
| 175 |
-
</span>
|
| 176 |
-
<h2 className="text-xl font-black tracking-tight mb-2">
|
| 177 |
-
Таинственный Свиток Квестов
|
| 178 |
-
</h2>
|
| 179 |
-
<p className="text-xs text-slate-400 font-bold max-w-xs mx-auto leading-relaxed">
|
| 180 |
-
Кто первый откроет этот свиток, тот привяжет интерактивный план проекта к своему аккаунту и станет его владельцем!
|
| 181 |
-
</p>
|
| 182 |
-
</div>
|
| 183 |
-
|
| 184 |
-
{/* Scroll Preview Box */}
|
| 185 |
-
<div className="bg-[#0B0F19]/90 border-2 border-dashed border-slate-700/60 rounded-2xl p-5 mt-2">
|
| 186 |
-
<p className="text-[10px] font-black text-yellow-500 uppercase tracking-widest mb-1.5">Содержимое свитка:</p>
|
| 187 |
-
<h3 className="text-sm font-black text-slate-200 mb-1 leading-snug">
|
| 188 |
-
{graphInfo?.title || 'Без названия'}
|
| 189 |
-
</h3>
|
| 190 |
-
<p className="text-xs text-slate-400 font-medium leading-relaxed line-clamp-3">
|
| 191 |
-
{graphInfo?.description || 'Описание отсутствует.'}
|
| 192 |
-
</p>
|
| 193 |
-
</div>
|
| 194 |
-
|
| 195 |
-
{/* Prompt logic */}
|
| 196 |
-
<div className="mt-4">
|
| 197 |
-
{user ? (
|
| 198 |
-
/* User logged in - ready to claim */
|
| 199 |
-
<button
|
| 200 |
-
onClick={handleClaim}
|
| 201 |
-
disabled={claiming}
|
| 202 |
-
className="w-full py-4 text-xs font-extrabold uppercase tracking-wider text-white bg-primary hover:bg-primary/95 border-2 border-primary rounded-xl transition-all cursor-pointer shadow-[4px_4px_0px_0px_rgba(255,255,255,0.15)] active:translate-y-0.5 flex items-center justify-center gap-2 hover:shadow-[6px_6px_0px_0px_var(--color-primary)]"
|
| 203 |
-
>
|
| 204 |
-
{claiming ? (
|
| 205 |
-
<>
|
| 206 |
-
<Loader2 size={16} className="animate-spin" />
|
| 207 |
-
Привязка квеста...
|
| 208 |
-
</>
|
| 209 |
-
) : (
|
| 210 |
-
<>
|
| 211 |
-
<Sword size={16} className="animate-bounce" />
|
| 212 |
-
Забрать права владельца ⚔️
|
| 213 |
-
</>
|
| 214 |
-
)}
|
| 215 |
-
</button>
|
| 216 |
-
) : (
|
| 217 |
-
/* User not logged in - needs to authorize */
|
| 218 |
-
<div className="space-y-3">
|
| 219 |
-
<div className="flex items-center gap-2 text-xs font-bold text-yellow-500/90 bg-yellow-500/5 border border-yellow-500/20 rounded-xl p-3">
|
| 220 |
-
<Lock size={16} className="shrink-0" />
|
| 221 |
-
<span>Вам нужно войти в систему, чтобы сохранить доску себе.</span>
|
| 222 |
-
</div>
|
| 223 |
-
<button
|
| 224 |
-
onClick={handleClaim}
|
| 225 |
-
className="w-full py-4 text-xs font-extrabold uppercase tracking-wider text-black bg-yellow-500 hover:bg-yellow-400 border-2 border-yellow-500 rounded-xl transition-all cursor-pointer shadow-[4px_4px_0px_0px_rgba(255,255,255,0.15)] flex items-center justify-center gap-1.5 group font-sans"
|
| 226 |
-
>
|
| 227 |
-
Авторизоваться и забрать <ArrowRight size={14} className="transition-transform group-hover:translate-x-1" />
|
| 228 |
-
</button>
|
| 229 |
-
</div>
|
| 230 |
-
)}
|
| 231 |
-
</div>
|
| 232 |
-
|
| 233 |
-
</div>
|
| 234 |
)}
|
| 235 |
|
| 236 |
</div>
|
|
|
|
| 2 |
import { useLocation, useNavigate, Link } from 'react-router-dom';
|
| 3 |
import axios from 'axios';
|
| 4 |
import { useAuth } from '../context/AuthContext';
|
| 5 |
+
import { Loader2, ShieldAlert, CheckCircle2, Map } from 'lucide-react';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
function ClaimPage() {
|
| 8 |
const location = useLocation();
|
| 9 |
const navigate = useNavigate();
|
| 10 |
const { user } = useAuth();
|
| 11 |
|
|
|
|
| 12 |
const [loading, setLoading] = useState(true);
|
|
|
|
| 13 |
const [error, setError] = useState('');
|
| 14 |
const [success, setSuccess] = useState(false);
|
|
|
|
| 15 |
|
| 16 |
const API_URL = import.meta.env.VITE_API_URL;
|
| 17 |
|
|
|
|
| 18 |
useEffect(() => {
|
| 19 |
const params = new URLSearchParams(location.search);
|
| 20 |
const claimToken = params.get('token');
|
|
|
|
| 24 |
setLoading(false);
|
| 25 |
return;
|
| 26 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
|
|
|
|
|
|
| 28 |
if (!user) {
|
| 29 |
+
// Redirect to authentication with current path as redirect return point
|
| 30 |
navigate(`/auth?redirect=${encodeURIComponent(location.pathname + location.search)}`);
|
| 31 |
return;
|
| 32 |
}
|
| 33 |
|
| 34 |
+
const performClaim = async () => {
|
| 35 |
+
let decodedGraphId = '';
|
| 36 |
+
try {
|
| 37 |
+
const decodedString = atob(claimToken);
|
| 38 |
+
const parts = decodedString.split('|');
|
| 39 |
+
if (parts.length > 0) {
|
| 40 |
+
decodedGraphId = parts[0];
|
| 41 |
+
}
|
| 42 |
+
} catch (e) {
|
| 43 |
+
console.error('Failed to parse token client-side:', e);
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
try {
|
| 47 |
+
const response = await axios.post(`${API_URL}/agents/canvas/claim`, { token: claimToken });
|
| 48 |
+
if (response.data.success) {
|
| 49 |
+
setSuccess(true);
|
| 50 |
+
// Redirect immediately to the claimed canvas
|
| 51 |
navigate(`/canvas/${response.data.graphId}`);
|
| 52 |
+
}
|
| 53 |
+
} catch (err) {
|
| 54 |
+
console.error('Failed to claim canvas:', err);
|
| 55 |
+
if (decodedGraphId) {
|
| 56 |
+
// If already claimed, redirect user straight to the canvas
|
| 57 |
+
// If they have access, they see it; if not, they see the auth error
|
| 58 |
+
navigate(`/canvas/${decodedGraphId}`);
|
| 59 |
+
} else {
|
| 60 |
+
setError(err.response?.data?.message || 'Не удалось активировать приглашение.');
|
| 61 |
+
setLoading(false);
|
| 62 |
+
}
|
| 63 |
}
|
| 64 |
+
};
|
| 65 |
+
|
| 66 |
+
performClaim();
|
| 67 |
+
}, [user, location, API_URL, navigate]);
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
return (
|
| 70 |
<div className="min-h-screen bg-[#0B0F19] text-white flex flex-col items-center justify-center p-4 relative overflow-hidden select-none font-sans">
|
| 71 |
{/* Background Glows */}
|
| 72 |
+
<div className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[500px] h-[500px] bg-primary/10 rounded-full blur-[120px] pointer-events-none" />
|
| 73 |
+
<div className="absolute bottom-10 right-10 w-[300px] h-[300px] bg-primary/5 rounded-full blur-[80px] pointer-events-none" />
|
| 74 |
|
| 75 |
<div className="max-w-md w-full relative z-10">
|
| 76 |
|
| 77 |
{/* Brand Header */}
|
| 78 |
+
<div className="flex items-center justify-center gap-2 mb-8">
|
| 79 |
<Map size={32} className="text-primary animate-pulse" />
|
| 80 |
<span className="text-2xl font-extrabold tracking-wider bg-clip-text text-transparent bg-gradient-to-r from-white via-slate-200 to-primary">
|
| 81 |
QuestboardAI
|
| 82 |
</span>
|
| 83 |
</div>
|
| 84 |
|
| 85 |
+
{/* Minimal Glass Card */}
|
| 86 |
+
<div className="bg-[#151B2C]/90 border border-slate-800 rounded-3xl p-8 shadow-2xl relative">
|
| 87 |
|
| 88 |
+
{loading && !success && (
|
| 89 |
+
<div className="flex flex-col items-center justify-center py-12 gap-5">
|
| 90 |
+
<Loader2 size={44} className="text-primary animate-spin" />
|
|
|
|
| 91 |
<p className="text-sm font-bold text-slate-400 animate-pulse">
|
| 92 |
+
Активация и подготовка холста...
|
| 93 |
</p>
|
| 94 |
</div>
|
| 95 |
+
)}
|
| 96 |
+
|
| 97 |
+
{success && (
|
| 98 |
+
<div className="flex flex-col items-center text-center gap-4 py-8">
|
| 99 |
+
<div className="w-12 h-12 bg-emerald-500/10 border border-emerald-500 rounded-full flex items-center justify-center text-emerald-500 animate-bounce">
|
| 100 |
+
<CheckCircle2 size={24} />
|
| 101 |
</div>
|
| 102 |
+
<h2 className="text-xl font-bold text-emerald-400 tracking-tight">
|
| 103 |
+
Успешно!
|
| 104 |
</h2>
|
| 105 |
+
<p className="text-sm text-slate-400 font-medium">
|
| 106 |
+
Перенаправление на ваш интерактивный холст...
|
| 107 |
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
</div>
|
| 109 |
+
)}
|
| 110 |
+
|
| 111 |
+
{error && (
|
| 112 |
<div className="flex flex-col items-center text-center gap-4 py-6">
|
| 113 |
+
<div className="w-12 h-12 bg-red-500/10 border border-red-500 rounded-full flex items-center justify-center text-red-500">
|
| 114 |
+
<ShieldAlert size={24} />
|
| 115 |
</div>
|
| 116 |
+
<h2 className="text-lg font-bold text-red-400 tracking-tight">
|
| 117 |
+
Ошибка активации
|
| 118 |
</h2>
|
| 119 |
<p className="text-sm text-slate-300 font-semibold leading-relaxed">
|
| 120 |
{error}
|
|
|
|
| 122 |
|
| 123 |
<Link
|
| 124 |
to="/dashboard"
|
| 125 |
+
className="w-full mt-6 py-3 text-xs font-bold uppercase tracking-wider text-white bg-primary hover:bg-primary/95 border border-primary rounded-xl transition-all shadow-md hover:translate-y-[-1px] active:translate-y-0 text-center"
|
| 126 |
>
|
| 127 |
+
Вернуться в панель управления
|
| 128 |
</Link>
|
| 129 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
)}
|
| 131 |
|
| 132 |
</div>
|