create-ej-app 25.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 +83 -28
- 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 -0
- package/template/nextjs/next.config.ts +8 -1
- package/template/nextjs/package.json +47 -40
- 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 +8 -0
- package/template/saas-starter/.env.example +25 -0
- package/template/saas-starter/.vscode/extensions.json +11 -0
- package/template/saas-starter/.vscode/settings.json +3 -0
- package/template/saas-starter/AGENTS.md +302 -0
- package/template/saas-starter/CLAUDE.md +1 -0
- package/template/saas-starter/Dockerfile +15 -0
- package/template/saas-starter/README.md +125 -0
- package/template/saas-starter/bunfig.toml +3 -0
- package/template/saas-starter/components.json +25 -0
- package/template/saas-starter/drizzle.config.ts +10 -0
- package/template/saas-starter/eslint.config.mjs +24 -0
- package/template/saas-starter/gitignore +14 -0
- package/template/saas-starter/next.config.ts +32 -0
- package/template/saas-starter/package.json +97 -0
- package/template/saas-starter/postcss.config.mjs +7 -0
- package/template/saas-starter/prettier.config.mjs +11 -0
- package/template/saas-starter/public/logo-dark.svg +4 -0
- package/template/saas-starter/public/logo.svg +4 -0
- package/template/saas-starter/public/placeholder.svg +1 -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 +183 -0
- package/template/saas-starter/src/app/(admin)/admin/_components/admin-header.tsx +24 -0
- package/template/saas-starter/src/app/(admin)/admin/_components/admin-search.tsx +16 -0
- package/template/saas-starter/src/app/(admin)/admin/_components/admin-sidebar.tsx +42 -0
- 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 +53 -0
- package/template/saas-starter/src/app/(admin)/admin/page.tsx +60 -0
- 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 +377 -0
- 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 +216 -0
- 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 +189 -0
- 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 +17 -0
- package/template/saas-starter/src/app/(app)/app/[orgId]/layout.tsx +31 -0
- package/template/saas-starter/src/app/(app)/app/[orgId]/settings/_components/billing-email-form.tsx +92 -0
- package/template/saas-starter/src/app/(app)/app/[orgId]/settings/_components/danger-zone.tsx +357 -0
- package/template/saas-starter/src/app/(app)/app/[orgId]/settings/_components/general-settings-form.tsx +130 -0
- package/template/saas-starter/src/app/(app)/app/[orgId]/settings/_components/plans-section.tsx +222 -0
- package/template/saas-starter/src/app/(app)/app/[orgId]/settings/billing/page.tsx +115 -0
- 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 +168 -0
- package/template/saas-starter/src/app/(app)/app/[orgId]/settings/members/_components/members-tabs.tsx +604 -0
- package/template/saas-starter/src/app/(app)/app/[orgId]/settings/members/page.tsx +33 -0
- package/template/saas-starter/src/app/(app)/app/[orgId]/settings/page.tsx +55 -0
- 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 +31 -0
- package/template/saas-starter/src/app/(app)/app/_components/app-search.tsx +26 -0
- package/template/saas-starter/src/app/(app)/app/_components/app-sidebar.tsx +30 -0
- 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 +37 -0
- package/template/saas-starter/src/app/(app)/app/_components/organization-switcher.tsx +200 -0
- package/template/saas-starter/src/app/(app)/app/layout.tsx +64 -0
- package/template/saas-starter/src/app/(app)/app/onboarding/_components/create-organization-form.tsx +117 -0
- package/template/saas-starter/src/app/(app)/app/onboarding/page.tsx +40 -0
- package/template/saas-starter/src/app/(app)/app/page.tsx +76 -0
- 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 +131 -0
- package/template/saas-starter/src/app/(auth)/login/page.tsx +105 -0
- package/template/saas-starter/src/app/(auth)/login/social-login-buttons.tsx +137 -0
- package/template/saas-starter/src/app/(invitation)/accept-invitation/[id]/accept-invitation-form.tsx +94 -0
- package/template/saas-starter/src/app/(invitation)/accept-invitation/[id]/page.tsx +153 -0
- 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 +48 -0
- package/template/saas-starter/src/app/(marketing)/legal.tsx +66 -0
- package/template/saas-starter/src/app/(marketing)/page.tsx +24 -0
- package/template/saas-starter/src/app/(marketing)/privacy/page.tsx +63 -0
- package/template/saas-starter/src/app/(marketing)/terms/page.tsx +41 -0
- 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/api/auth/[...all]/route.ts +4 -0
- package/template/saas-starter/src/app/api/webhooks/stripe/route.ts +94 -0
- package/template/saas-starter/src/app/error.tsx +37 -0
- package/template/saas-starter/src/app/favicon.ico +0 -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 +269 -0
- package/template/saas-starter/src/app/layout.tsx +77 -0
- package/template/saas-starter/src/app/not-found.tsx +49 -0
- package/template/saas-starter/src/app/robots.ts +36 -0
- package/template/saas-starter/src/app/sitemap.ts +21 -0
- package/template/saas-starter/src/components/confirm-dialog.tsx +79 -0
- package/template/saas-starter/src/components/dashboard-header.tsx +70 -0
- package/template/saas-starter/src/components/data-table/enum.ts +5 -0
- package/template/saas-starter/src/components/data-table/features.ts +49 -0
- package/template/saas-starter/src/components/data-table/index.tsx +961 -0
- package/template/saas-starter/src/components/data-table/types.ts +76 -0
- package/template/saas-starter/src/components/error.tsx +71 -0
- package/template/saas-starter/src/components/file-upload.tsx +254 -0
- package/template/saas-starter/src/components/loader.tsx +41 -0
- package/template/saas-starter/src/components/logo.tsx +49 -0
- package/template/saas-starter/src/components/navigation-search.tsx +140 -0
- package/template/saas-starter/src/components/navigation-sidebar.tsx +241 -0
- package/template/saas-starter/src/components/page-heading.tsx +38 -0
- package/template/saas-starter/src/components/react-query-provider.tsx +51 -0
- package/template/saas-starter/src/components/route-error.tsx +55 -0
- package/template/saas-starter/src/components/screen-size.tsx +76 -0
- package/template/saas-starter/src/components/site-footer.tsx +39 -0
- 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 +115 -0
- package/template/saas-starter/src/components/theme-toggle.tsx +75 -0
- package/template/saas-starter/src/components/ui/alert-dialog.tsx +199 -0
- package/template/saas-starter/src/components/ui/avatar.tsx +112 -0
- package/template/saas-starter/src/components/ui/badge.tsx +54 -0
- package/template/saas-starter/src/components/ui/button.tsx +69 -0
- package/template/saas-starter/src/components/ui/card.tsx +103 -0
- package/template/saas-starter/src/components/ui/checkbox.tsx +32 -0
- package/template/saas-starter/src/components/ui/collapsible.tsx +33 -0
- package/template/saas-starter/src/components/ui/command.tsx +192 -0
- package/template/saas-starter/src/components/ui/dialog.tsx +164 -0
- package/template/saas-starter/src/components/ui/dropdown-menu.tsx +273 -0
- package/template/saas-starter/src/components/ui/field.tsx +238 -0
- package/template/saas-starter/src/components/ui/input-group.tsx +156 -0
- package/template/saas-starter/src/components/ui/input.tsx +19 -0
- package/template/saas-starter/src/components/ui/label.tsx +24 -0
- package/template/saas-starter/src/components/ui/popover.tsx +89 -0
- package/template/saas-starter/src/components/ui/select.tsx +195 -0
- package/template/saas-starter/src/components/ui/separator.tsx +28 -0
- package/template/saas-starter/src/components/ui/sheet.tsx +143 -0
- package/template/saas-starter/src/components/ui/sidebar.tsx +702 -0
- package/template/saas-starter/src/components/ui/skeleton.tsx +13 -0
- package/template/saas-starter/src/components/ui/sonner.tsx +45 -0
- package/template/saas-starter/src/components/ui/switch.tsx +33 -0
- package/template/saas-starter/src/components/ui/table.tsx +116 -0
- package/template/saas-starter/src/components/ui/tabs.tsx +90 -0
- package/template/saas-starter/src/components/ui/textarea.tsx +18 -0
- package/template/saas-starter/src/components/ui/tooltip.tsx +57 -0
- package/template/saas-starter/src/components/user-menu.tsx +213 -0
- package/template/saas-starter/src/db/common.ts +63 -0
- package/template/saas-starter/src/db/enums.ts +50 -0
- package/template/saas-starter/src/db/index.ts +60 -0
- package/template/saas-starter/src/db/relations.ts +112 -0
- package/template/saas-starter/src/db/schema.ts +342 -0
- package/template/saas-starter/src/emails/components/email-layout.tsx +79 -0
- package/template/saas-starter/src/emails/invitation.tsx +69 -0
- package/template/saas-starter/src/emails/magic-link.tsx +51 -0
- package/template/saas-starter/src/emails/test.tsx +34 -0
- package/template/saas-starter/src/emails/welcome.tsx +37 -0
- package/template/saas-starter/src/env.ts +66 -0
- package/template/saas-starter/src/hooks/use-mobile.ts +21 -0
- package/template/saas-starter/src/instrumentation.ts +44 -0
- package/template/saas-starter/src/lib/actions.ts +55 -0
- package/template/saas-starter/src/lib/admin-navigation.ts +63 -0
- package/template/saas-starter/src/lib/app-navigation.ts +63 -0
- package/template/saas-starter/src/lib/auth-client.ts +34 -0
- package/template/saas-starter/src/lib/auth-permissions.ts +61 -0
- package/template/saas-starter/src/lib/auth.ts +312 -0
- package/template/saas-starter/src/lib/billing.ts +152 -0
- package/template/saas-starter/src/lib/callback-url.ts +28 -0
- package/template/saas-starter/src/lib/cn.ts +4 -0
- package/template/saas-starter/src/lib/constants.ts +91 -0
- package/template/saas-starter/src/lib/delay.ts +12 -0
- package/template/saas-starter/src/lib/email-service.ts +118 -0
- package/template/saas-starter/src/lib/errors.ts +74 -0
- package/template/saas-starter/src/lib/format-currency.ts +25 -0
- package/template/saas-starter/src/lib/format-date.ts +75 -0
- package/template/saas-starter/src/lib/image-url.ts +54 -0
- package/template/saas-starter/src/lib/nodemailer.ts +67 -0
- package/template/saas-starter/src/lib/organization-access.ts +73 -0
- package/template/saas-starter/src/lib/otel.ts +117 -0
- package/template/saas-starter/src/lib/plan-limits.ts +37 -0
- package/template/saas-starter/src/lib/plans.ts +90 -0
- package/template/saas-starter/src/lib/rbac.ts +44 -0
- package/template/saas-starter/src/lib/safe-action-client.ts +126 -0
- package/template/saas-starter/src/lib/safe-action.ts +187 -0
- 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 +20 -0
- package/template/saas-starter/src/lib/storage.ts +311 -0
- package/template/saas-starter/src/lib/stripe.ts +9 -0
- package/template/saas-starter/src/lib/toast-message.ts +101 -0
- package/template/saas-starter/src/lib/validations.ts +95 -0
- 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/reset-db.ts +22 -0
- package/template/saas-starter/src/scripts/seed.ts +85 -0
- package/template/saas-starter/src/scripts/setup-db.ts +72 -0
- package/template/saas-starter/src/scripts/setup-stripe-plans.ts +206 -0
- package/template/saas-starter/src/scripts/test-mail.ts +43 -0
- 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 +52 -0
- package/cli.js +0 -143
- 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
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { LayoutGrid } from 'lucide-react'
|
|
4
|
+
import { PageHeading } from '~/components/page-heading'
|
|
5
|
+
import { useOrganizationContext } from '../../_components/organization-context'
|
|
6
|
+
|
|
7
|
+
export default function DashboardPage() {
|
|
8
|
+
const org = useOrganizationContext()
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
<PageHeading
|
|
12
|
+
title={org.name}
|
|
13
|
+
description="Your organization's home. Build your product here."
|
|
14
|
+
icon={LayoutGrid}
|
|
15
|
+
/>
|
|
16
|
+
)
|
|
17
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { notFound } from 'next/navigation'
|
|
2
|
+
import { getOrganizationCached } from '../../actions/organizations'
|
|
3
|
+
import { OrganizationContextProvider } from '../_components/organization-context'
|
|
4
|
+
|
|
5
|
+
export default async function OrganizationLayout({
|
|
6
|
+
children,
|
|
7
|
+
params
|
|
8
|
+
}: {
|
|
9
|
+
children: React.ReactNode
|
|
10
|
+
params: Promise<{ orgId: string }>
|
|
11
|
+
}) {
|
|
12
|
+
const { orgId } = await params
|
|
13
|
+
const org = (await getOrganizationCached(orgId))?.data
|
|
14
|
+
|
|
15
|
+
if (!org) {
|
|
16
|
+
return notFound()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<OrganizationContextProvider
|
|
21
|
+
value={{
|
|
22
|
+
id: org.id,
|
|
23
|
+
name: org.name,
|
|
24
|
+
role: org.role,
|
|
25
|
+
memberId: org.memberId
|
|
26
|
+
}}
|
|
27
|
+
>
|
|
28
|
+
{children}
|
|
29
|
+
</OrganizationContextProvider>
|
|
30
|
+
)
|
|
31
|
+
}
|
package/template/saas-starter/src/app/(app)/app/[orgId]/settings/_components/billing-email-form.tsx
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { zodResolver } from '@hookform/resolvers/zod'
|
|
4
|
+
import { Loader2 } from 'lucide-react'
|
|
5
|
+
import { useRouter } from 'next/navigation'
|
|
6
|
+
import { Controller, useForm } from 'react-hook-form'
|
|
7
|
+
import { z } from 'zod'
|
|
8
|
+
import { updateBillingEmailAction } from '~/app/(app)/actions/billing'
|
|
9
|
+
import { Button } from '~/components/ui/button'
|
|
10
|
+
import {
|
|
11
|
+
Field,
|
|
12
|
+
FieldDescription,
|
|
13
|
+
FieldError,
|
|
14
|
+
FieldLabel
|
|
15
|
+
} from '~/components/ui/field'
|
|
16
|
+
import { Input } from '~/components/ui/input'
|
|
17
|
+
import { useSafeActionMutation } from '~/lib/safe-action-client'
|
|
18
|
+
import { toastActionError, toastSuccessMessage } from '~/lib/toast-message'
|
|
19
|
+
import { emailValidation } from '~/lib/validations'
|
|
20
|
+
|
|
21
|
+
const schema = z.object({
|
|
22
|
+
billingEmail: emailValidation
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
type Form = z.infer<typeof schema>
|
|
26
|
+
|
|
27
|
+
export function BillingEmailForm({
|
|
28
|
+
orgId,
|
|
29
|
+
defaultBillingEmail
|
|
30
|
+
}: {
|
|
31
|
+
orgId: string
|
|
32
|
+
defaultBillingEmail: string | null
|
|
33
|
+
}) {
|
|
34
|
+
const router = useRouter()
|
|
35
|
+
|
|
36
|
+
const form = useForm<Form>({
|
|
37
|
+
resolver: zodResolver(schema),
|
|
38
|
+
defaultValues: { billingEmail: defaultBillingEmail ?? '' }
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
const save = useSafeActionMutation(updateBillingEmailAction, {
|
|
42
|
+
onSuccess: (_, values) => {
|
|
43
|
+
form.reset({ billingEmail: values.billingEmail })
|
|
44
|
+
toastSuccessMessage('Billing email updated')
|
|
45
|
+
router.refresh()
|
|
46
|
+
},
|
|
47
|
+
onError: error =>
|
|
48
|
+
toastActionError(error, 'The billing email was not saved. Try again.')
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<form
|
|
53
|
+
onSubmit={form.handleSubmit(values =>
|
|
54
|
+
save.mutate({ organizationId: orgId, ...values })
|
|
55
|
+
)}
|
|
56
|
+
className="flex flex-col gap-6"
|
|
57
|
+
>
|
|
58
|
+
<Controller
|
|
59
|
+
control={form.control}
|
|
60
|
+
name="billingEmail"
|
|
61
|
+
render={({ field, fieldState }) => (
|
|
62
|
+
<Field data-invalid={fieldState.invalid}>
|
|
63
|
+
<FieldLabel htmlFor={field.name}>Billing email</FieldLabel>
|
|
64
|
+
<Input
|
|
65
|
+
id={field.name}
|
|
66
|
+
type="email"
|
|
67
|
+
placeholder="billing@example.com"
|
|
68
|
+
aria-invalid={fieldState.invalid}
|
|
69
|
+
{...field}
|
|
70
|
+
/>
|
|
71
|
+
<FieldDescription>
|
|
72
|
+
Required before you choose a paid plan.
|
|
73
|
+
</FieldDescription>
|
|
74
|
+
<FieldError
|
|
75
|
+
errors={fieldState.error ? [fieldState.error] : undefined}
|
|
76
|
+
/>
|
|
77
|
+
</Field>
|
|
78
|
+
)}
|
|
79
|
+
/>
|
|
80
|
+
|
|
81
|
+
<div>
|
|
82
|
+
<Button
|
|
83
|
+
type="submit"
|
|
84
|
+
disabled={save.isPending || !form.formState.isDirty}
|
|
85
|
+
>
|
|
86
|
+
{save.isPending && <Loader2 className="animate-spin" />}
|
|
87
|
+
Save Billing Email
|
|
88
|
+
</Button>
|
|
89
|
+
</div>
|
|
90
|
+
</form>
|
|
91
|
+
)
|
|
92
|
+
}
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { Loader2 } from 'lucide-react'
|
|
4
|
+
import { useRouter } from 'next/navigation'
|
|
5
|
+
import { useState } from 'react'
|
|
6
|
+
import { transferOrganizationOwnershipAction } from '~/app/(app)/actions/organizations'
|
|
7
|
+
import { Button } from '~/components/ui/button'
|
|
8
|
+
import {
|
|
9
|
+
Dialog,
|
|
10
|
+
DialogContent,
|
|
11
|
+
DialogDescription,
|
|
12
|
+
DialogFooter,
|
|
13
|
+
DialogHeader,
|
|
14
|
+
DialogTitle,
|
|
15
|
+
DialogTrigger
|
|
16
|
+
} from '~/components/ui/dialog'
|
|
17
|
+
import { Input } from '~/components/ui/input'
|
|
18
|
+
import { Label } from '~/components/ui/label'
|
|
19
|
+
import {
|
|
20
|
+
Select,
|
|
21
|
+
SelectContent,
|
|
22
|
+
SelectItem,
|
|
23
|
+
SelectTrigger,
|
|
24
|
+
SelectValue
|
|
25
|
+
} from '~/components/ui/select'
|
|
26
|
+
import { organization } from '~/lib/auth-client'
|
|
27
|
+
import { OWNERSHIP_DEMOTION_NOTICE } from '~/lib/rbac'
|
|
28
|
+
import { useSafeActionMutation } from '~/lib/safe-action-client'
|
|
29
|
+
import {
|
|
30
|
+
toastActionError,
|
|
31
|
+
toastErrorMessage,
|
|
32
|
+
toastSuccessMessage
|
|
33
|
+
} from '~/lib/toast-message'
|
|
34
|
+
|
|
35
|
+
type TransferTarget = {
|
|
36
|
+
memberId: string
|
|
37
|
+
name: string
|
|
38
|
+
email: string
|
|
39
|
+
role: string
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function DangerZone({
|
|
43
|
+
orgId,
|
|
44
|
+
orgName,
|
|
45
|
+
isOwner,
|
|
46
|
+
transferTargets
|
|
47
|
+
}: {
|
|
48
|
+
orgId: string
|
|
49
|
+
orgName: string
|
|
50
|
+
isOwner: boolean
|
|
51
|
+
transferTargets: TransferTarget[]
|
|
52
|
+
}) {
|
|
53
|
+
// The sole owner can't leave: ownership must first be handed to someone else.
|
|
54
|
+
const isSoleOwner =
|
|
55
|
+
isOwner && !transferTargets.some(target => target.role === 'owner')
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<section className="border-destructive/30 space-y-6 rounded-lg border p-6">
|
|
59
|
+
<div>
|
|
60
|
+
<h2 className="text-destructive text-lg font-semibold">Danger Zone</h2>
|
|
61
|
+
<p className="text-muted-foreground text-sm">
|
|
62
|
+
These actions are hard or impossible to undo.
|
|
63
|
+
</p>
|
|
64
|
+
</div>
|
|
65
|
+
|
|
66
|
+
{isOwner && transferTargets.length > 0 ? (
|
|
67
|
+
<TransferOwnershipRow orgId={orgId} transferTargets={transferTargets} />
|
|
68
|
+
) : null}
|
|
69
|
+
|
|
70
|
+
<LeaveOrganizationRow
|
|
71
|
+
orgId={orgId}
|
|
72
|
+
orgName={orgName}
|
|
73
|
+
isSoleOwner={isSoleOwner}
|
|
74
|
+
/>
|
|
75
|
+
|
|
76
|
+
{isOwner ? (
|
|
77
|
+
<DeleteOrganizationRow orgId={orgId} orgName={orgName} />
|
|
78
|
+
) : null}
|
|
79
|
+
</section>
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function Row({
|
|
84
|
+
title,
|
|
85
|
+
description,
|
|
86
|
+
children
|
|
87
|
+
}: {
|
|
88
|
+
title: string
|
|
89
|
+
description: string
|
|
90
|
+
children: React.ReactNode
|
|
91
|
+
}) {
|
|
92
|
+
return (
|
|
93
|
+
<div className="flex flex-col gap-3 border-t pt-6 sm:flex-row sm:items-center sm:justify-between">
|
|
94
|
+
<div className="space-y-0.5">
|
|
95
|
+
<p className="text-sm font-medium">{title}</p>
|
|
96
|
+
<p className="text-muted-foreground text-sm">{description}</p>
|
|
97
|
+
</div>
|
|
98
|
+
<div className="shrink-0">{children}</div>
|
|
99
|
+
</div>
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function TransferOwnershipRow({
|
|
104
|
+
orgId,
|
|
105
|
+
transferTargets
|
|
106
|
+
}: {
|
|
107
|
+
orgId: string
|
|
108
|
+
transferTargets: TransferTarget[]
|
|
109
|
+
}) {
|
|
110
|
+
const router = useRouter()
|
|
111
|
+
const [open, setOpen] = useState(false)
|
|
112
|
+
const [targetId, setTargetId] = useState('')
|
|
113
|
+
|
|
114
|
+
const transferOwnership = useSafeActionMutation(
|
|
115
|
+
transferOrganizationOwnershipAction,
|
|
116
|
+
{
|
|
117
|
+
onSuccess: () => {
|
|
118
|
+
toastSuccessMessage('Ownership transferred')
|
|
119
|
+
setOpen(false)
|
|
120
|
+
router.refresh()
|
|
121
|
+
},
|
|
122
|
+
onError: error =>
|
|
123
|
+
toastActionError(error, 'Ownership was not transferred. Try again.')
|
|
124
|
+
}
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
function handleTransfer() {
|
|
128
|
+
if (!targetId) return
|
|
129
|
+
|
|
130
|
+
transferOwnership.mutate({
|
|
131
|
+
organizationId: orgId,
|
|
132
|
+
targetMemberId: targetId
|
|
133
|
+
})
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<Row
|
|
138
|
+
title="Transfer Ownership"
|
|
139
|
+
description="Make another member the owner. You become an admin."
|
|
140
|
+
>
|
|
141
|
+
<Dialog open={open} onOpenChange={setOpen}>
|
|
142
|
+
<DialogTrigger asChild>
|
|
143
|
+
<Button variant="outline">Transfer</Button>
|
|
144
|
+
</DialogTrigger>
|
|
145
|
+
<DialogContent className="sm:max-w-md">
|
|
146
|
+
<DialogHeader>
|
|
147
|
+
<DialogTitle>Transfer Ownership</DialogTitle>
|
|
148
|
+
<DialogDescription>{OWNERSHIP_DEMOTION_NOTICE}</DialogDescription>
|
|
149
|
+
</DialogHeader>
|
|
150
|
+
|
|
151
|
+
<div className="space-y-2 py-1">
|
|
152
|
+
<Label htmlFor="new-owner">New owner</Label>
|
|
153
|
+
<Select value={targetId} onValueChange={setTargetId}>
|
|
154
|
+
<SelectTrigger id="new-owner" className="w-full">
|
|
155
|
+
<SelectValue placeholder="Select a member" />
|
|
156
|
+
</SelectTrigger>
|
|
157
|
+
<SelectContent>
|
|
158
|
+
{transferTargets.map(target => (
|
|
159
|
+
<SelectItem key={target.memberId} value={target.memberId}>
|
|
160
|
+
{target.name} ({target.email})
|
|
161
|
+
</SelectItem>
|
|
162
|
+
))}
|
|
163
|
+
</SelectContent>
|
|
164
|
+
</Select>
|
|
165
|
+
</div>
|
|
166
|
+
|
|
167
|
+
<DialogFooter>
|
|
168
|
+
<Button
|
|
169
|
+
variant="outline"
|
|
170
|
+
onClick={() => setOpen(false)}
|
|
171
|
+
disabled={transferOwnership.isPending}
|
|
172
|
+
>
|
|
173
|
+
Cancel
|
|
174
|
+
</Button>
|
|
175
|
+
<Button
|
|
176
|
+
onClick={handleTransfer}
|
|
177
|
+
disabled={transferOwnership.isPending || !targetId}
|
|
178
|
+
>
|
|
179
|
+
{transferOwnership.isPending && (
|
|
180
|
+
<Loader2 className="animate-spin" />
|
|
181
|
+
)}
|
|
182
|
+
Transfer Ownership
|
|
183
|
+
</Button>
|
|
184
|
+
</DialogFooter>
|
|
185
|
+
</DialogContent>
|
|
186
|
+
</Dialog>
|
|
187
|
+
</Row>
|
|
188
|
+
)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function LeaveOrganizationRow({
|
|
192
|
+
orgId,
|
|
193
|
+
orgName,
|
|
194
|
+
isSoleOwner
|
|
195
|
+
}: {
|
|
196
|
+
orgId: string
|
|
197
|
+
orgName: string
|
|
198
|
+
isSoleOwner: boolean
|
|
199
|
+
}) {
|
|
200
|
+
const router = useRouter()
|
|
201
|
+
const [open, setOpen] = useState(false)
|
|
202
|
+
const [submitting, setSubmitting] = useState(false)
|
|
203
|
+
|
|
204
|
+
async function handleLeave() {
|
|
205
|
+
// Guard: the only owner must transfer ownership before leaving.
|
|
206
|
+
if (isSoleOwner) {
|
|
207
|
+
toastErrorMessage(
|
|
208
|
+
'Transfer ownership to another member before you leave this organization.'
|
|
209
|
+
)
|
|
210
|
+
return
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
setSubmitting(true)
|
|
214
|
+
const { error } = await organization.leave({ organizationId: orgId })
|
|
215
|
+
|
|
216
|
+
if (error) {
|
|
217
|
+
toastActionError(error, 'You are still a member. Try again.')
|
|
218
|
+
setSubmitting(false)
|
|
219
|
+
return
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
toastSuccessMessage(`You left ${orgName}`)
|
|
223
|
+
router.push('/app')
|
|
224
|
+
// Re-render the app layout so the sidebar drops the organization.
|
|
225
|
+
router.refresh()
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return (
|
|
229
|
+
<Row
|
|
230
|
+
title="Leave Organization"
|
|
231
|
+
description="Remove yourself from this organization."
|
|
232
|
+
>
|
|
233
|
+
<Dialog open={open} onOpenChange={setOpen}>
|
|
234
|
+
<DialogTrigger asChild>
|
|
235
|
+
<Button variant="outline">Leave</Button>
|
|
236
|
+
</DialogTrigger>
|
|
237
|
+
<DialogContent className="sm:max-w-md">
|
|
238
|
+
<DialogHeader>
|
|
239
|
+
<DialogTitle>
|
|
240
|
+
{isSoleOwner ? 'Transfer Ownership First' : `Leave ${orgName}`}
|
|
241
|
+
</DialogTitle>
|
|
242
|
+
<DialogDescription>
|
|
243
|
+
{isSoleOwner
|
|
244
|
+
? "You're the only owner. Make another member the owner before you leave, or delete the organization instead."
|
|
245
|
+
: 'You lose access to this organization. An owner or admin must invite you to return.'}
|
|
246
|
+
</DialogDescription>
|
|
247
|
+
</DialogHeader>
|
|
248
|
+
<DialogFooter>
|
|
249
|
+
<Button
|
|
250
|
+
variant="outline"
|
|
251
|
+
onClick={() => setOpen(false)}
|
|
252
|
+
disabled={submitting}
|
|
253
|
+
>
|
|
254
|
+
{isSoleOwner ? 'Close' : 'Cancel'}
|
|
255
|
+
</Button>
|
|
256
|
+
{!isSoleOwner ? (
|
|
257
|
+
<Button
|
|
258
|
+
variant="destructive"
|
|
259
|
+
onClick={handleLeave}
|
|
260
|
+
disabled={submitting}
|
|
261
|
+
>
|
|
262
|
+
{submitting && <Loader2 className="animate-spin" />}
|
|
263
|
+
Leave Organization
|
|
264
|
+
</Button>
|
|
265
|
+
) : null}
|
|
266
|
+
</DialogFooter>
|
|
267
|
+
</DialogContent>
|
|
268
|
+
</Dialog>
|
|
269
|
+
</Row>
|
|
270
|
+
)
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function DeleteOrganizationRow({
|
|
274
|
+
orgId,
|
|
275
|
+
orgName
|
|
276
|
+
}: {
|
|
277
|
+
orgId: string
|
|
278
|
+
orgName: string
|
|
279
|
+
}) {
|
|
280
|
+
const router = useRouter()
|
|
281
|
+
const [open, setOpen] = useState(false)
|
|
282
|
+
const [confirmText, setConfirmText] = useState('')
|
|
283
|
+
const [submitting, setSubmitting] = useState(false)
|
|
284
|
+
|
|
285
|
+
async function handleDelete() {
|
|
286
|
+
setSubmitting(true)
|
|
287
|
+
const { error } = await organization.delete({ organizationId: orgId })
|
|
288
|
+
|
|
289
|
+
if (error) {
|
|
290
|
+
toastActionError(error, 'The organization was not deleted. Try again.')
|
|
291
|
+
setSubmitting(false)
|
|
292
|
+
return
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
toastSuccessMessage(`${orgName} deleted`)
|
|
296
|
+
router.push('/app')
|
|
297
|
+
router.refresh()
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
return (
|
|
301
|
+
<Row
|
|
302
|
+
title="Delete Organization"
|
|
303
|
+
description="Permanently delete this organization and all of its data."
|
|
304
|
+
>
|
|
305
|
+
<Dialog
|
|
306
|
+
open={open}
|
|
307
|
+
onOpenChange={next => {
|
|
308
|
+
setOpen(next)
|
|
309
|
+
if (!next) setConfirmText('')
|
|
310
|
+
}}
|
|
311
|
+
>
|
|
312
|
+
<DialogTrigger asChild>
|
|
313
|
+
<Button variant="destructive">Delete</Button>
|
|
314
|
+
</DialogTrigger>
|
|
315
|
+
<DialogContent className="sm:max-w-md">
|
|
316
|
+
<DialogHeader>
|
|
317
|
+
<DialogTitle>Delete {orgName}</DialogTitle>
|
|
318
|
+
<DialogDescription>
|
|
319
|
+
This permanently removes every member, invitation, and file, and
|
|
320
|
+
cancels the subscription. You cannot undo it.
|
|
321
|
+
</DialogDescription>
|
|
322
|
+
</DialogHeader>
|
|
323
|
+
|
|
324
|
+
<div className="space-y-2 py-1">
|
|
325
|
+
<Label htmlFor="confirm-delete">
|
|
326
|
+
Type <span className="font-semibold">{orgName}</span> to confirm
|
|
327
|
+
</Label>
|
|
328
|
+
<Input
|
|
329
|
+
id="confirm-delete"
|
|
330
|
+
value={confirmText}
|
|
331
|
+
onChange={e => setConfirmText(e.target.value)}
|
|
332
|
+
placeholder={orgName}
|
|
333
|
+
/>
|
|
334
|
+
</div>
|
|
335
|
+
|
|
336
|
+
<DialogFooter>
|
|
337
|
+
<Button
|
|
338
|
+
variant="outline"
|
|
339
|
+
onClick={() => setOpen(false)}
|
|
340
|
+
disabled={submitting}
|
|
341
|
+
>
|
|
342
|
+
Cancel
|
|
343
|
+
</Button>
|
|
344
|
+
<Button
|
|
345
|
+
variant="destructive"
|
|
346
|
+
onClick={handleDelete}
|
|
347
|
+
disabled={submitting || confirmText !== orgName}
|
|
348
|
+
>
|
|
349
|
+
{submitting && <Loader2 className="animate-spin" />}
|
|
350
|
+
Delete Organization
|
|
351
|
+
</Button>
|
|
352
|
+
</DialogFooter>
|
|
353
|
+
</DialogContent>
|
|
354
|
+
</Dialog>
|
|
355
|
+
</Row>
|
|
356
|
+
)
|
|
357
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { zodResolver } from '@hookform/resolvers/zod'
|
|
4
|
+
import { Loader2 } from 'lucide-react'
|
|
5
|
+
import { useRouter } from 'next/navigation'
|
|
6
|
+
import { useState } from 'react'
|
|
7
|
+
import { Controller, useForm } from 'react-hook-form'
|
|
8
|
+
import { z } from 'zod'
|
|
9
|
+
import { updateOrganizationAction } from '~/app/(app)/actions/organizations'
|
|
10
|
+
import { organizationDetailsSchema } from '~/app/(app)/actions/organizations.validation'
|
|
11
|
+
import { FileUpload } from '~/components/file-upload'
|
|
12
|
+
import { Button } from '~/components/ui/button'
|
|
13
|
+
import {
|
|
14
|
+
Field,
|
|
15
|
+
FieldDescription,
|
|
16
|
+
FieldError,
|
|
17
|
+
FieldLabel
|
|
18
|
+
} from '~/components/ui/field'
|
|
19
|
+
import { Input } from '~/components/ui/input'
|
|
20
|
+
import { useSafeActionMutation } from '~/lib/safe-action-client'
|
|
21
|
+
import { toastActionError, toastSuccessMessage } from '~/lib/toast-message'
|
|
22
|
+
|
|
23
|
+
type Form = z.infer<typeof organizationDetailsSchema>
|
|
24
|
+
|
|
25
|
+
export function GeneralSettingsForm({
|
|
26
|
+
orgId,
|
|
27
|
+
defaultName,
|
|
28
|
+
defaultSlug,
|
|
29
|
+
currentLogoKey,
|
|
30
|
+
currentLogoUrl
|
|
31
|
+
}: {
|
|
32
|
+
orgId: string
|
|
33
|
+
defaultName: string
|
|
34
|
+
defaultSlug: string
|
|
35
|
+
/** Stored logo value, sent back unchanged when you keep the logo. */
|
|
36
|
+
currentLogoKey: string | null
|
|
37
|
+
/** Renderable URL for the stored logo, from `resolveImageUrl`. */
|
|
38
|
+
currentLogoUrl: string | null
|
|
39
|
+
}) {
|
|
40
|
+
const router = useRouter()
|
|
41
|
+
const [logo, setLogo] = useState<string | null>(currentLogoKey)
|
|
42
|
+
|
|
43
|
+
const form = useForm<Form>({
|
|
44
|
+
resolver: zodResolver(organizationDetailsSchema),
|
|
45
|
+
defaultValues: { name: defaultName, slug: defaultSlug }
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
const save = useSafeActionMutation(updateOrganizationAction, {
|
|
49
|
+
onSuccess: (_, values) => {
|
|
50
|
+
toastSuccessMessage('Organization updated')
|
|
51
|
+
form.reset({ name: values.name, slug: values.slug })
|
|
52
|
+
router.refresh()
|
|
53
|
+
},
|
|
54
|
+
onError: error =>
|
|
55
|
+
toastActionError(error, 'Your changes were not saved. Try again.')
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
const logoChanged = logo !== currentLogoKey
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<form
|
|
62
|
+
onSubmit={form.handleSubmit(values =>
|
|
63
|
+
save.mutate({ ...values, organizationId: orgId, logo: logo ?? '' })
|
|
64
|
+
)}
|
|
65
|
+
className="flex flex-col gap-6"
|
|
66
|
+
>
|
|
67
|
+
<Controller
|
|
68
|
+
control={form.control}
|
|
69
|
+
name="name"
|
|
70
|
+
render={({ field, fieldState }) => (
|
|
71
|
+
<Field data-invalid={fieldState.invalid}>
|
|
72
|
+
<FieldLabel htmlFor={field.name}>Organization name</FieldLabel>
|
|
73
|
+
<Input
|
|
74
|
+
id={field.name}
|
|
75
|
+
aria-invalid={fieldState.invalid}
|
|
76
|
+
{...field}
|
|
77
|
+
/>
|
|
78
|
+
<FieldError
|
|
79
|
+
errors={fieldState.error ? [fieldState.error] : undefined}
|
|
80
|
+
/>
|
|
81
|
+
</Field>
|
|
82
|
+
)}
|
|
83
|
+
/>
|
|
84
|
+
|
|
85
|
+
<Controller
|
|
86
|
+
control={form.control}
|
|
87
|
+
name="slug"
|
|
88
|
+
render={({ field, fieldState }) => (
|
|
89
|
+
<Field data-invalid={fieldState.invalid}>
|
|
90
|
+
<FieldLabel htmlFor={field.name}>Slug</FieldLabel>
|
|
91
|
+
<Input
|
|
92
|
+
id={field.name}
|
|
93
|
+
aria-invalid={fieldState.invalid}
|
|
94
|
+
{...field}
|
|
95
|
+
/>
|
|
96
|
+
<FieldDescription>
|
|
97
|
+
Identifies the organization in links.
|
|
98
|
+
</FieldDescription>
|
|
99
|
+
<FieldError
|
|
100
|
+
errors={fieldState.error ? [fieldState.error] : undefined}
|
|
101
|
+
/>
|
|
102
|
+
</Field>
|
|
103
|
+
)}
|
|
104
|
+
/>
|
|
105
|
+
|
|
106
|
+
<Field>
|
|
107
|
+
<FieldLabel>Logo</FieldLabel>
|
|
108
|
+
<div className="w-32">
|
|
109
|
+
<FileUpload
|
|
110
|
+
organizationId={orgId}
|
|
111
|
+
accept="image/*"
|
|
112
|
+
onClientUploadFinish={setLogo}
|
|
113
|
+
currentUrl={currentLogoUrl}
|
|
114
|
+
sizes="128px"
|
|
115
|
+
/>
|
|
116
|
+
</div>
|
|
117
|
+
</Field>
|
|
118
|
+
|
|
119
|
+
<div>
|
|
120
|
+
<Button
|
|
121
|
+
type="submit"
|
|
122
|
+
disabled={save.isPending || (!form.formState.isDirty && !logoChanged)}
|
|
123
|
+
>
|
|
124
|
+
{save.isPending && <Loader2 className="animate-spin" />}
|
|
125
|
+
Save Changes
|
|
126
|
+
</Button>
|
|
127
|
+
</div>
|
|
128
|
+
</form>
|
|
129
|
+
)
|
|
130
|
+
}
|