danylokhodus commited on
Commit
aa5f38f
·
1 Parent(s): 8b3a059

Feat: Add gamified ClaimPage and register public /claim route

Browse files
Files changed (2) hide show
  1. src/App.jsx +2 -0
  2. src/pages/ClaimPage.jsx +243 -0
src/App.jsx CHANGED
@@ -10,6 +10,7 @@ import CanvasPage from './pages/CanvasPage';
10
  import HabitTrackerPage from './pages/HabitTrackerPage';
11
  import SubscriptionPage from './pages/SubscriptionPage';
12
  import SettingsPage from './pages/SettingsPage';
 
13
 
14
  function App() {
15
  return (
@@ -19,6 +20,7 @@ function App() {
19
  <Route path="/" element={<Layout><LandingPage /></Layout>} />
20
  <Route path="/auth" element={<Layout><AuthPage /></Layout>} />
21
  <Route path="/onboarding" element={<Layout><OnboardingPage /></Layout>} />
 
22
 
23
  {/* Protected Dashboard Route with its own internal layout */}
24
  <Route path="/dashboard" element={<DashboardPage />} />
 
10
  import HabitTrackerPage from './pages/HabitTrackerPage';
11
  import SubscriptionPage from './pages/SubscriptionPage';
12
  import SettingsPage from './pages/SettingsPage';
13
+ import ClaimPage from './pages/ClaimPage';
14
 
15
  function App() {
16
  return (
 
20
  <Route path="/" element={<Layout><LandingPage /></Layout>} />
21
  <Route path="/auth" element={<Layout><AuthPage /></Layout>} />
22
  <Route path="/onboarding" element={<Layout><OnboardingPage /></Layout>} />
23
+ <Route path="/claim" element={<ClaimPage />} />
24
 
25
  {/* Protected Dashboard Route with its own internal layout */}
26
  <Route path="/dashboard" element={<DashboardPage />} />
src/pages/ClaimPage.jsx ADDED
@@ -0,0 +1,243 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 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');
35
+
36
+ if (!claimToken) {
37
+ setError('Токен приглашения отсутствует или недействителен.');
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 auth page with return path
69
+ navigate(`/auth?redirect=${encodeURIComponent(location.pathname + location.search)}`);
70
+ return;
71
+ }
72
+
73
+ setClaiming(true);
74
+ setError('');
75
+
76
+ try {
77
+ const response = await axios.post(`${API_URL}/agents/canvas/claim`, { token });
78
+ if (response.data.success) {
79
+ setSuccess(true);
80
+ // Playful redirection after 2.5 seconds
81
+ setTimeout(() => {
82
+ navigate(`/canvas/${response.data.graphId}`);
83
+ }, 2500);
84
+ }
85
+ } catch (err) {
86
+ console.error('Failed to claim canvas:', err);
87
+ setError(err.response?.data?.message || 'Не удалось забрать права на доску.');
88
+ } finally {
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/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" />
97
+ <div className="absolute bottom-10 right-10 w-[300px] h-[300px] bg-yellow-500/5 rounded-full blur-[80px] pointer-events-none" />
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 animate-fade-in">
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
+ {/* Dynamic Card Container */}
110
+ <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)]">
111
+
112
+ {loading ? (
113
+ /* Loading State */
114
+ <div className="flex flex-col items-center justify-center py-12 gap-4">
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
+ ) : success ? (
121
+ /* Success State */
122
+ <div className="flex flex-col items-center text-center gap-4 py-6">
123
+ <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">
124
+ <CheckCircle2 size={36} />
125
+ </div>
126
+ <h2 className="text-2xl font-black text-emerald-400 tracking-tight">
127
+ Квест Принят! ⚔️📜
128
+ </h2>
129
+ <p className="text-sm text-slate-300 font-medium max-w-xs">
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
+ ) : error ? (
140
+ /* Error / Claimed State */
141
+ <div className="flex flex-col items-center text-center gap-4 py-6">
142
+ <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">
143
+ <ShieldAlert size={36} />
144
+ </div>
145
+ <h2 className="text-xl font-black text-red-400 tracking-tight">
146
+ Свиток Недоступен
147
+ </h2>
148
+ <p className="text-sm text-slate-300 font-semibold leading-relaxed">
149
+ {error}
150
+ </p>
151
+
152
+ <Link
153
+ to="/dashboard"
154
+ 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"
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>
237
+
238
+ </div>
239
+ </div>
240
+ );
241
+ }
242
+
243
+ export default ClaimPage;