create-ej-app 26.0.0 → 27.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 +125 -226
- package/cli.ts +79 -29
- package/package.json +2 -2
- package/template/api/.vscode/settings.json +1 -1
- package/template/api/{.github/copilot-instructions.md → AGENTS.md} +0 -2
- package/template/api/CLAUDE.md +1 -0
- package/template/api/package.json +10 -10
- package/template/nextjs/.dockerignore +1 -0
- package/template/nextjs/AGENTS.md +260 -0
- package/template/nextjs/CLAUDE.md +1 -0
- package/template/nextjs/README.md +109 -0
- package/template/nextjs/bunfig.toml +3 -0
- package/template/nextjs/eslint.config.mjs +6 -5
- package/template/nextjs/gitignore +6 -1
- package/template/nextjs/next.config.ts +8 -1
- package/template/nextjs/package.json +46 -39
- package/template/nextjs/public/logo-dark.svg +4 -0
- package/template/nextjs/public/logo.svg +4 -0
- package/template/nextjs/src/app/(admin)/actions/users.ts +183 -0
- package/template/nextjs/src/app/(admin)/admin/_components/admin-header.tsx +24 -0
- package/template/nextjs/src/app/(admin)/admin/_components/admin-search.tsx +16 -0
- package/template/nextjs/src/app/(admin)/admin/_components/admin-sidebar.tsx +42 -0
- package/template/nextjs/src/app/(admin)/admin/layout.tsx +53 -0
- package/template/nextjs/src/app/(admin)/admin/page.tsx +11 -2
- package/template/nextjs/src/app/(admin)/admin/settings/layout.tsx +24 -0
- package/template/nextjs/src/app/(admin)/admin/settings/users/[userId]/page.tsx +43 -0
- package/template/nextjs/src/app/(admin)/admin/settings/users/new/page.tsx +16 -0
- package/template/nextjs/src/app/(admin)/admin/settings/users/page.tsx +377 -0
- package/template/nextjs/src/app/(admin)/admin/settings/users/user-form.tsx +138 -0
- package/template/nextjs/src/app/(admin)/admin/settings/users/validation.ts +23 -0
- package/template/nextjs/src/app/(app)/app/layout.tsx +44 -0
- package/template/nextjs/src/app/(app)/app/page.tsx +14 -2
- package/template/nextjs/src/app/(auth)/(account)/layout.tsx +64 -0
- package/template/nextjs/src/app/(auth)/(account)/profile/page.tsx +16 -0
- package/template/nextjs/src/app/(auth)/(account)/profile/profile-form.tsx +247 -0
- package/template/nextjs/src/app/(auth)/login/email-login-form.tsx +56 -29
- package/template/nextjs/src/app/(auth)/login/page.tsx +45 -12
- package/template/nextjs/src/app/(auth)/login/social-login-buttons.tsx +85 -17
- package/template/nextjs/src/app/(marketing)/layout.tsx +35 -4
- package/template/nextjs/src/app/(marketing)/legal.tsx +56 -0
- package/template/nextjs/src/app/(marketing)/page.tsx +20 -2
- package/template/nextjs/src/app/(marketing)/privacy/page.tsx +43 -2
- package/template/nextjs/src/app/(marketing)/terms/page.tsx +33 -2
- package/template/nextjs/src/app/error.tsx +37 -0
- package/template/nextjs/src/app/fonts/geist-mono/GeistMono-Variable.woff2 +0 -0
- package/template/nextjs/src/app/fonts/geist-sans/Geist-Variable.woff2 +0 -0
- package/template/nextjs/src/app/fonts/index.ts +60 -0
- package/template/nextjs/src/app/global-error.tsx +38 -0
- package/template/nextjs/src/app/globals.css +29 -0
- package/template/nextjs/src/app/layout.tsx +45 -18
- package/template/nextjs/src/app/not-found.tsx +25 -3
- package/template/nextjs/src/app/robots.ts +29 -0
- package/template/nextjs/src/app/sitemap.ts +21 -0
- package/template/nextjs/src/components/confirm-dialog.tsx +79 -0
- package/template/nextjs/src/components/dashboard-header.tsx +70 -0
- package/template/nextjs/src/components/data-table/enum.ts +5 -0
- package/template/nextjs/src/components/data-table/features.ts +49 -0
- package/template/nextjs/src/components/data-table/index.tsx +961 -0
- package/template/nextjs/src/components/data-table/types.ts +76 -0
- package/template/nextjs/src/components/error.tsx +71 -0
- package/template/nextjs/src/components/loader.tsx +18 -2
- package/template/nextjs/src/components/logo.tsx +49 -0
- package/template/nextjs/src/components/navigation-search.tsx +140 -0
- package/template/nextjs/src/components/navigation-sidebar.tsx +241 -0
- package/template/nextjs/src/components/page-heading.tsx +38 -0
- package/template/nextjs/src/components/react-query-provider.tsx +41 -2
- package/template/nextjs/src/components/route-error.tsx +55 -0
- package/template/nextjs/src/components/screen-size.tsx +36 -0
- package/template/nextjs/src/components/site-footer.tsx +20 -4
- package/template/nextjs/src/components/theme-provider.tsx +48 -0
- package/template/nextjs/src/components/theme-toggle.tsx +58 -5
- package/template/nextjs/src/components/ui/alert-dialog.tsx +199 -0
- package/template/nextjs/src/components/ui/avatar.tsx +112 -0
- package/template/nextjs/src/components/ui/badge.tsx +54 -0
- package/template/nextjs/src/components/ui/button.tsx +3 -1
- package/template/nextjs/src/components/ui/card.tsx +4 -4
- package/template/nextjs/src/components/ui/collapsible.tsx +33 -0
- package/template/nextjs/src/components/ui/command.tsx +192 -0
- package/template/nextjs/src/components/ui/dialog.tsx +164 -0
- package/template/nextjs/src/components/ui/dropdown-menu.tsx +273 -0
- package/template/nextjs/src/components/ui/input-group.tsx +156 -0
- package/template/nextjs/src/components/ui/select.tsx +195 -0
- package/template/nextjs/src/components/ui/sheet.tsx +143 -0
- package/template/nextjs/src/components/ui/sidebar.tsx +702 -0
- package/template/nextjs/src/components/ui/skeleton.tsx +13 -0
- package/template/nextjs/src/components/ui/table.tsx +116 -0
- package/template/nextjs/src/components/ui/textarea.tsx +18 -0
- package/template/nextjs/src/components/ui/tooltip.tsx +57 -0
- package/template/nextjs/src/components/user-menu.tsx +206 -0
- package/template/nextjs/src/db/common.ts +10 -0
- package/template/nextjs/src/db/index.ts +16 -6
- package/template/nextjs/src/db/relations.ts +21 -0
- package/template/nextjs/src/db/schema.ts +85 -46
- package/template/nextjs/src/emails/components/email-layout.tsx +27 -11
- package/template/nextjs/src/emails/magic-link.tsx +15 -13
- package/template/nextjs/src/emails/test.tsx +11 -9
- package/template/nextjs/src/emails/welcome.tsx +12 -9
- package/template/nextjs/src/env.ts +1 -1
- package/template/nextjs/src/hooks/use-mobile.ts +14 -12
- package/template/nextjs/src/instrumentation.ts +20 -2
- package/template/nextjs/src/lib/actions.ts +55 -0
- package/template/nextjs/src/lib/admin-navigation.ts +43 -0
- package/template/nextjs/src/lib/auth-client.ts +20 -9
- package/template/nextjs/src/lib/auth-permissions.ts +61 -0
- package/template/nextjs/src/lib/auth.ts +33 -3
- package/template/nextjs/src/lib/callback-url.ts +28 -0
- package/template/nextjs/src/lib/constants.ts +21 -0
- package/template/nextjs/src/lib/delay.ts +10 -0
- package/template/nextjs/src/lib/email-service.ts +21 -0
- package/template/nextjs/src/lib/errors.ts +74 -0
- package/template/nextjs/src/lib/format-currency.ts +22 -24
- package/template/nextjs/src/lib/format-date.ts +69 -6
- package/template/nextjs/src/lib/nodemailer.ts +27 -3
- package/template/nextjs/src/lib/otel.ts +92 -2
- package/template/nextjs/src/lib/safe-action-client.ts +60 -9
- package/template/nextjs/src/lib/safe-action.ts +152 -16
- package/template/nextjs/src/lib/search.ts +16 -0
- package/template/nextjs/src/lib/seo.ts +7 -0
- package/template/nextjs/src/lib/siteConfig.ts +17 -1
- package/template/nextjs/src/lib/toast-message.ts +87 -1
- package/template/nextjs/src/lib/validations.ts +30 -0
- package/template/nextjs/src/proxy.ts +48 -0
- package/template/nextjs/src/scripts/reset-db.ts +22 -0
- package/template/nextjs/src/scripts/seed.ts +59 -8
- package/template/nextjs/src/scripts/test-mail.ts +28 -20
- package/template/nextjs/tests/admin/users.test.ts +64 -0
- package/template/nextjs/tests/db/fk-indexes.test.ts +62 -0
- package/template/nextjs/tests/db/seed.test.ts +49 -0
- package/template/nextjs/tests/helpers/action.ts +71 -0
- package/template/nextjs/tests/helpers/fixtures.ts +78 -0
- package/template/nextjs/tests/helpers/index.ts +2 -0
- package/template/nextjs/tests/lib/callback-url.test.ts +48 -0
- package/template/nextjs/tests/lib/client-server-boundary.test.ts +57 -0
- package/template/nextjs/tests/lib/errors.test.ts +10 -0
- package/template/nextjs/tests/lib/search.test.ts +23 -0
- package/template/nextjs/tests/setup/pglite-db.ts +63 -0
- package/template/nextjs/tests/setup/preload.ts +95 -0
- package/template/nextjs/tsconfig.json +1 -0
- package/template/saas-starter/.dockerignore +1 -0
- package/template/saas-starter/.env.example +15 -15
- package/template/saas-starter/AGENTS.md +302 -0
- package/template/saas-starter/CLAUDE.md +1 -0
- package/template/saas-starter/README.md +124 -2
- package/template/saas-starter/bunfig.toml +3 -0
- package/template/saas-starter/eslint.config.mjs +6 -5
- package/template/saas-starter/gitignore +6 -1
- package/template/saas-starter/next.config.ts +19 -1
- package/template/saas-starter/package.json +49 -44
- package/template/saas-starter/public/logo-dark.svg +4 -0
- package/template/saas-starter/public/logo.svg +4 -0
- package/template/saas-starter/src/app/(admin)/actions/contact-leads.ts +51 -0
- package/template/saas-starter/src/app/(admin)/actions/feedbacks.ts +91 -0
- package/template/saas-starter/src/app/(admin)/actions/users.ts +145 -59
- package/template/saas-starter/src/app/(admin)/admin/_components/admin-header.tsx +4 -1
- package/template/saas-starter/src/app/(admin)/admin/_components/admin-sidebar.tsx +12 -10
- package/template/saas-starter/src/app/(admin)/admin/contact-leads/page.tsx +123 -0
- package/template/saas-starter/src/app/(admin)/admin/feedbacks/page.tsx +161 -0
- package/template/saas-starter/src/app/(admin)/admin/layout.tsx +24 -28
- package/template/saas-starter/src/app/(admin)/admin/page.tsx +59 -2
- package/template/saas-starter/src/app/(admin)/admin/settings/layout.tsx +24 -0
- package/template/saas-starter/src/app/(admin)/admin/settings/users/[userId]/page.tsx +43 -0
- package/template/saas-starter/src/app/(admin)/admin/settings/users/new/page.tsx +16 -0
- package/template/saas-starter/src/app/(admin)/admin/settings/users/page.tsx +372 -10
- package/template/saas-starter/src/app/(admin)/admin/settings/users/user-form.tsx +138 -0
- package/template/saas-starter/src/app/(admin)/admin/settings/users/validation.ts +23 -0
- package/template/saas-starter/src/app/(admin)/admin/support-tickets/[ticketId]/page.tsx +17 -0
- package/template/saas-starter/src/app/(admin)/admin/support-tickets/page.tsx +5 -0
- package/template/saas-starter/src/app/(app)/actions/billing.ts +171 -107
- package/template/saas-starter/src/app/(app)/actions/feedbacks.ts +28 -0
- package/template/saas-starter/src/app/(app)/actions/feedbacks.validation.ts +12 -0
- package/template/saas-starter/src/app/(app)/actions/members.ts +149 -123
- package/template/saas-starter/src/app/(app)/actions/organizations.ts +230 -0
- package/template/saas-starter/src/app/(app)/actions/organizations.validation.ts +17 -0
- package/template/saas-starter/src/app/(app)/app/[orgId]/dashboard/page.tsx +6 -9
- package/template/saas-starter/src/app/(app)/app/[orgId]/layout.tsx +6 -9
- package/template/saas-starter/src/app/(app)/app/[orgId]/settings/_components/billing-email-form.tsx +45 -53
- package/template/saas-starter/src/app/(app)/app/[orgId]/settings/_components/danger-zone.tsx +40 -47
- package/template/saas-starter/src/app/(app)/app/[orgId]/settings/_components/general-settings-form.tsx +80 -105
- package/template/saas-starter/src/app/(app)/app/[orgId]/settings/_components/plans-section.tsx +72 -82
- package/template/saas-starter/src/app/(app)/app/[orgId]/settings/billing/page.tsx +51 -52
- package/template/saas-starter/src/app/(app)/app/[orgId]/settings/layout.tsx +24 -0
- package/template/saas-starter/src/app/(app)/app/[orgId]/settings/members/_components/invite-member-dialog.tsx +15 -16
- package/template/saas-starter/src/app/(app)/app/[orgId]/settings/members/_components/members-tabs.tsx +77 -44
- package/template/saas-starter/src/app/(app)/app/[orgId]/settings/members/page.tsx +11 -18
- package/template/saas-starter/src/app/(app)/app/[orgId]/settings/page.tsx +14 -28
- package/template/saas-starter/src/app/(app)/app/[orgId]/support-tickets/[ticketId]/page.tsx +25 -0
- package/template/saas-starter/src/app/(app)/app/[orgId]/support-tickets/page.tsx +25 -0
- package/template/saas-starter/src/app/(app)/app/_components/app-header.tsx +15 -13
- package/template/saas-starter/src/app/(app)/app/_components/app-search.tsx +15 -6
- package/template/saas-starter/src/app/(app)/app/_components/app-sidebar.tsx +6 -3
- package/template/saas-starter/src/app/(app)/app/_components/feedback-dialog.tsx +108 -0
- package/template/saas-starter/src/app/(app)/app/_components/organization-context.tsx +5 -9
- package/template/saas-starter/src/app/(app)/app/_components/organization-switcher.tsx +68 -8
- package/template/saas-starter/src/app/(app)/app/layout.tsx +44 -32
- package/template/saas-starter/src/app/(app)/app/onboarding/_components/create-organization-form.tsx +75 -87
- package/template/saas-starter/src/app/(app)/app/onboarding/page.tsx +10 -12
- package/template/saas-starter/src/app/(app)/app/page.tsx +16 -21
- package/template/saas-starter/src/app/(auth)/(account)/layout.tsx +64 -0
- package/template/saas-starter/src/app/(auth)/(account)/profile/page.tsx +16 -0
- package/template/saas-starter/src/app/(auth)/(account)/profile/profile-form.tsx +247 -0
- package/template/saas-starter/src/app/(auth)/(account)/support/[ticketId]/page.tsx +19 -0
- package/template/saas-starter/src/app/(auth)/(account)/support/page.tsx +9 -0
- package/template/saas-starter/src/app/(auth)/login/email-login-form.tsx +49 -27
- package/template/saas-starter/src/app/(auth)/login/page.tsx +39 -21
- package/template/saas-starter/src/app/(auth)/login/social-login-buttons.tsx +80 -18
- package/template/saas-starter/src/app/(invitation)/accept-invitation/[id]/accept-invitation-form.tsx +16 -10
- package/template/saas-starter/src/app/(invitation)/accept-invitation/[id]/page.tsx +28 -42
- package/template/saas-starter/src/app/(invitation)/actions/invitations.ts +32 -0
- package/template/saas-starter/src/app/(marketing)/contact-us/actions.ts +23 -0
- package/template/saas-starter/src/app/(marketing)/contact-us/contact-form.tsx +118 -0
- package/template/saas-starter/src/app/(marketing)/contact-us/page.tsx +20 -0
- package/template/saas-starter/src/app/(marketing)/contact-us/validation.ts +22 -0
- package/template/saas-starter/src/app/(marketing)/layout.tsx +38 -4
- package/template/saas-starter/src/app/(marketing)/legal.tsx +66 -0
- package/template/saas-starter/src/app/(marketing)/page.tsx +23 -2
- package/template/saas-starter/src/app/(marketing)/privacy/page.tsx +62 -2
- package/template/saas-starter/src/app/(marketing)/terms/page.tsx +40 -2
- package/template/saas-starter/src/app/actions/support-tickets.ts +510 -0
- package/template/saas-starter/src/app/actions/support-tickets.validation.ts +112 -0
- package/template/saas-starter/src/app/actions/uploads.ts +36 -0
- package/template/saas-starter/src/app/actions/uploads.validation.ts +24 -0
- package/template/saas-starter/src/app/error.tsx +37 -0
- package/template/saas-starter/src/app/fonts/geist-mono/GeistMono-Variable.woff2 +0 -0
- package/template/saas-starter/src/app/fonts/geist-sans/Geist-Variable.woff2 +0 -0
- package/template/saas-starter/src/app/fonts/index.ts +60 -0
- package/template/saas-starter/src/app/global-error.tsx +38 -0
- package/template/saas-starter/src/app/globals.css +29 -0
- package/template/saas-starter/src/app/layout.tsx +43 -19
- package/template/saas-starter/src/app/not-found.tsx +25 -3
- package/template/saas-starter/src/app/robots.ts +14 -10
- package/template/saas-starter/src/app/sitemap.ts +2 -1
- package/template/saas-starter/src/components/confirm-dialog.tsx +79 -0
- package/template/saas-starter/src/components/dashboard-header.tsx +7 -1
- package/template/saas-starter/src/components/data-table/features.ts +49 -0
- package/template/saas-starter/src/components/data-table/index.tsx +65 -64
- package/template/saas-starter/src/components/data-table/types.ts +5 -4
- package/template/saas-starter/src/components/error.tsx +45 -0
- package/template/saas-starter/src/components/file-upload.tsx +65 -26
- package/template/saas-starter/src/components/loader.tsx +18 -2
- package/template/saas-starter/src/components/logo.tsx +49 -0
- package/template/saas-starter/src/components/navigation-search.tsx +2 -2
- package/template/saas-starter/src/components/page-heading.tsx +6 -0
- package/template/saas-starter/src/components/react-query-provider.tsx +41 -2
- package/template/saas-starter/src/components/route-error.tsx +55 -0
- package/template/saas-starter/src/components/screen-size.tsx +36 -0
- package/template/saas-starter/src/components/site-footer.tsx +20 -4
- package/template/saas-starter/src/components/support/create-support-ticket-dialog.tsx +122 -0
- package/template/saas-starter/src/components/support/support-ticket-conversation.tsx +236 -0
- package/template/saas-starter/src/components/support/support-ticket-shared.tsx +58 -0
- package/template/saas-starter/src/components/support/support-tickets-table.tsx +281 -0
- package/template/saas-starter/src/components/theme-provider.tsx +48 -0
- package/template/saas-starter/src/components/theme-toggle.tsx +58 -5
- package/template/saas-starter/src/components/ui/alert-dialog.tsx +199 -0
- package/template/saas-starter/src/components/ui/badge.tsx +6 -1
- package/template/saas-starter/src/components/ui/button.tsx +2 -0
- package/template/saas-starter/src/components/ui/command.tsx +1 -1
- package/template/saas-starter/src/components/user-menu.tsx +147 -24
- package/template/saas-starter/src/db/common.ts +33 -1
- package/template/saas-starter/src/db/enums.ts +24 -0
- package/template/saas-starter/src/db/index.ts +14 -5
- package/template/saas-starter/src/db/relations.ts +40 -3
- package/template/saas-starter/src/db/schema.ts +186 -35
- package/template/saas-starter/src/emails/components/email-layout.tsx +27 -11
- package/template/saas-starter/src/emails/invitation.tsx +34 -21
- package/template/saas-starter/src/emails/magic-link.tsx +15 -13
- package/template/saas-starter/src/emails/test.tsx +11 -9
- package/template/saas-starter/src/emails/welcome.tsx +12 -9
- package/template/saas-starter/src/env.ts +1 -1
- package/template/saas-starter/src/hooks/use-mobile.ts +14 -12
- package/template/saas-starter/src/instrumentation.ts +20 -2
- package/template/saas-starter/src/lib/actions.ts +34 -0
- package/template/saas-starter/src/lib/admin-navigation.ts +33 -1
- package/template/saas-starter/src/lib/app-navigation.ts +45 -41
- package/template/saas-starter/src/lib/auth-client.ts +8 -3
- package/template/saas-starter/src/lib/auth-permissions.ts +50 -11
- package/template/saas-starter/src/lib/auth.ts +122 -21
- package/template/saas-starter/src/lib/billing.ts +59 -24
- package/template/saas-starter/src/lib/callback-url.ts +28 -0
- package/template/saas-starter/src/lib/constants.ts +78 -9
- package/template/saas-starter/src/lib/delay.ts +10 -0
- package/template/saas-starter/src/lib/email-service.ts +30 -1
- package/template/saas-starter/src/lib/errors.ts +74 -0
- package/template/saas-starter/src/lib/format-currency.ts +22 -24
- package/template/saas-starter/src/lib/format-date.ts +69 -6
- package/template/saas-starter/src/lib/image-url.ts +54 -0
- package/template/saas-starter/src/lib/nodemailer.ts +27 -3
- package/template/saas-starter/src/lib/organization-access.ts +56 -76
- package/template/saas-starter/src/lib/otel.ts +92 -2
- package/template/saas-starter/src/lib/plan-limits.ts +37 -0
- package/template/saas-starter/src/lib/plans.ts +40 -13
- package/template/saas-starter/src/lib/rbac.ts +44 -0
- package/template/saas-starter/src/lib/safe-action-client.ts +60 -9
- package/template/saas-starter/src/lib/safe-action.ts +137 -17
- package/template/saas-starter/src/lib/search.ts +16 -0
- package/template/saas-starter/src/lib/seo.ts +7 -0
- package/template/saas-starter/src/lib/siteConfig.ts +17 -1
- package/template/saas-starter/src/lib/storage.ts +176 -46
- package/template/saas-starter/src/lib/stripe.ts +4 -1
- package/template/saas-starter/src/lib/toast-message.ts +87 -1
- package/template/saas-starter/src/lib/validations.ts +85 -2
- package/template/saas-starter/src/proxy.ts +48 -0
- package/template/saas-starter/src/scripts/cleanup-temp-uploads.ts +24 -0
- package/template/saas-starter/src/scripts/seed.ts +82 -8
- package/template/saas-starter/src/scripts/setup-db.ts +72 -0
- package/template/saas-starter/src/scripts/setup-stripe-plans.ts +13 -7
- package/template/saas-starter/src/scripts/test-mail.ts +28 -20
- package/template/saas-starter/tests/admin/users.test.ts +64 -0
- package/template/saas-starter/tests/db/fk-indexes.test.ts +62 -0
- package/template/saas-starter/tests/db/seed.test.ts +57 -0
- package/template/saas-starter/tests/helpers/action.ts +71 -0
- package/template/saas-starter/tests/helpers/fixtures.ts +151 -0
- package/template/saas-starter/tests/helpers/index.ts +2 -0
- package/template/saas-starter/tests/lib/callback-url.test.ts +48 -0
- package/template/saas-starter/tests/lib/client-server-boundary.test.ts +57 -0
- package/template/saas-starter/tests/lib/errors.test.ts +10 -0
- package/template/saas-starter/tests/lib/image-url.test.ts +31 -0
- package/template/saas-starter/tests/lib/search.test.ts +23 -0
- package/template/saas-starter/tests/marketing/contact-and-feedback.test.ts +86 -0
- package/template/saas-starter/tests/organizations/organizations.test.ts +175 -0
- package/template/saas-starter/tests/setup/pglite-db.ts +67 -0
- package/template/saas-starter/tests/setup/preload.ts +108 -0
- package/template/saas-starter/tests/support/support-tickets.test.ts +145 -0
- package/template/saas-starter/tsconfig.json +1 -0
- package/cli.js +0 -147
- package/template/nextjs/src/app/(admin)/layout.tsx +0 -20
- package/template/nextjs/src/app/(app)/layout.tsx +0 -20
- package/template/nextjs/terraform/artifact-registry.tf +0 -5
- package/template/nextjs/terraform/backend-service.tf +0 -13
- package/template/nextjs/terraform/cleanup.sh +0 -9
- package/template/nextjs/terraform/cloudbuild.tf +0 -70
- package/template/nextjs/terraform/cloudrun.tf +0 -68
- package/template/nextjs/terraform/database.tf +0 -60
- package/template/nextjs/terraform/forwarding-rule.tf +0 -43
- package/template/nextjs/terraform/gitignore +0 -4
- package/template/nextjs/terraform/ip-address.tf +0 -11
- package/template/nextjs/terraform/network-endpoint-group.tf +0 -11
- package/template/nextjs/terraform/network.tf +0 -21
- package/template/nextjs/terraform/pre.sh +0 -3
- package/template/nextjs/terraform/providers.tf +0 -18
- package/template/nextjs/terraform/secret.txt +0 -11
- package/template/nextjs/terraform/setup.sh +0 -25
- package/template/nextjs/terraform/ssl-certs.tf +0 -32
- package/template/nextjs/terraform/target-https-proxy copy.tf +0 -14
- package/template/nextjs/terraform/target-https-proxy.tf +0 -14
- package/template/nextjs/terraform/terraform.tfvars +0 -4
- package/template/nextjs/terraform/url-map.tf +0 -23
- package/template/nextjs/terraform/variables.tf +0 -21
- package/template/saas-starter/next-env.d.ts +0 -6
- package/template/saas-starter/src/actions/uploads.ts +0 -28
- package/template/saas-starter/src/actions/uploads.validation.ts +0 -14
- package/template/saas-starter/src/app/(admin)/admin/settings/users/_components/create-user-dialog.tsx +0 -183
- package/template/saas-starter/src/app/(admin)/admin/settings/users/_components/edit-name-dialog.tsx +0 -129
- package/template/saas-starter/src/app/(admin)/admin/settings/users/_components/users-table.tsx +0 -415
- package/template/saas-starter/src/app/(app)/actions/organization.ts +0 -92
- package/template/saas-starter/src/app/proxy.ts +0 -28
- package/template/saas-starter/src/components/impersonation-banner.tsx +0 -44
- package/template/saas-starter/src/lib/organization-plan-limits.ts +0 -38
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useQueryClient } from '@tanstack/react-query'
|
|
4
|
+
import {
|
|
5
|
+
Ban,
|
|
6
|
+
Edit,
|
|
7
|
+
MoreHorizontal,
|
|
8
|
+
Plus,
|
|
9
|
+
Trash2,
|
|
10
|
+
UserCog,
|
|
11
|
+
Users
|
|
12
|
+
} from 'lucide-react'
|
|
13
|
+
import Link from 'next/link'
|
|
14
|
+
import { useRouter } from 'next/navigation'
|
|
15
|
+
import {
|
|
16
|
+
parseAsInteger,
|
|
17
|
+
parseAsJson,
|
|
18
|
+
parseAsString,
|
|
19
|
+
useQueryStates
|
|
20
|
+
} from 'nuqs'
|
|
21
|
+
import { useState } from 'react'
|
|
22
|
+
import { ConfirmDialog } from '~/components/confirm-dialog'
|
|
23
|
+
import { DataTable, type DataTableColumnDef } from '~/components/data-table'
|
|
24
|
+
import { SortOrderEnum } from '~/components/data-table/enum'
|
|
25
|
+
import { DataTableFilter } from '~/components/data-table/types'
|
|
26
|
+
import { PageHeading } from '~/components/page-heading'
|
|
27
|
+
import { Avatar, AvatarFallback, AvatarImage } from '~/components/ui/avatar'
|
|
28
|
+
import { Badge } from '~/components/ui/badge'
|
|
29
|
+
import { Button } from '~/components/ui/button'
|
|
30
|
+
import {
|
|
31
|
+
DropdownMenu,
|
|
32
|
+
DropdownMenuContent,
|
|
33
|
+
DropdownMenuItem,
|
|
34
|
+
DropdownMenuSeparator,
|
|
35
|
+
DropdownMenuTrigger
|
|
36
|
+
} from '~/components/ui/dropdown-menu'
|
|
37
|
+
import { admin, useSession } from '~/lib/auth-client'
|
|
38
|
+
import { formatDate } from '~/lib/format-date'
|
|
39
|
+
import { useSafeActionQuery } from '~/lib/safe-action-client'
|
|
40
|
+
import {
|
|
41
|
+
toastActionError,
|
|
42
|
+
toastErrorMessage,
|
|
43
|
+
toastSuccessMessage
|
|
44
|
+
} from '~/lib/toast-message'
|
|
45
|
+
import { getDistinctRoles, getUsers } from '../../../actions/users'
|
|
46
|
+
|
|
47
|
+
type User = {
|
|
48
|
+
id: string
|
|
49
|
+
name: string
|
|
50
|
+
email: string
|
|
51
|
+
emailVerified: boolean
|
|
52
|
+
image: string | null
|
|
53
|
+
role: string | null
|
|
54
|
+
banned: boolean | null
|
|
55
|
+
createdAt: Date
|
|
56
|
+
updatedAt: Date
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
type PendingConfirm = { kind: 'ban' | 'unban' | 'delete'; user: User }
|
|
60
|
+
|
|
61
|
+
const CONFIRM_COPY = {
|
|
62
|
+
ban: {
|
|
63
|
+
title: 'Ban User',
|
|
64
|
+
description: 'They are signed out and can no longer sign in.',
|
|
65
|
+
confirmLabel: 'Ban User',
|
|
66
|
+
success: 'User banned'
|
|
67
|
+
},
|
|
68
|
+
unban: {
|
|
69
|
+
title: 'Unban User',
|
|
70
|
+
description: 'They can sign in again.',
|
|
71
|
+
confirmLabel: 'Unban User',
|
|
72
|
+
success: 'User unbanned'
|
|
73
|
+
},
|
|
74
|
+
delete: {
|
|
75
|
+
title: 'Delete User',
|
|
76
|
+
description:
|
|
77
|
+
'This permanently deletes the account and signs it out everywhere.',
|
|
78
|
+
confirmLabel: 'Delete User',
|
|
79
|
+
success: 'User deleted'
|
|
80
|
+
}
|
|
81
|
+
} as const
|
|
82
|
+
|
|
83
|
+
function UserActionsCell({
|
|
84
|
+
user,
|
|
85
|
+
isSelf,
|
|
86
|
+
onConfirm
|
|
87
|
+
}: {
|
|
88
|
+
user: User
|
|
89
|
+
isSelf: boolean
|
|
90
|
+
onConfirm: (pending: PendingConfirm) => void
|
|
91
|
+
}) {
|
|
92
|
+
const router = useRouter()
|
|
93
|
+
const [isImpersonating, setIsImpersonating] = useState(false)
|
|
94
|
+
|
|
95
|
+
const handleImpersonate = async () => {
|
|
96
|
+
setIsImpersonating(true)
|
|
97
|
+
const { error } = await admin.impersonateUser({ userId: user.id })
|
|
98
|
+
if (error) {
|
|
99
|
+
toastActionError(error, 'Impersonation did not start. Try again.')
|
|
100
|
+
setIsImpersonating(false)
|
|
101
|
+
return
|
|
102
|
+
}
|
|
103
|
+
router.push('/app')
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return (
|
|
107
|
+
<DropdownMenu>
|
|
108
|
+
<DropdownMenuTrigger asChild>
|
|
109
|
+
<Button
|
|
110
|
+
variant="ghost"
|
|
111
|
+
size="sm"
|
|
112
|
+
className="h-8 w-8 p-0"
|
|
113
|
+
aria-label="User actions"
|
|
114
|
+
>
|
|
115
|
+
<MoreHorizontal className="h-4 w-4" />
|
|
116
|
+
</Button>
|
|
117
|
+
</DropdownMenuTrigger>
|
|
118
|
+
<DropdownMenuContent align="end">
|
|
119
|
+
<DropdownMenuItem asChild>
|
|
120
|
+
<Link href={`/admin/settings/users/${user.id}`}>
|
|
121
|
+
<Edit className="mr-2 h-4 w-4" /> Edit
|
|
122
|
+
</Link>
|
|
123
|
+
</DropdownMenuItem>
|
|
124
|
+
{isSelf ? null : (
|
|
125
|
+
<>
|
|
126
|
+
<DropdownMenuItem
|
|
127
|
+
disabled={isImpersonating}
|
|
128
|
+
onClick={handleImpersonate}
|
|
129
|
+
>
|
|
130
|
+
<UserCog className="mr-2 h-4 w-4" /> Impersonate
|
|
131
|
+
</DropdownMenuItem>
|
|
132
|
+
<DropdownMenuItem
|
|
133
|
+
onClick={() =>
|
|
134
|
+
onConfirm({ kind: user.banned ? 'unban' : 'ban', user })
|
|
135
|
+
}
|
|
136
|
+
>
|
|
137
|
+
<Ban className="mr-2 h-4 w-4" />
|
|
138
|
+
{user.banned ? 'Unban User' : 'Ban User'}
|
|
139
|
+
</DropdownMenuItem>
|
|
140
|
+
<DropdownMenuSeparator />
|
|
141
|
+
<DropdownMenuItem
|
|
142
|
+
variant="destructive"
|
|
143
|
+
onClick={() => onConfirm({ kind: 'delete', user })}
|
|
144
|
+
>
|
|
145
|
+
<Trash2 className="mr-2 h-4 w-4" />
|
|
146
|
+
Delete
|
|
147
|
+
</DropdownMenuItem>
|
|
148
|
+
</>
|
|
149
|
+
)}
|
|
150
|
+
</DropdownMenuContent>
|
|
151
|
+
</DropdownMenu>
|
|
152
|
+
)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const filters: DataTableFilter[] = [
|
|
156
|
+
{
|
|
157
|
+
id: 'role',
|
|
158
|
+
label: 'Role',
|
|
159
|
+
action: getDistinctRoles,
|
|
160
|
+
queryKey: 'admin-distinct-roles'
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
id: 'banned',
|
|
164
|
+
label: 'Status',
|
|
165
|
+
options: [
|
|
166
|
+
{ label: 'Active', value: false },
|
|
167
|
+
{ label: 'Banned', value: true }
|
|
168
|
+
]
|
|
169
|
+
}
|
|
170
|
+
]
|
|
171
|
+
|
|
172
|
+
const getInitials = (name: string) =>
|
|
173
|
+
name
|
|
174
|
+
.split(' ')
|
|
175
|
+
.map(n => n[0])
|
|
176
|
+
.join('')
|
|
177
|
+
.toUpperCase()
|
|
178
|
+
.slice(0, 2)
|
|
179
|
+
|
|
180
|
+
export default function UsersPage() {
|
|
181
|
+
const queryClient = useQueryClient()
|
|
182
|
+
const { data: session } = useSession()
|
|
183
|
+
const [pendingConfirm, setPendingConfirm] = useState<PendingConfirm | null>(
|
|
184
|
+
null
|
|
185
|
+
)
|
|
186
|
+
const [isConfirming, setIsConfirming] = useState(false)
|
|
187
|
+
|
|
188
|
+
const [queryState, setQueryState] = useQueryStates({
|
|
189
|
+
page: parseAsInteger.withDefault(1),
|
|
190
|
+
limit: parseAsInteger.withDefault(10),
|
|
191
|
+
sortBy: parseAsString,
|
|
192
|
+
sortOrder: parseAsString,
|
|
193
|
+
search: parseAsString,
|
|
194
|
+
filters: parseAsJson(v => v as Record<string, (string | boolean)[]>)
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
const params = {
|
|
198
|
+
page: queryState.page,
|
|
199
|
+
limit: queryState.limit,
|
|
200
|
+
sortBy: (queryState.sortBy ?? undefined) as
|
|
201
|
+
'name' | 'email' | 'createdAt' | undefined,
|
|
202
|
+
sortOrder: (queryState.sortOrder ?? undefined) as SortOrderEnum | undefined,
|
|
203
|
+
search: queryState.search ?? undefined,
|
|
204
|
+
filters: queryState.filters ?? undefined
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const { data, isLoading } = useSafeActionQuery(
|
|
208
|
+
'admin-users',
|
|
209
|
+
getUsers,
|
|
210
|
+
params
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
async function runConfirmedAction({ kind, user }: PendingConfirm) {
|
|
214
|
+
setIsConfirming(true)
|
|
215
|
+
try {
|
|
216
|
+
const { error } =
|
|
217
|
+
kind === 'delete'
|
|
218
|
+
? await admin.removeUser({ userId: user.id })
|
|
219
|
+
: kind === 'ban'
|
|
220
|
+
? await admin.banUser({ userId: user.id })
|
|
221
|
+
: await admin.unbanUser({ userId: user.id })
|
|
222
|
+
|
|
223
|
+
if (error) {
|
|
224
|
+
toastActionError(error, 'That change was not saved. Try again.')
|
|
225
|
+
return
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
toastSuccessMessage(CONFIRM_COPY[kind].success)
|
|
229
|
+
setPendingConfirm(null)
|
|
230
|
+
await queryClient.invalidateQueries({ queryKey: ['admin-users'] })
|
|
231
|
+
} catch {
|
|
232
|
+
toastErrorMessage('That change was not saved. Try again.')
|
|
233
|
+
} finally {
|
|
234
|
+
setIsConfirming(false)
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const columns: DataTableColumnDef<User>[] = [
|
|
239
|
+
{
|
|
240
|
+
accessorKey: 'name',
|
|
241
|
+
header: 'User',
|
|
242
|
+
enableSorting: true,
|
|
243
|
+
cell: ({ row }) => (
|
|
244
|
+
<Link
|
|
245
|
+
href={`/admin/settings/users/${row.original.id}`}
|
|
246
|
+
className="group/user-link flex items-center gap-3"
|
|
247
|
+
>
|
|
248
|
+
<Avatar className="h-8 w-8">
|
|
249
|
+
<AvatarImage src={row.original.image ?? undefined} />
|
|
250
|
+
<AvatarFallback className="text-xs">
|
|
251
|
+
{getInitials(row.original.name)}
|
|
252
|
+
</AvatarFallback>
|
|
253
|
+
</Avatar>
|
|
254
|
+
<div className="flex flex-col">
|
|
255
|
+
<span className="font-medium group-hover/user-link:underline">
|
|
256
|
+
{row.original.name}
|
|
257
|
+
</span>
|
|
258
|
+
<span className="text-muted-foreground text-xs">
|
|
259
|
+
{row.original.email}
|
|
260
|
+
</span>
|
|
261
|
+
</div>
|
|
262
|
+
</Link>
|
|
263
|
+
)
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
accessorKey: 'role',
|
|
267
|
+
header: 'Role',
|
|
268
|
+
cell: ({ row }) => (
|
|
269
|
+
<Badge variant="outline" className="capitalize">
|
|
270
|
+
{row.original.role ?? 'user'}
|
|
271
|
+
</Badge>
|
|
272
|
+
)
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
accessorKey: 'banned',
|
|
276
|
+
header: 'Status',
|
|
277
|
+
enableSorting: false,
|
|
278
|
+
cell: ({ row }) => (
|
|
279
|
+
<Badge variant={row.original.banned ? 'destructive' : 'success'}>
|
|
280
|
+
{row.original.banned ? 'Banned' : 'Active'}
|
|
281
|
+
</Badge>
|
|
282
|
+
)
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
accessorKey: 'emailVerified',
|
|
286
|
+
header: 'Verified',
|
|
287
|
+
enableSorting: false,
|
|
288
|
+
cell: ({ row }) => (
|
|
289
|
+
<Badge variant={row.original.emailVerified ? 'success' : 'secondary'}>
|
|
290
|
+
{row.original.emailVerified ? 'Verified' : 'Unverified'}
|
|
291
|
+
</Badge>
|
|
292
|
+
)
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
accessorKey: 'createdAt',
|
|
296
|
+
header: 'Joined',
|
|
297
|
+
enableSorting: true,
|
|
298
|
+
cell: ({ row }) => formatDate(row.original.createdAt, { short: true })
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
id: 'actions',
|
|
302
|
+
header: 'Actions',
|
|
303
|
+
enableSorting: false,
|
|
304
|
+
cell: ({ row }) => (
|
|
305
|
+
<UserActionsCell
|
|
306
|
+
user={row.original}
|
|
307
|
+
isSelf={row.original.id === session?.user.id}
|
|
308
|
+
onConfirm={setPendingConfirm}
|
|
309
|
+
/>
|
|
310
|
+
)
|
|
311
|
+
}
|
|
312
|
+
]
|
|
313
|
+
|
|
314
|
+
const confirmCopy = pendingConfirm ? CONFIRM_COPY[pendingConfirm.kind] : null
|
|
315
|
+
|
|
316
|
+
return (
|
|
317
|
+
<div className="space-y-6">
|
|
318
|
+
<PageHeading
|
|
319
|
+
title="Users"
|
|
320
|
+
description="Create accounts, assign roles, and ban or delete users."
|
|
321
|
+
icon={Users}
|
|
322
|
+
>
|
|
323
|
+
<Button size="lg" asChild>
|
|
324
|
+
<Link href="/admin/settings/users/new">
|
|
325
|
+
<Plus /> New User
|
|
326
|
+
</Link>
|
|
327
|
+
</Button>
|
|
328
|
+
</PageHeading>
|
|
329
|
+
|
|
330
|
+
<DataTable
|
|
331
|
+
columns={columns}
|
|
332
|
+
data={data?.[0]}
|
|
333
|
+
isLoading={isLoading}
|
|
334
|
+
totalCount={data?.[1]}
|
|
335
|
+
enableSearch
|
|
336
|
+
initialSearch={params.search}
|
|
337
|
+
searchPlaceholder="Search users…"
|
|
338
|
+
manualPagination
|
|
339
|
+
manualSorting
|
|
340
|
+
pageIndex={params.page - 1}
|
|
341
|
+
pageSize={params.limit}
|
|
342
|
+
filters={filters}
|
|
343
|
+
activeFilters={params.filters ?? {}}
|
|
344
|
+
onParamsChange={({ page, limit, sortBy, sortOrder, search, filters }) =>
|
|
345
|
+
setQueryState({
|
|
346
|
+
page,
|
|
347
|
+
limit,
|
|
348
|
+
sortBy: sortBy ?? null,
|
|
349
|
+
sortOrder: sortOrder ?? null,
|
|
350
|
+
search: search ?? null,
|
|
351
|
+
filters: filters ?? null
|
|
352
|
+
})
|
|
353
|
+
}
|
|
354
|
+
/>
|
|
355
|
+
|
|
356
|
+
<ConfirmDialog
|
|
357
|
+
open={pendingConfirm !== null}
|
|
358
|
+
onOpenChange={open => {
|
|
359
|
+
if (!open) setPendingConfirm(null)
|
|
360
|
+
}}
|
|
361
|
+
title={confirmCopy?.title ?? ''}
|
|
362
|
+
description={
|
|
363
|
+
<>
|
|
364
|
+
<span className="text-foreground font-medium">
|
|
365
|
+
{pendingConfirm?.user.email}
|
|
366
|
+
</span>
|
|
367
|
+
: {confirmCopy?.description}
|
|
368
|
+
</>
|
|
369
|
+
}
|
|
370
|
+
confirmLabel={confirmCopy?.confirmLabel ?? ''}
|
|
371
|
+
destructive={pendingConfirm?.kind !== 'unban'}
|
|
372
|
+
pending={isConfirming}
|
|
373
|
+
onConfirm={() => pendingConfirm && runConfirmedAction(pendingConfirm)}
|
|
374
|
+
/>
|
|
375
|
+
</div>
|
|
376
|
+
)
|
|
377
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { zodResolver } from '@hookform/resolvers/zod'
|
|
4
|
+
import { useRouter } from 'next/navigation'
|
|
5
|
+
import { useForm, useWatch } from 'react-hook-form'
|
|
6
|
+
import { z } from 'zod'
|
|
7
|
+
import { Button } from '~/components/ui/button'
|
|
8
|
+
import {
|
|
9
|
+
Field,
|
|
10
|
+
FieldContent,
|
|
11
|
+
FieldError,
|
|
12
|
+
FieldLabel
|
|
13
|
+
} from '~/components/ui/field'
|
|
14
|
+
import { Input } from '~/components/ui/input'
|
|
15
|
+
import {
|
|
16
|
+
Select,
|
|
17
|
+
SelectContent,
|
|
18
|
+
SelectItem,
|
|
19
|
+
SelectTrigger,
|
|
20
|
+
SelectValue
|
|
21
|
+
} from '~/components/ui/select'
|
|
22
|
+
import { useSafeActionMutation } from '~/lib/safe-action-client'
|
|
23
|
+
import { toastActionError, toastSuccessMessage } from '~/lib/toast-message'
|
|
24
|
+
import { createUser, updateUser } from '../../../actions/users'
|
|
25
|
+
import { baseUserFormSchema, type UserRole } from './validation'
|
|
26
|
+
|
|
27
|
+
type UserFormValues = z.infer<typeof baseUserFormSchema>
|
|
28
|
+
|
|
29
|
+
type UserFormProps = {
|
|
30
|
+
mode: 'create' | 'edit'
|
|
31
|
+
initialData?: {
|
|
32
|
+
id: string
|
|
33
|
+
name: string
|
|
34
|
+
email: string
|
|
35
|
+
role: string | null
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function UserForm({ mode, initialData }: UserFormProps) {
|
|
40
|
+
const router = useRouter()
|
|
41
|
+
|
|
42
|
+
const form = useForm<UserFormValues>({
|
|
43
|
+
resolver: zodResolver(baseUserFormSchema),
|
|
44
|
+
defaultValues: {
|
|
45
|
+
name: initialData?.name ?? '',
|
|
46
|
+
email: initialData?.email ?? '',
|
|
47
|
+
role: (initialData?.role as UserRole) ?? 'user'
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
const mutationOptions = {
|
|
52
|
+
onSuccess: () => {
|
|
53
|
+
toastSuccessMessage(mode === 'create' ? 'User created' : 'User updated')
|
|
54
|
+
router.push('/admin/settings/users')
|
|
55
|
+
},
|
|
56
|
+
onError: (error: Error) =>
|
|
57
|
+
toastActionError(error, 'The user was not saved. Try again.')
|
|
58
|
+
}
|
|
59
|
+
const create = useSafeActionMutation(createUser, mutationOptions)
|
|
60
|
+
const update = useSafeActionMutation(updateUser, mutationOptions)
|
|
61
|
+
const isPending = create.isPending || update.isPending
|
|
62
|
+
|
|
63
|
+
const onSubmit = (values: UserFormValues) => {
|
|
64
|
+
if (mode === 'edit' && initialData) {
|
|
65
|
+
update.mutate({ id: initialData.id, ...values })
|
|
66
|
+
} else {
|
|
67
|
+
create.mutate(values)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const errors = form.formState.errors
|
|
72
|
+
const role = useWatch({ control: form.control, name: 'role' })
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-6">
|
|
76
|
+
<div className="grid gap-6 md:grid-cols-2">
|
|
77
|
+
<Field>
|
|
78
|
+
<FieldLabel>Name</FieldLabel>
|
|
79
|
+
<FieldContent>
|
|
80
|
+
<Input
|
|
81
|
+
{...form.register('name')}
|
|
82
|
+
placeholder="Full name"
|
|
83
|
+
aria-invalid={!!errors.name}
|
|
84
|
+
/>
|
|
85
|
+
<FieldError errors={errors.name ? [errors.name] : []} />
|
|
86
|
+
</FieldContent>
|
|
87
|
+
</Field>
|
|
88
|
+
|
|
89
|
+
<Field>
|
|
90
|
+
<FieldLabel>Email</FieldLabel>
|
|
91
|
+
<FieldContent>
|
|
92
|
+
<Input
|
|
93
|
+
{...form.register('email')}
|
|
94
|
+
type="email"
|
|
95
|
+
placeholder="email@example.com"
|
|
96
|
+
aria-invalid={!!errors.email}
|
|
97
|
+
/>
|
|
98
|
+
<FieldError errors={errors.email ? [errors.email] : []} />
|
|
99
|
+
</FieldContent>
|
|
100
|
+
</Field>
|
|
101
|
+
|
|
102
|
+
<Field>
|
|
103
|
+
<FieldLabel>Role</FieldLabel>
|
|
104
|
+
<FieldContent>
|
|
105
|
+
<Select
|
|
106
|
+
value={role}
|
|
107
|
+
onValueChange={value => form.setValue('role', value as UserRole)}
|
|
108
|
+
>
|
|
109
|
+
<SelectTrigger aria-invalid={!!errors.role} className="w-full">
|
|
110
|
+
<SelectValue placeholder="Select role" />
|
|
111
|
+
</SelectTrigger>
|
|
112
|
+
<SelectContent>
|
|
113
|
+
<SelectItem value="superadmin">Superadmin</SelectItem>
|
|
114
|
+
<SelectItem value="admin">Admin</SelectItem>
|
|
115
|
+
<SelectItem value="user">User</SelectItem>
|
|
116
|
+
</SelectContent>
|
|
117
|
+
</Select>
|
|
118
|
+
<FieldError errors={errors.role ? [errors.role] : []} />
|
|
119
|
+
</FieldContent>
|
|
120
|
+
</Field>
|
|
121
|
+
</div>
|
|
122
|
+
|
|
123
|
+
<div className="flex justify-end gap-3">
|
|
124
|
+
<Button
|
|
125
|
+
type="button"
|
|
126
|
+
variant="outline"
|
|
127
|
+
onClick={() => router.push('/admin/settings/users')}
|
|
128
|
+
disabled={isPending}
|
|
129
|
+
>
|
|
130
|
+
Cancel
|
|
131
|
+
</Button>
|
|
132
|
+
<Button type="submit" disabled={isPending}>
|
|
133
|
+
{mode === 'create' ? 'Create User' : 'Save Changes'}
|
|
134
|
+
</Button>
|
|
135
|
+
</div>
|
|
136
|
+
</form>
|
|
137
|
+
)
|
|
138
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import { emailValidation, stringValidation } from '~/lib/validations'
|
|
3
|
+
|
|
4
|
+
/** The roles assignable to a platform user. */
|
|
5
|
+
export const userRoles = ['superadmin', 'admin', 'user'] as const
|
|
6
|
+
|
|
7
|
+
export type UserRole = (typeof userRoles)[number]
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Admin user form. Only superadmins reach it, and they may assign any role,
|
|
11
|
+
* including promoting a user to `superadmin`.
|
|
12
|
+
*/
|
|
13
|
+
export const baseUserFormSchema = z.object({
|
|
14
|
+
name: stringValidation,
|
|
15
|
+
email: emailValidation,
|
|
16
|
+
role: z.enum(userRoles)
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
export const createUserSchema = baseUserFormSchema
|
|
20
|
+
|
|
21
|
+
export const updateUserSchema = baseUserFormSchema.extend({
|
|
22
|
+
id: stringValidation
|
|
23
|
+
})
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Metadata } from 'next'
|
|
2
|
+
import { headers } from 'next/headers'
|
|
3
|
+
import Link from 'next/link'
|
|
4
|
+
import { redirect } from 'next/navigation'
|
|
5
|
+
import { Logo } from '~/components/logo'
|
|
6
|
+
import { UserMenu } from '~/components/user-menu'
|
|
7
|
+
import { getAuthSession } from '~/lib/auth'
|
|
8
|
+
import { sanitizeCallbackUrl } from '~/lib/callback-url'
|
|
9
|
+
import { privatePageRobots } from '~/lib/seo'
|
|
10
|
+
|
|
11
|
+
export const metadata: Metadata = {
|
|
12
|
+
robots: privatePageRobots
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default async function AppLayout({
|
|
16
|
+
children
|
|
17
|
+
}: {
|
|
18
|
+
children: React.ReactNode
|
|
19
|
+
}) {
|
|
20
|
+
const authSession = await getAuthSession()
|
|
21
|
+
|
|
22
|
+
if (!authSession) {
|
|
23
|
+
const headerStore = await headers()
|
|
24
|
+
const callbackUrl =
|
|
25
|
+
sanitizeCallbackUrl(headerStore.get('x-pathname') ?? undefined) ?? '/app'
|
|
26
|
+
redirect(`/login?callbackUrl=${encodeURIComponent(callbackUrl)}`)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<div className="flex min-h-screen flex-col">
|
|
31
|
+
<header className="bg-background sticky top-0 z-50 flex h-14 shrink-0 items-center justify-between gap-2 border-b px-4">
|
|
32
|
+
<Link href="/app" className="flex shrink-0 items-center">
|
|
33
|
+
<Logo size={32} priority className="text-lg" />
|
|
34
|
+
</Link>
|
|
35
|
+
<UserMenu
|
|
36
|
+
user={authSession.user}
|
|
37
|
+
isSuperAdmin={authSession.isSuperAdmin}
|
|
38
|
+
isImpersonating={!!authSession.session.impersonatedBy}
|
|
39
|
+
/>
|
|
40
|
+
</header>
|
|
41
|
+
<main className="flex-1 p-4">{children}</main>
|
|
42
|
+
</div>
|
|
43
|
+
)
|
|
44
|
+
}
|
|
@@ -1,3 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { LayoutGrid } from 'lucide-react'
|
|
2
|
+
import { PageHeading } from '~/components/page-heading'
|
|
3
|
+
import { siteConfig } from '~/lib/siteConfig'
|
|
4
|
+
|
|
5
|
+
export default function AppPage() {
|
|
6
|
+
return (
|
|
7
|
+
<div className="mx-auto w-full max-w-5xl">
|
|
8
|
+
<PageHeading
|
|
9
|
+
title={`Welcome to ${siteConfig.name}`}
|
|
10
|
+
description="Build your product here."
|
|
11
|
+
icon={LayoutGrid}
|
|
12
|
+
/>
|
|
13
|
+
</div>
|
|
14
|
+
)
|
|
3
15
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { ArrowLeft } from 'lucide-react'
|
|
2
|
+
import type { Metadata } from 'next'
|
|
3
|
+
import { headers } from 'next/headers'
|
|
4
|
+
import Link from 'next/link'
|
|
5
|
+
import { redirect } from 'next/navigation'
|
|
6
|
+
import { NuqsAdapter } from 'nuqs/adapters/next/app'
|
|
7
|
+
import { Logo } from '~/components/logo'
|
|
8
|
+
import { SiteFooter } from '~/components/site-footer'
|
|
9
|
+
import { Button } from '~/components/ui/button'
|
|
10
|
+
import { UserMenu } from '~/components/user-menu'
|
|
11
|
+
import { getAuthSession } from '~/lib/auth'
|
|
12
|
+
import { sanitizeCallbackUrl } from '~/lib/callback-url'
|
|
13
|
+
import { privatePageRobots } from '~/lib/seo'
|
|
14
|
+
import { siteConfig } from '~/lib/siteConfig'
|
|
15
|
+
|
|
16
|
+
export const metadata: Metadata = {
|
|
17
|
+
robots: privatePageRobots
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default async function AccountLayout({
|
|
21
|
+
children
|
|
22
|
+
}: {
|
|
23
|
+
children: React.ReactNode
|
|
24
|
+
}) {
|
|
25
|
+
const authSession = await getAuthSession()
|
|
26
|
+
|
|
27
|
+
if (!authSession) {
|
|
28
|
+
const headerStore = await headers()
|
|
29
|
+
const callbackUrl =
|
|
30
|
+
sanitizeCallbackUrl(headerStore.get('x-pathname') ?? undefined) ??
|
|
31
|
+
'/profile'
|
|
32
|
+
redirect(`/login?callbackUrl=${encodeURIComponent(callbackUrl)}`)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<NuqsAdapter>
|
|
37
|
+
<div className="flex min-h-screen flex-col">
|
|
38
|
+
<header className="bg-background sticky top-0 z-50 flex h-14 shrink-0 items-center gap-2 border-b px-4">
|
|
39
|
+
<Link href="/" className="flex shrink-0 items-center">
|
|
40
|
+
<Logo size={32} priority className="text-lg" />
|
|
41
|
+
</Link>
|
|
42
|
+
|
|
43
|
+
<div className="flex flex-1 items-center justify-end gap-2">
|
|
44
|
+
<Button asChild variant="ghost" size="sm">
|
|
45
|
+
<Link href="/app">
|
|
46
|
+
<ArrowLeft className="size-4" />
|
|
47
|
+
Back to App
|
|
48
|
+
</Link>
|
|
49
|
+
</Button>
|
|
50
|
+
<UserMenu
|
|
51
|
+
user={authSession.user}
|
|
52
|
+
isSuperAdmin={authSession.isSuperAdmin}
|
|
53
|
+
isImpersonating={!!authSession.session.impersonatedBy}
|
|
54
|
+
/>
|
|
55
|
+
</div>
|
|
56
|
+
</header>
|
|
57
|
+
|
|
58
|
+
<main className="flex-1">{children}</main>
|
|
59
|
+
|
|
60
|
+
<SiteFooter name={siteConfig.name} />
|
|
61
|
+
</div>
|
|
62
|
+
</NuqsAdapter>
|
|
63
|
+
)
|
|
64
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { UserCog } from 'lucide-react'
|
|
2
|
+
import { PageHeading } from '~/components/page-heading'
|
|
3
|
+
import { ProfileForm } from './profile-form'
|
|
4
|
+
|
|
5
|
+
export default function ProfilePage() {
|
|
6
|
+
return (
|
|
7
|
+
<div className="mx-auto w-full max-w-3xl space-y-6 p-4 sm:p-6">
|
|
8
|
+
<PageHeading
|
|
9
|
+
title="Your Profile"
|
|
10
|
+
description="Update your name and review your account details."
|
|
11
|
+
icon={UserCog}
|
|
12
|
+
/>
|
|
13
|
+
<ProfileForm />
|
|
14
|
+
</div>
|
|
15
|
+
)
|
|
16
|
+
}
|