create-mohit-next 1.0.0 → 2.0.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 +96 -65
- package/index.js +195 -195
- package/lib/features.js +358 -0
- package/lib/scaffold.js +471 -0
- package/package.json +10 -6
- package/templates/common/_editorconfig +12 -0
- package/templates/common/_gitattributes +5 -0
- package/templates/common/_github/dependabot.yml +14 -0
- package/templates/common/_github/workflows/ci.yml +66 -0
- package/templates/common/_husky/commit-msg +1 -0
- package/templates/common/_husky/pre-commit +1 -0
- package/templates/common/_nvmrc +1 -0
- package/{template → templates/common}/_prettierignore +4 -0
- package/templates/common/commitlint.config.mjs +10 -0
- package/templates/next/README.md +328 -0
- package/{template → templates/next}/_env.example +10 -1
- package/{template → templates/next}/_gitignore +8 -0
- package/templates/next/e2e/rbac.spec.ts +69 -0
- package/templates/next/e2e/server.mjs +35 -0
- package/{template → templates/next}/eslint.config.mjs +12 -0
- package/{template → templates/next}/next.config.ts +2 -0
- package/{template → templates/next}/package.json +18 -3
- package/templates/next/playwright.config.ts +30 -0
- package/templates/next/scripts/seed.ts +111 -0
- package/templates/next/src/app/(app)/admin/audit/page.tsx +99 -0
- package/templates/next/src/app/(app)/admin/page.tsx +92 -0
- package/{template → templates/next}/src/app/(app)/dashboard/page.tsx +22 -29
- package/{template → templates/next}/src/app/(app)/error.tsx +7 -7
- package/{template → templates/next}/src/app/(app)/layout.tsx +25 -2
- package/templates/next/src/app/(app)/reports/page.tsx +128 -0
- package/templates/next/src/app/(app)/settings/page.tsx +66 -0
- package/templates/next/src/app/(auth)/forgot-password/page.tsx +17 -0
- package/templates/next/src/app/(auth)/layout.tsx +18 -0
- package/{template → templates/next}/src/app/(auth)/register/page.tsx +2 -4
- package/templates/next/src/app/(auth)/reset-password/page.tsx +18 -0
- package/templates/next/src/app/api/account/password/route.ts +45 -0
- package/templates/next/src/app/api/account/route.ts +25 -0
- package/templates/next/src/app/api/account/sessions/route.ts +12 -0
- package/templates/next/src/app/api/admin/audit/route.ts +13 -0
- package/{template → templates/next}/src/app/api/admin/users/[id]/route.ts +25 -4
- package/templates/next/src/app/api/auth/forgot-password/route.ts +47 -0
- package/{template → templates/next}/src/app/api/auth/login/route.ts +19 -2
- package/{template → templates/next}/src/app/api/auth/me/route.ts +4 -2
- package/{template → templates/next}/src/app/api/auth/register/route.ts +38 -4
- package/templates/next/src/app/api/auth/resend-verification/route.ts +25 -0
- package/templates/next/src/app/api/auth/reset-password/route.ts +43 -0
- package/templates/next/src/app/api/auth/verify-email/route.ts +29 -0
- package/{template → templates/next}/src/app/forbidden/page.tsx +11 -13
- package/{template → templates/next}/src/app/layout.tsx +9 -6
- package/templates/next/src/app/not-found.tsx +20 -0
- package/templates/next/src/app/opengraph-image.tsx +49 -0
- package/templates/next/src/app/page.tsx +165 -0
- package/templates/next/src/app/robots.ts +15 -0
- package/templates/next/src/app/sitemap.ts +13 -0
- package/templates/next/src/app/verify-email/page.tsx +23 -0
- package/templates/next/src/components/admin/user-actions.tsx +124 -0
- package/templates/next/src/components/admin/users-data-table.tsx +221 -0
- package/templates/next/src/components/admin/users-table.tsx +67 -0
- package/{template → templates/next}/src/components/auth/auth-card.tsx +8 -8
- package/templates/next/src/components/auth/forgot-password-form.tsx +76 -0
- package/templates/next/src/components/auth/form-field.tsx +40 -0
- package/{template → templates/next}/src/components/auth/login-form.tsx +14 -9
- package/templates/next/src/components/auth/password-input.tsx +43 -0
- package/{template → templates/next}/src/components/auth/register-form.tsx +22 -19
- package/templates/next/src/components/auth/reset-password-form.tsx +80 -0
- package/{template → templates/next}/src/components/auth/session-refresher.tsx +1 -1
- package/templates/next/src/components/auth/verify-email-banner.tsx +43 -0
- package/templates/next/src/components/auth/verify-email-status.tsx +44 -0
- package/templates/next/src/components/layout/nav-links.tsx +37 -0
- package/templates/next/src/components/layout/navbar.tsx +27 -0
- package/templates/next/src/components/layout/page-header.tsx +21 -0
- package/templates/next/src/components/layout/sidebar.tsx +83 -0
- package/templates/next/src/components/layout/skeletons.tsx +57 -0
- package/templates/next/src/components/layout/user-menu.tsx +118 -0
- package/{template → templates/next}/src/components/logo.tsx +3 -6
- package/{template → templates/next}/src/components/reports/animated-bar.tsx +1 -5
- package/templates/next/src/components/reports/role-chart.tsx +61 -0
- package/templates/next/src/components/reports/signups-chart.tsx +64 -0
- package/templates/next/src/components/role-badge.tsx +11 -0
- package/templates/next/src/components/settings/password-form.tsx +80 -0
- package/templates/next/src/components/settings/profile-form.tsx +63 -0
- package/templates/next/src/components/settings/sessions-card.tsx +70 -0
- package/templates/next/src/components/theme-toggle.tsx +61 -0
- package/templates/next/src/config/rbac.test.ts +89 -0
- package/{template → templates/next}/src/config/rbac.ts +35 -5
- package/{template → templates/next}/src/lib/api.ts +40 -4
- package/templates/next/src/lib/audit.ts +66 -0
- package/{template → templates/next}/src/lib/auth.ts +10 -2
- package/{template → templates/next}/src/lib/dal.ts +8 -5
- package/templates/next/src/lib/email-templates.ts +55 -0
- package/templates/next/src/lib/email.ts +53 -0
- package/templates/next/src/lib/env.ts +90 -0
- package/templates/next/src/lib/password-strength.test.ts +20 -0
- package/templates/next/src/lib/password-strength.ts +24 -0
- package/templates/next/src/lib/rate-limit.test.ts +47 -0
- package/templates/next/src/lib/rate-limit.ts +70 -0
- package/templates/next/src/lib/redirect.test.ts +23 -0
- package/{template → templates/next}/src/lib/session.ts +5 -1
- package/templates/next/src/lib/theme.ts +32 -0
- package/templates/next/src/lib/tokens.ts +63 -0
- package/{template → templates/next}/src/lib/users.ts +49 -12
- package/templates/next/src/lib/validations/account.ts +20 -0
- package/templates/next/src/lib/validations/auth.test.ts +39 -0
- package/{template → templates/next}/src/lib/validations/auth.ts +24 -2
- package/templates/next/src/models/audit-log.ts +33 -0
- package/templates/next/src/models/auth-token.ts +26 -0
- package/{template → templates/next}/src/models/user.ts +5 -0
- package/{template → templates/next}/src/proxy.ts +1 -1
- package/templates/next/src/styles/app.css +1092 -0
- package/{template → templates/next}/src/types/user.ts +3 -0
- package/templates/next/vitest.config.mts +13 -0
- package/templates/styles/css.css +580 -0
- package/templates/styles/tailwind.css +140 -0
- package/templates/ui/css/components/alert-dialog.tsx +172 -0
- package/templates/ui/css/components/avatar.tsx +17 -0
- package/templates/ui/css/components/badge.tsx +18 -0
- package/templates/ui/css/components/button.tsx +41 -0
- package/templates/ui/css/components/card.tsx +33 -0
- package/templates/ui/css/components/dropdown-menu.tsx +230 -0
- package/templates/ui/css/components/input.tsx +7 -0
- package/templates/ui/css/components/label.tsx +7 -0
- package/templates/ui/css/components/native-select.tsx +23 -0
- package/templates/ui/css/components/skeleton.tsx +7 -0
- package/templates/ui/css/components/slot.tsx +30 -0
- package/templates/ui/css/components/table.tsx +31 -0
- package/templates/ui/css/utils.ts +16 -0
- package/templates/ui/shadcn/components/alert-dialog.tsx +199 -0
- package/templates/ui/shadcn/components/avatar.tsx +111 -0
- package/templates/ui/shadcn/components/dropdown-menu.tsx +268 -0
- package/templates/ui/shadcn/components/table.tsx +115 -0
- package/templates/ui/tailwind/components/alert-dialog.tsx +177 -0
- package/templates/ui/tailwind/components/avatar.tsx +36 -0
- package/templates/ui/tailwind/components/badge.tsx +29 -0
- package/templates/ui/tailwind/components/button.tsx +65 -0
- package/templates/ui/tailwind/components/card.tsx +70 -0
- package/templates/ui/tailwind/components/dropdown-menu.tsx +236 -0
- package/templates/ui/tailwind/components/input.tsx +17 -0
- package/templates/ui/tailwind/components/label.tsx +16 -0
- package/templates/ui/tailwind/components/native-select.tsx +32 -0
- package/templates/ui/tailwind/components/skeleton.tsx +13 -0
- package/templates/ui/tailwind/components/slot.tsx +34 -0
- package/templates/ui/tailwind/components/table.tsx +56 -0
- package/templates/ui/tailwind/utils.ts +1 -0
- package/templates/vite/Dockerfile +29 -0
- package/templates/vite/README.md +142 -0
- package/templates/vite/_dockerignore +14 -0
- package/templates/vite/_env.example +8 -0
- package/templates/vite/_gitignore +37 -0
- package/templates/vite/e2e/app.spec.ts +41 -0
- package/templates/vite/index.html +32 -0
- package/templates/vite/nginx.conf +26 -0
- package/templates/vite/package.json +61 -0
- package/templates/vite/playwright.config.ts +27 -0
- package/templates/vite/public/favicon.svg +1 -0
- package/templates/vite/src/App.test.tsx +28 -0
- package/templates/vite/src/App.tsx +26 -0
- package/templates/vite/src/components/home.tsx +121 -0
- package/templates/vite/src/components/layout/root-layout.tsx +18 -0
- package/templates/vite/src/components/layout/site-footer.tsx +10 -0
- package/templates/vite/src/components/layout/site-header.tsx +49 -0
- package/templates/vite/src/components/theme-toggle.tsx +90 -0
- package/templates/vite/src/env.ts +36 -0
- package/templates/vite/src/lib/theme.ts +26 -0
- package/templates/vite/src/main.tsx +13 -0
- package/templates/vite/src/pages/about.tsx +52 -0
- package/templates/vite/src/pages/not-found.tsx +33 -0
- package/templates/vite/src/router.ts +24 -0
- package/templates/vite/src/styles/app.css +281 -0
- package/templates/vite/src/test/setup.ts +21 -0
- package/templates/vite/tsconfig.app.json +31 -0
- package/templates/vite/tsconfig.json +7 -0
- package/templates/vite/tsconfig.node.json +23 -0
- package/templates/vite/vite.config.ts +30 -0
- package/template/README.md +0 -262
- package/template/_prettierrc +0 -9
- package/template/components.json +0 -25
- package/template/src/app/(app)/admin/page.tsx +0 -53
- package/template/src/app/(app)/reports/page.tsx +0 -109
- package/template/src/app/(auth)/layout.tsx +0 -22
- package/template/src/app/not-found.tsx +0 -18
- package/template/src/app/page.tsx +0 -187
- package/template/src/components/admin/users-table.tsx +0 -162
- package/template/src/components/auth/form-field.tsx +0 -32
- package/template/src/components/layout/logout-button.tsx +0 -34
- package/template/src/components/layout/navbar.tsx +0 -67
- package/template/src/components/layout/page-header.tsx +0 -21
- package/template/src/components/layout/skeletons.tsx +0 -35
- package/template/src/components/role-badge.tsx +0 -17
- package/template/src/components/theme-toggle.tsx +0 -25
- package/template/src/lib/env.ts +0 -36
- package/template/src/lib/theme.ts +0 -8
- /package/{template → templates/next}/AGENTS.md +0 -0
- /package/{template → templates/next}/Dockerfile +0 -0
- /package/{template → templates/next}/_dockerignore +0 -0
- /package/{template → templates/next}/docker-compose.yml +0 -0
- /package/{template → templates/next}/public/robots.txt +0 -0
- /package/{template → templates/next}/src/app/(app)/loading.tsx +0 -0
- /package/{template → templates/next}/src/app/(auth)/login/page.tsx +0 -0
- /package/{template → templates/next}/src/app/api/admin/users/route.ts +0 -0
- /package/{template → templates/next}/src/app/api/auth/logout/route.ts +0 -0
- /package/{template → templates/next}/src/app/api/health/route.ts +0 -0
- /package/{template → templates/next}/src/app/favicon.ico +0 -0
- /package/{template → templates/next}/src/components/auth/can.tsx +0 -0
- /package/{template → templates/next}/src/components/motion/fade-in.tsx +0 -0
- /package/{template → templates/next}/src/components/providers/user-provider.tsx +0 -0
- /package/{template → templates/next}/src/config/site.ts +0 -0
- /package/{template → templates/next}/src/lib/db.ts +0 -0
- /package/{template → templates/next}/src/lib/http.ts +0 -0
- /package/{template → templates/next}/src/lib/redirect.ts +0 -0
- /package/{template → templates/next}/src/lib/validations/user.ts +0 -0
- /package/{template → templates/next}/tsconfig.json +0 -0
- /package/{template/src/app/globals.css → templates/styles/shadcn.css} +0 -0
- /package/{template/src/components/ui → templates/ui/shadcn/components}/badge.tsx +0 -0
- /package/{template/src/components/ui → templates/ui/shadcn/components}/button.tsx +0 -0
- /package/{template/src/components/ui → templates/ui/shadcn/components}/card.tsx +0 -0
- /package/{template/src/components/ui → templates/ui/shadcn/components}/input.tsx +0 -0
- /package/{template/src/components/ui → templates/ui/shadcn/components}/label.tsx +0 -0
- /package/{template/src/components/ui → templates/ui/shadcn/components}/native-select.tsx +0 -0
- /package/{template/src/components/ui → templates/ui/shadcn/components}/skeleton.tsx +0 -0
- /package/{template/src/lib → templates/ui/shadcn}/utils.ts +0 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Skeleton } from "@/components/ui/skeleton";
|
|
2
|
+
|
|
3
|
+
export function PageSkeleton() {
|
|
4
|
+
return (
|
|
5
|
+
<div className="stack-lg" aria-busy="true" aria-label="Loading">
|
|
6
|
+
<div className="stack-sm">
|
|
7
|
+
<Skeleton className="skeleton-title" />
|
|
8
|
+
<Skeleton className="skeleton-line" />
|
|
9
|
+
</div>
|
|
10
|
+
<div className="cards-grid cards-grid--3">
|
|
11
|
+
<Skeleton className="skeleton-card" />
|
|
12
|
+
<Skeleton className="skeleton-card" />
|
|
13
|
+
<Skeleton className="skeleton-card" />
|
|
14
|
+
</div>
|
|
15
|
+
<Skeleton className="skeleton-panel" />
|
|
16
|
+
</div>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Static fallback shown while the authenticated shell streams in. */
|
|
21
|
+
export function ShellSkeleton() {
|
|
22
|
+
return (
|
|
23
|
+
// @feature sidebar
|
|
24
|
+
<div className="sidebar-layout">
|
|
25
|
+
<aside className="sidebar sidebar--skeleton" aria-hidden>
|
|
26
|
+
<Skeleton className="skeleton-logo" />
|
|
27
|
+
<div className="stack-sm">
|
|
28
|
+
<Skeleton className="skeleton-nav" />
|
|
29
|
+
<Skeleton className="skeleton-nav" />
|
|
30
|
+
<Skeleton className="skeleton-nav" />
|
|
31
|
+
</div>
|
|
32
|
+
</aside>
|
|
33
|
+
<div className="sidebar-main">
|
|
34
|
+
<div className="sidebar-topbar" />
|
|
35
|
+
<main className="sidebar-content">
|
|
36
|
+
<div className="page-container">
|
|
37
|
+
<PageSkeleton />
|
|
38
|
+
</div>
|
|
39
|
+
</main>
|
|
40
|
+
</div>
|
|
41
|
+
</div>
|
|
42
|
+
// @end sidebar
|
|
43
|
+
// @feature !sidebar
|
|
44
|
+
<>
|
|
45
|
+
<div className="app-header">
|
|
46
|
+
<div className="app-header-inner">
|
|
47
|
+
<Skeleton className="skeleton-logo" />
|
|
48
|
+
<Skeleton className="skeleton-nav-row" />
|
|
49
|
+
</div>
|
|
50
|
+
</div>
|
|
51
|
+
<main className="app-main">
|
|
52
|
+
<PageSkeleton />
|
|
53
|
+
</main>
|
|
54
|
+
</>
|
|
55
|
+
// @end !sidebar
|
|
56
|
+
);
|
|
57
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
ChevronsUpDown,
|
|
5
|
+
LayoutDashboard,
|
|
6
|
+
LoaderCircle,
|
|
7
|
+
LogOut,
|
|
8
|
+
// @feature profile
|
|
9
|
+
Settings,
|
|
10
|
+
// @end profile
|
|
11
|
+
} from "lucide-react";
|
|
12
|
+
import Link from "next/link";
|
|
13
|
+
import { useRouter } from "next/navigation";
|
|
14
|
+
import { useState } from "react";
|
|
15
|
+
import { toast } from "sonner";
|
|
16
|
+
|
|
17
|
+
import { useUser } from "@/components/providers/user-provider";
|
|
18
|
+
import { RoleBadge } from "@/components/role-badge";
|
|
19
|
+
import { Avatar, AvatarFallback } from "@/components/ui/avatar";
|
|
20
|
+
import { Button } from "@/components/ui/button";
|
|
21
|
+
import {
|
|
22
|
+
DropdownMenu,
|
|
23
|
+
DropdownMenuContent,
|
|
24
|
+
DropdownMenuGroup,
|
|
25
|
+
DropdownMenuItem,
|
|
26
|
+
DropdownMenuLabel,
|
|
27
|
+
DropdownMenuSeparator,
|
|
28
|
+
DropdownMenuTrigger,
|
|
29
|
+
} from "@/components/ui/dropdown-menu";
|
|
30
|
+
import { apiFetch, getErrorMessage } from "@/lib/http";
|
|
31
|
+
import { cn } from "@/lib/utils";
|
|
32
|
+
|
|
33
|
+
export function initials(name: string) {
|
|
34
|
+
const parts = name.trim().split(/\s+/);
|
|
35
|
+
return ((parts[0]?.[0] ?? "") + (parts.length > 1 ? (parts.at(-1)?.[0] ?? "") : "")).toUpperCase();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Avatar button with the account dropdown (profile links + sign out). */
|
|
39
|
+
export function UserMenu({
|
|
40
|
+
side = "bottom",
|
|
41
|
+
showName = false,
|
|
42
|
+
className,
|
|
43
|
+
}: {
|
|
44
|
+
side?: "top" | "bottom";
|
|
45
|
+
/** Show the name next to the avatar (used in the sidebar). */
|
|
46
|
+
showName?: boolean;
|
|
47
|
+
className?: string;
|
|
48
|
+
}) {
|
|
49
|
+
const user = useUser();
|
|
50
|
+
const router = useRouter();
|
|
51
|
+
const [signingOut, setSigningOut] = useState(false);
|
|
52
|
+
|
|
53
|
+
async function signOut() {
|
|
54
|
+
setSigningOut(true);
|
|
55
|
+
try {
|
|
56
|
+
await apiFetch("/api/auth/logout", { method: "POST" });
|
|
57
|
+
toast.success("Signed out");
|
|
58
|
+
router.replace("/login");
|
|
59
|
+
router.refresh();
|
|
60
|
+
} catch (error) {
|
|
61
|
+
toast.error(getErrorMessage(error, "Could not sign out"));
|
|
62
|
+
setSigningOut(false);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<DropdownMenu>
|
|
68
|
+
<DropdownMenuTrigger asChild>
|
|
69
|
+
<Button
|
|
70
|
+
variant="ghost"
|
|
71
|
+
className={cn("user-menu-trigger", showName && "user-menu-trigger--wide", className)}
|
|
72
|
+
aria-label="Account menu"
|
|
73
|
+
>
|
|
74
|
+
<Avatar size="sm">
|
|
75
|
+
<AvatarFallback>{initials(user.name)}</AvatarFallback>
|
|
76
|
+
</Avatar>
|
|
77
|
+
{showName && (
|
|
78
|
+
<>
|
|
79
|
+
<span className="user-menu-name">
|
|
80
|
+
<span>{user.name}</span>
|
|
81
|
+
<span className="muted text-xs">{user.email}</span>
|
|
82
|
+
</span>
|
|
83
|
+
<ChevronsUpDown className="muted" />
|
|
84
|
+
</>
|
|
85
|
+
)}
|
|
86
|
+
</Button>
|
|
87
|
+
</DropdownMenuTrigger>
|
|
88
|
+
<DropdownMenuContent align="end" side={side} className="user-menu-content">
|
|
89
|
+
<DropdownMenuLabel>
|
|
90
|
+
<div className="user-menu-label">
|
|
91
|
+
<span className="user-menu-label-name">{user.name}</span>
|
|
92
|
+
<span className="muted text-xs">{user.email}</span>
|
|
93
|
+
<RoleBadge role={user.role} />
|
|
94
|
+
</div>
|
|
95
|
+
</DropdownMenuLabel>
|
|
96
|
+
<DropdownMenuSeparator />
|
|
97
|
+
<DropdownMenuGroup>
|
|
98
|
+
<DropdownMenuItem asChild>
|
|
99
|
+
<Link href="/dashboard">
|
|
100
|
+
<LayoutDashboard /> Dashboard
|
|
101
|
+
</Link>
|
|
102
|
+
</DropdownMenuItem>
|
|
103
|
+
{/* @feature profile */}
|
|
104
|
+
<DropdownMenuItem asChild>
|
|
105
|
+
<Link href="/settings">
|
|
106
|
+
<Settings /> Settings
|
|
107
|
+
</Link>
|
|
108
|
+
</DropdownMenuItem>
|
|
109
|
+
{/* @end profile */}
|
|
110
|
+
</DropdownMenuGroup>
|
|
111
|
+
<DropdownMenuSeparator />
|
|
112
|
+
<DropdownMenuItem variant="destructive" disabled={signingOut} onSelect={signOut}>
|
|
113
|
+
{signingOut ? <LoaderCircle className="spin" /> : <LogOut />} Sign out
|
|
114
|
+
</DropdownMenuItem>
|
|
115
|
+
</DropdownMenuContent>
|
|
116
|
+
</DropdownMenu>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
@@ -6,12 +6,9 @@ import { cn } from "@/lib/utils";
|
|
|
6
6
|
|
|
7
7
|
export function Logo({ href = "/", className }: { href?: string; className?: string }) {
|
|
8
8
|
return (
|
|
9
|
-
<Link
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
>
|
|
13
|
-
<span className="flex size-7 items-center justify-center rounded-lg bg-primary text-primary-foreground">
|
|
14
|
-
<ShieldCheck className="size-4" />
|
|
9
|
+
<Link href={href} className={cn("logo", className)}>
|
|
10
|
+
<span className="logo-mark" aria-hidden>
|
|
11
|
+
<ShieldCheck size={16} />
|
|
15
12
|
</span>
|
|
16
13
|
<span>{siteConfig.name}</span>
|
|
17
14
|
</Link>
|
|
@@ -2,24 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
import { motion } from "motion/react";
|
|
4
4
|
|
|
5
|
-
import { cn } from "@/lib/utils";
|
|
6
|
-
|
|
7
5
|
/** A bar that grows to `value` percent (0-100). Horizontal by default. */
|
|
8
6
|
export function AnimatedBar({
|
|
9
7
|
value,
|
|
10
8
|
vertical = false,
|
|
11
9
|
delay = 0,
|
|
12
|
-
className,
|
|
13
10
|
}: {
|
|
14
11
|
value: number;
|
|
15
12
|
vertical?: boolean;
|
|
16
13
|
delay?: number;
|
|
17
|
-
className?: string;
|
|
18
14
|
}) {
|
|
19
15
|
const size = `${Math.max(0, Math.min(100, value))}%`;
|
|
20
16
|
return (
|
|
21
17
|
<motion.div
|
|
22
|
-
className={
|
|
18
|
+
className={vertical ? "bar-fill bar-fill--vertical" : "bar-fill"}
|
|
23
19
|
initial={vertical ? { height: 0 } : { width: 0 }}
|
|
24
20
|
animate={vertical ? { height: size } : { width: size }}
|
|
25
21
|
transition={{ duration: 0.7, delay, ease: "easeOut" }}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Cell, Pie, PieChart, ResponsiveContainer, Tooltip } from "recharts";
|
|
4
|
+
|
|
5
|
+
import { ROLE_LABELS, ROLES, type Role } from "@/config/rbac";
|
|
6
|
+
|
|
7
|
+
const COLORS: Record<Role, string> = {
|
|
8
|
+
user: "var(--chart-role-user)",
|
|
9
|
+
manager: "var(--chart-role-manager)",
|
|
10
|
+
admin: "var(--chart-role-admin)",
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/** Donut chart of accounts per role. */
|
|
14
|
+
export function RoleChart({ byRole }: { byRole: Record<Role, number> }) {
|
|
15
|
+
const data = ROLES.map((role) => ({ role, name: ROLE_LABELS[role], value: byRole[role] }));
|
|
16
|
+
const total = data.reduce((sum, d) => sum + d.value, 0);
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<div className="chart-with-legend">
|
|
20
|
+
<div className="chart chart--donut">
|
|
21
|
+
<ResponsiveContainer width="100%" height="100%">
|
|
22
|
+
<PieChart>
|
|
23
|
+
<Pie
|
|
24
|
+
data={data}
|
|
25
|
+
dataKey="value"
|
|
26
|
+
nameKey="name"
|
|
27
|
+
innerRadius="60%"
|
|
28
|
+
outerRadius="90%"
|
|
29
|
+
paddingAngle={total ? 2 : 0}
|
|
30
|
+
stroke="none"
|
|
31
|
+
isAnimationActive
|
|
32
|
+
>
|
|
33
|
+
{data.map((d) => (
|
|
34
|
+
<Cell key={d.role} fill={COLORS[d.role]} />
|
|
35
|
+
))}
|
|
36
|
+
</Pie>
|
|
37
|
+
<Tooltip
|
|
38
|
+
contentStyle={{
|
|
39
|
+
background: "var(--popover)",
|
|
40
|
+
border: "1px solid var(--border)",
|
|
41
|
+
borderRadius: 8,
|
|
42
|
+
color: "var(--popover-foreground)",
|
|
43
|
+
}}
|
|
44
|
+
/>
|
|
45
|
+
</PieChart>
|
|
46
|
+
</ResponsiveContainer>
|
|
47
|
+
</div>
|
|
48
|
+
<ul className="chart-legend">
|
|
49
|
+
{data.map((d) => (
|
|
50
|
+
<li key={d.role}>
|
|
51
|
+
<span className="chart-swatch" style={{ background: COLORS[d.role] }} aria-hidden />
|
|
52
|
+
<span>{d.name}</span>
|
|
53
|
+
<span className="muted tabular">
|
|
54
|
+
{d.value} · {total ? Math.round((d.value / total) * 100) : 0}%
|
|
55
|
+
</span>
|
|
56
|
+
</li>
|
|
57
|
+
))}
|
|
58
|
+
</ul>
|
|
59
|
+
</div>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Area, AreaChart, CartesianGrid, ResponsiveContainer, Tooltip, XAxis, YAxis } from "recharts";
|
|
4
|
+
|
|
5
|
+
const dayFormat = new Intl.DateTimeFormat("en-US", {
|
|
6
|
+
month: "short",
|
|
7
|
+
day: "numeric",
|
|
8
|
+
timeZone: "UTC",
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
/** Area chart of sign-ups per day. */
|
|
12
|
+
export function SignupsChart({ data }: { data: { date: string; count: number }[] }) {
|
|
13
|
+
const points = data.map((d) => ({
|
|
14
|
+
...d,
|
|
15
|
+
label: dayFormat.format(new Date(`${d.date}T00:00:00Z`)),
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<div className="chart chart--area">
|
|
20
|
+
<ResponsiveContainer width="100%" height="100%">
|
|
21
|
+
<AreaChart data={points} margin={{ top: 8, right: 8, left: -20, bottom: 0 }}>
|
|
22
|
+
<defs>
|
|
23
|
+
<linearGradient id="signups-fill" x1="0" y1="0" x2="0" y2="1">
|
|
24
|
+
<stop offset="0%" stopColor="var(--chart-primary)" stopOpacity={0.35} />
|
|
25
|
+
<stop offset="100%" stopColor="var(--chart-primary)" stopOpacity={0} />
|
|
26
|
+
</linearGradient>
|
|
27
|
+
</defs>
|
|
28
|
+
<CartesianGrid strokeDasharray="3 3" stroke="var(--border)" vertical={false} />
|
|
29
|
+
<XAxis
|
|
30
|
+
dataKey="label"
|
|
31
|
+
tickLine={false}
|
|
32
|
+
axisLine={false}
|
|
33
|
+
tick={{ fill: "var(--muted-foreground)", fontSize: 12 }}
|
|
34
|
+
interval="preserveStartEnd"
|
|
35
|
+
minTickGap={16}
|
|
36
|
+
/>
|
|
37
|
+
<YAxis
|
|
38
|
+
allowDecimals={false}
|
|
39
|
+
tickLine={false}
|
|
40
|
+
axisLine={false}
|
|
41
|
+
tick={{ fill: "var(--muted-foreground)", fontSize: 12 }}
|
|
42
|
+
/>
|
|
43
|
+
<Tooltip
|
|
44
|
+
cursor={{ stroke: "var(--border)" }}
|
|
45
|
+
contentStyle={{
|
|
46
|
+
background: "var(--popover)",
|
|
47
|
+
border: "1px solid var(--border)",
|
|
48
|
+
borderRadius: 8,
|
|
49
|
+
color: "var(--popover-foreground)",
|
|
50
|
+
}}
|
|
51
|
+
/>
|
|
52
|
+
<Area
|
|
53
|
+
type="monotone"
|
|
54
|
+
dataKey="count"
|
|
55
|
+
name="Sign-ups"
|
|
56
|
+
stroke="var(--chart-primary)"
|
|
57
|
+
strokeWidth={2}
|
|
58
|
+
fill="url(#signups-fill)"
|
|
59
|
+
/>
|
|
60
|
+
</AreaChart>
|
|
61
|
+
</ResponsiveContainer>
|
|
62
|
+
</div>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ROLE_LABELS, type Role } from "@/config/rbac";
|
|
2
|
+
import { Badge } from "@/components/ui/badge";
|
|
3
|
+
import { cn } from "@/lib/utils";
|
|
4
|
+
|
|
5
|
+
export function RoleBadge({ role, className }: { role: Role; className?: string }) {
|
|
6
|
+
return (
|
|
7
|
+
<Badge variant="outline" className={cn("role-badge", `role-badge--${role}`, className)}>
|
|
8
|
+
{ROLE_LABELS[role]}
|
|
9
|
+
</Badge>
|
|
10
|
+
);
|
|
11
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
4
|
+
import { LoaderCircle } from "lucide-react";
|
|
5
|
+
import { useForm, useWatch } from "react-hook-form";
|
|
6
|
+
import { toast } from "sonner";
|
|
7
|
+
|
|
8
|
+
import { FormField } from "@/components/auth/form-field";
|
|
9
|
+
import { PasswordInput, PasswordStrengthMeter } from "@/components/auth/password-input";
|
|
10
|
+
import { Button } from "@/components/ui/button";
|
|
11
|
+
import { apiFetch, getErrorMessage, HttpError } from "@/lib/http";
|
|
12
|
+
import { changePasswordFormSchema } from "@/lib/validations/account";
|
|
13
|
+
|
|
14
|
+
export function PasswordForm() {
|
|
15
|
+
const {
|
|
16
|
+
register,
|
|
17
|
+
handleSubmit,
|
|
18
|
+
control,
|
|
19
|
+
setError,
|
|
20
|
+
reset,
|
|
21
|
+
formState: { errors, isSubmitting },
|
|
22
|
+
} = useForm({
|
|
23
|
+
resolver: zodResolver(changePasswordFormSchema),
|
|
24
|
+
defaultValues: { currentPassword: "", newPassword: "", confirmPassword: "" },
|
|
25
|
+
});
|
|
26
|
+
const newPassword = useWatch({ control, name: "newPassword" });
|
|
27
|
+
|
|
28
|
+
const onSubmit = handleSubmit(async ({ currentPassword, newPassword }) => {
|
|
29
|
+
try {
|
|
30
|
+
await apiFetch("/api/account/password", {
|
|
31
|
+
method: "POST",
|
|
32
|
+
json: { currentPassword, newPassword },
|
|
33
|
+
});
|
|
34
|
+
reset();
|
|
35
|
+
toast.success("Password changed. Other devices have been signed out.");
|
|
36
|
+
} catch (error) {
|
|
37
|
+
const current = error instanceof HttpError ? error.fieldErrors?.currentPassword?.[0] : undefined;
|
|
38
|
+
if (current) setError("currentPassword", { message: current });
|
|
39
|
+
toast.error(getErrorMessage(error, "Could not change your password"));
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<form onSubmit={onSubmit} className="form" noValidate>
|
|
45
|
+
<FormField
|
|
46
|
+
id="currentPassword"
|
|
47
|
+
label="Current password"
|
|
48
|
+
autoComplete="current-password"
|
|
49
|
+
error={errors.currentPassword}
|
|
50
|
+
render={(props) => <PasswordInput {...props} />}
|
|
51
|
+
{...register("currentPassword")}
|
|
52
|
+
/>
|
|
53
|
+
<div className="field-group">
|
|
54
|
+
<FormField
|
|
55
|
+
id="newPassword"
|
|
56
|
+
label="New password"
|
|
57
|
+
autoComplete="new-password"
|
|
58
|
+
error={errors.newPassword}
|
|
59
|
+
render={(props) => <PasswordInput {...props} />}
|
|
60
|
+
{...register("newPassword")}
|
|
61
|
+
/>
|
|
62
|
+
<PasswordStrengthMeter password={newPassword} />
|
|
63
|
+
</div>
|
|
64
|
+
<FormField
|
|
65
|
+
id="confirmPassword"
|
|
66
|
+
label="Confirm new password"
|
|
67
|
+
autoComplete="new-password"
|
|
68
|
+
error={errors.confirmPassword}
|
|
69
|
+
render={(props) => <PasswordInput {...props} />}
|
|
70
|
+
{...register("confirmPassword")}
|
|
71
|
+
/>
|
|
72
|
+
<div>
|
|
73
|
+
<Button type="submit" disabled={isSubmitting}>
|
|
74
|
+
{isSubmitting && <LoaderCircle className="spin" />}
|
|
75
|
+
Change password
|
|
76
|
+
</Button>
|
|
77
|
+
</div>
|
|
78
|
+
</form>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
4
|
+
import { LoaderCircle } from "lucide-react";
|
|
5
|
+
import { useRouter } from "next/navigation";
|
|
6
|
+
import { useForm } from "react-hook-form";
|
|
7
|
+
import { toast } from "sonner";
|
|
8
|
+
|
|
9
|
+
import { FormField } from "@/components/auth/form-field";
|
|
10
|
+
import { useUser } from "@/components/providers/user-provider";
|
|
11
|
+
import { Button } from "@/components/ui/button";
|
|
12
|
+
import { Input } from "@/components/ui/input";
|
|
13
|
+
import { Label } from "@/components/ui/label";
|
|
14
|
+
import { apiFetch, getErrorMessage } from "@/lib/http";
|
|
15
|
+
import { updateProfileSchema } from "@/lib/validations/account";
|
|
16
|
+
|
|
17
|
+
export function ProfileForm() {
|
|
18
|
+
const user = useUser();
|
|
19
|
+
const router = useRouter();
|
|
20
|
+
const {
|
|
21
|
+
register,
|
|
22
|
+
handleSubmit,
|
|
23
|
+
formState: { errors, isSubmitting, isDirty },
|
|
24
|
+
reset,
|
|
25
|
+
} = useForm({
|
|
26
|
+
resolver: zodResolver(updateProfileSchema),
|
|
27
|
+
defaultValues: { name: user.name },
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const onSubmit = handleSubmit(async (values) => {
|
|
31
|
+
try {
|
|
32
|
+
await apiFetch("/api/account", { method: "PATCH", json: values });
|
|
33
|
+
reset(values);
|
|
34
|
+
toast.success("Profile updated");
|
|
35
|
+
router.refresh();
|
|
36
|
+
} catch (error) {
|
|
37
|
+
toast.error(getErrorMessage(error, "Could not update your profile"));
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<form onSubmit={onSubmit} className="form" noValidate>
|
|
43
|
+
<FormField
|
|
44
|
+
id="name"
|
|
45
|
+
label="Name"
|
|
46
|
+
autoComplete="name"
|
|
47
|
+
error={errors.name}
|
|
48
|
+
{...register("name")}
|
|
49
|
+
/>
|
|
50
|
+
<div className="field">
|
|
51
|
+
<Label htmlFor="email">Email</Label>
|
|
52
|
+
<Input id="email" value={user.email} disabled readOnly />
|
|
53
|
+
<p className="muted text-xs">Your email is used to sign in and can't be changed here.</p>
|
|
54
|
+
</div>
|
|
55
|
+
<div>
|
|
56
|
+
<Button type="submit" disabled={isSubmitting || !isDirty}>
|
|
57
|
+
{isSubmitting && <LoaderCircle className="spin" />}
|
|
58
|
+
Save changes
|
|
59
|
+
</Button>
|
|
60
|
+
</div>
|
|
61
|
+
</form>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { LoaderCircle, LogOut } from "lucide-react";
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
import { toast } from "sonner";
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
AlertDialog,
|
|
9
|
+
AlertDialogAction,
|
|
10
|
+
AlertDialogCancel,
|
|
11
|
+
AlertDialogContent,
|
|
12
|
+
AlertDialogDescription,
|
|
13
|
+
AlertDialogFooter,
|
|
14
|
+
AlertDialogHeader,
|
|
15
|
+
AlertDialogTitle,
|
|
16
|
+
AlertDialogTrigger,
|
|
17
|
+
} from "@/components/ui/alert-dialog";
|
|
18
|
+
import { Button } from "@/components/ui/button";
|
|
19
|
+
import { apiFetch, getErrorMessage } from "@/lib/http";
|
|
20
|
+
|
|
21
|
+
/** "Sign out everywhere else": bumps the token version, keeps this browser signed in. */
|
|
22
|
+
export function SignOutOtherSessions() {
|
|
23
|
+
const [open, setOpen] = useState(false);
|
|
24
|
+
const [pending, setPending] = useState(false);
|
|
25
|
+
|
|
26
|
+
async function revoke() {
|
|
27
|
+
setPending(true);
|
|
28
|
+
try {
|
|
29
|
+
await apiFetch("/api/account/sessions", { method: "DELETE" });
|
|
30
|
+
toast.success("Signed out of all other devices");
|
|
31
|
+
setOpen(false);
|
|
32
|
+
} catch (error) {
|
|
33
|
+
toast.error(getErrorMessage(error, "Could not sign out other devices"));
|
|
34
|
+
} finally {
|
|
35
|
+
setPending(false);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<AlertDialog open={open} onOpenChange={setOpen}>
|
|
41
|
+
<AlertDialogTrigger asChild>
|
|
42
|
+
<Button variant="outline">
|
|
43
|
+
<LogOut /> Sign out other devices
|
|
44
|
+
</Button>
|
|
45
|
+
</AlertDialogTrigger>
|
|
46
|
+
<AlertDialogContent>
|
|
47
|
+
<AlertDialogHeader>
|
|
48
|
+
<AlertDialogTitle>Sign out of all other devices?</AlertDialogTitle>
|
|
49
|
+
<AlertDialogDescription>
|
|
50
|
+
Every other browser and device signed in to your account will be signed out on its next
|
|
51
|
+
request. You stay signed in here.
|
|
52
|
+
</AlertDialogDescription>
|
|
53
|
+
</AlertDialogHeader>
|
|
54
|
+
<AlertDialogFooter>
|
|
55
|
+
<AlertDialogCancel disabled={pending}>Cancel</AlertDialogCancel>
|
|
56
|
+
<AlertDialogAction
|
|
57
|
+
disabled={pending}
|
|
58
|
+
onClick={(e) => {
|
|
59
|
+
e.preventDefault();
|
|
60
|
+
revoke();
|
|
61
|
+
}}
|
|
62
|
+
>
|
|
63
|
+
{pending && <LoaderCircle className="spin" />}
|
|
64
|
+
Sign out others
|
|
65
|
+
</AlertDialogAction>
|
|
66
|
+
</AlertDialogFooter>
|
|
67
|
+
</AlertDialogContent>
|
|
68
|
+
</AlertDialog>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Check, Monitor, Moon, Sun } from "lucide-react";
|
|
4
|
+
import { useSyncExternalStore } from "react";
|
|
5
|
+
|
|
6
|
+
import { Button } from "@/components/ui/button";
|
|
7
|
+
import {
|
|
8
|
+
DropdownMenu,
|
|
9
|
+
DropdownMenuContent,
|
|
10
|
+
DropdownMenuItem,
|
|
11
|
+
DropdownMenuTrigger,
|
|
12
|
+
} from "@/components/ui/dropdown-menu";
|
|
13
|
+
import { applyTheme, readTheme, THEME_STORAGE_KEY, type Theme } from "@/lib/theme";
|
|
14
|
+
|
|
15
|
+
const OPTIONS: { value: Theme; label: string; icon: typeof Sun }[] = [
|
|
16
|
+
{ value: "light", label: "Light", icon: Sun },
|
|
17
|
+
{ value: "dark", label: "Dark", icon: Moon },
|
|
18
|
+
{ value: "system", label: "System", icon: Monitor },
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
// Tiny external store over localStorage so every toggle stays in sync.
|
|
22
|
+
const listeners = new Set<() => void>();
|
|
23
|
+
function subscribe(listener: () => void) {
|
|
24
|
+
listeners.add(listener);
|
|
25
|
+
const onStorage = (e: StorageEvent) => e.key === THEME_STORAGE_KEY && listener();
|
|
26
|
+
window.addEventListener("storage", onStorage);
|
|
27
|
+
return () => {
|
|
28
|
+
listeners.delete(listener);
|
|
29
|
+
window.removeEventListener("storage", onStorage);
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Light / Dark / System switcher. The icon itself is swapped with CSS, so SSR matches. */
|
|
34
|
+
export function ThemeToggle() {
|
|
35
|
+
const theme = useSyncExternalStore(subscribe, readTheme, () => "system" as Theme);
|
|
36
|
+
|
|
37
|
+
function choose(value: Theme) {
|
|
38
|
+
applyTheme(value);
|
|
39
|
+
listeners.forEach((listener) => listener());
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<DropdownMenu>
|
|
44
|
+
<DropdownMenuTrigger asChild>
|
|
45
|
+
<Button variant="ghost" size="icon" aria-label="Change theme">
|
|
46
|
+
<Sun className="theme-icon-light" />
|
|
47
|
+
<Moon className="theme-icon-dark" />
|
|
48
|
+
</Button>
|
|
49
|
+
</DropdownMenuTrigger>
|
|
50
|
+
<DropdownMenuContent align="end">
|
|
51
|
+
{OPTIONS.map(({ value, label, icon: Icon }) => (
|
|
52
|
+
<DropdownMenuItem key={value} onSelect={() => choose(value)}>
|
|
53
|
+
<Icon />
|
|
54
|
+
<span className="menu-grow">{label}</span>
|
|
55
|
+
{theme === value && <Check aria-label="selected" />}
|
|
56
|
+
</DropdownMenuItem>
|
|
57
|
+
))}
|
|
58
|
+
</DropdownMenuContent>
|
|
59
|
+
</DropdownMenu>
|
|
60
|
+
);
|
|
61
|
+
}
|