@stevederico/skateboard-ui 2.9.4 → 2.9.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/App.jsx +2 -1
- package/CHANGELOG.md +15 -0
- package/components/AuthOverlay.jsx +18 -217
- package/core/Utilities.js +32 -1
- package/package.json +1 -1
- package/views/SignInView.jsx +87 -65
- package/views/SignUpView.jsx +114 -92
package/App.jsx
CHANGED
|
@@ -159,15 +159,16 @@ export function createSkateboardApp({ constants, appRoutes, defaultRoute = appRo
|
|
|
159
159
|
<ThemeProvider attribute="class" defaultTheme="system" enableSystem>
|
|
160
160
|
<Toaster position="top-right" richColors closeButton />
|
|
161
161
|
<ContextProvider constants={constants}>
|
|
162
|
-
<AuthOverlay />
|
|
163
162
|
{Wrapper ? (
|
|
164
163
|
<Wrapper>
|
|
165
164
|
<Router>
|
|
165
|
+
<AuthOverlay />
|
|
166
166
|
<App constants={constants} appRoutes={appRoutes} defaultRoute={defaultRoute} landingPage={landingPage} overrides={overrides} />
|
|
167
167
|
</Router>
|
|
168
168
|
</Wrapper>
|
|
169
169
|
) : (
|
|
170
170
|
<Router>
|
|
171
|
+
<AuthOverlay />
|
|
171
172
|
<App constants={constants} appRoutes={appRoutes} defaultRoute={defaultRoute} landingPage={landingPage} overrides={overrides} />
|
|
172
173
|
</Router>
|
|
173
174
|
)}
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
2.9.7
|
|
4
|
+
|
|
5
|
+
Add useSafeNavigate hook
|
|
6
|
+
Fix Router context error in auth views
|
|
7
|
+
|
|
8
|
+
2.9.6
|
|
9
|
+
|
|
10
|
+
Move AuthOverlay inside Router
|
|
11
|
+
|
|
12
|
+
2.9.5
|
|
13
|
+
|
|
14
|
+
Reuse SignInView in AuthOverlay
|
|
15
|
+
Reuse SignUpView in AuthOverlay
|
|
16
|
+
Add embedded prop to views
|
|
17
|
+
|
|
3
18
|
2.9.4
|
|
4
19
|
|
|
5
20
|
Remove unused Card imports
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import React, { useState, useEffect
|
|
2
|
-
import { Dialog, DialogContent, DialogHeader, DialogTitle
|
|
3
|
-
import { Input } from '../shadcn/ui/input.jsx';
|
|
4
|
-
import { Label } from '../shadcn/ui/label.jsx';
|
|
5
|
-
import { Button } from '../shadcn/ui/button.jsx';
|
|
6
|
-
import { Alert, AlertDescription } from '../shadcn/ui/alert.jsx';
|
|
1
|
+
import React, { useState, useEffect } from 'react';
|
|
2
|
+
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '../shadcn/ui/dialog.jsx';
|
|
7
3
|
import DynamicIcon from '../core/DynamicIcon.jsx';
|
|
8
4
|
import { getState } from '../core/Context.jsx';
|
|
9
|
-
import
|
|
5
|
+
import SignInView from '../views/SignInView.jsx';
|
|
6
|
+
import SignUpView from '../views/SignUpView.jsx';
|
|
10
7
|
|
|
11
8
|
/**
|
|
12
9
|
* Modal authentication overlay with sign-in and sign-up forms.
|
|
@@ -29,109 +26,25 @@ export default function AuthOverlay() {
|
|
|
29
26
|
const { visible } = state.authOverlay;
|
|
30
27
|
|
|
31
28
|
const [mode, setMode] = useState('signin');
|
|
32
|
-
const [email, setEmail] = useState('');
|
|
33
|
-
const [password, setPassword] = useState('');
|
|
34
|
-
const [name, setName] = useState('');
|
|
35
|
-
const [errorMessage, setErrorMessage] = useState('');
|
|
36
|
-
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
37
|
-
const firstInputRef = useRef(null);
|
|
38
29
|
|
|
39
|
-
// Reset
|
|
30
|
+
// Reset mode when dialog opens
|
|
40
31
|
useEffect(() => {
|
|
41
32
|
if (visible) {
|
|
42
33
|
setMode('signin');
|
|
43
|
-
setEmail('');
|
|
44
|
-
setPassword('');
|
|
45
|
-
setName('');
|
|
46
|
-
setErrorMessage('');
|
|
47
|
-
setIsSubmitting(false);
|
|
48
34
|
}
|
|
49
35
|
}, [visible]);
|
|
50
36
|
|
|
51
|
-
// Focus first input when dialog opens or mode changes
|
|
52
|
-
useEffect(() => {
|
|
53
|
-
if (visible && firstInputRef.current) {
|
|
54
|
-
const t = setTimeout(() => firstInputRef.current?.focus(), 100);
|
|
55
|
-
return () => clearTimeout(t);
|
|
56
|
-
}
|
|
57
|
-
}, [visible, mode]);
|
|
58
|
-
|
|
59
37
|
function handleClose() {
|
|
60
38
|
dispatch({ type: 'HIDE_AUTH_OVERLAY' });
|
|
61
39
|
}
|
|
62
40
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (isSubmitting) return;
|
|
66
|
-
setIsSubmitting(true);
|
|
67
|
-
try {
|
|
68
|
-
const response = await fetch(`${getBackendURL()}/signin`, {
|
|
69
|
-
method: 'POST',
|
|
70
|
-
credentials: 'include',
|
|
71
|
-
headers: { 'Content-Type': 'application/json' },
|
|
72
|
-
body: JSON.stringify({ email, password })
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
if (response.ok) {
|
|
76
|
-
const data = await response.json();
|
|
77
|
-
dispatch({ type: 'SET_USER', payload: data });
|
|
78
|
-
dispatch({ type: 'AUTH_OVERLAY_SUCCESS' });
|
|
79
|
-
} else {
|
|
80
|
-
setErrorMessage('Invalid Credentials');
|
|
81
|
-
}
|
|
82
|
-
} catch (error) {
|
|
83
|
-
setErrorMessage('Server Error');
|
|
84
|
-
} finally {
|
|
85
|
-
setIsSubmitting(false);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
async function handleSignUp(e) {
|
|
90
|
-
e.preventDefault();
|
|
91
|
-
if (isSubmitting) return;
|
|
92
|
-
if (password.length < 6) {
|
|
93
|
-
setErrorMessage('Password must be at least 6 characters');
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
if (password.length > 72) {
|
|
97
|
-
setErrorMessage('Password must be 72 characters or less');
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
setIsSubmitting(true);
|
|
101
|
-
try {
|
|
102
|
-
const response = await fetch(`${getBackendURL()}/signup`, {
|
|
103
|
-
method: 'POST',
|
|
104
|
-
credentials: 'include',
|
|
105
|
-
headers: { 'Content-Type': 'application/json' },
|
|
106
|
-
body: JSON.stringify({ email, password, name })
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
if (response.ok) {
|
|
110
|
-
const data = await response.json();
|
|
111
|
-
// Save CSRF token
|
|
112
|
-
const csrfCookie = document.cookie.split('; ').find(row => row.startsWith('csrf_token='));
|
|
113
|
-
const csrfToken = csrfCookie ? csrfCookie.split('=')[1] : data.csrfToken;
|
|
114
|
-
if (csrfToken) {
|
|
115
|
-
const appName = constants.appName || 'skateboard';
|
|
116
|
-
const csrfKey = `${appName.toLowerCase().replace(/\s+/g, '-')}_csrf`;
|
|
117
|
-
localStorage.setItem(csrfKey, csrfToken);
|
|
118
|
-
}
|
|
119
|
-
dispatch({ type: 'SET_USER', payload: data });
|
|
120
|
-
dispatch({ type: 'AUTH_OVERLAY_SUCCESS' });
|
|
121
|
-
} else {
|
|
122
|
-
setErrorMessage('Invalid Credentials');
|
|
123
|
-
}
|
|
124
|
-
} catch (error) {
|
|
125
|
-
setErrorMessage('Server Error');
|
|
126
|
-
} finally {
|
|
127
|
-
setIsSubmitting(false);
|
|
128
|
-
}
|
|
41
|
+
function handleSuccess() {
|
|
42
|
+
dispatch({ type: 'AUTH_OVERLAY_SUCCESS' });
|
|
129
43
|
}
|
|
130
44
|
|
|
131
45
|
return (
|
|
132
46
|
<Dialog open={visible} onOpenChange={(open) => { if (!open) handleClose(); }}>
|
|
133
47
|
<DialogContent>
|
|
134
|
-
{/* Branding */}
|
|
135
48
|
<DialogHeader className="items-center text-center">
|
|
136
49
|
<div className="flex items-center justify-center gap-3">
|
|
137
50
|
<div className="bg-app rounded-2xl flex aspect-square size-10 items-center justify-center">
|
|
@@ -139,133 +52,21 @@ export default function AuthOverlay() {
|
|
|
139
52
|
</div>
|
|
140
53
|
<span className="text-2xl font-bold">{constants.appName}</span>
|
|
141
54
|
</div>
|
|
142
|
-
<DialogTitle>{mode === 'signin' ? '
|
|
143
|
-
<DialogDescription>
|
|
144
|
-
{mode === 'signin' ? 'Sign in to your account' : 'Enter your details to get started'}
|
|
145
|
-
</DialogDescription>
|
|
55
|
+
<DialogTitle className="sr-only">{mode === 'signin' ? 'Sign In' : 'Sign Up'}</DialogTitle>
|
|
146
56
|
</DialogHeader>
|
|
147
57
|
|
|
148
|
-
{errorMessage && (
|
|
149
|
-
<Alert variant="destructive">
|
|
150
|
-
<AlertDescription className="text-center">{errorMessage}</AlertDescription>
|
|
151
|
-
</Alert>
|
|
152
|
-
)}
|
|
153
|
-
|
|
154
58
|
{mode === 'signin' ? (
|
|
155
|
-
<
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
id="overlay-email"
|
|
161
|
-
type="email"
|
|
162
|
-
placeholder="john@example.com"
|
|
163
|
-
required
|
|
164
|
-
value={email}
|
|
165
|
-
onChange={(e) => { setEmail(e.target.value); setErrorMessage(''); }}
|
|
166
|
-
/>
|
|
167
|
-
</div>
|
|
168
|
-
<div className="flex flex-col gap-2">
|
|
169
|
-
<Label htmlFor="overlay-password">Password</Label>
|
|
170
|
-
<Input
|
|
171
|
-
id="overlay-password"
|
|
172
|
-
type="password"
|
|
173
|
-
placeholder="••••••••"
|
|
174
|
-
required
|
|
175
|
-
value={password}
|
|
176
|
-
onChange={(e) => setPassword(e.target.value)}
|
|
177
|
-
/>
|
|
178
|
-
</div>
|
|
179
|
-
<Button
|
|
180
|
-
type="submit"
|
|
181
|
-
variant="gradient"
|
|
182
|
-
size="cta"
|
|
183
|
-
className="w-full"
|
|
184
|
-
disabled={isSubmitting}
|
|
185
|
-
>
|
|
186
|
-
<span className="relative z-20 flex items-center justify-center gap-2 drop-shadow-sm">
|
|
187
|
-
<DynamicIcon name="sparkles" size={16} color="currentColor" strokeWidth={2} className="animate-pulse" />
|
|
188
|
-
{isSubmitting ? 'Signing in...' : 'Sign In'}
|
|
189
|
-
</span>
|
|
190
|
-
</Button>
|
|
191
|
-
<div className="text-center text-sm">
|
|
192
|
-
<span className="text-muted-foreground">Don't have an account?</span>{' '}
|
|
193
|
-
<Button
|
|
194
|
-
variant="link"
|
|
195
|
-
className="p-0 h-auto"
|
|
196
|
-
onClick={() => { setMode('signup'); setErrorMessage(''); }}
|
|
197
|
-
>
|
|
198
|
-
Sign Up
|
|
199
|
-
</Button>
|
|
200
|
-
</div>
|
|
201
|
-
</form>
|
|
59
|
+
<SignInView
|
|
60
|
+
embedded
|
|
61
|
+
onSuccess={handleSuccess}
|
|
62
|
+
onSwitchMode={() => setMode('signup')}
|
|
63
|
+
/>
|
|
202
64
|
) : (
|
|
203
|
-
<
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
id="overlay-name"
|
|
209
|
-
placeholder="John Doe"
|
|
210
|
-
required
|
|
211
|
-
value={name}
|
|
212
|
-
onChange={(e) => { setName(e.target.value); setErrorMessage(''); }}
|
|
213
|
-
/>
|
|
214
|
-
</div>
|
|
215
|
-
<div className="flex flex-col gap-2">
|
|
216
|
-
<Label htmlFor="overlay-signup-email">Email</Label>
|
|
217
|
-
<Input
|
|
218
|
-
id="overlay-signup-email"
|
|
219
|
-
type="email"
|
|
220
|
-
placeholder="john@example.com"
|
|
221
|
-
required
|
|
222
|
-
value={email}
|
|
223
|
-
onChange={(e) => { setEmail(e.target.value); setErrorMessage(''); }}
|
|
224
|
-
/>
|
|
225
|
-
</div>
|
|
226
|
-
<div className="flex flex-col gap-2">
|
|
227
|
-
<Label htmlFor="overlay-signup-password">Password</Label>
|
|
228
|
-
<Input
|
|
229
|
-
id="overlay-signup-password"
|
|
230
|
-
type="password"
|
|
231
|
-
placeholder="••••••••"
|
|
232
|
-
required
|
|
233
|
-
minLength={6}
|
|
234
|
-
maxLength={72}
|
|
235
|
-
value={password}
|
|
236
|
-
onChange={(e) => { setPassword(e.target.value); setErrorMessage(''); }}
|
|
237
|
-
/>
|
|
238
|
-
<p className="text-xs text-muted-foreground">Minimum 6 characters</p>
|
|
239
|
-
</div>
|
|
240
|
-
<Button
|
|
241
|
-
type="submit"
|
|
242
|
-
variant="gradient"
|
|
243
|
-
size="cta"
|
|
244
|
-
className="w-full"
|
|
245
|
-
disabled={isSubmitting}
|
|
246
|
-
>
|
|
247
|
-
<span className="relative z-20 flex items-center justify-center gap-2 drop-shadow-sm">
|
|
248
|
-
<DynamicIcon name="sparkles" size={16} color="currentColor" strokeWidth={2} className="animate-pulse" />
|
|
249
|
-
{isSubmitting ? 'Signing up...' : 'Sign Up'}
|
|
250
|
-
</span>
|
|
251
|
-
</Button>
|
|
252
|
-
<div className="text-center text-sm">
|
|
253
|
-
<span className="text-muted-foreground">Already have an account?</span>{' '}
|
|
254
|
-
<Button
|
|
255
|
-
variant="link"
|
|
256
|
-
className="p-0 h-auto"
|
|
257
|
-
onClick={() => { setMode('signin'); setErrorMessage(''); }}
|
|
258
|
-
>
|
|
259
|
-
Sign In
|
|
260
|
-
</Button>
|
|
261
|
-
</div>
|
|
262
|
-
<div className="text-center text-xs text-muted-foreground">
|
|
263
|
-
By registering you agree to our{" "}
|
|
264
|
-
<a href="/terms" target="_blank" rel="noopener noreferrer" className="underline underline-offset-4 hover:text-foreground">Terms of Service</a>,{" "}
|
|
265
|
-
<a href="/eula" target="_blank" rel="noopener noreferrer" className="underline underline-offset-4 hover:text-foreground">EULA</a>,{" "}
|
|
266
|
-
<a href="/privacy" target="_blank" rel="noopener noreferrer" className="underline underline-offset-4 hover:text-foreground">Privacy Policy</a>
|
|
267
|
-
</div>
|
|
268
|
-
</form>
|
|
65
|
+
<SignUpView
|
|
66
|
+
embedded
|
|
67
|
+
onSuccess={handleSuccess}
|
|
68
|
+
onSwitchMode={() => setMode('signin')}
|
|
69
|
+
/>
|
|
269
70
|
)}
|
|
270
71
|
</DialogContent>
|
|
271
72
|
</Dialog>
|
package/core/Utilities.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
1
|
+
import { useEffect, useState, useContext } from 'react';
|
|
2
|
+
import { UNSAFE_NavigationContext } from 'react-router-dom';
|
|
2
3
|
import { getDispatch } from './Context.jsx';
|
|
3
4
|
|
|
4
5
|
// Constants will be initialized by the app shell
|
|
@@ -985,3 +986,33 @@ export function setUIVisibility({ sidebar, tabBar }) {
|
|
|
985
986
|
console.warn('setUIVisibility: Context not initialized');
|
|
986
987
|
}
|
|
987
988
|
}
|
|
989
|
+
|
|
990
|
+
/**
|
|
991
|
+
* Safe navigation hook that works with or without Router context.
|
|
992
|
+
*
|
|
993
|
+
* Uses UNSAFE_NavigationContext directly instead of useNavigate() to avoid
|
|
994
|
+
* throwing when rendered outside Router (e.g., in Portals or module duplication).
|
|
995
|
+
* Falls back to window.location.href if no Router context is available.
|
|
996
|
+
*
|
|
997
|
+
* @returns {function} Navigate function (path, options?) => void
|
|
998
|
+
*
|
|
999
|
+
* @example
|
|
1000
|
+
* const navigate = useSafeNavigate();
|
|
1001
|
+
* navigate('/app');
|
|
1002
|
+
* navigate('/app', { replace: true });
|
|
1003
|
+
*/
|
|
1004
|
+
export function useSafeNavigate() {
|
|
1005
|
+
const ctx = useContext(UNSAFE_NavigationContext);
|
|
1006
|
+
|
|
1007
|
+
if (!ctx) {
|
|
1008
|
+
return (path) => { window.location.href = path; };
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
return (path, options = {}) => {
|
|
1012
|
+
if (options.replace) {
|
|
1013
|
+
ctx.navigator.replace(path, options.state);
|
|
1014
|
+
} else {
|
|
1015
|
+
ctx.navigator.push(path, options.state);
|
|
1016
|
+
}
|
|
1017
|
+
};
|
|
1018
|
+
}
|
package/package.json
CHANGED
package/views/SignInView.jsx
CHANGED
|
@@ -6,27 +6,35 @@ import { Label } from "../shadcn/ui/label"
|
|
|
6
6
|
import { Card, CardContent, CardHeader } from "../shadcn/ui/card"
|
|
7
7
|
import { Alert, AlertDescription } from "../shadcn/ui/alert"
|
|
8
8
|
import DynamicIcon from '../core/DynamicIcon';
|
|
9
|
-
import { useNavigate } from 'react-router-dom';
|
|
10
9
|
import { getState } from "../core/Context.jsx";
|
|
11
|
-
import { getBackendURL } from '../core/Utilities'
|
|
10
|
+
import { getBackendURL, useSafeNavigate } from '../core/Utilities'
|
|
12
11
|
|
|
13
12
|
/**
|
|
14
|
-
*
|
|
13
|
+
* Sign-in form component.
|
|
15
14
|
*
|
|
16
|
-
* Authenticates via POST to /signin, dispatches SET_USER on success
|
|
17
|
-
*
|
|
15
|
+
* Authenticates via POST to /signin, dispatches SET_USER on success.
|
|
16
|
+
* In full-page mode, navigates to /app. In embedded mode, calls onSuccess.
|
|
18
17
|
*
|
|
19
18
|
* @param {Object} props
|
|
20
19
|
* @param {string} [props.className] - Additional CSS classes
|
|
21
|
-
* @
|
|
20
|
+
* @param {boolean} [props.embedded=false] - Render without page wrapper (for dialogs)
|
|
21
|
+
* @param {function} [props.onSuccess] - Called after successful sign-in (embedded mode)
|
|
22
|
+
* @param {function} [props.onSwitchMode] - Called when user clicks "Sign Up" (embedded mode)
|
|
23
|
+
* @returns {JSX.Element} Sign-in form
|
|
22
24
|
*
|
|
23
25
|
* @example
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
+
* // Full page
|
|
26
27
|
* <Route path="/signin" element={<SignInView />} />
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* // Embedded in dialog
|
|
31
|
+
* <SignInView embedded onSuccess={handleSuccess} onSwitchMode={() => setMode('signup')} />
|
|
27
32
|
*/
|
|
28
33
|
export default function LoginForm({
|
|
29
34
|
className,
|
|
35
|
+
embedded = false,
|
|
36
|
+
onSuccess,
|
|
37
|
+
onSwitchMode,
|
|
30
38
|
...props
|
|
31
39
|
}) {
|
|
32
40
|
const { state, dispatch } = getState();
|
|
@@ -34,7 +42,7 @@ export default function LoginForm({
|
|
|
34
42
|
const [email, setEmail] = useState('');
|
|
35
43
|
const [password, setPassword] = useState('');
|
|
36
44
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
37
|
-
const navigate =
|
|
45
|
+
const navigate = useSafeNavigate();
|
|
38
46
|
const emailInputRef = useRef(null);
|
|
39
47
|
|
|
40
48
|
const [errorMessage, setErrorMessage] = useState('')
|
|
@@ -62,7 +70,11 @@ export default function LoginForm({
|
|
|
62
70
|
if (response.ok) {
|
|
63
71
|
const data = await response.json();
|
|
64
72
|
dispatch({ type: 'SET_USER', payload: data });
|
|
65
|
-
|
|
73
|
+
if (embedded && onSuccess) {
|
|
74
|
+
onSuccess();
|
|
75
|
+
} else {
|
|
76
|
+
navigate('/app');
|
|
77
|
+
}
|
|
66
78
|
} else {
|
|
67
79
|
setErrorMessage('Invalid Credentials');
|
|
68
80
|
}
|
|
@@ -73,6 +85,70 @@ export default function LoginForm({
|
|
|
73
85
|
}
|
|
74
86
|
}
|
|
75
87
|
|
|
88
|
+
const formContent = (
|
|
89
|
+
<>
|
|
90
|
+
{errorMessage && (
|
|
91
|
+
<Alert variant="destructive" className="mb-4">
|
|
92
|
+
<AlertDescription className="text-center">{errorMessage}</AlertDescription>
|
|
93
|
+
</Alert>
|
|
94
|
+
)}
|
|
95
|
+
|
|
96
|
+
<form onSubmit={signInClicked} className="flex flex-col gap-4">
|
|
97
|
+
<div className="flex flex-col gap-2">
|
|
98
|
+
<Label htmlFor="email">Email</Label>
|
|
99
|
+
<Input
|
|
100
|
+
ref={emailInputRef}
|
|
101
|
+
id="email"
|
|
102
|
+
type="email"
|
|
103
|
+
placeholder="john@example.com"
|
|
104
|
+
required
|
|
105
|
+
value={email}
|
|
106
|
+
onChange={(e) => {
|
|
107
|
+
setEmail(e.target.value);
|
|
108
|
+
setErrorMessage('');
|
|
109
|
+
}}
|
|
110
|
+
/>
|
|
111
|
+
</div>
|
|
112
|
+
|
|
113
|
+
<div className="flex flex-col gap-2">
|
|
114
|
+
<Label htmlFor="password">Password</Label>
|
|
115
|
+
<Input
|
|
116
|
+
id="password"
|
|
117
|
+
type="password"
|
|
118
|
+
placeholder="••••••••"
|
|
119
|
+
required
|
|
120
|
+
value={password}
|
|
121
|
+
onChange={(e) => setPassword(e.target.value)}
|
|
122
|
+
/>
|
|
123
|
+
</div>
|
|
124
|
+
|
|
125
|
+
<Button
|
|
126
|
+
type="submit"
|
|
127
|
+
variant="gradient"
|
|
128
|
+
size="cta"
|
|
129
|
+
className="w-full"
|
|
130
|
+
disabled={isSubmitting}
|
|
131
|
+
>
|
|
132
|
+
<span className="relative z-20 flex items-center justify-center gap-2 drop-shadow-sm">
|
|
133
|
+
<DynamicIcon name="sparkles" size={16} color="currentColor" strokeWidth={2} className="animate-pulse" />
|
|
134
|
+
{isSubmitting ? "Signing in..." : "Sign In"}
|
|
135
|
+
</span>
|
|
136
|
+
</Button>
|
|
137
|
+
|
|
138
|
+
<div className="text-center text-sm">
|
|
139
|
+
<span className="text-muted-foreground">Don't have an account?</span>{" "}
|
|
140
|
+
<Button variant="link" className="p-0 h-auto" onClick={() => embedded && onSwitchMode ? onSwitchMode() : navigate('/signup')}>
|
|
141
|
+
Sign Up
|
|
142
|
+
</Button>
|
|
143
|
+
</div>
|
|
144
|
+
</form>
|
|
145
|
+
</>
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
if (embedded) {
|
|
149
|
+
return formContent;
|
|
150
|
+
}
|
|
151
|
+
|
|
76
152
|
return (
|
|
77
153
|
<div className="fixed inset-0 bg-background overflow-auto">
|
|
78
154
|
<div className={cn("flex flex-col items-center justify-center min-h-screen p-4", className)} {...props}>
|
|
@@ -86,61 +162,7 @@ export default function LoginForm({
|
|
|
86
162
|
</div>
|
|
87
163
|
</CardHeader>
|
|
88
164
|
<CardContent>
|
|
89
|
-
{
|
|
90
|
-
<Alert variant="destructive" className="mb-4">
|
|
91
|
-
<AlertDescription className="text-center">{errorMessage}</AlertDescription>
|
|
92
|
-
</Alert>
|
|
93
|
-
)}
|
|
94
|
-
|
|
95
|
-
<form onSubmit={signInClicked} className="flex flex-col gap-4">
|
|
96
|
-
<div className="flex flex-col gap-2">
|
|
97
|
-
<Label htmlFor="email">Email</Label>
|
|
98
|
-
<Input
|
|
99
|
-
ref={emailInputRef}
|
|
100
|
-
id="email"
|
|
101
|
-
type="email"
|
|
102
|
-
placeholder="john@example.com"
|
|
103
|
-
required
|
|
104
|
-
value={email}
|
|
105
|
-
onChange={(e) => {
|
|
106
|
-
setEmail(e.target.value);
|
|
107
|
-
setErrorMessage('');
|
|
108
|
-
}}
|
|
109
|
-
/>
|
|
110
|
-
</div>
|
|
111
|
-
|
|
112
|
-
<div className="flex flex-col gap-2">
|
|
113
|
-
<Label htmlFor="password">Password</Label>
|
|
114
|
-
<Input
|
|
115
|
-
id="password"
|
|
116
|
-
type="password"
|
|
117
|
-
placeholder="••••••••"
|
|
118
|
-
required
|
|
119
|
-
value={password}
|
|
120
|
-
onChange={(e) => setPassword(e.target.value)}
|
|
121
|
-
/>
|
|
122
|
-
</div>
|
|
123
|
-
|
|
124
|
-
<Button
|
|
125
|
-
type="submit"
|
|
126
|
-
variant="gradient"
|
|
127
|
-
size="cta"
|
|
128
|
-
className="w-full"
|
|
129
|
-
disabled={isSubmitting}
|
|
130
|
-
>
|
|
131
|
-
<span className="relative z-20 flex items-center justify-center gap-2 drop-shadow-sm">
|
|
132
|
-
<DynamicIcon name="sparkles" size={16} color="currentColor" strokeWidth={2} className="animate-pulse" />
|
|
133
|
-
{isSubmitting ? "Signing in..." : "Sign In"}
|
|
134
|
-
</span>
|
|
135
|
-
</Button>
|
|
136
|
-
|
|
137
|
-
<div className="text-center text-sm">
|
|
138
|
-
<span className="text-muted-foreground">Don't have an account?</span>{" "}
|
|
139
|
-
<Button variant="link" className="p-0 h-auto" onClick={() => navigate('/signup')}>
|
|
140
|
-
Sign Up
|
|
141
|
-
</Button>
|
|
142
|
-
</div>
|
|
143
|
-
</form>
|
|
165
|
+
{formContent}
|
|
144
166
|
</CardContent>
|
|
145
167
|
</Card>
|
|
146
168
|
</div>
|
package/views/SignUpView.jsx
CHANGED
|
@@ -6,28 +6,36 @@ import { Label } from "../shadcn/ui/label"
|
|
|
6
6
|
import { Card, CardContent, CardHeader } from "../shadcn/ui/card"
|
|
7
7
|
import { Alert, AlertDescription } from "../shadcn/ui/alert"
|
|
8
8
|
import DynamicIcon from '../core/DynamicIcon';
|
|
9
|
-
import { useNavigate } from 'react-router-dom';
|
|
10
9
|
import { getState } from "../core/Context.jsx";
|
|
11
|
-
import { getBackendURL } from '../core/Utilities'
|
|
10
|
+
import { getBackendURL, useSafeNavigate } from '../core/Utilities'
|
|
12
11
|
|
|
13
12
|
/**
|
|
14
|
-
*
|
|
13
|
+
* Sign-up form component.
|
|
15
14
|
*
|
|
16
15
|
* Creates account via POST to /signup with name, email, and password.
|
|
17
|
-
* Validates password length (6-72 chars), dispatches SET_USER on success
|
|
18
|
-
*
|
|
16
|
+
* Validates password length (6-72 chars), dispatches SET_USER on success.
|
|
17
|
+
* In full-page mode, navigates to /app. In embedded mode, calls onSuccess.
|
|
19
18
|
*
|
|
20
19
|
* @param {Object} props
|
|
21
20
|
* @param {string} [props.className] - Additional CSS classes
|
|
22
|
-
* @
|
|
21
|
+
* @param {boolean} [props.embedded=false] - Render without page wrapper (for dialogs)
|
|
22
|
+
* @param {function} [props.onSuccess] - Called after successful sign-up (embedded mode)
|
|
23
|
+
* @param {function} [props.onSwitchMode] - Called when user clicks "Sign In" (embedded mode)
|
|
24
|
+
* @returns {JSX.Element} Sign-up form
|
|
23
25
|
*
|
|
24
26
|
* @example
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
+
* // Full page
|
|
27
28
|
* <Route path="/signup" element={<SignUpView />} />
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* // Embedded in dialog
|
|
32
|
+
* <SignUpView embedded onSuccess={handleSuccess} onSwitchMode={() => setMode('signin')} />
|
|
28
33
|
*/
|
|
29
34
|
export default function LoginForm({
|
|
30
35
|
className,
|
|
36
|
+
embedded = false,
|
|
37
|
+
onSuccess,
|
|
38
|
+
onSwitchMode,
|
|
31
39
|
...props
|
|
32
40
|
}) {
|
|
33
41
|
const { state, dispatch } = getState();
|
|
@@ -35,8 +43,8 @@ export default function LoginForm({
|
|
|
35
43
|
const [email, setEmail] = useState('');
|
|
36
44
|
const [password, setPassword] = useState('');
|
|
37
45
|
const [name, setName] = useState('');
|
|
38
|
-
const
|
|
39
|
-
const
|
|
46
|
+
const [errorMessage, setErrorMessage] = useState('');
|
|
47
|
+
const navigate = useSafeNavigate();
|
|
40
48
|
const nameInputRef = useRef(null);
|
|
41
49
|
|
|
42
50
|
// Focus the first input on mount
|
|
@@ -76,7 +84,11 @@ export default function LoginForm({
|
|
|
76
84
|
localStorage.setItem(csrfKey, csrfToken);
|
|
77
85
|
}
|
|
78
86
|
dispatch({ type: 'SET_USER', payload: data });
|
|
79
|
-
|
|
87
|
+
if (embedded && onSuccess) {
|
|
88
|
+
onSuccess();
|
|
89
|
+
} else {
|
|
90
|
+
navigate('/app');
|
|
91
|
+
}
|
|
80
92
|
} else {
|
|
81
93
|
setErrorMessage('Invalid Credentials')
|
|
82
94
|
}
|
|
@@ -86,6 +98,96 @@ export default function LoginForm({
|
|
|
86
98
|
}
|
|
87
99
|
}
|
|
88
100
|
|
|
101
|
+
const formContent = (
|
|
102
|
+
<>
|
|
103
|
+
{errorMessage !== '' && (
|
|
104
|
+
<Alert variant="destructive" className="mb-4">
|
|
105
|
+
<AlertDescription className="text-center">{errorMessage}</AlertDescription>
|
|
106
|
+
</Alert>
|
|
107
|
+
)}
|
|
108
|
+
|
|
109
|
+
<form onSubmit={signUpClicked} className="flex flex-col gap-4">
|
|
110
|
+
<div className="flex flex-col gap-2">
|
|
111
|
+
<Label htmlFor="name">Name</Label>
|
|
112
|
+
<Input
|
|
113
|
+
ref={nameInputRef}
|
|
114
|
+
id="name"
|
|
115
|
+
placeholder="John Doe"
|
|
116
|
+
required
|
|
117
|
+
value={name}
|
|
118
|
+
onChange={(e) => {
|
|
119
|
+
setName(e.target.value);
|
|
120
|
+
setErrorMessage('');
|
|
121
|
+
}}
|
|
122
|
+
/>
|
|
123
|
+
</div>
|
|
124
|
+
|
|
125
|
+
<div className="flex flex-col gap-2">
|
|
126
|
+
<Label htmlFor="email">Email</Label>
|
|
127
|
+
<Input
|
|
128
|
+
id="email"
|
|
129
|
+
type="email"
|
|
130
|
+
placeholder="john@example.com"
|
|
131
|
+
required
|
|
132
|
+
value={email}
|
|
133
|
+
onChange={(e) => {
|
|
134
|
+
setEmail(e.target.value);
|
|
135
|
+
setErrorMessage('');
|
|
136
|
+
}}
|
|
137
|
+
/>
|
|
138
|
+
</div>
|
|
139
|
+
|
|
140
|
+
<div className="flex flex-col gap-2">
|
|
141
|
+
<Label htmlFor="password">Password</Label>
|
|
142
|
+
<Input
|
|
143
|
+
id="password"
|
|
144
|
+
type="password"
|
|
145
|
+
placeholder="••••••••"
|
|
146
|
+
required
|
|
147
|
+
minLength={6}
|
|
148
|
+
maxLength={72}
|
|
149
|
+
value={password}
|
|
150
|
+
onChange={(e) => {
|
|
151
|
+
setPassword(e.target.value);
|
|
152
|
+
setErrorMessage('');
|
|
153
|
+
}}
|
|
154
|
+
/>
|
|
155
|
+
<p className="text-xs text-muted-foreground">Minimum 6 characters</p>
|
|
156
|
+
</div>
|
|
157
|
+
|
|
158
|
+
<Button
|
|
159
|
+
type="submit"
|
|
160
|
+
variant="gradient"
|
|
161
|
+
size="cta"
|
|
162
|
+
className="w-full"
|
|
163
|
+
>
|
|
164
|
+
<span className="relative z-20 flex items-center justify-center gap-2 drop-shadow-sm">
|
|
165
|
+
<DynamicIcon name="sparkles" size={16} color="currentColor" strokeWidth={2} className="animate-pulse" />
|
|
166
|
+
Sign Up
|
|
167
|
+
</span>
|
|
168
|
+
</Button>
|
|
169
|
+
|
|
170
|
+
<div className="text-center text-sm">
|
|
171
|
+
<span className="text-muted-foreground">Already have an account?</span>{" "}
|
|
172
|
+
<Button variant="link" className="p-0 h-auto" onClick={(e) => { e.preventDefault(); embedded && onSwitchMode ? onSwitchMode() : navigate('/signin'); }}>
|
|
173
|
+
Sign In
|
|
174
|
+
</Button>
|
|
175
|
+
</div>
|
|
176
|
+
</form>
|
|
177
|
+
|
|
178
|
+
<div className="mt-4 text-center text-xs text-muted-foreground">
|
|
179
|
+
By registering you agree to our{" "}
|
|
180
|
+
<a href="/terms" className="underline underline-offset-4 hover:text-foreground">Terms of Service</a>,{" "}
|
|
181
|
+
<a href="/eula" className="underline underline-offset-4 hover:text-foreground">EULA</a>,{" "}
|
|
182
|
+
<a href="/privacy" className="underline underline-offset-4 hover:text-foreground">Privacy Policy</a>
|
|
183
|
+
</div>
|
|
184
|
+
</>
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
if (embedded) {
|
|
188
|
+
return formContent;
|
|
189
|
+
}
|
|
190
|
+
|
|
89
191
|
return (
|
|
90
192
|
<div className="fixed inset-0 bg-background overflow-auto">
|
|
91
193
|
<div className={cn("flex flex-col items-center justify-center min-h-screen p-4", className)} {...props}>
|
|
@@ -99,87 +201,7 @@ export default function LoginForm({
|
|
|
99
201
|
</div>
|
|
100
202
|
</CardHeader>
|
|
101
203
|
<CardContent>
|
|
102
|
-
{
|
|
103
|
-
<Alert variant="destructive" className="mb-4">
|
|
104
|
-
<AlertDescription className="text-center">{errorMessage}</AlertDescription>
|
|
105
|
-
</Alert>
|
|
106
|
-
)}
|
|
107
|
-
|
|
108
|
-
<form onSubmit={signUpClicked} className="flex flex-col gap-4">
|
|
109
|
-
<div className="flex flex-col gap-2">
|
|
110
|
-
<Label htmlFor="name">Name</Label>
|
|
111
|
-
<Input
|
|
112
|
-
ref={nameInputRef}
|
|
113
|
-
id="name"
|
|
114
|
-
placeholder="John Doe"
|
|
115
|
-
required
|
|
116
|
-
value={name}
|
|
117
|
-
onChange={(e) => {
|
|
118
|
-
setName(e.target.value);
|
|
119
|
-
setErrorMessage('');
|
|
120
|
-
}}
|
|
121
|
-
/>
|
|
122
|
-
</div>
|
|
123
|
-
|
|
124
|
-
<div className="flex flex-col gap-2">
|
|
125
|
-
<Label htmlFor="email">Email</Label>
|
|
126
|
-
<Input
|
|
127
|
-
id="email"
|
|
128
|
-
type="email"
|
|
129
|
-
placeholder="john@example.com"
|
|
130
|
-
required
|
|
131
|
-
value={email}
|
|
132
|
-
onChange={(e) => {
|
|
133
|
-
setEmail(e.target.value);
|
|
134
|
-
setErrorMessage('');
|
|
135
|
-
}}
|
|
136
|
-
/>
|
|
137
|
-
</div>
|
|
138
|
-
|
|
139
|
-
<div className="flex flex-col gap-2">
|
|
140
|
-
<Label htmlFor="password">Password</Label>
|
|
141
|
-
<Input
|
|
142
|
-
id="password"
|
|
143
|
-
type="password"
|
|
144
|
-
placeholder="••••••••"
|
|
145
|
-
required
|
|
146
|
-
minLength={6}
|
|
147
|
-
maxLength={72}
|
|
148
|
-
value={password}
|
|
149
|
-
onChange={(e) => {
|
|
150
|
-
setPassword(e.target.value);
|
|
151
|
-
setErrorMessage('');
|
|
152
|
-
}}
|
|
153
|
-
/>
|
|
154
|
-
<p className="text-xs text-muted-foreground">Minimum 6 characters</p>
|
|
155
|
-
</div>
|
|
156
|
-
|
|
157
|
-
<Button
|
|
158
|
-
type="submit"
|
|
159
|
-
variant="gradient"
|
|
160
|
-
size="cta"
|
|
161
|
-
className="w-full"
|
|
162
|
-
>
|
|
163
|
-
<span className="relative z-20 flex items-center justify-center gap-2 drop-shadow-sm">
|
|
164
|
-
<DynamicIcon name="sparkles" size={16} color="currentColor" strokeWidth={2} className="animate-pulse" />
|
|
165
|
-
Sign Up
|
|
166
|
-
</span>
|
|
167
|
-
</Button>
|
|
168
|
-
|
|
169
|
-
<div className="text-center text-sm">
|
|
170
|
-
<span className="text-muted-foreground">Already have an account?</span>{" "}
|
|
171
|
-
<Button variant="link" className="p-0 h-auto" onClick={(e) => { e.preventDefault(); navigate('/signin'); }}>
|
|
172
|
-
Sign In
|
|
173
|
-
</Button>
|
|
174
|
-
</div>
|
|
175
|
-
</form>
|
|
176
|
-
|
|
177
|
-
<div className="mt-4 text-center text-xs text-muted-foreground">
|
|
178
|
-
By registering you agree to our{" "}
|
|
179
|
-
<a href="/terms" className="underline underline-offset-4 hover:text-foreground">Terms of Service</a>,{" "}
|
|
180
|
-
<a href="/eula" className="underline underline-offset-4 hover:text-foreground">EULA</a>,{" "}
|
|
181
|
-
<a href="/privacy" className="underline underline-offset-4 hover:text-foreground">Privacy Policy</a>
|
|
182
|
-
</div>
|
|
204
|
+
{formContent}
|
|
183
205
|
</CardContent>
|
|
184
206
|
</Card>
|
|
185
207
|
</div>
|