create-reactivite 1.1.0 → 1.2.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/README.md +198 -197
- package/index.js +26 -1
- package/package.json +4 -3
- package/template/_gitignore +24 -0
- package/template2/.env.example +8 -0
- package/template2/.husky/pre-commit +4 -0
- package/template2/.prettierrc +5 -0
- package/template2/README.md +73 -0
- package/template2/__tests__/example.test.ts +20 -0
- package/template2/_gitignore +37 -0
- package/template2/app/[locale]/(private)/dashboard/page.tsx +52 -0
- package/template2/app/[locale]/(public)/login/page.tsx +83 -0
- package/template2/app/[locale]/layout.tsx +56 -0
- package/template2/app/[locale]/locales.ts +10 -0
- package/template2/app/[locale]/page.tsx +38 -0
- package/template2/app/api/clear-session/route.ts +10 -0
- package/template2/app/globals.css +127 -0
- package/template2/app/layout.tsx +7 -0
- package/template2/app/page.tsx +6 -0
- package/template2/components/AuthEventListener.tsx +22 -0
- package/template2/components/theme-provider.tsx +78 -0
- package/template2/components/ui/button.tsx +60 -0
- package/template2/components/ui/card.tsx +92 -0
- package/template2/components/ui/input.tsx +21 -0
- package/template2/components/ui/label.tsx +24 -0
- package/template2/components/ui/sonner.tsx +40 -0
- package/template2/components.json +22 -0
- package/template2/config/constants.ts +7 -0
- package/template2/config/env.ts +5 -0
- package/template2/contexts/translation-context.tsx +70 -0
- package/template2/eslint.config.mjs +18 -0
- package/template2/hoc/provider.tsx +27 -0
- package/template2/lib/paramsSerializer.ts +40 -0
- package/template2/lib/utils.ts +6 -0
- package/template2/locales/az.json +20 -0
- package/template2/locales/en.json +20 -0
- package/template2/next-env.d.ts +6 -0
- package/template2/next.config.ts +17 -0
- package/template2/orval.config.ts +66 -0
- package/template2/package.json +62 -0
- package/template2/pnpm-lock.yaml +6804 -0
- package/template2/postcss.config.mjs +7 -0
- package/template2/public/.gitkeep +0 -0
- package/template2/scripts/fix-generated-types.mjs +13 -0
- package/template2/services/generated/.gitkeep +2 -0
- package/template2/services/httpClient/httpClient.ts +70 -0
- package/template2/services/httpClient/orvalMutator.ts +10 -0
- package/template2/store/example-store.tsx +16 -0
- package/template2/store/user-store.tsx +29 -0
- package/template2/testing/msw/handlers/index.ts +6 -0
- package/template2/testing/msw/server.ts +4 -0
- package/template2/tsconfig.json +34 -0
- package/template2/tsconfig.tsbuildinfo +1 -0
- package/template2/vitest.config.ts +17 -0
- package/template2/vitest.setup.ts +7 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useEffect } from 'react';
|
|
4
|
+
import { useRouter, useParams } from 'next/navigation';
|
|
5
|
+
import { Button } from '@/components/ui/button';
|
|
6
|
+
import {
|
|
7
|
+
Card,
|
|
8
|
+
CardContent,
|
|
9
|
+
CardDescription,
|
|
10
|
+
CardHeader,
|
|
11
|
+
CardTitle,
|
|
12
|
+
} from '@/components/ui/card';
|
|
13
|
+
import { useTranslations } from '@/contexts/translation-context';
|
|
14
|
+
import { useUserStore } from '@/store/user-store';
|
|
15
|
+
|
|
16
|
+
export default function DashboardPage() {
|
|
17
|
+
const t = useTranslations('dashboard');
|
|
18
|
+
const router = useRouter();
|
|
19
|
+
const { locale } = useParams<{ locale: string }>();
|
|
20
|
+
const user = useUserStore((s) => s.user);
|
|
21
|
+
const clearUser = useUserStore((s) => s.clearUser);
|
|
22
|
+
|
|
23
|
+
// Client-side guard. For a real app prefer a server check via cookies.
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (!user) router.replace(`/${locale}/login`);
|
|
26
|
+
}, [user, router, locale]);
|
|
27
|
+
|
|
28
|
+
if (!user) return null;
|
|
29
|
+
|
|
30
|
+
const logout = () => {
|
|
31
|
+
clearUser();
|
|
32
|
+
router.replace(`/${locale}/login`);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<main className="flex min-h-screen items-center justify-center p-6">
|
|
37
|
+
<Card className="w-full max-w-xl">
|
|
38
|
+
<CardHeader>
|
|
39
|
+
<CardTitle>{t('title')}</CardTitle>
|
|
40
|
+
<CardDescription>
|
|
41
|
+
{t('welcome')}, {user.email}
|
|
42
|
+
</CardDescription>
|
|
43
|
+
</CardHeader>
|
|
44
|
+
<CardContent>
|
|
45
|
+
<Button variant="outline" onClick={logout}>
|
|
46
|
+
{t('logout')}
|
|
47
|
+
</Button>
|
|
48
|
+
</CardContent>
|
|
49
|
+
</Card>
|
|
50
|
+
</main>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useForm } from 'react-hook-form';
|
|
4
|
+
import { zodResolver } from '@hookform/resolvers/zod';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { useRouter, useParams } from 'next/navigation';
|
|
7
|
+
import { toast } from 'sonner';
|
|
8
|
+
import { Button } from '@/components/ui/button';
|
|
9
|
+
import { Input } from '@/components/ui/input';
|
|
10
|
+
import { Label } from '@/components/ui/label';
|
|
11
|
+
import {
|
|
12
|
+
Card,
|
|
13
|
+
CardContent,
|
|
14
|
+
CardHeader,
|
|
15
|
+
CardTitle,
|
|
16
|
+
} from '@/components/ui/card';
|
|
17
|
+
import { useTranslations } from '@/contexts/translation-context';
|
|
18
|
+
import { useUserStore } from '@/store/user-store';
|
|
19
|
+
|
|
20
|
+
const schema = z.object({
|
|
21
|
+
email: z.string().email(),
|
|
22
|
+
password: z.string().min(6),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
type FormValues = z.infer<typeof schema>;
|
|
26
|
+
|
|
27
|
+
export default function LoginPage() {
|
|
28
|
+
const t = useTranslations('login');
|
|
29
|
+
const router = useRouter();
|
|
30
|
+
const { locale } = useParams<{ locale: string }>();
|
|
31
|
+
const setUser = useUserStore((s) => s.setUser);
|
|
32
|
+
|
|
33
|
+
const {
|
|
34
|
+
register,
|
|
35
|
+
handleSubmit,
|
|
36
|
+
formState: { errors, isSubmitting },
|
|
37
|
+
} = useForm<FormValues>({ resolver: zodResolver(schema) });
|
|
38
|
+
|
|
39
|
+
// Demo only: replace with a real orval-generated mutation.
|
|
40
|
+
const onSubmit = async (values: FormValues) => {
|
|
41
|
+
setUser({ id: 'demo', email: values.email });
|
|
42
|
+
toast.success(t('success'));
|
|
43
|
+
router.push(`/${locale}/dashboard`);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<main className="flex min-h-screen items-center justify-center p-6">
|
|
48
|
+
<Card className="w-full max-w-sm">
|
|
49
|
+
<CardHeader>
|
|
50
|
+
<CardTitle>{t('title')}</CardTitle>
|
|
51
|
+
</CardHeader>
|
|
52
|
+
<CardContent>
|
|
53
|
+
<form
|
|
54
|
+
onSubmit={handleSubmit(onSubmit)}
|
|
55
|
+
className="flex flex-col gap-4"
|
|
56
|
+
>
|
|
57
|
+
<div className="flex flex-col gap-2">
|
|
58
|
+
<Label htmlFor="email">{t('email')}</Label>
|
|
59
|
+
<Input id="email" type="email" {...register('email')} />
|
|
60
|
+
{errors.email && (
|
|
61
|
+
<p className="text-destructive text-sm">
|
|
62
|
+
{errors.email.message}
|
|
63
|
+
</p>
|
|
64
|
+
)}
|
|
65
|
+
</div>
|
|
66
|
+
<div className="flex flex-col gap-2">
|
|
67
|
+
<Label htmlFor="password">{t('password')}</Label>
|
|
68
|
+
<Input id="password" type="password" {...register('password')} />
|
|
69
|
+
{errors.password && (
|
|
70
|
+
<p className="text-destructive text-sm">
|
|
71
|
+
{errors.password.message}
|
|
72
|
+
</p>
|
|
73
|
+
)}
|
|
74
|
+
</div>
|
|
75
|
+
<Button type="submit" disabled={isSubmitting}>
|
|
76
|
+
{t('submit')}
|
|
77
|
+
</Button>
|
|
78
|
+
</form>
|
|
79
|
+
</CardContent>
|
|
80
|
+
</Card>
|
|
81
|
+
</main>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { Metadata } from 'next';
|
|
3
|
+
import { Geist } from 'next/font/google';
|
|
4
|
+
import { Suspense } from 'react';
|
|
5
|
+
import { notFound } from 'next/navigation';
|
|
6
|
+
import '../globals.css';
|
|
7
|
+
import { ThemeProvider } from '@/components/theme-provider';
|
|
8
|
+
import { TranslationProvider } from '@/contexts/translation-context';
|
|
9
|
+
import { Toaster } from '@/components/ui/sonner';
|
|
10
|
+
import { QueryProvider } from '@/hoc/provider';
|
|
11
|
+
import { AuthEventListener } from '@/components/AuthEventListener';
|
|
12
|
+
import { LOCALES, type Locale } from '@/config/constants';
|
|
13
|
+
import { getDictionary } from './locales';
|
|
14
|
+
|
|
15
|
+
const geist = Geist({ subsets: ['latin'] });
|
|
16
|
+
|
|
17
|
+
export const metadata: Metadata = {
|
|
18
|
+
title: 'Nextivite',
|
|
19
|
+
description: 'Next.js boilerplate scaffolded by create-reactivite.',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export function generateStaticParams() {
|
|
23
|
+
return LOCALES.map((locale) => ({ locale }));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default async function LocaleLayout({
|
|
27
|
+
children,
|
|
28
|
+
params,
|
|
29
|
+
}: Readonly<{
|
|
30
|
+
children: React.ReactNode;
|
|
31
|
+
params: Promise<{ locale: string }>;
|
|
32
|
+
}>) {
|
|
33
|
+
const { locale } = await params;
|
|
34
|
+
|
|
35
|
+
if (!LOCALES.includes(locale as Locale)) {
|
|
36
|
+
notFound();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const messages = await getDictionary(locale as Locale);
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<html lang={locale} suppressHydrationWarning>
|
|
43
|
+
<body className={`${geist.className} font-sans antialiased`}>
|
|
44
|
+
<QueryProvider>
|
|
45
|
+
<ThemeProvider defaultMode="light" storageKey="app-theme">
|
|
46
|
+
<TranslationProvider locale={locale} messages={messages}>
|
|
47
|
+
<AuthEventListener />
|
|
48
|
+
<Suspense fallback={null}>{children}</Suspense>
|
|
49
|
+
</TranslationProvider>
|
|
50
|
+
<Toaster />
|
|
51
|
+
</ThemeProvider>
|
|
52
|
+
</QueryProvider>
|
|
53
|
+
</body>
|
|
54
|
+
</html>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
import type { Locale } from '@/config/constants';
|
|
3
|
+
|
|
4
|
+
const locales = {
|
|
5
|
+
az: () => import('../../locales/az.json').then((m) => m.default),
|
|
6
|
+
en: () => import('../../locales/en.json').then((m) => m.default),
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const getDictionary = async (locale: Locale) =>
|
|
10
|
+
locales[locale]?.() ?? locales.az();
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import Link from 'next/link';
|
|
2
|
+
import { Button } from '@/components/ui/button';
|
|
3
|
+
import {
|
|
4
|
+
Card,
|
|
5
|
+
CardContent,
|
|
6
|
+
CardDescription,
|
|
7
|
+
CardHeader,
|
|
8
|
+
CardTitle,
|
|
9
|
+
} from '@/components/ui/card';
|
|
10
|
+
import { getDictionary } from './locales';
|
|
11
|
+
import type { Locale } from '@/config/constants';
|
|
12
|
+
|
|
13
|
+
export default async function HomePage({
|
|
14
|
+
params,
|
|
15
|
+
}: Readonly<{ params: Promise<{ locale: Locale }> }>) {
|
|
16
|
+
const { locale } = await params;
|
|
17
|
+
const dict = await getDictionary(locale);
|
|
18
|
+
const t = dict.home;
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<main className="flex min-h-screen items-center justify-center p-6">
|
|
22
|
+
<Card className="w-full max-w-xl">
|
|
23
|
+
<CardHeader>
|
|
24
|
+
<CardTitle className="text-2xl">{t.title}</CardTitle>
|
|
25
|
+
<CardDescription>{t.subtitle}</CardDescription>
|
|
26
|
+
</CardHeader>
|
|
27
|
+
<CardContent className="flex flex-wrap gap-3">
|
|
28
|
+
<Button asChild>
|
|
29
|
+
<Link href={`/${locale}/login`}>{t.login}</Link>
|
|
30
|
+
</Button>
|
|
31
|
+
<Button asChild variant="outline">
|
|
32
|
+
<Link href={`/${locale}/dashboard`}>{t.dashboard}</Link>
|
|
33
|
+
</Button>
|
|
34
|
+
</CardContent>
|
|
35
|
+
</Card>
|
|
36
|
+
</main>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { NextResponse } from 'next/server';
|
|
2
|
+
|
|
3
|
+
// Clears the auth cookie(s) when the backend logout call fails or is skipped.
|
|
4
|
+
// Add the cookie names your backend sets.
|
|
5
|
+
export async function POST() {
|
|
6
|
+
const res = NextResponse.json({ ok: true });
|
|
7
|
+
res.cookies.delete('access_token');
|
|
8
|
+
res.cookies.delete('refresh_token');
|
|
9
|
+
return res;
|
|
10
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
@import "tailwindcss";
|
|
2
|
+
@import "tw-animate-css";
|
|
3
|
+
|
|
4
|
+
@custom-variant dark (&:is(.dark *));
|
|
5
|
+
|
|
6
|
+
:root,
|
|
7
|
+
.default {
|
|
8
|
+
--background: oklch(0.99 0 0);
|
|
9
|
+
--foreground: oklch(0.15 0 0);
|
|
10
|
+
--card: oklch(1 0 0);
|
|
11
|
+
--card-foreground: oklch(0.15 0 0);
|
|
12
|
+
--popover: oklch(1 0 0);
|
|
13
|
+
--popover-foreground: oklch(0.15 0 0);
|
|
14
|
+
--primary: oklch(0.55 0.18 250);
|
|
15
|
+
--primary-foreground: oklch(0.99 0 0);
|
|
16
|
+
--secondary: oklch(0.96 0 0);
|
|
17
|
+
--secondary-foreground: oklch(0.15 0 0);
|
|
18
|
+
--muted: oklch(0.96 0.01 250);
|
|
19
|
+
--muted-foreground: oklch(0.5 0 0);
|
|
20
|
+
--accent: oklch(0.65 0.2 30);
|
|
21
|
+
--accent-foreground: oklch(0.99 0 0);
|
|
22
|
+
--destructive: oklch(0.577 0.245 27.325);
|
|
23
|
+
--destructive-foreground: oklch(0.99 0 0);
|
|
24
|
+
--border: oklch(0.9 0 0);
|
|
25
|
+
--input: oklch(0.9 0 0);
|
|
26
|
+
--ring: oklch(0.55 0.18 250);
|
|
27
|
+
--chart-1: oklch(0.55 0.18 250);
|
|
28
|
+
--chart-2: oklch(0.65 0.2 30);
|
|
29
|
+
--chart-3: oklch(0.6 0.15 180);
|
|
30
|
+
--chart-4: oklch(0.7 0.18 320);
|
|
31
|
+
--chart-5: oklch(0.65 0.16 140);
|
|
32
|
+
--radius: 0.75rem;
|
|
33
|
+
--sidebar: oklch(0.99 0 0);
|
|
34
|
+
--sidebar-foreground: oklch(0.15 0 0);
|
|
35
|
+
--sidebar-primary: oklch(0.55 0.18 250);
|
|
36
|
+
--sidebar-primary-foreground: oklch(0.99 0 0);
|
|
37
|
+
--sidebar-accent: oklch(0.96 0 0);
|
|
38
|
+
--sidebar-accent-foreground: oklch(0.15 0 0);
|
|
39
|
+
--sidebar-border: oklch(0.9 0 0);
|
|
40
|
+
--sidebar-ring: oklch(0.55 0.18 250);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.dark {
|
|
44
|
+
--background: oklch(0.12 0 0);
|
|
45
|
+
--foreground: oklch(0.98 0 0);
|
|
46
|
+
--card: oklch(0.15 0 0);
|
|
47
|
+
--card-foreground: oklch(0.98 0 0);
|
|
48
|
+
--popover: oklch(0.15 0 0);
|
|
49
|
+
--popover-foreground: oklch(0.98 0 0);
|
|
50
|
+
--primary: oklch(0.65 0.2 250);
|
|
51
|
+
--primary-foreground: oklch(0.12 0 0);
|
|
52
|
+
--secondary: oklch(0.2 0 0);
|
|
53
|
+
--secondary-foreground: oklch(0.98 0 0);
|
|
54
|
+
--muted: oklch(0.2 0.01 250);
|
|
55
|
+
--muted-foreground: oklch(0.6 0 0);
|
|
56
|
+
--accent: oklch(0.7 0.22 30);
|
|
57
|
+
--accent-foreground: oklch(0.12 0 0);
|
|
58
|
+
--destructive: oklch(0.5 0.2 27);
|
|
59
|
+
--destructive-foreground: oklch(0.98 0 0);
|
|
60
|
+
--border: oklch(0.25 0 0);
|
|
61
|
+
--input: oklch(0.25 0 0);
|
|
62
|
+
--ring: oklch(0.65 0.2 250);
|
|
63
|
+
--chart-1: oklch(0.65 0.2 250);
|
|
64
|
+
--chart-2: oklch(0.7 0.22 30);
|
|
65
|
+
--chart-3: oklch(0.6 0.15 180);
|
|
66
|
+
--chart-4: oklch(0.7 0.18 320);
|
|
67
|
+
--chart-5: oklch(0.65 0.16 140);
|
|
68
|
+
--sidebar: oklch(0.15 0 0);
|
|
69
|
+
--sidebar-foreground: oklch(0.98 0 0);
|
|
70
|
+
--sidebar-primary: oklch(0.65 0.2 250);
|
|
71
|
+
--sidebar-primary-foreground: oklch(0.12 0 0);
|
|
72
|
+
--sidebar-accent: oklch(0.2 0 0);
|
|
73
|
+
--sidebar-accent-foreground: oklch(0.98 0 0);
|
|
74
|
+
--sidebar-border: oklch(0.25 0 0);
|
|
75
|
+
--sidebar-ring: oklch(0.65 0.2 250);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@theme inline {
|
|
79
|
+
--font-sans: "Geist", "Geist Fallback";
|
|
80
|
+
--font-mono: "Geist Mono", "Geist Mono Fallback";
|
|
81
|
+
--color-background: var(--background);
|
|
82
|
+
--color-foreground: var(--foreground);
|
|
83
|
+
--color-card: var(--card);
|
|
84
|
+
--color-card-foreground: var(--card-foreground);
|
|
85
|
+
--color-popover: var(--popover);
|
|
86
|
+
--color-popover-foreground: var(--popover-foreground);
|
|
87
|
+
--color-primary: var(--primary);
|
|
88
|
+
--color-primary-foreground: var(--primary-foreground);
|
|
89
|
+
--color-secondary: var(--secondary);
|
|
90
|
+
--color-secondary-foreground: var(--secondary-foreground);
|
|
91
|
+
--color-muted: var(--muted);
|
|
92
|
+
--color-muted-foreground: var(--muted-foreground);
|
|
93
|
+
--color-accent: var(--accent);
|
|
94
|
+
--color-accent-foreground: var(--accent-foreground);
|
|
95
|
+
--color-destructive: var(--destructive);
|
|
96
|
+
--color-destructive-foreground: var(--destructive-foreground);
|
|
97
|
+
--color-border: var(--border);
|
|
98
|
+
--color-input: var(--input);
|
|
99
|
+
--color-ring: var(--ring);
|
|
100
|
+
--color-chart-1: var(--chart-1);
|
|
101
|
+
--color-chart-2: var(--chart-2);
|
|
102
|
+
--color-chart-3: var(--chart-3);
|
|
103
|
+
--color-chart-4: var(--chart-4);
|
|
104
|
+
--color-chart-5: var(--chart-5);
|
|
105
|
+
--radius-sm: calc(var(--radius) - 4px);
|
|
106
|
+
--radius-md: calc(var(--radius) - 2px);
|
|
107
|
+
--radius-lg: var(--radius);
|
|
108
|
+
--radius-xl: calc(var(--radius) + 4px);
|
|
109
|
+
--color-sidebar: var(--sidebar);
|
|
110
|
+
--color-sidebar-foreground: var(--sidebar-foreground);
|
|
111
|
+
--color-sidebar-primary: var(--sidebar-primary);
|
|
112
|
+
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
|
|
113
|
+
--color-sidebar-accent: var(--sidebar-accent);
|
|
114
|
+
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
|
|
115
|
+
--color-sidebar-border: var(--sidebar-border);
|
|
116
|
+
--color-sidebar-ring: var(--sidebar-ring);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
@layer base {
|
|
120
|
+
* {
|
|
121
|
+
@apply border-border outline-ring/50;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
body {
|
|
125
|
+
@apply bg-background text-foreground;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
// Root layout is a passthrough — the real <html>/<body> shell lives in
|
|
4
|
+
// app/[locale]/layout.tsx so every page is locale-scoped.
|
|
5
|
+
export default function RootLayout({ children }: { children: ReactNode }) {
|
|
6
|
+
return children;
|
|
7
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useEffect } from 'react';
|
|
4
|
+
import { usePathname } from 'next/navigation';
|
|
5
|
+
|
|
6
|
+
// Listens for the `auth:unauthorized` event dispatched by the axios interceptor
|
|
7
|
+
// (see services/httpClient/httpClient.ts) and bounces the user to /login.
|
|
8
|
+
export function AuthEventListener() {
|
|
9
|
+
const pathname = usePathname();
|
|
10
|
+
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
const locale = pathname.split('/')[1] || 'az';
|
|
13
|
+
const handler = async () => {
|
|
14
|
+
await fetch('/api/clear-session', { method: 'POST' }).catch(() => {});
|
|
15
|
+
window.location.href = `/${locale}/login`;
|
|
16
|
+
};
|
|
17
|
+
window.addEventListener('auth:unauthorized', handler);
|
|
18
|
+
return () => window.removeEventListener('auth:unauthorized', handler);
|
|
19
|
+
}, [pathname]);
|
|
20
|
+
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
|
|
5
|
+
type Mode = "dark" | "light";
|
|
6
|
+
|
|
7
|
+
type ThemeProviderProps = {
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
defaultMode?: Mode;
|
|
10
|
+
storageKey?: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
type ThemeProviderState = {
|
|
14
|
+
mode: Mode;
|
|
15
|
+
setMode: (mode: Mode) => void;
|
|
16
|
+
toggleMode: () => void;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const initialState: ThemeProviderState = {
|
|
20
|
+
mode: "light",
|
|
21
|
+
setMode: () => null,
|
|
22
|
+
toggleMode: () => null,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const ThemeProviderContext =
|
|
26
|
+
React.createContext<ThemeProviderState>(initialState);
|
|
27
|
+
|
|
28
|
+
export function ThemeProvider({
|
|
29
|
+
children,
|
|
30
|
+
defaultMode = "light",
|
|
31
|
+
storageKey = "app-theme",
|
|
32
|
+
...props
|
|
33
|
+
}: Readonly<ThemeProviderProps>) {
|
|
34
|
+
const [mode, setModeState] = React.useState<Mode>(() => {
|
|
35
|
+
if (typeof window !== "undefined") {
|
|
36
|
+
return (localStorage.getItem(`${storageKey}-mode`) as Mode) || defaultMode;
|
|
37
|
+
}
|
|
38
|
+
return defaultMode;
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
React.useEffect(() => {
|
|
42
|
+
const root = window.document.documentElement;
|
|
43
|
+
root.classList.remove("light", "dark");
|
|
44
|
+
root.classList.add(mode);
|
|
45
|
+
}, [mode]);
|
|
46
|
+
|
|
47
|
+
const setMode = React.useCallback(
|
|
48
|
+
(next: Mode) => {
|
|
49
|
+
localStorage.setItem(`${storageKey}-mode`, next);
|
|
50
|
+
setModeState(next);
|
|
51
|
+
},
|
|
52
|
+
[storageKey],
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const value = React.useMemo<ThemeProviderState>(
|
|
56
|
+
() => ({
|
|
57
|
+
mode,
|
|
58
|
+
setMode,
|
|
59
|
+
toggleMode: () => setMode(mode === "dark" ? "light" : "dark"),
|
|
60
|
+
}),
|
|
61
|
+
[mode, setMode],
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<ThemeProviderContext.Provider {...props} value={value}>
|
|
66
|
+
{children}
|
|
67
|
+
</ThemeProviderContext.Provider>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export const useTheme = () => {
|
|
72
|
+
const context = React.useContext(ThemeProviderContext);
|
|
73
|
+
|
|
74
|
+
if (context === undefined)
|
|
75
|
+
throw new Error("useTheme must be used within a ThemeProvider");
|
|
76
|
+
|
|
77
|
+
return context;
|
|
78
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { Slot } from "@radix-ui/react-slot"
|
|
3
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
4
|
+
|
|
5
|
+
import { cn } from "@/lib/utils"
|
|
6
|
+
|
|
7
|
+
const buttonVariants = cva(
|
|
8
|
+
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
|
9
|
+
{
|
|
10
|
+
variants: {
|
|
11
|
+
variant: {
|
|
12
|
+
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
13
|
+
destructive:
|
|
14
|
+
"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
|
15
|
+
outline:
|
|
16
|
+
"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
|
|
17
|
+
secondary:
|
|
18
|
+
"bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
19
|
+
ghost:
|
|
20
|
+
"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
|
21
|
+
link: "text-primary underline-offset-4 hover:underline",
|
|
22
|
+
},
|
|
23
|
+
size: {
|
|
24
|
+
default: "h-9 px-4 py-2 has-[>svg]:px-3",
|
|
25
|
+
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
|
|
26
|
+
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
|
27
|
+
icon: "size-9",
|
|
28
|
+
"icon-sm": "size-8",
|
|
29
|
+
"icon-lg": "size-10",
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
defaultVariants: {
|
|
33
|
+
variant: "default",
|
|
34
|
+
size: "default",
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
function Button({
|
|
40
|
+
className,
|
|
41
|
+
variant,
|
|
42
|
+
size,
|
|
43
|
+
asChild = false,
|
|
44
|
+
...props
|
|
45
|
+
}: React.ComponentProps<"button"> &
|
|
46
|
+
VariantProps<typeof buttonVariants> & {
|
|
47
|
+
asChild?: boolean
|
|
48
|
+
}) {
|
|
49
|
+
const Comp = asChild ? Slot : "button"
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<Comp
|
|
53
|
+
data-slot="button"
|
|
54
|
+
className={cn(buttonVariants({ variant, size, className }))}
|
|
55
|
+
{...props}
|
|
56
|
+
/>
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { Button, buttonVariants }
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
|
|
3
|
+
import { cn } from "@/lib/utils"
|
|
4
|
+
|
|
5
|
+
function Card({ className, ...props }: React.ComponentProps<"div">) {
|
|
6
|
+
return (
|
|
7
|
+
<div
|
|
8
|
+
data-slot="card"
|
|
9
|
+
className={cn(
|
|
10
|
+
"bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",
|
|
11
|
+
className
|
|
12
|
+
)}
|
|
13
|
+
{...props}
|
|
14
|
+
/>
|
|
15
|
+
)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
|
|
19
|
+
return (
|
|
20
|
+
<div
|
|
21
|
+
data-slot="card-header"
|
|
22
|
+
className={cn(
|
|
23
|
+
"@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-2 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",
|
|
24
|
+
className
|
|
25
|
+
)}
|
|
26
|
+
{...props}
|
|
27
|
+
/>
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
|
|
32
|
+
return (
|
|
33
|
+
<div
|
|
34
|
+
data-slot="card-title"
|
|
35
|
+
className={cn("leading-none font-semibold", className)}
|
|
36
|
+
{...props}
|
|
37
|
+
/>
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
|
|
42
|
+
return (
|
|
43
|
+
<div
|
|
44
|
+
data-slot="card-description"
|
|
45
|
+
className={cn("text-muted-foreground text-sm", className)}
|
|
46
|
+
{...props}
|
|
47
|
+
/>
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function CardAction({ className, ...props }: React.ComponentProps<"div">) {
|
|
52
|
+
return (
|
|
53
|
+
<div
|
|
54
|
+
data-slot="card-action"
|
|
55
|
+
className={cn(
|
|
56
|
+
"col-start-2 row-span-2 row-start-1 self-start justify-self-end",
|
|
57
|
+
className
|
|
58
|
+
)}
|
|
59
|
+
{...props}
|
|
60
|
+
/>
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function CardContent({ className, ...props }: React.ComponentProps<"div">) {
|
|
65
|
+
return (
|
|
66
|
+
<div
|
|
67
|
+
data-slot="card-content"
|
|
68
|
+
className={cn("px-6", className)}
|
|
69
|
+
{...props}
|
|
70
|
+
/>
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
|
|
75
|
+
return (
|
|
76
|
+
<div
|
|
77
|
+
data-slot="card-footer"
|
|
78
|
+
className={cn("flex items-center px-6 [.border-t]:pt-6", className)}
|
|
79
|
+
{...props}
|
|
80
|
+
/>
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export {
|
|
85
|
+
Card,
|
|
86
|
+
CardHeader,
|
|
87
|
+
CardFooter,
|
|
88
|
+
CardTitle,
|
|
89
|
+
CardAction,
|
|
90
|
+
CardDescription,
|
|
91
|
+
CardContent,
|
|
92
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
|
|
3
|
+
import { cn } from "@/lib/utils"
|
|
4
|
+
|
|
5
|
+
function Input({ className, type, ...props }: React.ComponentProps<"input">) {
|
|
6
|
+
return (
|
|
7
|
+
<input
|
|
8
|
+
type={type}
|
|
9
|
+
data-slot="input"
|
|
10
|
+
className={cn(
|
|
11
|
+
"file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
|
|
12
|
+
"focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]",
|
|
13
|
+
"aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
|
14
|
+
className
|
|
15
|
+
)}
|
|
16
|
+
{...props}
|
|
17
|
+
/>
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { Input }
|