@digilogiclabs/create-saas-app 1.4.0 → 1.5.0
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/CHANGELOG.md +42 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.js +45 -3
- package/dist/index.js.map +1 -1
- package/dist/templates/web/base/template/package.json +20 -10
- package/dist/templates/web/base/template/src/app/error.tsx +97 -0
- package/dist/templates/web/base/template/src/app/layout.tsx +8 -2
- package/dist/templates/web/base/template/src/app/loading.tsx +34 -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 +6 -2
- 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 +2 -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 +133 -0
- package/dist/templates/web/base/template/src/test/setup.ts +79 -0
- package/dist/templates/web/base/template/vitest.config.ts +17 -0
- package/dist/templates/web/ui-auth/template/package.json +14 -4
- package/dist/templates/web/ui-auth/template/src/app/error.tsx +67 -0
- package/dist/templates/web/ui-auth/template/src/app/layout.tsx +6 -2
- package/dist/templates/web/ui-auth/template/src/app/loading.tsx +20 -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 +6 -2
- 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 +2 -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 +133 -0
- package/dist/templates/web/ui-auth/template/src/test/setup.ts +79 -0
- package/dist/templates/web/ui-auth/template/vitest.config.ts +17 -0
- package/dist/templates/web/ui-auth-payments/template/middleware.ts +68 -0
- package/dist/templates/web/ui-auth-payments/template/package.json +14 -4
- 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/layout.tsx +6 -2
- 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/signup/loading.tsx +50 -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 +6 -2
- 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 +2 -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 +133 -0
- package/dist/templates/web/ui-auth-payments/template/src/test/setup.ts +79 -0
- package/dist/templates/web/ui-auth-payments/template/vitest.config.ts +17 -0
- package/dist/templates/web/ui-auth-payments-audio/template/package.json +14 -4
- 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/layout.tsx +8 -2
- 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/components/__tests__/example.test.tsx +49 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/components/providers/app-providers.tsx +6 -2
- 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 +2 -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/env.ts +49 -0
- package/dist/templates/web/ui-auth-payments-audio/template/src/lib/utils.ts +133 -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/vitest.config.ts +17 -0
- package/dist/templates/web/ui-auth-payments-video/template/package.json +14 -4
- 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/layout.tsx +6 -2
- 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/components/__tests__/example.test.tsx +49 -0
- package/dist/templates/web/ui-auth-payments-video/template/src/components/providers/app-providers.tsx +6 -2
- 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 +2 -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 +133 -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/vitest.config.ts +17 -0
- package/dist/templates/web/ui-only/template/package.json +14 -4
- package/dist/templates/web/ui-only/template/src/app/error.tsx +67 -0
- package/dist/templates/web/ui-only/template/src/app/layout.tsx +6 -2
- package/dist/templates/web/ui-only/template/src/app/loading.tsx +20 -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 +6 -2
- 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 +2 -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 +133 -0
- package/dist/templates/web/ui-only/template/src/test/setup.ts +79 -0
- package/dist/templates/web/ui-only/template/vitest.config.ts +17 -0
- package/package.json +1 -1
- package/src/templates/web/base/template/package.json +20 -10
- package/src/templates/web/base/template/src/app/error.tsx +97 -0
- package/src/templates/web/base/template/src/app/layout.tsx +8 -2
- package/src/templates/web/base/template/src/app/loading.tsx +34 -0
- package/src/templates/web/base/template/src/components/__tests__/example.test.tsx +49 -0
- package/src/templates/web/base/template/src/components/providers/app-providers.tsx +6 -2
- package/src/templates/web/base/template/src/components/providers/theme-provider.tsx +94 -0
- package/src/templates/web/base/template/src/components/shared/footer.tsx +36 -0
- package/src/templates/web/base/template/src/components/shared/header.tsx +2 -0
- package/src/templates/web/base/template/src/components/ui/theme-toggle.tsx +34 -0
- package/src/templates/web/base/template/src/lib/auth-server.ts +177 -0
- package/src/templates/web/base/template/src/lib/env.ts +46 -0
- package/src/templates/web/base/template/src/lib/utils.ts +133 -0
- package/src/templates/web/base/template/src/test/setup.ts +79 -0
- package/src/templates/web/base/template/vitest.config.ts +17 -0
- package/src/templates/web/ui-auth/template/package.json +14 -4
- package/src/templates/web/ui-auth/template/src/app/error.tsx +67 -0
- package/src/templates/web/ui-auth/template/src/app/layout.tsx +6 -2
- package/src/templates/web/ui-auth/template/src/app/loading.tsx +20 -0
- package/src/templates/web/ui-auth/template/src/components/__tests__/example.test.tsx +49 -0
- package/src/templates/web/ui-auth/template/src/components/providers/app-providers.tsx +6 -2
- package/src/templates/web/ui-auth/template/src/components/providers/theme-provider.tsx +94 -0
- package/src/templates/web/ui-auth/template/src/components/shared/footer.tsx +36 -0
- package/src/templates/web/ui-auth/template/src/components/shared/header.tsx +2 -0
- package/src/templates/web/ui-auth/template/src/components/ui/theme-toggle.tsx +34 -0
- package/src/templates/web/ui-auth/template/src/lib/env.ts +49 -0
- package/src/templates/web/ui-auth/template/src/lib/utils.ts +133 -0
- package/src/templates/web/ui-auth/template/src/test/setup.ts +79 -0
- package/src/templates/web/ui-auth/template/vitest.config.ts +17 -0
- package/src/templates/web/ui-auth-payments/template/middleware.ts +68 -0
- package/src/templates/web/ui-auth-payments/template/package.json +14 -4
- package/src/templates/web/ui-auth-payments/template/src/app/dashboard/layout.tsx +22 -0
- package/src/templates/web/ui-auth-payments/template/src/app/dashboard/page.tsx +183 -0
- package/src/templates/web/ui-auth-payments/template/src/app/error.tsx +67 -0
- package/src/templates/web/ui-auth-payments/template/src/app/layout.tsx +6 -2
- package/src/templates/web/ui-auth-payments/template/src/app/loading.tsx +20 -0
- package/src/templates/web/ui-auth-payments/template/src/app/login/loading.tsx +38 -0
- package/src/templates/web/ui-auth-payments/template/src/app/signup/loading.tsx +50 -0
- package/src/templates/web/ui-auth-payments/template/src/components/__tests__/example.test.tsx +49 -0
- package/src/templates/web/ui-auth-payments/template/src/components/client/auth-status.tsx +52 -0
- package/src/templates/web/ui-auth-payments/template/src/components/client/login-form.tsx +144 -0
- package/src/templates/web/ui-auth-payments/template/src/components/client/newsletter-signup.tsx +68 -0
- package/src/templates/web/ui-auth-payments/template/src/components/client/signup-form.tsx +185 -0
- package/src/templates/web/ui-auth-payments/template/src/components/providers/app-providers.tsx +6 -2
- package/src/templates/web/ui-auth-payments/template/src/components/providers/theme-provider.tsx +94 -0
- package/src/templates/web/ui-auth-payments/template/src/components/shared/footer.tsx +36 -0
- package/src/templates/web/ui-auth-payments/template/src/components/shared/header.tsx +2 -0
- package/src/templates/web/ui-auth-payments/template/src/components/ui/theme-toggle.tsx +34 -0
- package/src/templates/web/ui-auth-payments/template/src/lib/actions/auth.ts +246 -0
- package/src/templates/web/ui-auth-payments/template/src/lib/actions/index.ts +340 -0
- package/src/templates/web/ui-auth-payments/template/src/lib/auth-server.ts +177 -0
- package/src/templates/web/ui-auth-payments/template/src/lib/env.ts +49 -0
- package/src/templates/web/ui-auth-payments/template/src/lib/utils.ts +133 -0
- package/src/templates/web/ui-auth-payments/template/src/test/setup.ts +79 -0
- package/src/templates/web/ui-auth-payments/template/vitest.config.ts +17 -0
- package/src/templates/web/ui-auth-payments-audio/template/package.json +14 -4
- package/src/templates/web/ui-auth-payments-audio/template/src/app/error.tsx +67 -0
- package/src/templates/web/ui-auth-payments-audio/template/src/app/layout.tsx +8 -2
- package/src/templates/web/ui-auth-payments-audio/template/src/app/loading.tsx +20 -0
- package/src/templates/web/ui-auth-payments-audio/template/src/components/__tests__/example.test.tsx +49 -0
- package/src/templates/web/ui-auth-payments-audio/template/src/components/providers/app-providers.tsx +6 -2
- package/src/templates/web/ui-auth-payments-audio/template/src/components/providers/theme-provider.tsx +94 -0
- package/src/templates/web/ui-auth-payments-audio/template/src/components/shared/footer.tsx +36 -0
- package/src/templates/web/ui-auth-payments-audio/template/src/components/shared/header.tsx +2 -0
- package/src/templates/web/ui-auth-payments-audio/template/src/components/ui/theme-toggle.tsx +34 -0
- package/src/templates/web/ui-auth-payments-audio/template/src/lib/env.ts +49 -0
- package/src/templates/web/ui-auth-payments-audio/template/src/lib/utils.ts +133 -0
- package/src/templates/web/ui-auth-payments-audio/template/src/test/setup.ts +79 -0
- package/src/templates/web/ui-auth-payments-audio/template/vitest.config.ts +17 -0
- package/src/templates/web/ui-auth-payments-video/template/package.json +14 -4
- package/src/templates/web/ui-auth-payments-video/template/src/app/error.tsx +67 -0
- package/src/templates/web/ui-auth-payments-video/template/src/app/layout.tsx +6 -2
- package/src/templates/web/ui-auth-payments-video/template/src/app/loading.tsx +20 -0
- package/src/templates/web/ui-auth-payments-video/template/src/components/__tests__/example.test.tsx +49 -0
- package/src/templates/web/ui-auth-payments-video/template/src/components/providers/app-providers.tsx +6 -2
- package/src/templates/web/ui-auth-payments-video/template/src/components/providers/theme-provider.tsx +94 -0
- package/src/templates/web/ui-auth-payments-video/template/src/components/shared/footer.tsx +36 -0
- package/src/templates/web/ui-auth-payments-video/template/src/components/shared/header.tsx +2 -0
- package/src/templates/web/ui-auth-payments-video/template/src/components/ui/theme-toggle.tsx +34 -0
- package/src/templates/web/ui-auth-payments-video/template/src/lib/env.ts +49 -0
- package/src/templates/web/ui-auth-payments-video/template/src/lib/utils.ts +133 -0
- package/src/templates/web/ui-auth-payments-video/template/src/test/setup.ts +79 -0
- package/src/templates/web/ui-auth-payments-video/template/vitest.config.ts +17 -0
- package/src/templates/web/ui-only/template/package.json +14 -4
- package/src/templates/web/ui-only/template/src/app/error.tsx +67 -0
- package/src/templates/web/ui-only/template/src/app/layout.tsx +6 -2
- package/src/templates/web/ui-only/template/src/app/loading.tsx +20 -0
- package/src/templates/web/ui-only/template/src/components/__tests__/example.test.tsx +49 -0
- package/src/templates/web/ui-only/template/src/components/providers/app-providers.tsx +6 -2
- package/src/templates/web/ui-only/template/src/components/providers/theme-provider.tsx +94 -0
- package/src/templates/web/ui-only/template/src/components/shared/footer.tsx +36 -0
- package/src/templates/web/ui-only/template/src/components/shared/header.tsx +2 -0
- package/src/templates/web/ui-only/template/src/components/ui/theme-toggle.tsx +34 -0
- package/src/templates/web/ui-only/template/src/lib/env.ts +49 -0
- package/src/templates/web/ui-only/template/src/lib/utils.ts +133 -0
- package/src/templates/web/ui-only/template/src/test/setup.ts +79 -0
- package/src/templates/web/ui-only/template/vitest.config.ts +17 -0
|
@@ -1,7 +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
|
+
|
|
1
8
|
import { type ClassValue, clsx } from "clsx"
|
|
2
9
|
import { twMerge } from "tailwind-merge"
|
|
3
10
|
|
|
11
|
+
// Core utility function (keeps existing functionality)
|
|
4
12
|
export function cn(...inputs: ClassValue[]) {
|
|
5
13
|
return twMerge(clsx(inputs))
|
|
6
14
|
}
|
|
7
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
|
+
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import '@testing-library/jest-dom'
|
|
2
|
+
import { vi } from 'vitest'
|
|
3
|
+
|
|
4
|
+
// Mock Next.js router
|
|
5
|
+
vi.mock('next/navigation', () => ({
|
|
6
|
+
useRouter: () => ({
|
|
7
|
+
push: vi.fn(),
|
|
8
|
+
back: vi.fn(),
|
|
9
|
+
forward: vi.fn(),
|
|
10
|
+
refresh: vi.fn(),
|
|
11
|
+
replace: vi.fn(),
|
|
12
|
+
prefetch: vi.fn(),
|
|
13
|
+
}),
|
|
14
|
+
useSearchParams: () => new URLSearchParams(),
|
|
15
|
+
usePathname: () => '/',
|
|
16
|
+
}))
|
|
17
|
+
|
|
18
|
+
// Mock SaaS Factory Auth (optional - only if testing auth components)
|
|
19
|
+
vi.mock('@digilogiclabs/saas-factory-auth', () => ({
|
|
20
|
+
useAuth: () => ({
|
|
21
|
+
user: null,
|
|
22
|
+
loading: false,
|
|
23
|
+
error: null,
|
|
24
|
+
signIn: vi.fn(),
|
|
25
|
+
signUp: vi.fn(),
|
|
26
|
+
signOut: vi.fn(),
|
|
27
|
+
signInWithOAuth: vi.fn(),
|
|
28
|
+
}),
|
|
29
|
+
AuthProvider: ({ children }: { children: React.ReactNode }) => children,
|
|
30
|
+
}))
|
|
31
|
+
|
|
32
|
+
// Mock SaaS Factory Payments (optional - only if testing payment components)
|
|
33
|
+
vi.mock('@digilogiclabs/saas-factory-payments', () => ({
|
|
34
|
+
usePayments: () => ({
|
|
35
|
+
createCheckoutSession: vi.fn(),
|
|
36
|
+
createPortalSession: vi.fn(),
|
|
37
|
+
subscription: null,
|
|
38
|
+
loading: false,
|
|
39
|
+
}),
|
|
40
|
+
PaymentsProvider: ({ children }: { children: React.ReactNode }) => children,
|
|
41
|
+
}))
|
|
42
|
+
|
|
43
|
+
// Global test utilities
|
|
44
|
+
global.ResizeObserver = vi.fn().mockImplementation(() => ({
|
|
45
|
+
observe: vi.fn(),
|
|
46
|
+
unobserve: vi.fn(),
|
|
47
|
+
disconnect: vi.fn(),
|
|
48
|
+
}))
|
|
49
|
+
|
|
50
|
+
// Suppress console warnings in tests unless needed
|
|
51
|
+
const originalConsoleError = console.error
|
|
52
|
+
const originalConsoleWarn = console.warn
|
|
53
|
+
|
|
54
|
+
beforeEach(() => {
|
|
55
|
+
console.error = (...args: any[]) => {
|
|
56
|
+
if (
|
|
57
|
+
typeof args[0] === 'string' &&
|
|
58
|
+
args[0].includes('Warning: ReactDOM.render is no longer supported')
|
|
59
|
+
) {
|
|
60
|
+
return
|
|
61
|
+
}
|
|
62
|
+
originalConsoleError.call(console, ...args)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
console.warn = (...args: any[]) => {
|
|
66
|
+
if (
|
|
67
|
+
typeof args[0] === 'string' &&
|
|
68
|
+
args[0].includes('useLayoutEffect does nothing on the server')
|
|
69
|
+
) {
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
originalConsoleWarn.call(console, ...args)
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
afterAll(() => {
|
|
77
|
+
console.error = originalConsoleError
|
|
78
|
+
console.warn = originalConsoleWarn
|
|
79
|
+
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defineConfig } from 'vitest/config'
|
|
2
|
+
import react from '@vitejs/plugin-react'
|
|
3
|
+
import path from 'path'
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
plugins: [react()],
|
|
7
|
+
test: {
|
|
8
|
+
environment: 'jsdom',
|
|
9
|
+
setupFiles: ['./src/test/setup.ts'],
|
|
10
|
+
globals: true,
|
|
11
|
+
},
|
|
12
|
+
resolve: {
|
|
13
|
+
alias: {
|
|
14
|
+
'@': path.resolve(__dirname, './src'),
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
})
|
|
@@ -4,11 +4,14 @@
|
|
|
4
4
|
"description": "{{description}} (with UI Package v0.11.1 + Auth v1.0.0)",
|
|
5
5
|
"private": true,
|
|
6
6
|
"scripts": {
|
|
7
|
-
"dev": "next dev",
|
|
7
|
+
"dev": "next dev --turbo",
|
|
8
8
|
"build": "next build",
|
|
9
9
|
"start": "next start",
|
|
10
10
|
"lint": "next lint",
|
|
11
|
-
"type-check": "tsc --noEmit"
|
|
11
|
+
"type-check": "tsc --noEmit",
|
|
12
|
+
"test": "vitest",
|
|
13
|
+
"test:ui": "vitest --ui",
|
|
14
|
+
"test:run": "vitest run"
|
|
12
15
|
},
|
|
13
16
|
"dependencies": {
|
|
14
17
|
"next": "^15.0.0",
|
|
@@ -23,7 +26,8 @@
|
|
|
23
26
|
"class-variance-authority": "^0.7.0",
|
|
24
27
|
"tailwind-merge": "^2.0.0",
|
|
25
28
|
"next-themes": "^0.2.1",
|
|
26
|
-
"lucide-react": "^0.542.0"
|
|
29
|
+
"lucide-react": "^0.542.0",
|
|
30
|
+
"zod": "^3.22.4"
|
|
27
31
|
},
|
|
28
32
|
"devDependencies": {
|
|
29
33
|
"typescript": "^5.0.0",
|
|
@@ -32,7 +36,13 @@
|
|
|
32
36
|
"@types/react-dom": "^19.0.0",
|
|
33
37
|
"eslint": "^8.0.0",
|
|
34
38
|
"eslint-config-next": "^15.0.0",
|
|
35
|
-
"prettier": "^3.0.0"
|
|
39
|
+
"prettier": "^3.0.0",
|
|
40
|
+
"vitest": "^1.0.0",
|
|
41
|
+
"@vitejs/plugin-react": "^4.0.0",
|
|
42
|
+
"@testing-library/react": "^14.0.0",
|
|
43
|
+
"@testing-library/jest-dom": "^6.0.0",
|
|
44
|
+
"@testing-library/user-event": "^14.0.0",
|
|
45
|
+
"jsdom": "^24.0.0"
|
|
36
46
|
},
|
|
37
47
|
"engines": {
|
|
38
48
|
"node": ">=18.0.0"
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useEffect } from 'react'
|
|
4
|
+
import { Button, Card } from '@digilogiclabs/saas-factory-ui'
|
|
5
|
+
import { RefreshCw, Home, AlertCircle } from 'lucide-react'
|
|
6
|
+
|
|
7
|
+
interface ErrorProps {
|
|
8
|
+
error: Error & { digest?: string }
|
|
9
|
+
reset: () => void
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default function Error({ error, reset }: ErrorProps) {
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
// Log the error to an error reporting service
|
|
15
|
+
console.error('Application error:', error)
|
|
16
|
+
}, [error])
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<div className="min-h-screen bg-gray-50 dark:bg-gray-900 flex items-center justify-center p-4">
|
|
20
|
+
<Card className="w-full max-w-md p-8 text-center">
|
|
21
|
+
<div className="mb-6">
|
|
22
|
+
<div className="mx-auto w-16 h-16 bg-red-100 dark:bg-red-900 rounded-full flex items-center justify-center mb-4">
|
|
23
|
+
<AlertCircle className="h-8 w-8 text-red-600 dark:text-red-400" />
|
|
24
|
+
</div>
|
|
25
|
+
<h1 className="text-2xl font-bold text-gray-900 dark:text-white mb-2">
|
|
26
|
+
Something went wrong
|
|
27
|
+
</h1>
|
|
28
|
+
<p className="text-gray-600 dark:text-gray-300 mb-6">
|
|
29
|
+
We apologize for the inconvenience. Please try again or return to the home page.
|
|
30
|
+
</p>
|
|
31
|
+
</div>
|
|
32
|
+
|
|
33
|
+
<div className="space-y-3">
|
|
34
|
+
<Button
|
|
35
|
+
onClick={reset}
|
|
36
|
+
className="w-full"
|
|
37
|
+
variant="default"
|
|
38
|
+
>
|
|
39
|
+
<RefreshCw className="w-4 h-4 mr-2" />
|
|
40
|
+
Try Again
|
|
41
|
+
</Button>
|
|
42
|
+
|
|
43
|
+
<Button
|
|
44
|
+
onClick={() => window.location.href = '/'}
|
|
45
|
+
variant="outline"
|
|
46
|
+
className="w-full"
|
|
47
|
+
>
|
|
48
|
+
<Home className="w-4 h-4 mr-2" />
|
|
49
|
+
Go Home
|
|
50
|
+
</Button>
|
|
51
|
+
</div>
|
|
52
|
+
|
|
53
|
+
{process.env.NODE_ENV === 'development' && (
|
|
54
|
+
<details className="mt-6 text-left">
|
|
55
|
+
<summary className="text-sm font-medium text-gray-500 cursor-pointer hover:text-gray-700 dark:hover:text-gray-300">
|
|
56
|
+
Error Details (Development)
|
|
57
|
+
</summary>
|
|
58
|
+
<pre className="mt-2 text-xs bg-gray-100 dark:bg-gray-800 p-3 rounded-md overflow-auto">
|
|
59
|
+
{error.message}
|
|
60
|
+
{error.stack}
|
|
61
|
+
</pre>
|
|
62
|
+
</details>
|
|
63
|
+
)}
|
|
64
|
+
</Card>
|
|
65
|
+
</div>
|
|
66
|
+
)
|
|
67
|
+
}
|
|
@@ -3,6 +3,7 @@ import { Inter } from 'next/font/google'
|
|
|
3
3
|
import './globals.css'
|
|
4
4
|
import { AppProviders } from '@/components/providers/app-providers'
|
|
5
5
|
import { Header } from '@/components/shared/header'
|
|
6
|
+
import { Footer } from '@/components/shared/footer'
|
|
6
7
|
|
|
7
8
|
const inter = Inter({ subsets: ['latin'] })
|
|
8
9
|
|
|
@@ -18,10 +19,13 @@ export default function RootLayout({
|
|
|
18
19
|
}) {
|
|
19
20
|
return (
|
|
20
21
|
<html lang="en" suppressHydrationWarning>
|
|
21
|
-
<body className={inter.className}>
|
|
22
|
+
<body className={`${inter.className} min-h-screen flex flex-col`}>
|
|
22
23
|
<AppProviders>
|
|
23
24
|
<Header />
|
|
24
|
-
|
|
25
|
+
<main className="flex-1">
|
|
26
|
+
{children}
|
|
27
|
+
</main>
|
|
28
|
+
<Footer />
|
|
25
29
|
</AppProviders>
|
|
26
30
|
</body>
|
|
27
31
|
</html>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Card } from '@digilogiclabs/saas-factory-ui'
|
|
2
|
+
import { Loader2 } from 'lucide-react'
|
|
3
|
+
|
|
4
|
+
export default function Loading() {
|
|
5
|
+
return (
|
|
6
|
+
<div className="min-h-screen bg-gray-50 dark:bg-gray-900 flex items-center justify-center p-4">
|
|
7
|
+
<Card className="w-full max-w-md p-8 text-center">
|
|
8
|
+
<div className="flex flex-col items-center">
|
|
9
|
+
<Loader2 className="h-8 w-8 animate-spin text-blue-600 dark:text-blue-400 mb-4" />
|
|
10
|
+
<h2 className="text-lg font-medium text-gray-900 dark:text-white mb-2">
|
|
11
|
+
Loading
|
|
12
|
+
</h2>
|
|
13
|
+
<p className="text-sm text-gray-600 dark:text-gray-300">
|
|
14
|
+
Please wait while we load your content...
|
|
15
|
+
</p>
|
|
16
|
+
</div>
|
|
17
|
+
</Card>
|
|
18
|
+
</div>
|
|
19
|
+
)
|
|
20
|
+
}
|
|
@@ -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
|
+
})
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import React from 'react'
|
|
4
4
|
import { ThemeProvider } from 'next-themes'
|
|
5
5
|
import { AuthProvider } from '@digilogiclabs/saas-factory-auth'
|
|
6
|
+
import { AppThemeProvider } from './theme-provider'
|
|
6
7
|
|
|
7
8
|
interface AppProvidersProps {
|
|
8
9
|
children: React.ReactNode
|
|
@@ -12,12 +13,15 @@ export function AppProviders({ children }: AppProvidersProps) {
|
|
|
12
13
|
return (
|
|
13
14
|
<ThemeProvider
|
|
14
15
|
attribute="class"
|
|
15
|
-
defaultTheme="
|
|
16
|
+
defaultTheme="{{defaultTheme}}"
|
|
16
17
|
enableSystem
|
|
17
18
|
disableTransitionOnChange
|
|
19
|
+
storageKey="{{packageName}}-theme"
|
|
18
20
|
>
|
|
19
21
|
<AuthProvider>
|
|
20
|
-
{
|
|
22
|
+
<AppThemeProvider themeColor="{{themeColor}}">
|
|
23
|
+
{children}
|
|
24
|
+
</AppThemeProvider>
|
|
21
25
|
</AuthProvider>
|
|
22
26
|
</ThemeProvider>
|
|
23
27
|
)
|
|
@@ -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
|
+
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import Link from 'next/link';
|
|
5
5
|
import { LogOut } from 'lucide-react';
|
|
6
|
+
import { ThemeToggle } from '../ui/theme-toggle';
|
|
6
7
|
|
|
7
8
|
export function Header() {
|
|
8
9
|
const user = null; // Placeholder for auth state
|
|
@@ -18,6 +19,7 @@ export function Header() {
|
|
|
18
19
|
{{titleCaseName}}
|
|
19
20
|
</Link>
|
|
20
21
|
<nav className="flex items-center gap-4">
|
|
22
|
+
<ThemeToggle />
|
|
21
23
|
{user ? (
|
|
22
24
|
<>
|
|
23
25
|
<Link href="/dashboard" className="text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white">
|
|
@@ -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
|
+
}
|