Spaces:
Running
Running
Commit ·
aa5f38f
1
Parent(s): 8b3a059
Feat: Add gamified ClaimPage and register public /claim route
Browse filesFiles changed (2)
- src/App.jsx+2
- src/pages/ClaimPage.jsxAdded+243
9 unmodified lines101112131415163 unmodified lines202122232425269 unmodified linesimport HabitTrackerPage from './pages/HabitTrackerPage';import SubscriptionPage from './pages/SubscriptionPage';import SettingsPage from './pages/SettingsPage';import ClaimPage from './pages/ClaimPage';
function App() { return (3 unmodified lines <Route path="/" element={<Layout><LandingPage /></Layout>} /> <Route path="/auth" element={<Layout><AuthPage /></Layout>} /> <Route path="/onboarding" element={<Layout><OnboardingPage /></Layout>} /> <Route path="/claim" element={<ClaimPage />} /> {/* Protected Dashboard Route with its own internal layout */} <Route path="/dashboard" element={<DashboardPage />} />123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243import React, { useState, useEffect } from 'react';import { 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';
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'); if (!claimToken) { setError('Токен приглашения отсутствует или недействителен.'); 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 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(() => { navigate(`/canvas/${response.data.graphId}`); }, 2500); } } catch (err) { console.error('Failed to claim canvas:', err); setError(err.response?.data?.message || 'Не удалось забрать права на доску.'); } finally { setClaiming(false); } };
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="max-w-md w-full relative z-10"> {/* Brand Header */} <div className="flex items-center justify-center gap-2 mb-8 animate-fade-in"> <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)]"> {loading ? ( /* Loading State */ <div className="flex flex-col items-center justify-center py-12 gap-4"> <Loader2 size={48} 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} /> </div> <h2 className="text-2xl font-black text-emerald-400 tracking-tight"> Квест Принят! ⚔️📜 </h2> <p className="text-sm text-slate-300 font-medium max-w-xs"> Права на доску успешно перенесены на ваш аккаунт. Теперь этот план полностью принадлежит вам! </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 */ <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> <h2 className="text-xl font-black text-red-400 tracking-tight"> Свиток Недоступен </h2> <p className="text-sm text-slate-300 font-semibold leading-relaxed"> {error} </p> <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" > Вернуться в цитадель </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>
</div> </div> );}
export default ClaimPage;src/App.jsx+2
src/pages/ClaimPage.jsxAdded+243