@digilogiclabs/create-saas-app 1.5.2 → 1.5.3
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/dist/.tsbuildinfo +1 -1
- package/dist/templates/mobile/base/template/.env.example +15 -0
- package/dist/templates/mobile/base/template/App.tsx +88 -0
- package/dist/templates/mobile/base/template/app/(auth)/login.tsx +44 -0
- package/dist/templates/mobile/base/template/app/(auth)/signup.tsx +43 -0
- package/dist/templates/mobile/base/template/app/checkout.tsx +20 -0
- package/dist/templates/mobile/base/template/package.json +38 -0
- package/dist/templates/shared/auth/firebase/web/config.ts +23 -0
- package/dist/templates/shared/auth/supabase/web/config.ts +8 -0
- package/dist/templates/web/base/template/.env.example +15 -0
- package/dist/templates/web/base/template/.eslintrc.js +8 -0
- package/dist/templates/web/base/template/README.md +68 -0
- package/dist/templates/web/base/template/next.config.js +15 -0
- package/dist/templates/web/base/template/package.json +58 -0
- package/dist/templates/web/base/template/postcss.config.js +7 -0
- package/dist/templates/web/base/template/src/app/auth/callback/route.ts +18 -0
- package/dist/templates/web/base/template/src/app/checkout/page.tsx +28 -0
- package/dist/templates/web/base/template/src/app/error.tsx +97 -0
- package/dist/templates/web/base/template/src/app/globals.css +60 -0
- package/dist/templates/web/base/template/src/app/layout.tsx +35 -0
- package/dist/templates/web/base/template/src/app/loading.tsx +34 -0
- package/dist/templates/web/base/template/src/app/login/page.tsx +39 -0
- package/dist/templates/web/base/template/src/app/page.tsx +132 -0
- package/dist/templates/web/base/template/src/app/signup/page.tsx +39 -0
- package/dist/templates/web/base/template/src/components/__tests__/example.test.tsx +49 -0
- package/dist/templates/web/base/template/src/components/providers/app-providers.tsx +33 -0
- package/dist/templates/web/base/template/src/components/providers/theme-provider.tsx +94 -0
- package/dist/templates/web/base/template/src/components/shared/footer.tsx +36 -0
- package/dist/templates/web/base/template/src/components/shared/header.tsx +44 -0
- package/dist/templates/web/base/template/src/components/ui/badge.tsx +36 -0
- package/dist/templates/web/base/template/src/components/ui/button.tsx +56 -0
- package/dist/templates/web/base/template/src/components/ui/card.tsx +71 -0
- package/dist/templates/web/base/template/src/components/ui/theme-toggle.tsx +34 -0
- package/dist/templates/web/base/template/src/lib/auth-server.ts +177 -0
- package/dist/templates/web/base/template/src/lib/env.ts +46 -0
- package/dist/templates/web/base/template/src/lib/utils.ts +140 -0
- package/dist/templates/web/base/template/src/test/setup.ts +79 -0
- package/dist/templates/web/base/template/tailwind.config.js +77 -0
- package/dist/templates/web/base/template/tsconfig.json +33 -0
- package/dist/templates/web/base/template/vitest.config.ts +17 -0
- package/dist/templates/web/base/template.backup/.env.example +15 -0
- package/dist/templates/web/base/template.backup.20250817/.env.example +15 -0
- package/dist/templates/web/ui-auth/template/.env.example +15 -0
- package/dist/templates/web/ui-auth/template/.eslintrc.js +8 -0
- package/dist/templates/web/ui-auth/template/README.md +68 -0
- package/dist/templates/web/ui-auth/template/next.config.js +12 -0
- package/dist/templates/web/ui-auth/template/package.json +50 -0
- package/dist/templates/web/ui-auth/template/postcss.config.js +7 -0
- package/dist/templates/web/ui-auth/template/src/app/auth/callback/route.ts +12 -0
- package/dist/templates/web/ui-auth/template/src/app/checkout/page.tsx +25 -0
- package/dist/templates/web/ui-auth/template/src/app/error.tsx +67 -0
- package/dist/templates/web/ui-auth/template/src/app/globals.css +42 -0
- package/dist/templates/web/ui-auth/template/src/app/layout.tsx +33 -0
- package/dist/templates/web/ui-auth/template/src/app/loading.tsx +20 -0
- package/dist/templates/web/ui-auth/template/src/app/login/page.tsx +109 -0
- package/dist/templates/web/ui-auth/template/src/app/page.tsx +129 -0
- package/dist/templates/web/ui-auth/template/src/app/signup/page.tsx +128 -0
- package/dist/templates/web/ui-auth/template/src/components/__tests__/example.test.tsx +49 -0
- package/dist/templates/web/ui-auth/template/src/components/providers/app-providers.tsx +29 -0
- package/dist/templates/web/ui-auth/template/src/components/providers/theme-provider.tsx +94 -0
- package/dist/templates/web/ui-auth/template/src/components/shared/footer.tsx +36 -0
- package/dist/templates/web/ui-auth/template/src/components/shared/header.tsx +53 -0
- package/dist/templates/web/ui-auth/template/src/components/ui/badge.tsx +36 -0
- package/dist/templates/web/ui-auth/template/src/components/ui/theme-toggle.tsx +34 -0
- package/dist/templates/web/ui-auth/template/src/lib/env.ts +49 -0
- package/dist/templates/web/ui-auth/template/src/lib/utils.ts +140 -0
- package/dist/templates/web/ui-auth/template/src/test/setup.ts +79 -0
- package/dist/templates/web/ui-auth/template/tailwind.config.js +77 -0
- package/dist/templates/web/ui-auth/template/tsconfig.json +33 -0
- package/dist/templates/web/ui-auth/template/vitest.config.ts +17 -0
- package/dist/templates/web/ui-auth/template.backup/.env.example +15 -0
- package/dist/templates/web/ui-auth/template.backup.20250817/.env.example +15 -0
- package/dist/templates/web/ui-auth-payments/template/.env.example +15 -0
- package/dist/templates/web/ui-auth-payments/template/README.md +165 -0
- package/dist/templates/web/ui-auth-payments/template/middleware.ts +68 -0
- package/dist/templates/web/ui-auth-payments/template/next.config.js +12 -0
- package/dist/templates/web/ui-auth-payments/template/package-lock.json +12240 -0
- package/dist/templates/web/ui-auth-payments/template/package.json +52 -0
- package/dist/templates/web/ui-auth-payments/template/postcss.config.js +7 -0
- package/dist/templates/web/ui-auth-payments/template/src/app/auth/callback/route.ts +12 -0
- package/dist/templates/web/ui-auth-payments/template/src/app/billing/page.tsx +211 -0
- package/dist/templates/web/ui-auth-payments/template/src/app/checkout/page.tsx +142 -0
- package/dist/templates/web/ui-auth-payments/template/src/app/dashboard/layout.tsx +22 -0
- package/dist/templates/web/ui-auth-payments/template/src/app/dashboard/page.tsx +183 -0
- package/dist/templates/web/ui-auth-payments/template/src/app/error.tsx +67 -0
- package/dist/templates/web/ui-auth-payments/template/src/app/globals.css +42 -0
- package/dist/templates/web/ui-auth-payments/template/src/app/layout.tsx +33 -0
- package/dist/templates/web/ui-auth-payments/template/src/app/loading.tsx +20 -0
- package/dist/templates/web/ui-auth-payments/template/src/app/login/loading.tsx +38 -0
- package/dist/templates/web/ui-auth-payments/template/src/app/login/page.tsx +109 -0
- package/dist/templates/web/ui-auth-payments/template/src/app/page.tsx +143 -0
- package/dist/templates/web/ui-auth-payments/template/src/app/signup/loading.tsx +50 -0
- package/dist/templates/web/ui-auth-payments/template/src/app/signup/page.tsx +128 -0
- package/dist/templates/web/ui-auth-payments/template/src/components/__tests__/example.test.tsx +49 -0
- package/dist/templates/web/ui-auth-payments/template/src/components/client/auth-status.tsx +52 -0
- package/dist/templates/web/ui-auth-payments/template/src/components/client/login-form.tsx +144 -0
- package/dist/templates/web/ui-auth-payments/template/src/components/client/newsletter-signup.tsx +68 -0
- package/dist/templates/web/ui-auth-payments/template/src/components/client/signup-form.tsx +185 -0
- package/dist/templates/web/ui-auth-payments/template/src/components/providers/app-providers.tsx +32 -0
- package/dist/templates/web/ui-auth-payments/template/src/components/providers/theme-provider.tsx +94 -0
- package/dist/templates/web/ui-auth-payments/template/src/components/shared/footer.tsx +36 -0
- package/dist/templates/web/ui-auth-payments/template/src/components/shared/header.tsx +62 -0
- package/dist/templates/web/ui-auth-payments/template/src/components/ui/badge.tsx +36 -0
- package/dist/templates/web/ui-auth-payments/template/src/components/ui/theme-toggle.tsx +34 -0
- package/dist/templates/web/ui-auth-payments/template/src/lib/actions/auth.ts +246 -0
- package/dist/templates/web/ui-auth-payments/template/src/lib/actions/index.ts +340 -0
- package/dist/templates/web/ui-auth-payments/template/src/lib/auth-server.ts +177 -0
- package/dist/templates/web/ui-auth-payments/template/src/lib/env.ts +49 -0
- package/dist/templates/web/ui-auth-payments/template/src/lib/utils.ts +140 -0
- package/dist/templates/web/ui-auth-payments/template/src/test/setup.ts +79 -0
- package/dist/templates/web/ui-auth-payments/template/tailwind.config.js +77 -0
- package/dist/templates/web/ui-auth-payments/template/tsconfig.json +33 -0
- package/dist/templates/web/ui-auth-payments/template/tsconfig.tsbuildinfo +1 -0
- package/dist/templates/web/ui-auth-payments/template/vitest.config.ts +17 -0
- package/dist/templates/web/ui-auth-payments-audio/template/.env.example +15 -0
- package/dist/templates/web/ui-auth-payments-audio/template/README.md +187 -0
- package/dist/templates/web/ui-auth-payments-audio/template/middleware.ts +68 -0
- package/dist/templates/web/ui-auth-payments-audio/template/next.config.js +12 -0
- package/dist/templates/web/ui-auth-payments-audio/template/package-lock.json +12241 -0
- package/dist/templates/web/ui-auth-payments-audio/template/package.json +53 -0
- package/dist/templates/web/ui-auth-payments-audio/template/postcss.config.js +7 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/app/auth/callback/route.ts +12 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/app/billing/page.tsx +211 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/app/checkout/page.tsx +142 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/app/dashboard/layout.tsx +22 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/app/dashboard/page.tsx +183 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/app/error.tsx +67 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/app/globals.css +42 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/app/layout.tsx +35 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/app/loading.tsx +20 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/app/login/page.tsx +6 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/app/page.tsx +181 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/app/signup/page.tsx +6 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/components/__tests__/example.test.tsx +49 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/components/client/auth-status.tsx +52 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/components/client/login-form.tsx +144 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/components/client/signup-form.tsx +185 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/components/providers/app-providers.tsx +32 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/components/providers/theme-provider.tsx +94 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/components/shared/footer.tsx +36 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/components/shared/header.tsx +62 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/components/ui/badge.tsx +36 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/components/ui/theme-toggle.tsx +34 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/lib/actions/auth.ts +246 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/lib/actions/index.ts +14 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/lib/auth-server.ts +177 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/lib/env.ts +49 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/lib/utils.ts +140 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/test/setup.ts +79 -0
- package/dist/templates/web/ui-auth-payments-audio/template/tailwind.config.js +77 -0
- package/dist/templates/web/ui-auth-payments-audio/template/tsconfig.json +33 -0
- package/dist/templates/web/ui-auth-payments-audio/template/tsconfig.tsbuildinfo +1 -0
- package/dist/templates/web/ui-auth-payments-audio/template/vitest.config.ts +17 -0
- package/dist/templates/web/ui-auth-payments-video/template/.env.example +15 -0
- package/dist/templates/web/ui-auth-payments-video/template/README.md +190 -0
- package/dist/templates/web/ui-auth-payments-video/template/next.config.js +12 -0
- package/dist/templates/web/ui-auth-payments-video/template/package.json +53 -0
- package/dist/templates/web/ui-auth-payments-video/template/postcss.config.js +7 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/app/auth/callback/route.ts +12 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/app/billing/page.tsx +211 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/app/checkout/page.tsx +142 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/app/error.tsx +67 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/app/globals.css +42 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/app/layout.tsx +33 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/app/loading.tsx +20 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/app/login/page.tsx +109 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/app/page.tsx +187 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/app/signup/page.tsx +128 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/components/__tests__/example.test.tsx +49 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/components/providers/app-providers.tsx +32 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/components/providers/theme-provider.tsx +94 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/components/shared/footer.tsx +36 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/components/shared/header.tsx +62 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/components/ui/badge.tsx +36 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/components/ui/theme-toggle.tsx +34 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/lib/env.ts +49 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/lib/utils.ts +140 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/test/setup.ts +79 -0
- package/dist/templates/web/ui-auth-payments-video/template/tailwind.config.js +77 -0
- package/dist/templates/web/ui-auth-payments-video/template/tsconfig.json +33 -0
- package/dist/templates/web/ui-auth-payments-video/template/vitest.config.ts +17 -0
- package/dist/templates/web/ui-only/template/.env.example +15 -0
- package/dist/templates/web/ui-only/template/.eslintrc.js +8 -0
- package/dist/templates/web/ui-only/template/README.md +68 -0
- package/dist/templates/web/ui-only/template/next.config.js +12 -0
- package/dist/templates/web/ui-only/template/package.json +49 -0
- package/dist/templates/web/ui-only/template/postcss.config.js +7 -0
- package/dist/templates/web/ui-only/template/src/app/auth/callback/route.ts +12 -0
- package/dist/templates/web/ui-only/template/src/app/checkout/page.tsx +25 -0
- package/dist/templates/web/ui-only/template/src/app/error.tsx +67 -0
- package/dist/templates/web/ui-only/template/src/app/globals.css +42 -0
- package/dist/templates/web/ui-only/template/src/app/layout.tsx +33 -0
- package/dist/templates/web/ui-only/template/src/app/loading.tsx +20 -0
- package/dist/templates/web/ui-only/template/src/app/login/page.tsx +63 -0
- package/dist/templates/web/ui-only/template/src/app/page.tsx +91 -0
- package/dist/templates/web/ui-only/template/src/app/signup/page.tsx +79 -0
- package/dist/templates/web/ui-only/template/src/components/__tests__/example.test.tsx +49 -0
- package/dist/templates/web/ui-only/template/src/components/providers/app-providers.tsx +26 -0
- package/dist/templates/web/ui-only/template/src/components/providers/theme-provider.tsx +94 -0
- package/dist/templates/web/ui-only/template/src/components/shared/footer.tsx +36 -0
- package/dist/templates/web/ui-only/template/src/components/shared/header.tsx +53 -0
- package/dist/templates/web/ui-only/template/src/components/ui/badge.tsx +36 -0
- package/dist/templates/web/ui-only/template/src/components/ui/theme-toggle.tsx +34 -0
- package/dist/templates/web/ui-only/template/src/lib/env.ts +49 -0
- package/dist/templates/web/ui-only/template/src/lib/utils.ts +140 -0
- package/dist/templates/web/ui-only/template/src/test/setup.ts +79 -0
- package/dist/templates/web/ui-only/template/tailwind.config.js +77 -0
- package/dist/templates/web/ui-only/template/tsconfig.json +33 -0
- package/dist/templates/web/ui-only/template/vitest.config.ts +17 -0
- package/dist/templates/web/ui-only/template.backup/.env.example +15 -0
- package/dist/templates/web/ui-only/template.backup.20250817/.env.example +15 -0
- package/dist/templates/web/ui-package-test/template/next-env.d.ts +5 -0
- package/dist/templates/web/ui-package-test/template/package.json +42 -0
- package/dist/templates/web/ui-package-test/template/src/app/page.tsx +106 -0
- package/dist/templates/web/ui-package-test/template/tsconfig.json +41 -0
- package/package.json +3 -2
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import React, { useState } from 'react';
|
|
4
|
+
import { Button, Card, Input, Label } from '@digilogiclabs/saas-factory-ui';
|
|
5
|
+
import { useAuth } from '@digilogiclabs/saas-factory-auth';
|
|
6
|
+
import { useRouter } from 'next/navigation';
|
|
7
|
+
|
|
8
|
+
export default function SignupPage() {
|
|
9
|
+
const [email, setEmail] = useState('');
|
|
10
|
+
const [password, setPassword] = useState('');
|
|
11
|
+
const [confirmPassword, setConfirmPassword] = useState('');
|
|
12
|
+
const { signUp, signInWithOAuth, loading, error, user } = useAuth();
|
|
13
|
+
const router = useRouter();
|
|
14
|
+
|
|
15
|
+
// Redirect if already logged in
|
|
16
|
+
React.useEffect(() => {
|
|
17
|
+
if (user) {
|
|
18
|
+
router.push('/');
|
|
19
|
+
}
|
|
20
|
+
}, [user, router]);
|
|
21
|
+
|
|
22
|
+
const handleSignup = async (e: React.FormEvent) => {
|
|
23
|
+
e.preventDefault();
|
|
24
|
+
|
|
25
|
+
if (password !== confirmPassword) {
|
|
26
|
+
alert('Passwords do not match');
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
await signUp(email, password);
|
|
32
|
+
router.push('/');
|
|
33
|
+
} catch (err) {
|
|
34
|
+
console.error('Signup error:', err);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const handleGoogleSignup = async () => {
|
|
39
|
+
try {
|
|
40
|
+
await signInWithOAuth('google', window.location.origin);
|
|
41
|
+
} catch (err) {
|
|
42
|
+
console.error('Google signup error:', err);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
if (loading) {
|
|
47
|
+
return (
|
|
48
|
+
<div className="flex items-center justify-center min-h-screen bg-gray-100">
|
|
49
|
+
<div>Loading...</div>
|
|
50
|
+
</div>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<div className="flex items-center justify-center min-h-screen bg-gray-100">
|
|
56
|
+
<Card className="w-full max-w-md p-8">
|
|
57
|
+
<h1 className="text-2xl font-bold text-center mb-6">Sign Up</h1>
|
|
58
|
+
|
|
59
|
+
{error && (
|
|
60
|
+
<div className="mb-4 p-3 bg-red-100 border border-red-400 text-red-700 rounded">
|
|
61
|
+
{error.message}
|
|
62
|
+
</div>
|
|
63
|
+
)}
|
|
64
|
+
|
|
65
|
+
<form onSubmit={handleSignup} className="space-y-4">
|
|
66
|
+
<div>
|
|
67
|
+
<Label htmlFor="email">Email</Label>
|
|
68
|
+
<Input
|
|
69
|
+
id="email"
|
|
70
|
+
type="email"
|
|
71
|
+
value={email}
|
|
72
|
+
onChange={(e) => setEmail(e.target.value)}
|
|
73
|
+
placeholder="Enter your email"
|
|
74
|
+
required
|
|
75
|
+
disabled={loading}
|
|
76
|
+
/>
|
|
77
|
+
</div>
|
|
78
|
+
<div>
|
|
79
|
+
<Label htmlFor="password">Password</Label>
|
|
80
|
+
<Input
|
|
81
|
+
id="password"
|
|
82
|
+
type="password"
|
|
83
|
+
value={password}
|
|
84
|
+
onChange={(e) => setPassword(e.target.value)}
|
|
85
|
+
placeholder="Enter your password"
|
|
86
|
+
required
|
|
87
|
+
disabled={loading}
|
|
88
|
+
/>
|
|
89
|
+
</div>
|
|
90
|
+
<div>
|
|
91
|
+
<Label htmlFor="confirmPassword">Confirm Password</Label>
|
|
92
|
+
<Input
|
|
93
|
+
id="confirmPassword"
|
|
94
|
+
type="password"
|
|
95
|
+
value={confirmPassword}
|
|
96
|
+
onChange={(e) => setConfirmPassword(e.target.value)}
|
|
97
|
+
placeholder="Confirm your password"
|
|
98
|
+
required
|
|
99
|
+
disabled={loading}
|
|
100
|
+
/>
|
|
101
|
+
</div>
|
|
102
|
+
<Button type="submit" className="w-full" disabled={loading}>
|
|
103
|
+
{loading ? 'Signing Up...' : 'Sign Up'}
|
|
104
|
+
</Button>
|
|
105
|
+
<Button
|
|
106
|
+
type="button"
|
|
107
|
+
variant="outline"
|
|
108
|
+
className="w-full"
|
|
109
|
+
onClick={handleGoogleSignup}
|
|
110
|
+
disabled={loading}
|
|
111
|
+
>
|
|
112
|
+
Sign up with Google
|
|
113
|
+
</Button>
|
|
114
|
+
</form>
|
|
115
|
+
|
|
116
|
+
<div className="mt-4 text-center">
|
|
117
|
+
<p className="text-sm text-gray-600">
|
|
118
|
+
Already have an account?{' '}
|
|
119
|
+
<a href="/login" className="text-blue-600 hover:underline">
|
|
120
|
+
Sign in
|
|
121
|
+
</a>
|
|
122
|
+
</p>
|
|
123
|
+
</div>
|
|
124
|
+
</Card>
|
|
125
|
+
</div>
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example test file demonstrating testing patterns for SaaS Factory components
|
|
3
|
+
*
|
|
4
|
+
* This is optional and serves as a reference for testing your components.
|
|
5
|
+
* You can delete this file if you don't need example tests.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { render, screen } from '@testing-library/react'
|
|
9
|
+
import { Button } from '@digilogiclabs/saas-factory-ui'
|
|
10
|
+
|
|
11
|
+
// Example: Testing UI components
|
|
12
|
+
describe('UI Components', () => {
|
|
13
|
+
it('renders button with correct text', () => {
|
|
14
|
+
render(<Button>Click me</Button>)
|
|
15
|
+
expect(screen.getByRole('button', { name: /click me/i })).toBeInTheDocument()
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it('button can be disabled', () => {
|
|
19
|
+
render(<Button disabled>Disabled button</Button>)
|
|
20
|
+
expect(screen.getByRole('button')).toBeDisabled()
|
|
21
|
+
})
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
// Example: Testing custom components
|
|
25
|
+
function MockComponent({ title }: { title: string }) {
|
|
26
|
+
return <h1>{title}</h1>
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
describe('Custom Components', () => {
|
|
30
|
+
it('renders with correct title', () => {
|
|
31
|
+
render(<MockComponent title="Test Title" />)
|
|
32
|
+
expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent('Test Title')
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
// Example: Testing utilities
|
|
37
|
+
function formatCurrency(amount: number): string {
|
|
38
|
+
return new Intl.NumberFormat('en-US', {
|
|
39
|
+
style: 'currency',
|
|
40
|
+
currency: 'USD',
|
|
41
|
+
}).format(amount)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
describe('Utilities', () => {
|
|
45
|
+
it('formats currency correctly', () => {
|
|
46
|
+
expect(formatCurrency(1000)).toBe('$1,000.00')
|
|
47
|
+
expect(formatCurrency(0)).toBe('$0.00')
|
|
48
|
+
})
|
|
49
|
+
})
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import React from 'react'
|
|
4
|
+
import { ThemeProvider } from 'next-themes'
|
|
5
|
+
import { AuthProvider } from '@digilogiclabs/saas-factory-auth'
|
|
6
|
+
import { AppThemeProvider } from './theme-provider'
|
|
7
|
+
|
|
8
|
+
interface AppProvidersProps {
|
|
9
|
+
children: React.ReactNode
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function AppProviders({ children }: AppProvidersProps) {
|
|
13
|
+
return (
|
|
14
|
+
<ThemeProvider
|
|
15
|
+
attribute="class"
|
|
16
|
+
defaultTheme="{{defaultTheme}}"
|
|
17
|
+
enableSystem
|
|
18
|
+
disableTransitionOnChange
|
|
19
|
+
storageKey="{{packageName}}-theme"
|
|
20
|
+
>
|
|
21
|
+
<AuthProvider>
|
|
22
|
+
<AppThemeProvider themeColor="{{themeColor}}">
|
|
23
|
+
{children}
|
|
24
|
+
</AppThemeProvider>
|
|
25
|
+
</AuthProvider>
|
|
26
|
+
</ThemeProvider>
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import React, { createContext, useContext, useEffect } from 'react'
|
|
4
|
+
|
|
5
|
+
interface ThemeContextType {
|
|
6
|
+
themeColor: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const ThemeContext = createContext<ThemeContextType | undefined>(undefined)
|
|
10
|
+
|
|
11
|
+
interface AppThemeProviderProps {
|
|
12
|
+
children: React.ReactNode
|
|
13
|
+
themeColor: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const THEME_COLORS = {
|
|
17
|
+
blue: {
|
|
18
|
+
primary: '221.2 83.2% 53.3%',
|
|
19
|
+
primaryForeground: '210 40% 98%',
|
|
20
|
+
secondary: '210 40% 96%',
|
|
21
|
+
accent: '210 40% 96%',
|
|
22
|
+
ring: '221.2 83.2% 53.3%',
|
|
23
|
+
},
|
|
24
|
+
green: {
|
|
25
|
+
primary: '142.1 76.2% 36.3%',
|
|
26
|
+
primaryForeground: '355.7 100% 97.3%',
|
|
27
|
+
secondary: '138.5 76.2% 96.7%',
|
|
28
|
+
accent: '138.5 76.2% 96.7%',
|
|
29
|
+
ring: '142.1 76.2% 36.3%',
|
|
30
|
+
},
|
|
31
|
+
purple: {
|
|
32
|
+
primary: '262.1 83.3% 57.8%',
|
|
33
|
+
primaryForeground: '210 40% 98%',
|
|
34
|
+
secondary: '270 3.18% 96.5%',
|
|
35
|
+
accent: '270 3.18% 96.5%',
|
|
36
|
+
ring: '262.1 83.3% 57.8%',
|
|
37
|
+
},
|
|
38
|
+
orange: {
|
|
39
|
+
primary: '24.6 95% 53.1%',
|
|
40
|
+
primaryForeground: '60 9.1% 97.8%',
|
|
41
|
+
secondary: '60 4.8% 95.9%',
|
|
42
|
+
accent: '60 4.8% 95.9%',
|
|
43
|
+
ring: '24.6 95% 53.1%',
|
|
44
|
+
},
|
|
45
|
+
red: {
|
|
46
|
+
primary: '0 72.2% 50.6%',
|
|
47
|
+
primaryForeground: '0 85.7% 97.3%',
|
|
48
|
+
secondary: '0 0% 96.3%',
|
|
49
|
+
accent: '0 0% 96.3%',
|
|
50
|
+
ring: '0 72.2% 50.6%',
|
|
51
|
+
},
|
|
52
|
+
slate: {
|
|
53
|
+
primary: '215 27.9% 16.9%',
|
|
54
|
+
primaryForeground: '0 0% 98%',
|
|
55
|
+
secondary: '210 40% 96%',
|
|
56
|
+
accent: '210 40% 96%',
|
|
57
|
+
ring: '215 27.9% 16.9%',
|
|
58
|
+
},
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function AppThemeProvider({ children, themeColor }: AppThemeProviderProps) {
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
const colorScheme = THEME_COLORS[themeColor as keyof typeof THEME_COLORS] || THEME_COLORS.blue
|
|
64
|
+
|
|
65
|
+
// Apply theme colors to CSS custom properties
|
|
66
|
+
const root = document.documentElement
|
|
67
|
+
root.style.setProperty('--primary', colorScheme.primary)
|
|
68
|
+
root.style.setProperty('--primary-foreground', colorScheme.primaryForeground)
|
|
69
|
+
root.style.setProperty('--secondary', colorScheme.secondary)
|
|
70
|
+
root.style.setProperty('--accent', colorScheme.accent)
|
|
71
|
+
root.style.setProperty('--ring', colorScheme.ring)
|
|
72
|
+
|
|
73
|
+
// Store theme color preference
|
|
74
|
+
localStorage.setItem('{{packageName}}-theme-color', themeColor)
|
|
75
|
+
}, [themeColor])
|
|
76
|
+
|
|
77
|
+
const contextValue: ThemeContextType = {
|
|
78
|
+
themeColor,
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<ThemeContext.Provider value={contextValue}>
|
|
83
|
+
{children}
|
|
84
|
+
</ThemeContext.Provider>
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function useAppTheme() {
|
|
89
|
+
const context = useContext(ThemeContext)
|
|
90
|
+
if (context === undefined) {
|
|
91
|
+
throw new Error('useAppTheme must be used within a AppThemeProvider')
|
|
92
|
+
}
|
|
93
|
+
return context
|
|
94
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import React from 'react'
|
|
4
|
+
|
|
5
|
+
interface FooterProps {
|
|
6
|
+
className?: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function Footer({ className = '' }: FooterProps) {
|
|
10
|
+
return (
|
|
11
|
+
<footer className={`border-t bg-background py-4 ${className}`}>
|
|
12
|
+
<div className="container mx-auto px-4">
|
|
13
|
+
<div className="flex flex-col sm:flex-row justify-between items-center gap-4 text-sm text-muted-foreground">
|
|
14
|
+
<div className="flex items-center gap-2">
|
|
15
|
+
<span>© {new Date().getFullYear()} {{titleCaseName}}</span>
|
|
16
|
+
</div>
|
|
17
|
+
|
|
18
|
+
<div className="flex items-center gap-2 text-xs">
|
|
19
|
+
<span>Generated with</span>
|
|
20
|
+
<a
|
|
21
|
+
href="https://docs.digilogiclabs.com"
|
|
22
|
+
target="_blank"
|
|
23
|
+
rel="noopener noreferrer"
|
|
24
|
+
className="hover:text-foreground transition-colors"
|
|
25
|
+
>
|
|
26
|
+
Digi Logic Labs
|
|
27
|
+
</a>
|
|
28
|
+
<span className="text-muted-foreground/60">
|
|
29
|
+
• UI v{{uiVersion}} • Auth v{{authVersion}} • {{generatedDate}}
|
|
30
|
+
</span>
|
|
31
|
+
</div>
|
|
32
|
+
</div>
|
|
33
|
+
</div>
|
|
34
|
+
</footer>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import Link from 'next/link';
|
|
5
|
+
import { LogOut } from 'lucide-react';
|
|
6
|
+
import { ThemeToggle } from '../ui/theme-toggle';
|
|
7
|
+
|
|
8
|
+
export function Header() {
|
|
9
|
+
const user = null; // Placeholder for auth state
|
|
10
|
+
|
|
11
|
+
const handleSignOut = () => {
|
|
12
|
+
alert('Sign out functionality requires @digilogiclabs/saas-factory-auth package');
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<header className="bg-white dark:bg-gray-800 shadow-md">
|
|
17
|
+
<div className="container mx-auto px-4 py-4 flex justify-between items-center">
|
|
18
|
+
<Link href="/" className="text-2xl font-bold text-gray-900 dark:text-white">
|
|
19
|
+
{{titleCaseName}}
|
|
20
|
+
</Link>
|
|
21
|
+
<nav className="flex items-center gap-4">
|
|
22
|
+
<ThemeToggle />
|
|
23
|
+
{user ? (
|
|
24
|
+
<>
|
|
25
|
+
<Link href="/dashboard" className="text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white">
|
|
26
|
+
Dashboard
|
|
27
|
+
</Link>
|
|
28
|
+
<button
|
|
29
|
+
onClick={handleSignOut}
|
|
30
|
+
className="p-2 text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white"
|
|
31
|
+
>
|
|
32
|
+
<LogOut className="h-5 w-5" />
|
|
33
|
+
</button>
|
|
34
|
+
</>
|
|
35
|
+
) : (
|
|
36
|
+
<>
|
|
37
|
+
<Link href="/login" className="text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white">
|
|
38
|
+
Login
|
|
39
|
+
</Link>
|
|
40
|
+
<Link
|
|
41
|
+
href="/signup"
|
|
42
|
+
className="px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700"
|
|
43
|
+
>
|
|
44
|
+
Sign Up
|
|
45
|
+
</Link>
|
|
46
|
+
</>
|
|
47
|
+
)}
|
|
48
|
+
</nav>
|
|
49
|
+
</div>
|
|
50
|
+
</header>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
3
|
+
import { cn } from "@/lib/utils"
|
|
4
|
+
|
|
5
|
+
const badgeVariants = cva(
|
|
6
|
+
"inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
|
|
7
|
+
{
|
|
8
|
+
variants: {
|
|
9
|
+
variant: {
|
|
10
|
+
default:
|
|
11
|
+
"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",
|
|
12
|
+
secondary:
|
|
13
|
+
"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
14
|
+
destructive:
|
|
15
|
+
"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",
|
|
16
|
+
outline: "text-foreground",
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
defaultVariants: {
|
|
20
|
+
variant: "default",
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
export interface BadgeProps
|
|
26
|
+
extends React.HTMLAttributes<HTMLDivElement>,
|
|
27
|
+
VariantProps<typeof badgeVariants> {}
|
|
28
|
+
|
|
29
|
+
function Badge({ className, variant, ...props }: BadgeProps) {
|
|
30
|
+
return (
|
|
31
|
+
<div className={cn(badgeVariants({ variant }), className)} {...props} />
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { Badge, badgeVariants }
|
|
36
|
+
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { Moon, Sun } from "lucide-react"
|
|
5
|
+
import { useTheme } from "next-themes"
|
|
6
|
+
|
|
7
|
+
import { Button } from "@digilogiclabs/saas-factory-ui"
|
|
8
|
+
|
|
9
|
+
export function ThemeToggle() {
|
|
10
|
+
const { theme, setTheme } = useTheme()
|
|
11
|
+
|
|
12
|
+
const toggleTheme = () => {
|
|
13
|
+
if (theme === 'light') {
|
|
14
|
+
setTheme('dark')
|
|
15
|
+
} else if (theme === 'dark') {
|
|
16
|
+
setTheme('system')
|
|
17
|
+
} else {
|
|
18
|
+
setTheme('light')
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<Button
|
|
24
|
+
variant="outline"
|
|
25
|
+
size="icon"
|
|
26
|
+
onClick={toggleTheme}
|
|
27
|
+
className="h-9 w-9"
|
|
28
|
+
>
|
|
29
|
+
<Sun className="h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" />
|
|
30
|
+
<Moon className="absolute h-4 w-4 rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" />
|
|
31
|
+
<span className="sr-only">Toggle theme</span>
|
|
32
|
+
</Button>
|
|
33
|
+
)
|
|
34
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional Environment Configuration with Zod validation
|
|
3
|
+
*
|
|
4
|
+
* This provides type-safe environment variable validation.
|
|
5
|
+
* Usage is optional - existing templates will continue to work without this.
|
|
6
|
+
*
|
|
7
|
+
* To use: import { env } from '@/lib/env' instead of process.env
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { z } from 'zod'
|
|
11
|
+
|
|
12
|
+
const envSchema = z.object({
|
|
13
|
+
// Next.js built-in
|
|
14
|
+
NODE_ENV: z.enum(['development', 'production', 'test']).default('development'),
|
|
15
|
+
|
|
16
|
+
// App configuration
|
|
17
|
+
NEXT_PUBLIC_APP_URL: z.string().url().optional(),
|
|
18
|
+
NEXT_PUBLIC_APP_NAME: z.string().default('{{titleCaseName}}'),
|
|
19
|
+
|
|
20
|
+
// Auth configuration (if using server-side auth)
|
|
21
|
+
SUPABASE_URL: z.string().url().optional(),
|
|
22
|
+
SUPABASE_ANON_KEY: z.string().optional(),
|
|
23
|
+
SUPABASE_SERVICE_ROLE_KEY: z.string().optional(),
|
|
24
|
+
|
|
25
|
+
// Payment configuration
|
|
26
|
+
STRIPE_SECRET_KEY: z.string().optional(),
|
|
27
|
+
STRIPE_WEBHOOK_SECRET: z.string().optional(),
|
|
28
|
+
|
|
29
|
+
// Optional analytics
|
|
30
|
+
ANALYTICS_ID: z.string().optional(),
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
// Parse with fallback to process.env for backward compatibility
|
|
34
|
+
function parseEnv() {
|
|
35
|
+
try {
|
|
36
|
+
return envSchema.parse(process.env)
|
|
37
|
+
} catch (error) {
|
|
38
|
+
if (process.env.NODE_ENV === 'development') {
|
|
39
|
+
console.warn('Environment validation failed. Using process.env fallback:', error)
|
|
40
|
+
}
|
|
41
|
+
// Fallback to process.env for backward compatibility
|
|
42
|
+
return process.env as any
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const env = parseEnv()
|
|
47
|
+
|
|
48
|
+
// Type helper for environment variables
|
|
49
|
+
export type Env = z.infer<typeof envSchema>
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enhanced utility functions for {{titleCaseName}}
|
|
3
|
+
*
|
|
4
|
+
* This extends the basic utils with additional functionality while
|
|
5
|
+
* maintaining compatibility with existing templates.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { type ClassValue, clsx } from "clsx"
|
|
9
|
+
import { twMerge } from "tailwind-merge"
|
|
10
|
+
|
|
11
|
+
// Core utility function (keeps existing functionality)
|
|
12
|
+
export function cn(...inputs: ClassValue[]) {
|
|
13
|
+
return twMerge(clsx(inputs))
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Additional utilities for enhanced templates
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Format currency with proper locale support
|
|
20
|
+
*/
|
|
21
|
+
export function formatCurrency(
|
|
22
|
+
amount: number,
|
|
23
|
+
currency: string = 'USD',
|
|
24
|
+
locale: string = 'en-US'
|
|
25
|
+
): string {
|
|
26
|
+
return new Intl.NumberFormat(locale, {
|
|
27
|
+
style: 'currency',
|
|
28
|
+
currency,
|
|
29
|
+
}).format(amount)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Format date with relative time support
|
|
34
|
+
*/
|
|
35
|
+
export function formatDate(
|
|
36
|
+
date: Date | string,
|
|
37
|
+
options?: Intl.DateTimeFormatOptions
|
|
38
|
+
): string {
|
|
39
|
+
const dateObj = typeof date === 'string' ? new Date(date) : date
|
|
40
|
+
|
|
41
|
+
const defaultOptions: Intl.DateTimeFormatOptions = {
|
|
42
|
+
year: 'numeric',
|
|
43
|
+
month: 'short',
|
|
44
|
+
day: 'numeric',
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return new Intl.DateTimeFormat('en-US', options || defaultOptions).format(dateObj)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Get relative time string (e.g., "2 hours ago")
|
|
52
|
+
*/
|
|
53
|
+
export function getRelativeTime(date: Date | string): string {
|
|
54
|
+
const dateObj = typeof date === 'string' ? new Date(date) : date
|
|
55
|
+
const now = new Date()
|
|
56
|
+
const diffInMs = now.getTime() - dateObj.getTime()
|
|
57
|
+
const diffInSeconds = Math.floor(diffInMs / 1000)
|
|
58
|
+
const diffInMinutes = Math.floor(diffInSeconds / 60)
|
|
59
|
+
const diffInHours = Math.floor(diffInMinutes / 60)
|
|
60
|
+
const diffInDays = Math.floor(diffInHours / 24)
|
|
61
|
+
|
|
62
|
+
if (diffInSeconds < 60) return 'just now'
|
|
63
|
+
if (diffInMinutes < 60) return `${diffInMinutes} minute${diffInMinutes > 1 ? 's' : ''} ago`
|
|
64
|
+
if (diffInHours < 24) return `${diffInHours} hour${diffInHours > 1 ? 's' : ''} ago`
|
|
65
|
+
if (diffInDays < 7) return `${diffInDays} day${diffInDays > 1 ? 's' : ''} ago`
|
|
66
|
+
|
|
67
|
+
return formatDate(dateObj)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Truncate text to specified length with ellipsis
|
|
72
|
+
*/
|
|
73
|
+
export function truncate(text: string, length: number = 50): string {
|
|
74
|
+
if (text.length <= length) return text
|
|
75
|
+
return text.slice(0, length).trim() + '...'
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Generate initials from a name
|
|
80
|
+
*/
|
|
81
|
+
export function getInitials(name: string): string {
|
|
82
|
+
return name
|
|
83
|
+
.split(' ')
|
|
84
|
+
.map(word => word.charAt(0).toUpperCase())
|
|
85
|
+
.slice(0, 2)
|
|
86
|
+
.join('')
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Validate email format
|
|
91
|
+
*/
|
|
92
|
+
export function isValidEmail(email: string): boolean {
|
|
93
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
|
|
94
|
+
return emailRegex.test(email)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Generate a random ID
|
|
99
|
+
*/
|
|
100
|
+
export function generateId(prefix: string = ''): string {
|
|
101
|
+
const timestamp = Date.now().toString(36)
|
|
102
|
+
const randomString = Math.random().toString(36).substring(2)
|
|
103
|
+
return prefix ? `${prefix}-${timestamp}-${randomString}` : `${timestamp}-${randomString}`
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Debounce function
|
|
108
|
+
*/
|
|
109
|
+
export function debounce<T extends (...args: any[]) => any>(
|
|
110
|
+
func: T,
|
|
111
|
+
delay: number
|
|
112
|
+
): (...args: Parameters<T>) => void {
|
|
113
|
+
let timeoutId: NodeJS.Timeout | null = null
|
|
114
|
+
|
|
115
|
+
return (...args: Parameters<T>) => {
|
|
116
|
+
if (timeoutId !== null) {
|
|
117
|
+
clearTimeout(timeoutId)
|
|
118
|
+
}
|
|
119
|
+
timeoutId = setTimeout(() => func(...args), delay)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Sleep/delay function for async operations
|
|
125
|
+
*/
|
|
126
|
+
export function sleep(ms: number): Promise<void> {
|
|
127
|
+
return new Promise(resolve => setTimeout(resolve, ms))
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Safe JSON parse with fallback
|
|
132
|
+
*/
|
|
133
|
+
export function safeJsonParse<T>(json: string, fallback: T): T {
|
|
134
|
+
try {
|
|
135
|
+
return JSON.parse(json)
|
|
136
|
+
} catch {
|
|
137
|
+
return fallback
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|