@djangocfg/layouts 1.0.1
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/LICENSE +21 -0
- package/README.md +77 -0
- package/package.json +86 -0
- package/src/auth/README.md +962 -0
- package/src/auth/context/AuthContext.tsx +458 -0
- package/src/auth/context/index.ts +2 -0
- package/src/auth/context/types.ts +63 -0
- package/src/auth/hooks/index.ts +6 -0
- package/src/auth/hooks/useAuthForm.ts +329 -0
- package/src/auth/hooks/useAuthGuard.ts +23 -0
- package/src/auth/hooks/useAuthRedirect.ts +51 -0
- package/src/auth/hooks/useAutoAuth.ts +42 -0
- package/src/auth/hooks/useLocalStorage.ts +211 -0
- package/src/auth/hooks/useSessionStorage.ts +186 -0
- package/src/auth/index.ts +10 -0
- package/src/auth/middlewares/index.ts +1 -0
- package/src/auth/middlewares/proxy.ts +24 -0
- package/src/auth/server.ts +6 -0
- package/src/auth/utils/errors.ts +34 -0
- package/src/auth/utils/index.ts +2 -0
- package/src/auth/utils/validation.ts +14 -0
- package/src/index.ts +15 -0
- package/src/layouts/AppLayout/AppLayout.tsx +123 -0
- package/src/layouts/AppLayout/README.md +204 -0
- package/src/layouts/AppLayout/SUMMARY.md +240 -0
- package/src/layouts/AppLayout/USAGE.md +312 -0
- package/src/layouts/AppLayout/components/PageProgress.tsx +104 -0
- package/src/layouts/AppLayout/components/Seo.tsx +87 -0
- package/src/layouts/AppLayout/components/index.ts +6 -0
- package/src/layouts/AppLayout/context/AppContext.tsx +146 -0
- package/src/layouts/AppLayout/context/index.ts +5 -0
- package/src/layouts/AppLayout/hooks/index.ts +6 -0
- package/src/layouts/AppLayout/hooks/useLayoutMode.ts +26 -0
- package/src/layouts/AppLayout/hooks/useNavigation.ts +49 -0
- package/src/layouts/AppLayout/index.ts +31 -0
- package/src/layouts/AppLayout/layouts/AuthLayout/AuthContext.tsx +51 -0
- package/src/layouts/AppLayout/layouts/AuthLayout/AuthHelp.tsx +111 -0
- package/src/layouts/AppLayout/layouts/AuthLayout/AuthLayout.tsx +40 -0
- package/src/layouts/AppLayout/layouts/AuthLayout/IdentifierForm.tsx +330 -0
- package/src/layouts/AppLayout/layouts/AuthLayout/OTPForm.tsx +158 -0
- package/src/layouts/AppLayout/layouts/AuthLayout/index.ts +13 -0
- package/src/layouts/AppLayout/layouts/AuthLayout/types.ts +61 -0
- package/src/layouts/AppLayout/layouts/PrivateLayout/PrivateLayout.tsx +92 -0
- package/src/layouts/AppLayout/layouts/PrivateLayout/components/DashboardContent.tsx +60 -0
- package/src/layouts/AppLayout/layouts/PrivateLayout/components/DashboardHeader.tsx +170 -0
- package/src/layouts/AppLayout/layouts/PrivateLayout/components/DashboardSidebar.tsx +164 -0
- package/src/layouts/AppLayout/layouts/PrivateLayout/components/index.ts +7 -0
- package/src/layouts/AppLayout/layouts/PrivateLayout/index.ts +5 -0
- package/src/layouts/AppLayout/layouts/PublicLayout/PublicLayout.tsx +44 -0
- package/src/layouts/AppLayout/layouts/PublicLayout/components/DesktopUserMenu.tsx +136 -0
- package/src/layouts/AppLayout/layouts/PublicLayout/components/Footer.tsx +262 -0
- package/src/layouts/AppLayout/layouts/PublicLayout/components/MobileMenu.tsx +289 -0
- package/src/layouts/AppLayout/layouts/PublicLayout/components/Navigation.tsx +159 -0
- package/src/layouts/AppLayout/layouts/PublicLayout/index.ts +5 -0
- package/src/layouts/AppLayout/layouts/index.ts +7 -0
- package/src/layouts/AppLayout/providers/CoreProviders.tsx +47 -0
- package/src/layouts/AppLayout/providers/index.ts +5 -0
- package/src/layouts/AppLayout/types/config.ts +40 -0
- package/src/layouts/AppLayout/types/index.ts +10 -0
- package/src/layouts/AppLayout/types/layout.ts +47 -0
- package/src/layouts/AppLayout/types/navigation.ts +41 -0
- package/src/layouts/AppLayout/types/routes.ts +45 -0
- package/src/layouts/AppLayout/utils/index.ts +5 -0
- package/src/layouts/AppLayout/utils/routeDetection.ts +31 -0
- package/src/layouts/PaymentsLayout/PaymentsLayout.tsx +125 -0
- package/src/layouts/PaymentsLayout/README.md +133 -0
- package/src/layouts/PaymentsLayout/components/CreateApiKeyDialog.tsx +172 -0
- package/src/layouts/PaymentsLayout/components/CreatePaymentDialog.tsx +203 -0
- package/src/layouts/PaymentsLayout/components/DeleteApiKeyDialog.tsx +100 -0
- package/src/layouts/PaymentsLayout/components/index.ts +4 -0
- package/src/layouts/PaymentsLayout/events.ts +106 -0
- package/src/layouts/PaymentsLayout/index.ts +20 -0
- package/src/layouts/PaymentsLayout/types.ts +19 -0
- package/src/layouts/PaymentsLayout/views/apikeys/components/ApiKeyMetrics.tsx +109 -0
- package/src/layouts/PaymentsLayout/views/apikeys/components/ApiKeysList.tsx +194 -0
- package/src/layouts/PaymentsLayout/views/apikeys/components/index.ts +3 -0
- package/src/layouts/PaymentsLayout/views/apikeys/index.tsx +19 -0
- package/src/layouts/PaymentsLayout/views/overview/components/BalanceCard.tsx +99 -0
- package/src/layouts/PaymentsLayout/views/overview/components/MetricsCards.tsx +103 -0
- package/src/layouts/PaymentsLayout/views/overview/components/RecentPayments.tsx +138 -0
- package/src/layouts/PaymentsLayout/views/overview/components/index.ts +4 -0
- package/src/layouts/PaymentsLayout/views/overview/index.tsx +23 -0
- package/src/layouts/PaymentsLayout/views/payments/components/PaymentsList.tsx +282 -0
- package/src/layouts/PaymentsLayout/views/payments/components/index.ts +2 -0
- package/src/layouts/PaymentsLayout/views/payments/index.tsx +18 -0
- package/src/layouts/PaymentsLayout/views/tariffs/index.tsx +29 -0
- package/src/layouts/PaymentsLayout/views/transactions/index.tsx +29 -0
- package/src/layouts/ProfileLayout/ProfileLayout.tsx +110 -0
- package/src/layouts/ProfileLayout/components/AvatarSection.tsx +146 -0
- package/src/layouts/ProfileLayout/components/ProfileForm.tsx +208 -0
- package/src/layouts/ProfileLayout/components/index.ts +3 -0
- package/src/layouts/ProfileLayout/index.ts +3 -0
- package/src/layouts/SupportLayout/README.md +91 -0
- package/src/layouts/SupportLayout/SupportLayout.tsx +178 -0
- package/src/layouts/SupportLayout/components/CreateTicketDialog.tsx +154 -0
- package/src/layouts/SupportLayout/components/MessageInput.tsx +92 -0
- package/src/layouts/SupportLayout/components/MessageList.tsx +312 -0
- package/src/layouts/SupportLayout/components/TicketCard.tsx +96 -0
- package/src/layouts/SupportLayout/components/TicketList.tsx +152 -0
- package/src/layouts/SupportLayout/components/index.ts +6 -0
- package/src/layouts/SupportLayout/context/SupportLayoutContext.tsx +260 -0
- package/src/layouts/SupportLayout/context/index.ts +2 -0
- package/src/layouts/SupportLayout/events.ts +31 -0
- package/src/layouts/SupportLayout/hooks/index.ts +2 -0
- package/src/layouts/SupportLayout/hooks/useInfiniteMessages.ts +118 -0
- package/src/layouts/SupportLayout/hooks/useInfiniteTickets.ts +91 -0
- package/src/layouts/SupportLayout/index.ts +6 -0
- package/src/layouts/SupportLayout/types.ts +23 -0
- package/src/layouts/index.ts +9 -0
- package/src/snippets/AuthDialog/AuthDialog.tsx +88 -0
- package/src/snippets/AuthDialog/events.ts +21 -0
- package/src/snippets/AuthDialog/index.ts +3 -0
- package/src/snippets/AuthDialog/useAuthDialog.ts +27 -0
- package/src/snippets/Breadcrumbs.tsx +80 -0
- package/src/snippets/Chat/ChatUIContext.tsx +110 -0
- package/src/snippets/Chat/ChatWidget.tsx +476 -0
- package/src/snippets/Chat/README.md +122 -0
- package/src/snippets/Chat/components/MessageInput.tsx +124 -0
- package/src/snippets/Chat/components/MessageList.tsx +168 -0
- package/src/snippets/Chat/components/SessionList.tsx +192 -0
- package/src/snippets/Chat/components/index.ts +9 -0
- package/src/snippets/Chat/hooks/index.ts +6 -0
- package/src/snippets/Chat/hooks/useInfiniteSessions.ts +83 -0
- package/src/snippets/Chat/index.tsx +44 -0
- package/src/snippets/Chat/types.ts +79 -0
- package/src/snippets/VideoPlayer/README.md +203 -0
- package/src/snippets/VideoPlayer/VideoControls.tsx +133 -0
- package/src/snippets/VideoPlayer/VideoPlayer.tsx +114 -0
- package/src/snippets/VideoPlayer/index.ts +8 -0
- package/src/snippets/VideoPlayer/types.ts +61 -0
- package/src/snippets/index.ts +10 -0
- package/src/styles/dashboard.css +41 -0
- package/src/styles/index.css +20 -0
- package/src/styles/sources.css +6 -0
- package/src/types/index.ts +1 -0
- package/src/types/pageConfig.ts +103 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/logger.ts +57 -0
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import React, { useState, useEffect } from 'react';
|
|
2
|
+
import { Mail, Phone, User } from 'lucide-react';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
Button,
|
|
6
|
+
Card,
|
|
7
|
+
CardContent,
|
|
8
|
+
CardDescription,
|
|
9
|
+
CardHeader,
|
|
10
|
+
CardTitle,
|
|
11
|
+
Checkbox,
|
|
12
|
+
Input,
|
|
13
|
+
Label,
|
|
14
|
+
Tabs,
|
|
15
|
+
TabsContent,
|
|
16
|
+
TabsList,
|
|
17
|
+
TabsTrigger,
|
|
18
|
+
PhoneInput,
|
|
19
|
+
} from '@djangocfg/ui/components';
|
|
20
|
+
|
|
21
|
+
import { useAuthContext } from './AuthContext';
|
|
22
|
+
import { AuthHelp } from './AuthHelp';
|
|
23
|
+
|
|
24
|
+
export const IdentifierForm: React.FC = () => {
|
|
25
|
+
const {
|
|
26
|
+
identifier,
|
|
27
|
+
channel,
|
|
28
|
+
isLoading,
|
|
29
|
+
acceptedTerms,
|
|
30
|
+
termsUrl,
|
|
31
|
+
privacyUrl,
|
|
32
|
+
enablePhoneAuth,
|
|
33
|
+
setIdentifier,
|
|
34
|
+
setChannel,
|
|
35
|
+
setAcceptedTerms,
|
|
36
|
+
handleIdentifierSubmit,
|
|
37
|
+
detectChannelFromIdentifier,
|
|
38
|
+
validateIdentifier,
|
|
39
|
+
error,
|
|
40
|
+
} = useAuthContext();
|
|
41
|
+
|
|
42
|
+
const [localChannel, setLocalChannel] = useState<'email' | 'phone'>(channel);
|
|
43
|
+
|
|
44
|
+
// Sync localChannel with channel from context (for localStorage updates)
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
setLocalChannel(channel);
|
|
47
|
+
}, [channel]);
|
|
48
|
+
|
|
49
|
+
// Force email channel if phone auth is disabled
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
if (!enablePhoneAuth && localChannel === 'phone') {
|
|
52
|
+
setLocalChannel('email');
|
|
53
|
+
setChannel('email');
|
|
54
|
+
// Clear identifier if it's a phone number
|
|
55
|
+
if (identifier && detectChannelFromIdentifier(identifier) === 'phone') {
|
|
56
|
+
setIdentifier('');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}, [
|
|
60
|
+
enablePhoneAuth,
|
|
61
|
+
localChannel,
|
|
62
|
+
identifier,
|
|
63
|
+
setChannel,
|
|
64
|
+
setIdentifier,
|
|
65
|
+
detectChannelFromIdentifier,
|
|
66
|
+
]);
|
|
67
|
+
|
|
68
|
+
// Handle identifier change with auto-detection
|
|
69
|
+
const handleIdentifierChange = (value: string) => {
|
|
70
|
+
setIdentifier(value);
|
|
71
|
+
|
|
72
|
+
// Auto-detect channel if user is typing (only if phone auth is enabled)
|
|
73
|
+
const detectedChannel = detectChannelFromIdentifier(value);
|
|
74
|
+
if (detectedChannel && detectedChannel !== localChannel) {
|
|
75
|
+
// Only switch to phone if phone auth is enabled
|
|
76
|
+
if (detectedChannel === 'phone' && !enablePhoneAuth) {
|
|
77
|
+
return; // Don't switch to phone channel if disabled
|
|
78
|
+
}
|
|
79
|
+
setLocalChannel(detectedChannel);
|
|
80
|
+
setChannel(detectedChannel);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// Handle manual channel switch
|
|
85
|
+
const handleChannelChange = (newChannel: 'email' | 'phone') => {
|
|
86
|
+
// Prevent switching to phone if phone auth is disabled
|
|
87
|
+
if (newChannel === 'phone' && !enablePhoneAuth) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
setLocalChannel(newChannel);
|
|
92
|
+
setChannel(newChannel);
|
|
93
|
+
// Clear identifier when switching channels
|
|
94
|
+
if (identifier && !validateIdentifier(identifier, newChannel)) {
|
|
95
|
+
setIdentifier('');
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const getChannelDescription = () => {
|
|
100
|
+
return localChannel === 'phone'
|
|
101
|
+
? 'Enter your phone number to receive a verification code via SMS'
|
|
102
|
+
: 'Enter your email address to receive a verification code';
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const getChannelIcon = () => {
|
|
106
|
+
return localChannel === 'phone' ? (
|
|
107
|
+
<Phone className="w-5 h-5" />
|
|
108
|
+
) : (
|
|
109
|
+
<Mail className="w-5 h-5" />
|
|
110
|
+
);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<Card className="w-full max-w-md mx-auto shadow-lg border border-border bg-card/50 backdrop-blur-sm">
|
|
115
|
+
<CardHeader className="text-center pb-6">
|
|
116
|
+
<div className="mx-auto w-12 h-12 bg-primary/10 rounded-full flex items-center justify-center mb-4">
|
|
117
|
+
<User className="w-6 h-6 text-primary" />
|
|
118
|
+
</div>
|
|
119
|
+
<CardTitle className="text-xl font-semibold">Sign In</CardTitle>
|
|
120
|
+
<CardDescription className="text-muted-foreground">
|
|
121
|
+
{getChannelDescription()}
|
|
122
|
+
</CardDescription>
|
|
123
|
+
</CardHeader>
|
|
124
|
+
<CardContent className="space-y-6">
|
|
125
|
+
{enablePhoneAuth ? (
|
|
126
|
+
<Tabs
|
|
127
|
+
value={localChannel}
|
|
128
|
+
onValueChange={(value) => handleChannelChange(value as 'email' | 'phone')}
|
|
129
|
+
>
|
|
130
|
+
{/* Channel Selection Tabs */}
|
|
131
|
+
<TabsList className="grid w-full grid-cols-2">
|
|
132
|
+
<TabsTrigger value="email" className="flex items-center gap-2">
|
|
133
|
+
<Mail className="w-4 h-4" />
|
|
134
|
+
Email
|
|
135
|
+
</TabsTrigger>
|
|
136
|
+
<TabsTrigger value="phone" className="flex items-center gap-2">
|
|
137
|
+
<Phone className="w-4 h-4" />
|
|
138
|
+
Phone
|
|
139
|
+
</TabsTrigger>
|
|
140
|
+
</TabsList>
|
|
141
|
+
|
|
142
|
+
<form onSubmit={handleIdentifierSubmit} className="space-y-6 mt-6">
|
|
143
|
+
<TabsContent value="email" className="space-y-3 mt-0">
|
|
144
|
+
<Label
|
|
145
|
+
htmlFor="identifier"
|
|
146
|
+
className="text-sm font-medium text-foreground flex items-center gap-2"
|
|
147
|
+
>
|
|
148
|
+
<Mail className="w-4 h-4" />
|
|
149
|
+
Email Address
|
|
150
|
+
</Label>
|
|
151
|
+
<Input
|
|
152
|
+
id="identifier"
|
|
153
|
+
type="email"
|
|
154
|
+
placeholder="Enter your email address"
|
|
155
|
+
value={identifier}
|
|
156
|
+
onChange={(e) => handleIdentifierChange(e.target.value)}
|
|
157
|
+
disabled={isLoading}
|
|
158
|
+
required
|
|
159
|
+
className="h-11 text-base"
|
|
160
|
+
/>
|
|
161
|
+
</TabsContent>
|
|
162
|
+
|
|
163
|
+
<TabsContent value="phone" className="space-y-3 mt-0">
|
|
164
|
+
<Label
|
|
165
|
+
htmlFor="phone-identifier"
|
|
166
|
+
className="text-sm font-medium text-foreground flex items-center gap-2"
|
|
167
|
+
>
|
|
168
|
+
<Phone className="w-4 h-4" />
|
|
169
|
+
Phone Number
|
|
170
|
+
</Label>
|
|
171
|
+
<PhoneInput
|
|
172
|
+
value={identifier}
|
|
173
|
+
onChange={(value) => handleIdentifierChange(value || '')}
|
|
174
|
+
disabled={isLoading}
|
|
175
|
+
placeholder="Enter your phone number"
|
|
176
|
+
defaultCountry="US"
|
|
177
|
+
className="h-11 text-base"
|
|
178
|
+
/>
|
|
179
|
+
</TabsContent>
|
|
180
|
+
|
|
181
|
+
{/* Terms and Conditions */}
|
|
182
|
+
<div className="flex items-start space-x-3">
|
|
183
|
+
<Checkbox
|
|
184
|
+
id="terms"
|
|
185
|
+
checked={acceptedTerms}
|
|
186
|
+
onCheckedChange={setAcceptedTerms}
|
|
187
|
+
disabled={isLoading}
|
|
188
|
+
className="mt-1"
|
|
189
|
+
/>
|
|
190
|
+
<div className="text-sm text-muted-foreground leading-5">
|
|
191
|
+
<Label htmlFor="terms" className="cursor-pointer">
|
|
192
|
+
I agree to the{' '}
|
|
193
|
+
<a
|
|
194
|
+
href={termsUrl}
|
|
195
|
+
target="_blank"
|
|
196
|
+
rel="noopener noreferrer"
|
|
197
|
+
className="text-primary hover:underline font-medium"
|
|
198
|
+
>
|
|
199
|
+
Terms of Service
|
|
200
|
+
</a>{' '}
|
|
201
|
+
and{' '}
|
|
202
|
+
<a
|
|
203
|
+
href={privacyUrl}
|
|
204
|
+
target="_blank"
|
|
205
|
+
rel="noopener noreferrer"
|
|
206
|
+
className="text-primary hover:underline font-medium"
|
|
207
|
+
>
|
|
208
|
+
Privacy Policy
|
|
209
|
+
</a>
|
|
210
|
+
</Label>
|
|
211
|
+
</div>
|
|
212
|
+
</div>
|
|
213
|
+
|
|
214
|
+
{/* Error Message */}
|
|
215
|
+
{error && (
|
|
216
|
+
<div className="text-sm text-destructive bg-destructive/10 p-3 rounded-md border border-destructive/20">
|
|
217
|
+
{error}
|
|
218
|
+
</div>
|
|
219
|
+
)}
|
|
220
|
+
|
|
221
|
+
{/* Submit Button */}
|
|
222
|
+
<Button
|
|
223
|
+
type="submit"
|
|
224
|
+
className="w-full h-11 text-base font-medium"
|
|
225
|
+
disabled={isLoading || !identifier || !acceptedTerms}
|
|
226
|
+
>
|
|
227
|
+
{isLoading ? (
|
|
228
|
+
<div className="flex items-center gap-2">
|
|
229
|
+
<div className="w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin" />
|
|
230
|
+
Sending code...
|
|
231
|
+
</div>
|
|
232
|
+
) : (
|
|
233
|
+
<div className="flex items-center gap-2">
|
|
234
|
+
{getChannelIcon()}
|
|
235
|
+
Send verification code
|
|
236
|
+
</div>
|
|
237
|
+
)}
|
|
238
|
+
</Button>
|
|
239
|
+
</form>
|
|
240
|
+
</Tabs>
|
|
241
|
+
) : (
|
|
242
|
+
<form onSubmit={handleIdentifierSubmit} className="space-y-6 mt-6">
|
|
243
|
+
{/* Email-only input when phone auth is disabled */}
|
|
244
|
+
<div className="space-y-3">
|
|
245
|
+
<Label
|
|
246
|
+
htmlFor="email-only"
|
|
247
|
+
className="text-sm font-medium text-foreground flex items-center gap-2"
|
|
248
|
+
>
|
|
249
|
+
<Mail className="w-4 h-4" />
|
|
250
|
+
Email Address
|
|
251
|
+
</Label>
|
|
252
|
+
<Input
|
|
253
|
+
id="email-only"
|
|
254
|
+
type="email"
|
|
255
|
+
placeholder="Enter your email address"
|
|
256
|
+
value={identifier}
|
|
257
|
+
onChange={(e) => handleIdentifierChange(e.target.value)}
|
|
258
|
+
disabled={isLoading}
|
|
259
|
+
required
|
|
260
|
+
className="h-11 text-base"
|
|
261
|
+
/>
|
|
262
|
+
</div>
|
|
263
|
+
|
|
264
|
+
{/* Terms and Conditions */}
|
|
265
|
+
<div className="flex items-start space-x-3">
|
|
266
|
+
<Checkbox
|
|
267
|
+
id="terms-email"
|
|
268
|
+
checked={acceptedTerms}
|
|
269
|
+
onCheckedChange={setAcceptedTerms}
|
|
270
|
+
disabled={isLoading}
|
|
271
|
+
className="mt-1"
|
|
272
|
+
/>
|
|
273
|
+
<div className="text-sm text-muted-foreground leading-5">
|
|
274
|
+
<Label htmlFor="terms-email" className="cursor-pointer">
|
|
275
|
+
I agree to the{' '}
|
|
276
|
+
<a
|
|
277
|
+
href={termsUrl}
|
|
278
|
+
target="_blank"
|
|
279
|
+
rel="noopener noreferrer"
|
|
280
|
+
className="text-primary hover:underline font-medium"
|
|
281
|
+
>
|
|
282
|
+
Terms of Service
|
|
283
|
+
</a>{' '}
|
|
284
|
+
and{' '}
|
|
285
|
+
<a
|
|
286
|
+
href={privacyUrl}
|
|
287
|
+
target="_blank"
|
|
288
|
+
rel="noopener noreferrer"
|
|
289
|
+
className="text-primary hover:underline font-medium"
|
|
290
|
+
>
|
|
291
|
+
Privacy Policy
|
|
292
|
+
</a>
|
|
293
|
+
</Label>
|
|
294
|
+
</div>
|
|
295
|
+
</div>
|
|
296
|
+
|
|
297
|
+
{/* Error Message */}
|
|
298
|
+
{error && (
|
|
299
|
+
<div className="text-sm text-destructive bg-destructive/10 p-3 rounded-md border border-destructive/20">
|
|
300
|
+
{error}
|
|
301
|
+
</div>
|
|
302
|
+
)}
|
|
303
|
+
|
|
304
|
+
{/* Submit Button */}
|
|
305
|
+
<Button
|
|
306
|
+
type="submit"
|
|
307
|
+
className="w-full h-11 text-base font-medium"
|
|
308
|
+
disabled={isLoading || !identifier || !acceptedTerms}
|
|
309
|
+
>
|
|
310
|
+
{isLoading ? (
|
|
311
|
+
<div className="flex items-center gap-2">
|
|
312
|
+
<div className="w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin" />
|
|
313
|
+
Sending code...
|
|
314
|
+
</div>
|
|
315
|
+
) : (
|
|
316
|
+
<div className="flex items-center gap-2">
|
|
317
|
+
{getChannelIcon()}
|
|
318
|
+
Send verification code
|
|
319
|
+
</div>
|
|
320
|
+
)}
|
|
321
|
+
</Button>
|
|
322
|
+
</form>
|
|
323
|
+
)}
|
|
324
|
+
|
|
325
|
+
{/* Help Section */}
|
|
326
|
+
<AuthHelp />
|
|
327
|
+
</CardContent>
|
|
328
|
+
</Card>
|
|
329
|
+
);
|
|
330
|
+
};
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Mail, MessageCircle } from 'lucide-react';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
Button,
|
|
6
|
+
Card,
|
|
7
|
+
CardContent,
|
|
8
|
+
CardDescription,
|
|
9
|
+
CardHeader,
|
|
10
|
+
CardTitle,
|
|
11
|
+
InputOTP,
|
|
12
|
+
InputOTPGroup,
|
|
13
|
+
InputOTPSlot,
|
|
14
|
+
} from '@djangocfg/ui/components';
|
|
15
|
+
|
|
16
|
+
import { useAuthContext } from './AuthContext';
|
|
17
|
+
import { AuthHelp } from './AuthHelp';
|
|
18
|
+
|
|
19
|
+
export const OTPForm: React.FC = () => {
|
|
20
|
+
const {
|
|
21
|
+
identifier,
|
|
22
|
+
channel,
|
|
23
|
+
otp,
|
|
24
|
+
isLoading,
|
|
25
|
+
error,
|
|
26
|
+
supportUrl,
|
|
27
|
+
setOtp,
|
|
28
|
+
handleOTPSubmit,
|
|
29
|
+
handleResendOTP,
|
|
30
|
+
handleBackToIdentifier,
|
|
31
|
+
} = useAuthContext();
|
|
32
|
+
|
|
33
|
+
const getChannelIcon = () => {
|
|
34
|
+
return channel === 'phone' ? (
|
|
35
|
+
<div className="flex items-center justify-center">
|
|
36
|
+
<MessageCircle className="w-5 h-5 text-primary" />
|
|
37
|
+
</div>
|
|
38
|
+
) : (
|
|
39
|
+
<Mail className="w-5 h-5 text-primary" />
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const getChannelTitle = () => {
|
|
44
|
+
return channel === 'phone' ? 'Verify Your Phone' : 'Verify Your Email';
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const getChannelDescription = () => {
|
|
48
|
+
const channelName = channel === 'phone' ? 'phone number' : 'email address';
|
|
49
|
+
const method = channel === 'phone' ? 'WhatsApp/SMS' : 'email';
|
|
50
|
+
return `We've sent a 6-digit verification code to your ${channelName} via ${method}`;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<Card className="w-full max-w-md mx-auto shadow-lg border border-border bg-card/50 backdrop-blur-sm">
|
|
55
|
+
<CardHeader className="text-center pb-6">
|
|
56
|
+
<div className="mx-auto w-12 h-12 bg-primary/10 rounded-full flex items-center justify-center mb-4">
|
|
57
|
+
{getChannelIcon()}
|
|
58
|
+
</div>
|
|
59
|
+
<CardTitle className="text-xl font-semibold">{getChannelTitle()}</CardTitle>
|
|
60
|
+
<CardDescription className="text-muted-foreground">
|
|
61
|
+
{getChannelDescription()}
|
|
62
|
+
<br />
|
|
63
|
+
<span className="font-medium text-foreground">{identifier}</span>
|
|
64
|
+
</CardDescription>
|
|
65
|
+
</CardHeader>
|
|
66
|
+
<CardContent className="space-y-6">
|
|
67
|
+
<form onSubmit={handleOTPSubmit} className="space-y-6">
|
|
68
|
+
<div className="space-y-3">
|
|
69
|
+
<label className="text-sm font-medium text-foreground text-center block">
|
|
70
|
+
Enter verification code
|
|
71
|
+
</label>
|
|
72
|
+
<div className="flex justify-center">
|
|
73
|
+
<InputOTP
|
|
74
|
+
value={otp}
|
|
75
|
+
onChange={setOtp}
|
|
76
|
+
maxLength={6}
|
|
77
|
+
disabled={isLoading}
|
|
78
|
+
containerClassName="gap-3"
|
|
79
|
+
>
|
|
80
|
+
<InputOTPGroup className="gap-2">
|
|
81
|
+
<InputOTPSlot
|
|
82
|
+
index={0}
|
|
83
|
+
className="h-12 w-12 text-lg font-semibold border-2 border-border bg-background rounded-lg shadow-sm"
|
|
84
|
+
/>
|
|
85
|
+
<InputOTPSlot
|
|
86
|
+
index={1}
|
|
87
|
+
className="h-12 w-12 text-lg font-semibold border-2 border-border bg-background rounded-lg shadow-sm"
|
|
88
|
+
/>
|
|
89
|
+
<InputOTPSlot
|
|
90
|
+
index={2}
|
|
91
|
+
className="h-12 w-12 text-lg font-semibold border-2 border-border bg-background rounded-lg shadow-sm"
|
|
92
|
+
/>
|
|
93
|
+
<InputOTPSlot
|
|
94
|
+
index={3}
|
|
95
|
+
className="h-12 w-12 text-lg font-semibold border-2 border-border bg-background rounded-lg shadow-sm"
|
|
96
|
+
/>
|
|
97
|
+
<InputOTPSlot
|
|
98
|
+
index={4}
|
|
99
|
+
className="h-12 w-12 text-lg font-semibold border-2 border-border bg-background rounded-lg shadow-sm"
|
|
100
|
+
/>
|
|
101
|
+
<InputOTPSlot
|
|
102
|
+
index={5}
|
|
103
|
+
className="h-12 w-12 text-lg font-semibold border-2 border-border bg-background rounded-lg shadow-sm"
|
|
104
|
+
/>
|
|
105
|
+
</InputOTPGroup>
|
|
106
|
+
</InputOTP>
|
|
107
|
+
</div>
|
|
108
|
+
</div>
|
|
109
|
+
|
|
110
|
+
<div className="space-y-4">
|
|
111
|
+
<Button
|
|
112
|
+
type="submit"
|
|
113
|
+
className="w-full h-11 text-base font-medium"
|
|
114
|
+
disabled={isLoading || otp.length < 6}
|
|
115
|
+
>
|
|
116
|
+
{isLoading ? 'Verifying...' : 'Verify Code'}
|
|
117
|
+
</Button>
|
|
118
|
+
|
|
119
|
+
<div className="flex gap-3">
|
|
120
|
+
<Button
|
|
121
|
+
type="button"
|
|
122
|
+
variant="outline"
|
|
123
|
+
onClick={handleBackToIdentifier}
|
|
124
|
+
disabled={isLoading}
|
|
125
|
+
className="flex-1 h-10"
|
|
126
|
+
>
|
|
127
|
+
← Back
|
|
128
|
+
</Button>
|
|
129
|
+
|
|
130
|
+
<Button
|
|
131
|
+
type="button"
|
|
132
|
+
variant="outline"
|
|
133
|
+
onClick={handleResendOTP}
|
|
134
|
+
disabled={isLoading}
|
|
135
|
+
className="flex-1 h-10"
|
|
136
|
+
>
|
|
137
|
+
↻ Resend
|
|
138
|
+
</Button>
|
|
139
|
+
</div>
|
|
140
|
+
</div>
|
|
141
|
+
</form>
|
|
142
|
+
|
|
143
|
+
{/* Error Message */}
|
|
144
|
+
{error && (
|
|
145
|
+
<div className="text-sm text-destructive bg-destructive/10 p-3 rounded-md border border-destructive/20">
|
|
146
|
+
{error}
|
|
147
|
+
</div>
|
|
148
|
+
)}
|
|
149
|
+
|
|
150
|
+
{supportUrl && (
|
|
151
|
+
<div className="mt-4">
|
|
152
|
+
<AuthHelp />
|
|
153
|
+
</div>
|
|
154
|
+
)}
|
|
155
|
+
</CardContent>
|
|
156
|
+
</Card>
|
|
157
|
+
);
|
|
158
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { AuthLayout } from './AuthLayout';
|
|
2
|
+
export {
|
|
3
|
+
AuthProvider as AuthLayoutProvider,
|
|
4
|
+
useAuthContext as useAuthLayoutContext
|
|
5
|
+
} from './AuthContext';
|
|
6
|
+
export { IdentifierForm } from './IdentifierForm';
|
|
7
|
+
export { OTPForm } from './OTPForm';
|
|
8
|
+
export { AuthHelp } from './AuthHelp';
|
|
9
|
+
export type {
|
|
10
|
+
AuthProps,
|
|
11
|
+
AuthContextType as AuthLayoutContextType,
|
|
12
|
+
AuthHelpProps
|
|
13
|
+
} from './types';
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
// Auth Context Types - Multi-channel support
|
|
4
|
+
export interface AuthContextType {
|
|
5
|
+
// Form state
|
|
6
|
+
identifier: string; // Email or phone number
|
|
7
|
+
channel: 'email' | 'phone';
|
|
8
|
+
otp: string;
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
acceptedTerms: boolean;
|
|
11
|
+
|
|
12
|
+
// Auth state
|
|
13
|
+
step: 'identifier' | 'otp';
|
|
14
|
+
error: string;
|
|
15
|
+
|
|
16
|
+
// Support configuration
|
|
17
|
+
supportUrl?: string;
|
|
18
|
+
termsUrl?: string;
|
|
19
|
+
privacyUrl?: string;
|
|
20
|
+
sourceUrl: string;
|
|
21
|
+
enablePhoneAuth?: boolean;
|
|
22
|
+
|
|
23
|
+
// Form handlers
|
|
24
|
+
setIdentifier: (identifier: string) => void;
|
|
25
|
+
setChannel: (channel: 'email' | 'phone') => void;
|
|
26
|
+
setOtp: (otp: string) => void;
|
|
27
|
+
setAcceptedTerms: (accepted: boolean) => void;
|
|
28
|
+
setError: (error: string) => void;
|
|
29
|
+
clearError: () => void;
|
|
30
|
+
|
|
31
|
+
// Auth handlers
|
|
32
|
+
handleIdentifierSubmit: (e: React.FormEvent) => Promise<void>;
|
|
33
|
+
handleOTPSubmit: (e: React.FormEvent) => Promise<void>;
|
|
34
|
+
handleResendOTP: () => Promise<void>;
|
|
35
|
+
handleBackToIdentifier: () => void;
|
|
36
|
+
forceOTPStep: () => void;
|
|
37
|
+
|
|
38
|
+
// Utility methods
|
|
39
|
+
detectChannelFromIdentifier: (identifier: string) => 'email' | 'phone' | null;
|
|
40
|
+
validateIdentifier: (identifier: string, channel?: 'email' | 'phone') => boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Unified Auth Props - used by both AuthProvider and AuthLayout
|
|
44
|
+
export interface AuthProps {
|
|
45
|
+
children?: React.ReactNode;
|
|
46
|
+
sourceUrl?: string;
|
|
47
|
+
supportUrl?: string;
|
|
48
|
+
termsUrl?: string;
|
|
49
|
+
privacyUrl?: string;
|
|
50
|
+
className?: string;
|
|
51
|
+
enablePhoneAuth?: boolean; // Controls whether phone authentication is available
|
|
52
|
+
onIdentifierSuccess?: (identifier: string, channel: 'email' | 'phone') => void;
|
|
53
|
+
onOTPSuccess?: () => void;
|
|
54
|
+
onError?: (message: string) => void;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Auth Help Types
|
|
58
|
+
export interface AuthHelpProps {
|
|
59
|
+
className?: string;
|
|
60
|
+
variant?: 'default' | 'compact';
|
|
61
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Private Layout
|
|
3
|
+
*
|
|
4
|
+
* Dashboard layout for authenticated pages
|
|
5
|
+
* Refactored from _old/DashboardLayout - uses context only!
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use client';
|
|
9
|
+
|
|
10
|
+
import React, { ReactNode, useEffect } from 'react';
|
|
11
|
+
import { SidebarInset, SidebarProvider } from '@djangocfg/ui/components';
|
|
12
|
+
import { useAuth } from '../../../../auth';
|
|
13
|
+
import { KnowledgeChat } from '../../../../snippets/Chat';
|
|
14
|
+
import { useAppContext } from '../../context';
|
|
15
|
+
import { DashboardContent, DashboardHeader, DashboardSidebar } from './components';
|
|
16
|
+
|
|
17
|
+
export interface PrivateLayoutProps {
|
|
18
|
+
children: ReactNode;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Private Layout Component
|
|
23
|
+
*
|
|
24
|
+
* Features:
|
|
25
|
+
* - SidebarProvider for collapsible sidebar
|
|
26
|
+
* - DashboardSidebar with navigation
|
|
27
|
+
* - DashboardHeader with user menu, notifications, theme toggle
|
|
28
|
+
* - DashboardContent with configurable padding
|
|
29
|
+
* - KnowledgeChat (optional)
|
|
30
|
+
* - Auth loading state
|
|
31
|
+
* - Auth redirect for unauthenticated users
|
|
32
|
+
*
|
|
33
|
+
* All data from useAppContext() - no props!
|
|
34
|
+
*/
|
|
35
|
+
export function PrivateLayout({ children }: PrivateLayoutProps) {
|
|
36
|
+
const { config } = useAppContext();
|
|
37
|
+
const { isLoading, isAuthenticated } = useAuth();
|
|
38
|
+
|
|
39
|
+
const { privateLayout, routes } = config;
|
|
40
|
+
|
|
41
|
+
// Redirect unauthenticated users
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (!isLoading && !isAuthenticated) {
|
|
44
|
+
const redirect = routes.detectors.getUnauthenticatedRedirect(
|
|
45
|
+
window.location.pathname
|
|
46
|
+
);
|
|
47
|
+
if (redirect) {
|
|
48
|
+
window.location.href = redirect;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}, [isLoading, isAuthenticated, routes]);
|
|
52
|
+
|
|
53
|
+
// Show loading state while checking auth
|
|
54
|
+
if (isLoading) {
|
|
55
|
+
return (
|
|
56
|
+
<div className="min-h-screen bg-background flex items-center justify-center">
|
|
57
|
+
<div className="flex flex-col items-center gap-4">
|
|
58
|
+
<div className="w-8 h-8 border-4 border-primary border-t-transparent rounded-full animate-spin" />
|
|
59
|
+
<p className="text-sm text-muted-foreground">Loading...</p>
|
|
60
|
+
</div>
|
|
61
|
+
</div>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Don't render content if user is not authenticated
|
|
66
|
+
if (!isAuthenticated) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<>
|
|
72
|
+
<SidebarProvider defaultOpen={true}>
|
|
73
|
+
{/* Sidebar */}
|
|
74
|
+
<DashboardSidebar />
|
|
75
|
+
|
|
76
|
+
{/* Main content area */}
|
|
77
|
+
<SidebarInset className="flex flex-col">
|
|
78
|
+
{/* Header */}
|
|
79
|
+
<DashboardHeader />
|
|
80
|
+
|
|
81
|
+
{/* Page content */}
|
|
82
|
+
<div className="flex-1 overflow-y-auto">
|
|
83
|
+
<DashboardContent>{children}</DashboardContent>
|
|
84
|
+
</div>
|
|
85
|
+
</SidebarInset>
|
|
86
|
+
</SidebarProvider>
|
|
87
|
+
|
|
88
|
+
{/* Chat positioned outside main layout for proper fixed positioning */}
|
|
89
|
+
{privateLayout.showChat && <KnowledgeChat />}
|
|
90
|
+
</>
|
|
91
|
+
);
|
|
92
|
+
}
|