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 files1 unmodified line23456789101112131415567891011221224131427151617311819203 unmodified lines242526414243444546474849505152535455565758596061626327656628682930313233737475767778798081343536373839404142434445464748495051835253545556575859606162638586878889909164656667686970719697727374757677102787980818283841091108586871121131141158889909111792939412012112212312495969798991001011261271021031041291301051061071321331341351361371081391401091101111121421431131141151451461161171181191201 unmodified line1221231241541251261561271281291591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322331301311321 unmodified lineimport { useLocation, useNavigate, Link } from 'react-router-dom';import axios from 'axios';import { useAuth } from '../context/AuthContext';import { Scroll, ShieldAlert, CheckCircle2, Sparkles, Loader2, Sword, Lock, ArrowRight, Map} from 'lucide-react';import { Loader2, ShieldAlert, CheckCircle2, Map } from 'lucide-react';
function ClaimPage() { const location = useLocation(); const navigate = useNavigate(); const { user } = useAuth(); const [token, setToken] = useState(''); const [loading, setLoading] = useState(true); const [claiming, setClaiming] = useState(false); const [error, setError] = useState(''); const [success, setSuccess] = useState(false); const [graphInfo, setGraphInfo] = useState(null);
const API_URL = import.meta.env.VITE_API_URL;
// 1. Extract and verify token on load useEffect(() => { const params = new URLSearchParams(location.search); const claimToken = params.get('token');3 unmodified lines setLoading(false); return; } setToken(claimToken); // Check token status anonymously const checkToken = async () => { try { const response = await axios.post(`${API_URL}/agents/canvas/claim/check`, { token: claimToken }); if (response.data.success) { setGraphInfo(response.data); if (response.data.isClaimed) { setError('Этот свиток с планом уже был забран другим искателем приключений! 🍂'); } } } catch (err) { console.error('Failed to verify claim token:', err); setError(err.response?.data?.message || 'Свиток пуст, поврежден или срок его действия истек.'); } finally { setLoading(false); } }; checkToken(); }, [location, API_URL]);
// 2. Claim handler const handleClaim = async () => { if (!user) { // Redirect to auth page with return path // Redirect to authentication with current path as redirect return point navigate(`/auth?redirect=${encodeURIComponent(location.pathname + location.search)}`); return; }
setClaiming(true); setError(''); try { const response = await axios.post(`${API_URL}/agents/canvas/claim`, { token }); if (response.data.success) { setSuccess(true); // Playful redirection after 2.5 seconds setTimeout(() => { const performClaim = async () => { let decodedGraphId = ''; try { const decodedString = atob(claimToken); const parts = decodedString.split('|'); if (parts.length > 0) { decodedGraphId = parts[0]; } } catch (e) { console.error('Failed to parse token client-side:', e); }
try { const response = await axios.post(`${API_URL}/agents/canvas/claim`, { token: claimToken }); if (response.data.success) { setSuccess(true); // Redirect immediately to the claimed canvas navigate(`/canvas/${response.data.graphId}`); }, 2500); } } catch (err) { console.error('Failed to claim canvas:', err); if (decodedGraphId) { // If already claimed, redirect user straight to the canvas // If they have access, they see it; if not, they see the auth error navigate(`/canvas/${decodedGraphId}`); } else { setError(err.response?.data?.message || 'Не удалось активировать приглашение.'); setLoading(false); } } } catch (err) { console.error('Failed to claim canvas:', err); setError(err.response?.data?.message || 'Не удалось забрать права на доску.'); } finally { setClaiming(false); } }; };
performClaim(); }, [user, location, API_URL, navigate]);
return ( <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"> {/* Background Glows */} <div className="absolute top-1/4 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" /> <div className="absolute bottom-10 right-10 w-[300px] h-[300px] bg-yellow-500/5 rounded-full blur-[80px] pointer-events-none" /> <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" /> <div className="absolute bottom-10 right-10 w-[300px] h-[300px] bg-primary/5 rounded-full blur-[80px] pointer-events-none" />
<div className="max-w-md w-full relative z-10"> {/* Brand Header */} <div className="flex items-center justify-center gap-2 mb-8 animate-fade-in"> <div className="flex items-center justify-center gap-2 mb-8"> <Map size={32} className="text-primary animate-pulse" /> <span className="text-2xl font-extrabold tracking-wider bg-clip-text text-transparent bg-gradient-to-r from-white via-slate-200 to-primary"> QuestboardAI </span> </div>
{/* Dynamic Card Container */} <div className="bg-[#151B2C]/90 border-4 border-primary rounded-3xl p-8 shadow-[8px_8px_0px_0px_var(--color-primary)] relative transition-all hover:translate-x-[-2px] hover:translate-y-[-2px] hover:shadow-[10px_10px_0px_0px_var(--color-primary)]"> {/* Minimal Glass Card */} <div className="bg-[#151B2C]/90 border border-slate-800 rounded-3xl p-8 shadow-2xl relative"> {loading ? ( /* Loading State */ <div className="flex flex-col items-center justify-center py-12 gap-4"> <Loader2 size={48} className="text-primary animate-spin" /> {loading && !success && ( <div className="flex flex-col items-center justify-center py-12 gap-5"> <Loader2 size={44} className="text-primary animate-spin" /> <p className="text-sm font-bold text-slate-400 animate-pulse"> Расшифровка таинственного свитка... Активация и подготовка холста... </p> </div> ) : success ? ( /* Success State */ <div className="flex flex-col items-center text-center gap-4 py-6"> <div className="w-16 h-16 bg-emerald-500/10 border-2 border-emerald-500 rounded-full flex items-center justify-center text-emerald-500 animate-bounce"> <CheckCircle2 size={36} /> )}
{success && ( <div className="flex flex-col items-center text-center gap-4 py-8"> <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"> <CheckCircle2 size={24} /> </div> <h2 className="text-2xl font-black text-emerald-400 tracking-tight"> Квест Принят! ⚔️📜 <h2 className="text-xl font-bold text-emerald-400 tracking-tight"> Успешно! </h2> <p className="text-sm text-slate-300 font-medium max-w-xs"> Права на доску успешно перенесены на ваш аккаунт. Теперь этот план полностью принадлежит вам! <p className="text-sm text-slate-400 font-medium"> Перенаправление на ваш интерактивный холст... </p> <div className="w-full bg-slate-800/40 rounded-xl p-3 border border-slate-700/50 mt-2"> <p className="text-xs text-slate-400 font-bold uppercase tracking-widest mb-1">Загрузка холста</p> <div className="w-full bg-slate-700 h-1.5 rounded-full overflow-hidden"> <div className="bg-emerald-500 h-full w-full animate-[progress_2s_ease-in-out_infinite]" /> </div> </div> </div> ) : error ? ( /* Error / Claimed State */ )}
{error && ( <div className="flex flex-col items-center text-center gap-4 py-6"> <div className="w-16 h-16 bg-red-500/10 border-2 border-red-500 rounded-full flex items-center justify-center text-red-500"> <ShieldAlert size={36} /> <div className="w-12 h-12 bg-red-500/10 border border-red-500 rounded-full flex items-center justify-center text-red-500"> <ShieldAlert size={24} /> </div> <h2 className="text-xl font-black text-red-400 tracking-tight"> Свиток Недоступен <h2 className="text-lg font-bold text-red-400 tracking-tight"> Ошибка активации </h2> <p className="text-sm text-slate-300 font-semibold leading-relaxed"> {error}1 unmodified line <Link to="/dashboard" className="w-full mt-6 py-3.5 text-xs font-bold uppercase tracking-wider text-white bg-primary hover:bg-primary/95 border-2 border-primary rounded-xl transition-all shadow-[4px_4px_0px_0px_rgba(255,255,255,0.15)] hover:translate-y-[-1px] active:translate-y-0" 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" > Вернутьс�� в цитадель Вернуться в панель управления </Link> </div> ) : ( /* Active Unclaimed State */ <div className="flex flex-col gap-5"> {/* Floating Scroll Icon */} <div className="flex justify-center relative"> <div className="absolute inset-0 bg-yellow-500/20 rounded-full blur-xl animate-pulse" /> <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]"> <Scroll size={40} /> </div> </div>
{/* Title & Badge */} <div className="text-center"> <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"> <Sparkles size={12} /> Находка: ИИ-План </span> <h2 className="text-xl font-black tracking-tight mb-2"> Таинственный Свиток Квестов </h2> <p className="text-xs text-slate-400 font-bold max-w-xs mx-auto leading-relaxed"> Кто первый откроет этот свиток, тот привяжет интерактивный план проекта к своему аккаунту и станет его владельцем! </p> </div>
{/* Scroll Preview Box */} <div className="bg-[#0B0F19]/90 border-2 border-dashed border-slate-700/60 rounded-2xl p-5 mt-2"> <p className="text-[10px] font-black text-yellow-500 uppercase tracking-widest mb-1.5">Содержимое свитка:</p> <h3 className="text-sm font-black text-slate-200 mb-1 leading-snug"> {graphInfo?.title || 'Без названия'} </h3> <p className="text-xs text-slate-400 font-medium leading-relaxed line-clamp-3"> {graphInfo?.description || 'Описание отсутствует.'} </p> </div>
{/* Prompt logic */} <div className="mt-4"> {user ? ( /* User logged in - ready to claim */ <button onClick={handleClaim} disabled={claiming} 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)]" > {claiming ? ( <> <Loader2 size={16} className="animate-spin" /> Привязка квеста... </> ) : ( <> <Sword size={16} className="animate-bounce" /> Забрать права владельца ⚔️ </> )} </button> ) : ( /* User not logged in - needs to authorize */ <div className="space-y-3"> <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"> <Lock size={16} className="shrink-0" /> <span>Вам нужно войти в систему, чтобы сохранить доску себе.</span> </div> <button onClick={handleClaim} 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" > Авторизоваться и забрать <ArrowRight size={14} className="transition-transform group-hover:translate-x-1" /> </button> </div> )} </div>
</div> )}
</div>src/pages/ClaimPage.jsx+62-166