create-pet-adopt 0.0.0 → 0.3.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/LICENSE +21 -0
- package/README.md +120 -0
- package/index.js +920 -0
- package/package.json +43 -1
- package/template/.env.example +136 -0
- package/template/.pet-adopt/template.json +581 -0
- package/template/LICENSE +21 -0
- package/template/README.md +109 -0
- package/template/_gitignore +28 -0
- package/template/_pnpm-lock.yaml +9251 -0
- package/template/assets/sample-pet.png +0 -0
- package/template/components.json +25 -0
- package/template/docker-compose.yml +110 -0
- package/template/drizzle/pg/0000_initial.sql +176 -0
- package/template/drizzle/pg/0001_greedy_the_renegades.sql +1 -0
- package/template/drizzle/pg/0002_fuzzy_the_renegades.sql +1 -0
- package/template/drizzle/pg/0003_thin_multiple_man.sql +1 -0
- package/template/drizzle/pg/0004_boring_norman_osborn.sql +15 -0
- package/template/drizzle/pg/0005_bitter_proemial_gods.sql +3 -0
- package/template/drizzle/pg/0006_friendly_black_knight.sql +2 -0
- package/template/drizzle/pg/0007_wise_ozymandias.sql +11 -0
- package/template/drizzle/pg/0008_messy_human_fly.sql +2 -0
- package/template/drizzle/pg/0009_amused_lady_bullseye.sql +1 -0
- package/template/drizzle/pg/0010_cute_mauler.sql +7 -0
- package/template/drizzle/pg/0011_clear_purple_man.sql +3 -0
- package/template/drizzle/pg/0012_tiresome_gunslinger.sql +2 -0
- package/template/drizzle/pg/0013_awesome_wong.sql +18 -0
- package/template/drizzle/pg/0014_fantastic_sumo.sql +12 -0
- package/template/drizzle/pg/0015_pink_carnage.sql +12 -0
- package/template/drizzle/pg/0016_sloppy_king_bedlam.sql +2 -0
- package/template/drizzle/pg/0017_steep_warhawk.sql +15 -0
- package/template/drizzle/pg/0018_mixed_otto_octavius.sql +4 -0
- package/template/drizzle/pg/0019_talented_rocket_raccoon.sql +1 -0
- package/template/drizzle/pg/0020_worthless_zodiak.sql +19 -0
- package/template/drizzle/pg/0021_adorable_squadron_supreme.sql +1 -0
- package/template/drizzle/pg/0022_soft_pixie.sql +5 -0
- package/template/drizzle/pg/0023_fluffy_quasar.sql +1 -0
- package/template/drizzle/pg/0024_uneven_ken_ellis.sql +2 -0
- package/template/drizzle/pg/0025_rich_white_queen.sql +3 -0
- package/template/drizzle/pg/0026_spooky_komodo.sql +16 -0
- package/template/drizzle/pg/0027_big_thunderbolts.sql +2 -0
- package/template/drizzle/pg/meta/0000_snapshot.json +1265 -0
- package/template/drizzle/pg/meta/0001_snapshot.json +1272 -0
- package/template/drizzle/pg/meta/0002_snapshot.json +1278 -0
- package/template/drizzle/pg/meta/0003_snapshot.json +1284 -0
- package/template/drizzle/pg/meta/0004_snapshot.json +1401 -0
- package/template/drizzle/pg/meta/0005_snapshot.json +1401 -0
- package/template/drizzle/pg/meta/0006_snapshot.json +1414 -0
- package/template/drizzle/pg/meta/0007_snapshot.json +1485 -0
- package/template/drizzle/pg/meta/0008_snapshot.json +1504 -0
- package/template/drizzle/pg/meta/0009_snapshot.json +1510 -0
- package/template/drizzle/pg/meta/0010_snapshot.json +1556 -0
- package/template/drizzle/pg/meta/0011_snapshot.json +1574 -0
- package/template/drizzle/pg/meta/0012_snapshot.json +1586 -0
- package/template/drizzle/pg/meta/0013_snapshot.json +1730 -0
- package/template/drizzle/pg/meta/0014_snapshot.json +1805 -0
- package/template/drizzle/pg/meta/0015_snapshot.json +1883 -0
- package/template/drizzle/pg/meta/0016_snapshot.json +1897 -0
- package/template/drizzle/pg/meta/0017_snapshot.json +2013 -0
- package/template/drizzle/pg/meta/0018_snapshot.json +1988 -0
- package/template/drizzle/pg/meta/0019_snapshot.json +1994 -0
- package/template/drizzle/pg/meta/0020_snapshot.json +2108 -0
- package/template/drizzle/pg/meta/0021_snapshot.json +2114 -0
- package/template/drizzle/pg/meta/0022_snapshot.json +2126 -0
- package/template/drizzle/pg/meta/0023_snapshot.json +2132 -0
- package/template/drizzle/pg/meta/0024_snapshot.json +2151 -0
- package/template/drizzle/pg/meta/0025_snapshot.json +2169 -0
- package/template/drizzle/pg/meta/0026_snapshot.json +2294 -0
- package/template/drizzle/pg/meta/0027_snapshot.json +2330 -0
- package/template/drizzle/pg/meta/_journal.json +202 -0
- package/template/drizzle/sqlite/0000_initial.sql +176 -0
- package/template/drizzle/sqlite/0001_easy_sebastian_shaw.sql +1 -0
- package/template/drizzle/sqlite/0002_past_king_cobra.sql +1 -0
- package/template/drizzle/sqlite/0003_organic_masked_marvel.sql +1 -0
- package/template/drizzle/sqlite/0004_panoramic_inhumans.sql +15 -0
- package/template/drizzle/sqlite/0005_small_sunset_bain.sql +19 -0
- package/template/drizzle/sqlite/0006_narrow_medusa.sql +2 -0
- package/template/drizzle/sqlite/0007_gray_grandmaster.sql +10 -0
- package/template/drizzle/sqlite/0008_chief_toxin.sql +1 -0
- package/template/drizzle/sqlite/0009_vengeful_tag.sql +1 -0
- package/template/drizzle/sqlite/0010_kind_klaw.sql +7 -0
- package/template/drizzle/sqlite/0011_overrated_meltdown.sql +3 -0
- package/template/drizzle/sqlite/0012_robust_next_avengers.sql +2 -0
- package/template/drizzle/sqlite/0013_melodic_kitty_pryde.sql +18 -0
- package/template/drizzle/sqlite/0014_stormy_cyclops.sql +12 -0
- package/template/drizzle/sqlite/0015_parallel_mongu.sql +11 -0
- package/template/drizzle/sqlite/0016_grey_quicksilver.sql +2 -0
- package/template/drizzle/sqlite/0017_daily_psylocke.sql +15 -0
- package/template/drizzle/sqlite/0018_whole_redwing.sql +4 -0
- package/template/drizzle/sqlite/0019_spotty_mandroid.sql +1 -0
- package/template/drizzle/sqlite/0020_wild_wendell_rand.sql +19 -0
- package/template/drizzle/sqlite/0021_calm_lockheed.sql +1 -0
- package/template/drizzle/sqlite/0022_lonely_emma_frost.sql +5 -0
- package/template/drizzle/sqlite/0023_elite_tony_stark.sql +1 -0
- package/template/drizzle/sqlite/0024_little_lily_hollister.sql +1 -0
- package/template/drizzle/sqlite/0025_tough_shotgun.sql +3 -0
- package/template/drizzle/sqlite/0026_faithful_mephistopheles.sql +16 -0
- package/template/drizzle/sqlite/0027_rapid_arclight.sql +2 -0
- package/template/drizzle/sqlite/meta/0000_snapshot.json +1237 -0
- package/template/drizzle/sqlite/meta/0001_snapshot.json +1245 -0
- package/template/drizzle/sqlite/meta/0002_snapshot.json +1252 -0
- package/template/drizzle/sqlite/meta/0003_snapshot.json +1259 -0
- package/template/drizzle/sqlite/meta/0004_snapshot.json +1369 -0
- package/template/drizzle/sqlite/meta/0005_snapshot.json +1369 -0
- package/template/drizzle/sqlite/meta/0006_snapshot.json +1384 -0
- package/template/drizzle/sqlite/meta/0007_snapshot.json +1459 -0
- package/template/drizzle/sqlite/meta/0008_snapshot.json +1479 -0
- package/template/drizzle/sqlite/meta/0009_snapshot.json +1486 -0
- package/template/drizzle/sqlite/meta/0010_snapshot.json +1533 -0
- package/template/drizzle/sqlite/meta/0011_snapshot.json +1554 -0
- package/template/drizzle/sqlite/meta/0012_snapshot.json +1568 -0
- package/template/drizzle/sqlite/meta/0013_snapshot.json +1687 -0
- package/template/drizzle/sqlite/meta/0014_snapshot.json +1769 -0
- package/template/drizzle/sqlite/meta/0015_snapshot.json +1852 -0
- package/template/drizzle/sqlite/meta/0016_snapshot.json +1867 -0
- package/template/drizzle/sqlite/meta/0017_snapshot.json +1973 -0
- package/template/drizzle/sqlite/meta/0018_snapshot.json +1944 -0
- package/template/drizzle/sqlite/meta/0019_snapshot.json +1951 -0
- package/template/drizzle/sqlite/meta/0020_snapshot.json +2077 -0
- package/template/drizzle/sqlite/meta/0021_snapshot.json +2084 -0
- package/template/drizzle/sqlite/meta/0022_snapshot.json +2098 -0
- package/template/drizzle/sqlite/meta/0023_snapshot.json +2105 -0
- package/template/drizzle/sqlite/meta/0024_snapshot.json +2125 -0
- package/template/drizzle/sqlite/meta/0025_snapshot.json +2146 -0
- package/template/drizzle/sqlite/meta/0026_snapshot.json +2265 -0
- package/template/drizzle/sqlite/meta/0027_snapshot.json +2280 -0
- package/template/drizzle/sqlite/meta/_journal.json +202 -0
- package/template/drizzle.pg.config.ts +8 -0
- package/template/drizzle.sqlite.config.ts +8 -0
- package/template/eslint.config.mjs +22 -0
- package/template/next.config.ts +153 -0
- package/template/package.json +102 -0
- package/template/pet-adopt.blocks.ts +9 -0
- package/template/pet-adopt.config.ts +17 -0
- package/template/pnpm-workspace.yaml +19 -0
- package/template/postcss.config.mjs +5 -0
- package/template/scripts/check-routes.ts +405 -0
- package/template/scripts/check-schemas.ts +58 -0
- package/template/scripts/migrate-all.ts +25 -0
- package/template/scripts/migrate-on-build.ts +71 -0
- package/template/scripts/migrate.ts +20 -0
- package/template/scripts/plugin-generate.ts +92 -0
- package/template/scripts/reset-password.ts +45 -0
- package/template/scripts/reset-two-factor.ts +53 -0
- package/template/scripts/seed.ts +79 -0
- package/template/scripts/setup-env.ts +91 -0
- package/template/scripts/storage-check.ts +53 -0
- package/template/src/app/(admin)/admin/account/AccountForms.tsx +194 -0
- package/template/src/app/(admin)/admin/account/page.tsx +59 -0
- package/template/src/app/(admin)/admin/activity/page.tsx +76 -0
- package/template/src/app/(admin)/admin/authentication/archived/page.tsx +24 -0
- package/template/src/app/(admin)/admin/authentication/layout.tsx +20 -0
- package/template/src/app/(admin)/admin/authentication/page.tsx +36 -0
- package/template/src/app/(admin)/admin/authentication/providers/page.tsx +33 -0
- package/template/src/app/(admin)/admin/email/layout.tsx +21 -0
- package/template/src/app/(admin)/admin/email/page.tsx +43 -0
- package/template/src/app/(admin)/admin/email/templates/page.tsx +38 -0
- package/template/src/app/(admin)/admin/error.tsx +36 -0
- package/template/src/app/(admin)/admin/layout.tsx +26 -0
- package/template/src/app/(admin)/admin/loading.tsx +9 -0
- package/template/src/app/(admin)/admin/media/[id]/page.tsx +97 -0
- package/template/src/app/(admin)/admin/media/page.tsx +34 -0
- package/template/src/app/(admin)/admin/media/search-params.ts +16 -0
- package/template/src/app/(admin)/admin/page.tsx +79 -0
- package/template/src/app/(admin)/admin/pages/PageForm.tsx +604 -0
- package/template/src/app/(admin)/admin/pages/[id]/page.tsx +51 -0
- package/template/src/app/(admin)/admin/pages/new/page.tsx +19 -0
- package/template/src/app/(admin)/admin/pages/page.tsx +49 -0
- package/template/src/app/(admin)/admin/pets/PetForm.tsx +437 -0
- package/template/src/app/(admin)/admin/pets/[id]/page.tsx +41 -0
- package/template/src/app/(admin)/admin/pets/new/page.tsx +26 -0
- package/template/src/app/(admin)/admin/pets/page.tsx +70 -0
- package/template/src/app/(admin)/admin/pets/search-params.ts +16 -0
- package/template/src/app/(admin)/admin/plugins/[plugin]/[[...path]]/page.tsx +73 -0
- package/template/src/app/(admin)/admin/plugins/page.tsx +66 -0
- package/template/src/app/(admin)/admin/settings/SettingsForm.tsx +644 -0
- package/template/src/app/(admin)/admin/settings/email/page.tsx +9 -0
- package/template/src/app/(admin)/admin/settings/page.tsx +40 -0
- package/template/src/app/(admin)/admin/settings/templates/page.tsx +9 -0
- package/template/src/app/(admin)/admin/theme/[id]/page.tsx +28 -0
- package/template/src/app/(admin)/admin/theme/page.tsx +30 -0
- package/template/src/app/(admin)/admin/users/page.tsx +33 -0
- package/template/src/app/(admin)/layout.tsx +75 -0
- package/template/src/app/(admin)/providers.tsx +42 -0
- package/template/src/app/(auth)/admin/confirm-email/page.tsx +40 -0
- package/template/src/app/(auth)/admin/invite/page.tsx +38 -0
- package/template/src/app/(auth)/admin/login/DemoSignIn.tsx +69 -0
- package/template/src/app/(auth)/admin/login/page.tsx +83 -0
- package/template/src/app/(auth)/admin/reset-password/page.tsx +73 -0
- package/template/src/app/(auth)/error.tsx +9 -0
- package/template/src/app/(auth)/layout.tsx +71 -0
- package/template/src/app/(editor)/EditorToast.tsx +43 -0
- package/template/src/app/(editor)/edit/[id]/PageEditor.tsx +586 -0
- package/template/src/app/(editor)/edit/[id]/actions.ts +139 -0
- package/template/src/app/(editor)/edit/[id]/page.tsx +76 -0
- package/template/src/app/(editor)/edit/[id]/preview/page.tsx +81 -0
- package/template/src/app/(editor)/edit/email/[id]/EmailEditor.tsx +236 -0
- package/template/src/app/(editor)/edit/email/[id]/page.tsx +64 -0
- package/template/src/app/(editor)/edit/theme-preview/page.tsx +94 -0
- package/template/src/app/(editor)/editor.css +223 -0
- package/template/src/app/(editor)/error.tsx +32 -0
- package/template/src/app/(editor)/layout.tsx +67 -0
- package/template/src/app/(frontend)/[slug]/page.tsx +53 -0
- package/template/src/app/(frontend)/fonts.ts +8 -0
- package/template/src/app/(frontend)/layout.tsx +107 -0
- package/template/src/app/(frontend)/not-found.tsx +16 -0
- package/template/src/app/(frontend)/page.tsx +42 -0
- package/template/src/app/(frontend)/pets/[slug]/page.tsx +92 -0
- package/template/src/app/(frontend)/pets/page.tsx +42 -0
- package/template/src/app/(frontend)/styles.css +537 -0
- package/template/src/app/(setup)/error.tsx +9 -0
- package/template/src/app/(setup)/layout.tsx +41 -0
- package/template/src/app/(setup)/setup/page.tsx +105 -0
- package/template/src/app/(setup)/setup/storage-check.ts +43 -0
- package/template/src/app/api/auth/[...all]/route.ts +144 -0
- package/template/src/app/health/route.ts +9 -0
- package/template/src/app/media/[...path]/route.ts +45 -0
- package/template/src/app/media/email/[name]/route.ts +60 -0
- package/template/src/app/robots.ts +19 -0
- package/template/src/app/sitemap.ts +24 -0
- package/template/src/components/admin/AdminNav.tsx +153 -0
- package/template/src/components/admin/AdminShell.tsx +107 -0
- package/template/src/components/admin/DemoNotice.tsx +31 -0
- package/template/src/components/admin/EmailConfirmBanner.tsx +44 -0
- package/template/src/components/admin/EmptyState.tsx +10 -0
- package/template/src/components/admin/ErrorSummary.tsx +72 -0
- package/template/src/components/admin/MediaDetails.tsx +218 -0
- package/template/src/components/admin/MediaGrid.tsx +307 -0
- package/template/src/components/admin/MediaLibrary.tsx +103 -0
- package/template/src/components/admin/MediaPager.tsx +66 -0
- package/template/src/components/admin/PageHeader.tsx +22 -0
- package/template/src/components/admin/PhoneInput.tsx +128 -0
- package/template/src/components/admin/PluginWidgetBoundary.tsx +38 -0
- package/template/src/components/admin/PluginWidgets.tsx +51 -0
- package/template/src/components/admin/RemountOnNavigate.tsx +37 -0
- package/template/src/components/admin/StatusBadge.tsx +16 -0
- package/template/src/components/admin/UploadPhotosDialog.tsx +387 -0
- package/template/src/components/admin/UserAvatar.tsx +18 -0
- package/template/src/components/admin/UserMenu.tsx +118 -0
- package/template/src/components/admin/ViewSiteLink.tsx +24 -0
- package/template/src/components/admin/account/ConnectedProviders.tsx +91 -0
- package/template/src/components/admin/account/DeleteAccountCard.tsx +136 -0
- package/template/src/components/admin/account/EmailCard.tsx +137 -0
- package/template/src/components/admin/account/ProfilePicture.tsx +159 -0
- package/template/src/components/admin/activity/ActivityFilters.tsx +146 -0
- package/template/src/components/admin/activity/ActivityLog.tsx +159 -0
- package/template/src/components/admin/activity/RecentActivity.tsx +52 -0
- package/template/src/components/admin/demo-mode.tsx +17 -0
- package/template/src/components/admin/nav-items.ts +47 -0
- package/template/src/components/admin/pages/PageDetails.tsx +198 -0
- package/template/src/components/admin/pages/PageVersions.tsx +296 -0
- package/template/src/components/admin/pages/PagesTable.tsx +467 -0
- package/template/src/components/admin/pets/FilterBar.tsx +154 -0
- package/template/src/components/admin/pets/PetCard.tsx +170 -0
- package/template/src/components/admin/pets/PetList.tsx +112 -0
- package/template/src/components/admin/pets/PetListSkeleton.tsx +84 -0
- package/template/src/components/admin/pets/PetPagination.tsx +91 -0
- package/template/src/components/admin/pets/form/AgeFields.tsx +132 -0
- package/template/src/components/admin/pets/form/LocationFields.tsx +231 -0
- package/template/src/components/admin/pets/form/MediaPickerDialog.tsx +359 -0
- package/template/src/components/admin/pets/form/PhotosField.tsx +176 -0
- package/template/src/components/admin/pets/form/RichTextField.tsx +438 -0
- package/template/src/components/admin/pets/form/SeoImageField.tsx +87 -0
- package/template/src/components/admin/pets/form/SeoPreview.tsx +142 -0
- package/template/src/components/admin/pets/form/fields.tsx +434 -0
- package/template/src/components/admin/pets/form/rich-text-extensions.ts +45 -0
- package/template/src/components/admin/pets/timeline/PetTimeline.tsx +297 -0
- package/template/src/components/admin/pets/timeline/TimelineEntryForm.tsx +289 -0
- package/template/src/components/admin/pets/timeline/TimelinePhotosField.tsx +173 -0
- package/template/src/components/admin/plugins/PluginNotReady.tsx +28 -0
- package/template/src/components/admin/plugins/PluginOverview.tsx +121 -0
- package/template/src/components/admin/plugins/SendTestEmail.tsx +70 -0
- package/template/src/components/admin/settings/AuthProviders.tsx +373 -0
- package/template/src/components/admin/settings/AuthenticationNav.tsx +42 -0
- package/template/src/components/admin/settings/EmailNav.tsx +40 -0
- package/template/src/components/admin/settings/EmailSettingsForm.tsx +325 -0
- package/template/src/components/admin/settings/EmailTemplates.tsx +551 -0
- package/template/src/components/admin/settings/RegionFields.tsx +203 -0
- package/template/src/components/admin/site-time.tsx +26 -0
- package/template/src/components/admin/theme/ThemeEditor.tsx +467 -0
- package/template/src/components/admin/theme/ThemeLibrary.tsx +339 -0
- package/template/src/components/admin/theme/ThemeSwatches.tsx +30 -0
- package/template/src/components/admin/theme/theme-utils.ts +32 -0
- package/template/src/components/admin/two-factor/BackupCodeList.tsx +54 -0
- package/template/src/components/admin/two-factor/TwoFactorCard.tsx +237 -0
- package/template/src/components/admin/two-factor/TwoFactorRequired.tsx +52 -0
- package/template/src/components/admin/two-factor/TwoFactorSetup.tsx +180 -0
- package/template/src/components/admin/use-unsaved-changes.tsx +101 -0
- package/template/src/components/admin/users/ArchivedAccounts.tsx +159 -0
- package/template/src/components/admin/users/InviteDialogs.tsx +131 -0
- package/template/src/components/admin/users/TwoFactorRoles.tsx +80 -0
- package/template/src/components/admin/users/UserDialogs.tsx +681 -0
- package/template/src/components/admin/users/UsersTable.tsx +374 -0
- package/template/src/components/admin/view-only.tsx +43 -0
- package/template/src/components/auth/AcceptInviteForm.tsx +123 -0
- package/template/src/components/auth/AuthNav.tsx +80 -0
- package/template/src/components/auth/ConfirmEmailForm.tsx +73 -0
- package/template/src/components/auth/LoginForm.tsx +250 -0
- package/template/src/components/auth/PageError.tsx +37 -0
- package/template/src/components/auth/ProviderSignIn.tsx +53 -0
- package/template/src/components/auth/ResetPasswordForm.tsx +267 -0
- package/template/src/components/demo/DemoBanner.tsx +38 -0
- package/template/src/components/demo/SiteDemoBanner.tsx +22 -0
- package/template/src/components/demo/wording.ts +21 -0
- package/template/src/components/setup/SetupAccountForm.tsx +93 -0
- package/template/src/components/setup/SetupDone.tsx +95 -0
- package/template/src/components/setup/SetupNav.tsx +49 -0
- package/template/src/components/setup/SetupSampleContent.tsx +67 -0
- package/template/src/components/setup/SetupSiteForm.tsx +104 -0
- package/template/src/components/setup/SetupThemePicker.tsx +73 -0
- package/template/src/components/setup/SkipSetup.tsx +35 -0
- package/template/src/components/site/BuilderContent.tsx +46 -0
- package/template/src/components/site/CopyButton.tsx +28 -0
- package/template/src/components/site/ImageCarousel.tsx +52 -0
- package/template/src/components/site/PetCard.tsx +32 -0
- package/template/src/components/site/PetCatalog.tsx +106 -0
- package/template/src/components/site/PetGallery.tsx +75 -0
- package/template/src/components/site/PetTimeline.tsx +82 -0
- package/template/src/components/site/RemountOnNavigate.tsx +13 -0
- package/template/src/components/site/RichText.tsx +56 -0
- package/template/src/components/site/SmartLink.tsx +37 -0
- package/template/src/components/site/SocialIcons.tsx +26 -0
- package/template/src/components/site/ThemePreviewBridge.tsx +29 -0
- package/template/src/components/site/ThemeStyle.tsx +22 -0
- package/template/src/components/site/ThemeToggle.tsx +36 -0
- package/template/src/components/site/WhatsAppButton.tsx +27 -0
- package/template/src/components/site/timeline-format.ts +20 -0
- package/template/src/db/client.ts +702 -0
- package/template/src/db/compare-tables.ts +41 -0
- package/template/src/db/migrate.ts +28 -0
- package/template/src/db/plugin-migrations.ts +167 -0
- package/template/src/db/schema/pg.ts +484 -0
- package/template/src/db/schema/sqlite.ts +492 -0
- package/template/src/instrumentation.ts +110 -0
- package/template/src/lib/activity.ts +29 -0
- package/template/src/lib/admin/call-action.ts +19 -0
- package/template/src/lib/admin/initials.ts +9 -0
- package/template/src/lib/admin/media-cache.ts +16 -0
- package/template/src/lib/admin/media-page.ts +3 -0
- package/template/src/lib/admin/pet-form.ts +242 -0
- package/template/src/lib/admin/pets-cache.ts +22 -0
- package/template/src/lib/admin/unwrap-client.ts +11 -0
- package/template/src/lib/admin/unwrap.ts +38 -0
- package/template/src/lib/admin/use-media-list.ts +41 -0
- package/template/src/lib/admin/use-pet-list.ts +58 -0
- package/template/src/lib/age.ts +117 -0
- package/template/src/lib/auth-provider-errors.ts +38 -0
- package/template/src/lib/cache.ts +69 -0
- package/template/src/lib/color-mode.ts +48 -0
- package/template/src/lib/demo.ts +78 -0
- package/template/src/lib/email-address.ts +9 -0
- package/template/src/lib/email-template.ts +691 -0
- package/template/src/lib/links.ts +78 -0
- package/template/src/lib/mail-error.ts +38 -0
- package/template/src/lib/media-name.ts +31 -0
- package/template/src/lib/options.ts +134 -0
- package/template/src/lib/pagination.ts +28 -0
- package/template/src/lib/pet-placeholders.ts +34 -0
- package/template/src/lib/pet-seo.ts +40 -0
- package/template/src/lib/pet-timeline.ts +62 -0
- package/template/src/lib/phone.ts +129 -0
- package/template/src/lib/places.ts +84 -0
- package/template/src/lib/queries.ts +549 -0
- package/template/src/lib/revalidate.ts +32 -0
- package/template/src/lib/rich-text.ts +215 -0
- package/template/src/lib/seo.ts +121 -0
- package/template/src/lib/slugify.ts +11 -0
- package/template/src/lib/theme.ts +546 -0
- package/template/src/lib/utils.ts +2 -0
- package/template/src/lib/whatsapp.ts +29 -0
- package/template/src/lib/zod-schema/auth.ts +56 -0
- package/template/src/lib/zod-schema/page.ts +57 -0
- package/template/src/lib/zod-schema/pet-timeline.ts +118 -0
- package/template/src/lib/zod-schema/pet.ts +172 -0
- package/template/src/lib/zod-schema/settings.ts +162 -0
- package/template/src/plugins/host.ts +117 -0
- package/template/src/plugins/icon.ts +89 -0
- package/template/src/plugins/registry.ts +369 -0
- package/template/src/plugins/storage-rules.ts +87 -0
- package/template/src/plugins/storage.ts +184 -0
- package/template/src/puck/actions.ts +46 -0
- package/template/src/puck/config.tsx +1693 -0
- package/template/src/puck/data.ts +196 -0
- package/template/src/puck/demo-mode.tsx +20 -0
- package/template/src/puck/email-config.tsx +267 -0
- package/template/src/puck/icons.tsx +76 -0
- package/template/src/puck/media-picker.tsx +273 -0
- package/template/src/puck/padding.tsx +71 -0
- package/template/src/puck/pet-page-config.tsx +511 -0
- package/template/src/puck/pet-picker.tsx +40 -0
- package/template/src/puck/plugin-block-data.ts +91 -0
- package/template/src/puck/plugin-blocks.tsx +235 -0
- package/template/src/puck/plugin-choice-field.tsx +87 -0
- package/template/src/puck/sanitize.ts +107 -0
- package/template/src/puck/server.ts +36 -0
- package/template/src/puck/types.ts +41 -0
- package/template/src/server/actions/activity.ts +48 -0
- package/template/src/server/actions/auth-providers.ts +171 -0
- package/template/src/server/actions/auth.ts +217 -0
- package/template/src/server/actions/demo.ts +30 -0
- package/template/src/server/actions/email-change.ts +80 -0
- package/template/src/server/actions/email-templates.ts +144 -0
- package/template/src/server/actions/email.ts +70 -0
- package/template/src/server/actions/media.ts +127 -0
- package/template/src/server/actions/pages.ts +159 -0
- package/template/src/server/actions/password-reset.ts +80 -0
- package/template/src/server/actions/pet-timeline.ts +75 -0
- package/template/src/server/actions/pets.ts +74 -0
- package/template/src/server/actions/places.ts +36 -0
- package/template/src/server/actions/settings.ts +29 -0
- package/template/src/server/actions/setup.ts +72 -0
- package/template/src/server/actions/themes.ts +80 -0
- package/template/src/server/actions/two-factor.ts +306 -0
- package/template/src/server/actions/users.ts +200 -0
- package/template/src/server/activity.ts +409 -0
- package/template/src/server/auth-errors.ts +17 -0
- package/template/src/server/auth-providers.ts +359 -0
- package/template/src/server/auth.ts +266 -0
- package/template/src/server/avatars.ts +263 -0
- package/template/src/server/demo-site.ts +169 -0
- package/template/src/server/email-change.ts +278 -0
- package/template/src/server/email-templates.ts +350 -0
- package/template/src/server/email.ts +442 -0
- package/template/src/server/invites.ts +143 -0
- package/template/src/server/media-url.ts +20 -0
- package/template/src/server/media.ts +236 -0
- package/template/src/server/pages.ts +812 -0
- package/template/src/server/password-reset.ts +158 -0
- package/template/src/server/pending-links.ts +46 -0
- package/template/src/server/pet-timeline.ts +181 -0
- package/template/src/server/pets.ts +555 -0
- package/template/src/server/places.ts +113 -0
- package/template/src/server/privacy.ts +21 -0
- package/template/src/server/provider-endpoints.ts +94 -0
- package/template/src/server/provider-guard.ts +157 -0
- package/template/src/server/result.ts +280 -0
- package/template/src/server/sample-content.ts +368 -0
- package/template/src/server/search-text.ts +43 -0
- package/template/src/server/secret-box.ts +38 -0
- package/template/src/server/session.ts +154 -0
- package/template/src/server/settings.ts +361 -0
- package/template/src/server/setup.ts +110 -0
- package/template/src/server/sitemap.ts +88 -0
- package/template/src/server/storage.ts +267 -0
- package/template/src/server/strip-metadata.ts +357 -0
- package/template/src/server/themes.ts +195 -0
- package/template/src/server/throttle.ts +258 -0
- package/template/src/server/two-factor-codes.ts +32 -0
- package/template/src/server/two-factor.ts +158 -0
- package/template/src/server/types.ts +198 -0
- package/template/src/server/uploads.ts +137 -0
- package/template/src/server/users.ts +500 -0
- package/template/tsconfig.json +44 -0
- package/template/ui/components.json +25 -0
- package/template/ui/package.json +12 -0
- package/template/ui/src/components/alert-dialog.tsx +187 -0
- package/template/ui/src/components/avatar.tsx +108 -0
- package/template/ui/src/components/badge.tsx +51 -0
- package/template/ui/src/components/button.tsx +57 -0
- package/template/ui/src/components/card.tsx +102 -0
- package/template/ui/src/components/carousel.tsx +245 -0
- package/template/ui/src/components/checkbox.tsx +27 -0
- package/template/ui/src/components/combobox.tsx +297 -0
- package/template/ui/src/components/dialog.tsx +159 -0
- package/template/ui/src/components/dropdown-menu.tsx +265 -0
- package/template/ui/src/components/field.tsx +238 -0
- package/template/ui/src/components/input-group.tsx +158 -0
- package/template/ui/src/components/input.tsx +19 -0
- package/template/ui/src/components/label.tsx +19 -0
- package/template/ui/src/components/pagination.tsx +127 -0
- package/template/ui/src/components/popover.tsx +89 -0
- package/template/ui/src/components/radio-group.tsx +37 -0
- package/template/ui/src/components/select.tsx +200 -0
- package/template/ui/src/components/separator.tsx +24 -0
- package/template/ui/src/components/sheet.tsx +138 -0
- package/template/ui/src/components/sidebar.tsx +723 -0
- package/template/ui/src/components/skeleton.tsx +13 -0
- package/template/ui/src/components/switch.tsx +31 -0
- package/template/ui/src/components/table.tsx +115 -0
- package/template/ui/src/components/tabs.tsx +81 -0
- package/template/ui/src/components/textarea.tsx +17 -0
- package/template/ui/src/components/toggle.tsx +44 -0
- package/template/ui/src/components/tooltip.tsx +65 -0
- package/template/ui/src/hooks/use-mobile.ts +21 -0
- package/template/ui/src/lib/utils.ts +2 -0
- package/template/ui/src/styles/globals.css +145 -0
|
@@ -0,0 +1,551 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import Link from 'next/link'
|
|
4
|
+
import { useRouter } from 'next/navigation'
|
|
5
|
+
import React from 'react'
|
|
6
|
+
import { FiPlus } from 'react-icons/fi'
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
AlertDialog,
|
|
10
|
+
AlertDialogCancel,
|
|
11
|
+
AlertDialogContent,
|
|
12
|
+
AlertDialogDescription,
|
|
13
|
+
AlertDialogFooter,
|
|
14
|
+
AlertDialogHeader,
|
|
15
|
+
AlertDialogTitle,
|
|
16
|
+
AlertDialogTrigger,
|
|
17
|
+
} from '@pet-adopt/ui/components/alert-dialog'
|
|
18
|
+
import { Badge } from '@pet-adopt/ui/components/badge'
|
|
19
|
+
import { Button, buttonVariants } from '@pet-adopt/ui/components/button'
|
|
20
|
+
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from '@pet-adopt/ui/components/dialog'
|
|
21
|
+
import { Input } from '@pet-adopt/ui/components/input'
|
|
22
|
+
import { Label } from '@pet-adopt/ui/components/label'
|
|
23
|
+
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@pet-adopt/ui/components/table'
|
|
24
|
+
import { useViewOnly } from '@/components/admin/view-only'
|
|
25
|
+
import { LIBRARY_PURPOSES, PURPOSE_INFO, type EmailPurpose, type SystemPurpose } from '@/lib/email-template'
|
|
26
|
+
import {
|
|
27
|
+
createEmailTemplateAction,
|
|
28
|
+
deleteEmailTemplateAction,
|
|
29
|
+
restoreSeededTemplateAction,
|
|
30
|
+
restoreSystemEmailAction,
|
|
31
|
+
saveEmailTemplateAction,
|
|
32
|
+
} from '@/server/actions/email-templates'
|
|
33
|
+
import type { EmailTemplateSummary } from '@/server/email-templates'
|
|
34
|
+
import { useWhen } from '@/components/admin/site-time'
|
|
35
|
+
|
|
36
|
+
// Email > Templates, as one table:
|
|
37
|
+
// - System emails first (password reset, test email): one each, edited in place, with "Restore
|
|
38
|
+
// default" (back to the built-in version).
|
|
39
|
+
// - Then every other template, as many as people like. A template is used only where something
|
|
40
|
+
// picks it ("Used by": a form, or any other plugin). Plugins ship default templates ("Default"):
|
|
41
|
+
// editable and restorable, never deleted, used when nothing else is picked. "Created by" is blank
|
|
42
|
+
// for system emails and plugin defaults.
|
|
43
|
+
// From sm up it is a table; on phones one card per row. Results go to one status line (an alert for failures).
|
|
44
|
+
|
|
45
|
+
export type SystemEmailStatus = { purpose: SystemPurpose; customised: boolean; updatedAt: Date | string | null }
|
|
46
|
+
export type TemplateRow = EmailTemplateSummary & { usedBy: Array<{ label: string; href?: string }> }
|
|
47
|
+
|
|
48
|
+
type Announce = (text: string, isError?: boolean) => void
|
|
49
|
+
|
|
50
|
+
/** Short names for the kinds of templates people make. */
|
|
51
|
+
const TYPE_LABELS: Record<EmailPurpose, string> = {
|
|
52
|
+
'password-reset': 'System email',
|
|
53
|
+
invite: 'System email',
|
|
54
|
+
'email-verify': 'System email',
|
|
55
|
+
'email-change': 'System email',
|
|
56
|
+
'email-changed': 'System email',
|
|
57
|
+
'account-deletion': 'System email',
|
|
58
|
+
test: 'System email',
|
|
59
|
+
'team-notification': 'Team notification',
|
|
60
|
+
'visitor-message': 'Message to a visitor',
|
|
61
|
+
}
|
|
62
|
+
const TYPE_HINTS: Record<EmailPurpose, string> = {
|
|
63
|
+
'password-reset': '',
|
|
64
|
+
invite: '',
|
|
65
|
+
'email-verify': '',
|
|
66
|
+
'email-change': '',
|
|
67
|
+
'email-changed': '',
|
|
68
|
+
'account-deletion': '',
|
|
69
|
+
test: '',
|
|
70
|
+
'team-notification': 'To your team; can list the details',
|
|
71
|
+
'visitor-message': 'To someone outside the team; never repeats what they typed',
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
export function EmailTemplates({ templates, system }: { templates: TemplateRow[]; system: SystemEmailStatus[] }) {
|
|
76
|
+
const when = useWhen()
|
|
77
|
+
const router = useRouter()
|
|
78
|
+
const viewOnly = useViewOnly()
|
|
79
|
+
const [message, setMessage] = React.useState<{ text: string; isError: boolean; id: number } | null>(null)
|
|
80
|
+
const announce = React.useCallback<Announce>((text, isError = false) => setMessage((previous) => ({ text, isError, id: (previous?.id ?? 0) + 1 })), [])
|
|
81
|
+
const done = (text: string) => {
|
|
82
|
+
announce(text)
|
|
83
|
+
router.refresh()
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const systemActions = (email: SystemEmailStatus) => (
|
|
87
|
+
<>
|
|
88
|
+
<Link href={`/edit/email/${email.purpose}`} className={buttonVariants({ variant: 'outline', size: 'sm' })}>
|
|
89
|
+
{viewOnly ? 'View' : 'Edit'}
|
|
90
|
+
<span className="sr-only"> the {PURPOSE_INFO[email.purpose].label} email</span>
|
|
91
|
+
</Link>
|
|
92
|
+
{email.customised && !viewOnly ? <RestoreSystemEmail purpose={email.purpose} announce={announce} onDone={done} /> : null}
|
|
93
|
+
</>
|
|
94
|
+
)
|
|
95
|
+
const templateActions = (template: TemplateRow) => (
|
|
96
|
+
<>
|
|
97
|
+
<Link href={`/edit/email/${template.id}`} className={buttonVariants({ variant: 'outline', size: 'sm' })}>
|
|
98
|
+
{viewOnly ? 'View' : 'Edit'}
|
|
99
|
+
<span className="sr-only"> {template.name}</span>
|
|
100
|
+
</Link>
|
|
101
|
+
{viewOnly ? null : (
|
|
102
|
+
<>
|
|
103
|
+
<RenameTemplate template={template} onDone={done} />
|
|
104
|
+
<CopyTemplate template={template} announce={announce} />
|
|
105
|
+
{template.seedKey ? (
|
|
106
|
+
template.edited ? <RestoreSeededTemplate template={template} announce={announce} onDone={done} /> : null
|
|
107
|
+
) : (
|
|
108
|
+
<DeleteTemplate template={template} announce={announce} onDone={done} />
|
|
109
|
+
)}
|
|
110
|
+
</>
|
|
111
|
+
)}
|
|
112
|
+
</>
|
|
113
|
+
)
|
|
114
|
+
const usedBy = (template: TemplateRow) =>
|
|
115
|
+
template.usedBy.length ? (
|
|
116
|
+
<ul className="flex flex-col gap-0.5">
|
|
117
|
+
{template.usedBy.map((use) => (
|
|
118
|
+
<li key={use.label}>
|
|
119
|
+
{use.href ? (
|
|
120
|
+
<Link href={use.href} className="underline underline-offset-4">
|
|
121
|
+
{use.label}
|
|
122
|
+
</Link>
|
|
123
|
+
) : (
|
|
124
|
+
use.label
|
|
125
|
+
)}
|
|
126
|
+
</li>
|
|
127
|
+
))}
|
|
128
|
+
</ul>
|
|
129
|
+
) : (
|
|
130
|
+
<span className="text-muted-foreground">Not used</span>
|
|
131
|
+
)
|
|
132
|
+
const templateName = (template: TemplateRow) => (
|
|
133
|
+
<span className="flex flex-wrap items-center gap-2">
|
|
134
|
+
<span className="font-medium">{template.name}</span>
|
|
135
|
+
{template.seedKey ? <Badge variant="outline">Default</Badge> : null}
|
|
136
|
+
</span>
|
|
137
|
+
)
|
|
138
|
+
const systemStatus = (email: SystemEmailStatus) =>
|
|
139
|
+
email.customised ? <span>{email.updatedAt ? when(email.updatedAt, 'date') : null}</span> : <span className="text-muted-foreground">Never</span>
|
|
140
|
+
|
|
141
|
+
return (
|
|
142
|
+
<div className="flex flex-col gap-3">
|
|
143
|
+
<div className="flex flex-wrap items-center gap-3">
|
|
144
|
+
<p className="mr-auto max-w-2xl text-sm text-muted-foreground">
|
|
145
|
+
System emails are edited directly; Restore default brings back the built-in version. Make as many templates as you like and choose them where emails are sent, such as on a form. Templates marked Default come with a plugin and are used when nothing else is chosen.
|
|
146
|
+
</p>
|
|
147
|
+
{viewOnly ? null : <NewTemplate announce={announce} />}
|
|
148
|
+
</div>
|
|
149
|
+
|
|
150
|
+
<div aria-live="polite" className="min-h-5 text-sm">
|
|
151
|
+
{message && !message.isError ? <p key={message.id}>{message.text}</p> : null}
|
|
152
|
+
</div>
|
|
153
|
+
{message?.isError ? (
|
|
154
|
+
<p key={message.id} role="alert" className="text-sm text-destructive">
|
|
155
|
+
{message.text}
|
|
156
|
+
</p>
|
|
157
|
+
) : null}
|
|
158
|
+
|
|
159
|
+
{/* Phones: one card per row. From sm up: the table. Only one is displayed. */}
|
|
160
|
+
<ul className="flex flex-col gap-3 sm:hidden" aria-label="Email templates">
|
|
161
|
+
{system.map((email) => (
|
|
162
|
+
<li key={email.purpose} className="flex flex-col gap-2 rounded-lg border p-3 text-sm">
|
|
163
|
+
<span className="flex flex-wrap items-center gap-2">
|
|
164
|
+
<span className="font-medium">{PURPOSE_INFO[email.purpose].label}</span>
|
|
165
|
+
<Badge variant="secondary">System email</Badge>
|
|
166
|
+
</span>
|
|
167
|
+
<span className="text-muted-foreground">{PURPOSE_INFO[email.purpose].description}</span>
|
|
168
|
+
{systemStatus(email)}
|
|
169
|
+
<span className="flex flex-wrap gap-2 pt-1">{systemActions(email)}</span>
|
|
170
|
+
</li>
|
|
171
|
+
))}
|
|
172
|
+
{templates.map((template) => (
|
|
173
|
+
<li key={template.id} className="flex flex-col gap-2 rounded-lg border p-3 text-sm">
|
|
174
|
+
{templateName(template)}
|
|
175
|
+
<span>
|
|
176
|
+
{TYPE_LABELS[template.purpose]} <span className="text-muted-foreground">· {TYPE_HINTS[template.purpose]}</span>
|
|
177
|
+
</span>
|
|
178
|
+
<span className="flex flex-col gap-0.5">
|
|
179
|
+
<span className="text-muted-foreground">Used by</span>
|
|
180
|
+
{usedBy(template)}
|
|
181
|
+
</span>
|
|
182
|
+
<span className="text-muted-foreground">
|
|
183
|
+
Edited {template.updatedAt ? when(template.updatedAt, 'date') : null}
|
|
184
|
+
{template.createdByName ? ` · Created by ${template.createdByName}` : ''}
|
|
185
|
+
</span>
|
|
186
|
+
<span className="flex flex-wrap gap-2 pt-1">{templateActions(template)}</span>
|
|
187
|
+
</li>
|
|
188
|
+
))}
|
|
189
|
+
</ul>
|
|
190
|
+
|
|
191
|
+
<div className="hidden overflow-x-auto rounded-lg border sm:block">
|
|
192
|
+
<Table>
|
|
193
|
+
<caption className="sr-only">System emails, then the templates people made, in name order.</caption>
|
|
194
|
+
<TableHeader>
|
|
195
|
+
<TableRow>
|
|
196
|
+
<TableHead>Name</TableHead>
|
|
197
|
+
<TableHead>Type</TableHead>
|
|
198
|
+
<TableHead>Used by</TableHead>
|
|
199
|
+
<TableHead>Created by</TableHead>
|
|
200
|
+
<TableHead>Last edited</TableHead>
|
|
201
|
+
<TableHead>
|
|
202
|
+
<span className="sr-only">Actions</span>
|
|
203
|
+
</TableHead>
|
|
204
|
+
</TableRow>
|
|
205
|
+
</TableHeader>
|
|
206
|
+
<TableBody>
|
|
207
|
+
{system.map((email) => (
|
|
208
|
+
<TableRow key={email.purpose} className="align-top">
|
|
209
|
+
<TableCell className="font-medium">{PURPOSE_INFO[email.purpose].label}</TableCell>
|
|
210
|
+
<TableCell>
|
|
211
|
+
<Badge variant="secondary">System email</Badge>
|
|
212
|
+
</TableCell>
|
|
213
|
+
<TableCell className="whitespace-normal text-muted-foreground">{PURPOSE_INFO[email.purpose].description}</TableCell>
|
|
214
|
+
<TableCell>
|
|
215
|
+
<span className="sr-only">None</span>
|
|
216
|
+
</TableCell>
|
|
217
|
+
<TableCell className="whitespace-nowrap">{systemStatus(email)}</TableCell>
|
|
218
|
+
<TableCell>
|
|
219
|
+
<span className="flex flex-wrap items-center justify-end gap-2">{systemActions(email)}</span>
|
|
220
|
+
</TableCell>
|
|
221
|
+
</TableRow>
|
|
222
|
+
))}
|
|
223
|
+
{templates.map((template) => (
|
|
224
|
+
<TableRow key={template.id} className="align-top">
|
|
225
|
+
<TableCell className="whitespace-normal">{templateName(template)}</TableCell>
|
|
226
|
+
<TableCell className="whitespace-normal">
|
|
227
|
+
<span className="flex flex-col">
|
|
228
|
+
<span>{TYPE_LABELS[template.purpose]}</span>
|
|
229
|
+
<span className="text-xs text-muted-foreground">{TYPE_HINTS[template.purpose]}</span>
|
|
230
|
+
</span>
|
|
231
|
+
</TableCell>
|
|
232
|
+
<TableCell className="whitespace-normal">{usedBy(template)}</TableCell>
|
|
233
|
+
<TableCell className="whitespace-normal">{template.createdByName ?? <span className="sr-only">None</span>}</TableCell>
|
|
234
|
+
<TableCell className="whitespace-nowrap">{template.updatedAt ? when(template.updatedAt, 'date') : null}</TableCell>
|
|
235
|
+
<TableCell>
|
|
236
|
+
<span className="flex flex-wrap items-center justify-end gap-2">{templateActions(template)}</span>
|
|
237
|
+
</TableCell>
|
|
238
|
+
</TableRow>
|
|
239
|
+
))}
|
|
240
|
+
{templates.length === 0 ? (
|
|
241
|
+
<TableRow>
|
|
242
|
+
<TableCell colSpan={6} className="whitespace-normal text-center text-muted-foreground">
|
|
243
|
+
No templates yet. Make one, then choose it where emails are sent, for example on a form.
|
|
244
|
+
</TableCell>
|
|
245
|
+
</TableRow>
|
|
246
|
+
) : null}
|
|
247
|
+
</TableBody>
|
|
248
|
+
</Table>
|
|
249
|
+
</div>
|
|
250
|
+
</div>
|
|
251
|
+
)
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function RestoreSystemEmail({ purpose, announce, onDone }: { purpose: SystemPurpose; announce: Announce; onDone: (text: string) => void }) {
|
|
255
|
+
const [open, setOpen] = React.useState(false)
|
|
256
|
+
const [pending, startTransition] = React.useTransition()
|
|
257
|
+
const label = PURPOSE_INFO[purpose].label
|
|
258
|
+
return (
|
|
259
|
+
<AlertDialog open={open} onOpenChange={setOpen}>
|
|
260
|
+
<AlertDialogTrigger render={<Button type="button" variant="outline" size="sm" />}>
|
|
261
|
+
Restore default<span className="sr-only"> {label} email</span>
|
|
262
|
+
</AlertDialogTrigger>
|
|
263
|
+
<AlertDialogContent>
|
|
264
|
+
<AlertDialogHeader>
|
|
265
|
+
<AlertDialogTitle>Restore the default “{label}” email?</AlertDialogTitle>
|
|
266
|
+
<AlertDialogDescription>Your changes to this email are removed and the built-in version is sent again. This cannot be undone.</AlertDialogDescription>
|
|
267
|
+
</AlertDialogHeader>
|
|
268
|
+
<AlertDialogFooter>
|
|
269
|
+
<AlertDialogCancel>Keep my changes</AlertDialogCancel>
|
|
270
|
+
<Button
|
|
271
|
+
aria-disabled={pending || undefined}
|
|
272
|
+
onClick={() => {
|
|
273
|
+
if (pending) return
|
|
274
|
+
startTransition(async () => {
|
|
275
|
+
const result = await restoreSystemEmailAction(purpose)
|
|
276
|
+
setOpen(false)
|
|
277
|
+
if (result.ok) onDone(`The “${label}” email is back to its default.`)
|
|
278
|
+
else announce(result.error, true)
|
|
279
|
+
})
|
|
280
|
+
}}
|
|
281
|
+
>
|
|
282
|
+
{pending ? 'Restoring…' : 'Restore default'}
|
|
283
|
+
</Button>
|
|
284
|
+
</AlertDialogFooter>
|
|
285
|
+
</AlertDialogContent>
|
|
286
|
+
</AlertDialog>
|
|
287
|
+
)
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function RestoreSeededTemplate({ template, announce, onDone }: { template: TemplateRow; announce: Announce; onDone: (text: string) => void }) {
|
|
291
|
+
const [open, setOpen] = React.useState(false)
|
|
292
|
+
const [pending, startTransition] = React.useTransition()
|
|
293
|
+
return (
|
|
294
|
+
<AlertDialog open={open} onOpenChange={setOpen}>
|
|
295
|
+
<AlertDialogTrigger render={<Button type="button" variant="outline" size="sm" />}>
|
|
296
|
+
Restore default<span className="sr-only"> {template.name}</span>
|
|
297
|
+
</AlertDialogTrigger>
|
|
298
|
+
<AlertDialogContent>
|
|
299
|
+
<AlertDialogHeader>
|
|
300
|
+
<AlertDialogTitle>Restore the default “{template.name}”?</AlertDialogTitle>
|
|
301
|
+
<AlertDialogDescription>Your changes to its layout are removed and the plugin’s original comes back. Its name stays. This cannot be undone.</AlertDialogDescription>
|
|
302
|
+
</AlertDialogHeader>
|
|
303
|
+
<AlertDialogFooter>
|
|
304
|
+
<AlertDialogCancel>Keep my changes</AlertDialogCancel>
|
|
305
|
+
<Button
|
|
306
|
+
aria-disabled={pending || undefined}
|
|
307
|
+
onClick={() => {
|
|
308
|
+
if (pending) return
|
|
309
|
+
startTransition(async () => {
|
|
310
|
+
const result = await restoreSeededTemplateAction(template.id)
|
|
311
|
+
setOpen(false)
|
|
312
|
+
if (result.ok) onDone(`${template.name} is back to its default.`)
|
|
313
|
+
else announce(result.error, true)
|
|
314
|
+
})
|
|
315
|
+
}}
|
|
316
|
+
>
|
|
317
|
+
{pending ? 'Restoring…' : 'Restore default'}
|
|
318
|
+
</Button>
|
|
319
|
+
</AlertDialogFooter>
|
|
320
|
+
</AlertDialogContent>
|
|
321
|
+
</AlertDialog>
|
|
322
|
+
)
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
type NameErrors = { name?: string; purpose?: string; general?: string }
|
|
326
|
+
|
|
327
|
+
/** A dialog asking for a name (and, for a new template, its type): used to create, copy and rename. */
|
|
328
|
+
function NameDialog({
|
|
329
|
+
trigger,
|
|
330
|
+
label,
|
|
331
|
+
title,
|
|
332
|
+
description,
|
|
333
|
+
initial,
|
|
334
|
+
submitLabel,
|
|
335
|
+
withType = false,
|
|
336
|
+
onSubmit,
|
|
337
|
+
}: {
|
|
338
|
+
trigger: React.ReactElement
|
|
339
|
+
label: React.ReactNode
|
|
340
|
+
title: string
|
|
341
|
+
description: string
|
|
342
|
+
initial: string
|
|
343
|
+
submitLabel: string
|
|
344
|
+
withType?: boolean
|
|
345
|
+
onSubmit: (name: string, purpose: EmailPurpose) => Promise<{ ok: true } | { ok: false; errors: NameErrors }>
|
|
346
|
+
}) {
|
|
347
|
+
const [open, setOpen] = React.useState(false)
|
|
348
|
+
const [name, setName] = React.useState(initial)
|
|
349
|
+
const [purpose, setPurpose] = React.useState<EmailPurpose>('team-notification')
|
|
350
|
+
const [errors, setErrors] = React.useState<NameErrors>({})
|
|
351
|
+
const [pending, startTransition] = React.useTransition()
|
|
352
|
+
const id = React.useId()
|
|
353
|
+
|
|
354
|
+
return (
|
|
355
|
+
<Dialog
|
|
356
|
+
open={open}
|
|
357
|
+
onOpenChange={(next) => {
|
|
358
|
+
setOpen(next)
|
|
359
|
+
if (next) {
|
|
360
|
+
setName(initial)
|
|
361
|
+
setErrors({})
|
|
362
|
+
}
|
|
363
|
+
}}
|
|
364
|
+
>
|
|
365
|
+
<DialogTrigger render={trigger}>{label}</DialogTrigger>
|
|
366
|
+
<DialogContent>
|
|
367
|
+
<form
|
|
368
|
+
noValidate
|
|
369
|
+
className="flex flex-col gap-4"
|
|
370
|
+
onSubmit={(event) => {
|
|
371
|
+
event.preventDefault()
|
|
372
|
+
if (pending) return
|
|
373
|
+
startTransition(async () => {
|
|
374
|
+
const result = await onSubmit(name, purpose)
|
|
375
|
+
if (result.ok) setOpen(false)
|
|
376
|
+
else setErrors(result.errors)
|
|
377
|
+
})
|
|
378
|
+
}}
|
|
379
|
+
>
|
|
380
|
+
<DialogHeader>
|
|
381
|
+
<DialogTitle>{title}</DialogTitle>
|
|
382
|
+
<DialogDescription>{description}</DialogDescription>
|
|
383
|
+
</DialogHeader>
|
|
384
|
+
<div className="flex flex-col gap-2">
|
|
385
|
+
<Label htmlFor={`${id}-name`}>Name</Label>
|
|
386
|
+
<Input
|
|
387
|
+
id={`${id}-name`}
|
|
388
|
+
value={name}
|
|
389
|
+
maxLength={80}
|
|
390
|
+
autoComplete="off"
|
|
391
|
+
onChange={(event) => setName(event.target.value)}
|
|
392
|
+
aria-invalid={errors.name ? true : undefined}
|
|
393
|
+
aria-describedby={errors.name ? `${id}-name-error` : undefined}
|
|
394
|
+
/>
|
|
395
|
+
{errors.name ? (
|
|
396
|
+
<p id={`${id}-name-error`} className="text-sm text-destructive">
|
|
397
|
+
{errors.name}
|
|
398
|
+
</p>
|
|
399
|
+
) : null}
|
|
400
|
+
</div>
|
|
401
|
+
{withType ? (
|
|
402
|
+
<fieldset className="flex flex-col gap-2">
|
|
403
|
+
<legend className="mb-1 text-sm font-medium">Type</legend>
|
|
404
|
+
{LIBRARY_PURPOSES.map((value) => (
|
|
405
|
+
<label key={value} className="flex items-start gap-2 text-sm">
|
|
406
|
+
<input type="radio" name={`${id}-type`} value={value} checked={purpose === value} onChange={() => setPurpose(value)} className="mt-1" />
|
|
407
|
+
<span>
|
|
408
|
+
<span className="font-medium">{TYPE_LABELS[value]}</span>
|
|
409
|
+
<span className="block text-muted-foreground">{PURPOSE_INFO[value].description}</span>
|
|
410
|
+
</span>
|
|
411
|
+
</label>
|
|
412
|
+
))}
|
|
413
|
+
{errors.purpose ? <p className="text-sm text-destructive">{errors.purpose}</p> : null}
|
|
414
|
+
</fieldset>
|
|
415
|
+
) : null}
|
|
416
|
+
{errors.general ? (
|
|
417
|
+
<p role="alert" className="text-sm text-destructive">
|
|
418
|
+
{errors.general}
|
|
419
|
+
</p>
|
|
420
|
+
) : null}
|
|
421
|
+
<DialogFooter>
|
|
422
|
+
<Button type="submit" aria-disabled={pending || undefined}>
|
|
423
|
+
{pending ? 'Working…' : submitLabel}
|
|
424
|
+
</Button>
|
|
425
|
+
</DialogFooter>
|
|
426
|
+
</form>
|
|
427
|
+
</DialogContent>
|
|
428
|
+
</Dialog>
|
|
429
|
+
)
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
const failure = (result: { error: string; fieldErrors?: Record<string, string> }) => ({
|
|
433
|
+
ok: false as const,
|
|
434
|
+
errors: result.fieldErrors ? { name: result.fieldErrors.name, purpose: result.fieldErrors.purpose } : { general: result.error },
|
|
435
|
+
})
|
|
436
|
+
|
|
437
|
+
function NewTemplate({ announce }: { announce: Announce }) {
|
|
438
|
+
const router = useRouter()
|
|
439
|
+
return (
|
|
440
|
+
<NameDialog
|
|
441
|
+
trigger={<Button type="button" />}
|
|
442
|
+
label={
|
|
443
|
+
<>
|
|
444
|
+
<FiPlus aria-hidden />
|
|
445
|
+
New template
|
|
446
|
+
</>
|
|
447
|
+
}
|
|
448
|
+
title="New email template"
|
|
449
|
+
description="It starts from the built-in email of that type; the builder opens next. Choose it where emails are sent, such as on a form."
|
|
450
|
+
initial=""
|
|
451
|
+
submitLabel="Create and open the builder"
|
|
452
|
+
withType
|
|
453
|
+
onSubmit={async (name, purpose) => {
|
|
454
|
+
const result = await createEmailTemplateAction({ name, purpose })
|
|
455
|
+
if (!result.ok) return failure(result)
|
|
456
|
+
announce('Template created. Opening the builder…')
|
|
457
|
+
router.push(`/edit/email/${result.data.id}`)
|
|
458
|
+
return { ok: true }
|
|
459
|
+
}}
|
|
460
|
+
/>
|
|
461
|
+
)
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
function RenameTemplate({ template, onDone }: { template: TemplateRow; onDone: (text: string) => void }) {
|
|
465
|
+
return (
|
|
466
|
+
<NameDialog
|
|
467
|
+
trigger={<Button type="button" variant="outline" size="sm" />}
|
|
468
|
+
label={
|
|
469
|
+
<>
|
|
470
|
+
Rename<span className="sr-only"> {template.name}</span>
|
|
471
|
+
</>
|
|
472
|
+
}
|
|
473
|
+
title="Rename the template"
|
|
474
|
+
description="Only people in the admin see this name."
|
|
475
|
+
initial={template.name}
|
|
476
|
+
submitLabel="Rename"
|
|
477
|
+
onSubmit={async (name) => {
|
|
478
|
+
const result = await saveEmailTemplateAction(template.id, { name })
|
|
479
|
+
if (!result.ok) return failure(result)
|
|
480
|
+
onDone(`Renamed to ${result.data.name}.`)
|
|
481
|
+
return { ok: true }
|
|
482
|
+
}}
|
|
483
|
+
/>
|
|
484
|
+
)
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
function CopyTemplate({ template, announce }: { template: TemplateRow; announce: Announce }) {
|
|
488
|
+
const router = useRouter()
|
|
489
|
+
return (
|
|
490
|
+
<NameDialog
|
|
491
|
+
trigger={<Button type="button" variant="outline" size="sm" />}
|
|
492
|
+
label={
|
|
493
|
+
<>
|
|
494
|
+
Copy<span className="sr-only"> {template.name}</span>
|
|
495
|
+
</>
|
|
496
|
+
}
|
|
497
|
+
title={`Copy “${template.name}”`}
|
|
498
|
+
description="The copy opens in the builder; the original stays as it is."
|
|
499
|
+
initial={`${template.name} (copy)`.slice(0, 80)}
|
|
500
|
+
submitLabel="Copy and open the builder"
|
|
501
|
+
onSubmit={async (name) => {
|
|
502
|
+
const result = await createEmailTemplateAction({ name, purpose: template.purpose, fromId: template.id })
|
|
503
|
+
if (!result.ok) return failure(result)
|
|
504
|
+
announce('Copied. Opening the builder…')
|
|
505
|
+
router.push(`/edit/email/${result.data.id}`)
|
|
506
|
+
return { ok: true }
|
|
507
|
+
}}
|
|
508
|
+
/>
|
|
509
|
+
)
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
function DeleteTemplate({ template, announce, onDone }: { template: TemplateRow; announce: Announce; onDone: (text: string) => void }) {
|
|
513
|
+
const [open, setOpen] = React.useState(false)
|
|
514
|
+
const [pending, startTransition] = React.useTransition()
|
|
515
|
+
const uses = template.usedBy.length
|
|
516
|
+
return (
|
|
517
|
+
<AlertDialog open={open} onOpenChange={setOpen}>
|
|
518
|
+
<AlertDialogTrigger render={<Button type="button" variant="destructive" size="sm" />}>
|
|
519
|
+
Delete
|
|
520
|
+
<span className="sr-only"> {template.name}</span>
|
|
521
|
+
</AlertDialogTrigger>
|
|
522
|
+
<AlertDialogContent>
|
|
523
|
+
<AlertDialogHeader>
|
|
524
|
+
<AlertDialogTitle>Delete “{template.name}”?</AlertDialogTitle>
|
|
525
|
+
<AlertDialogDescription>
|
|
526
|
+
{uses ? `It is used ${uses === 1 ? 'once' : `${uses} times`} (${template.usedBy.map((use) => use.label).join(', ')}); those send the built-in email instead. ` : ''}
|
|
527
|
+
This cannot be undone.
|
|
528
|
+
</AlertDialogDescription>
|
|
529
|
+
</AlertDialogHeader>
|
|
530
|
+
<AlertDialogFooter>
|
|
531
|
+
<AlertDialogCancel>Keep</AlertDialogCancel>
|
|
532
|
+
<Button
|
|
533
|
+
variant="destructive"
|
|
534
|
+
aria-disabled={pending || undefined}
|
|
535
|
+
onClick={() => {
|
|
536
|
+
if (pending) return
|
|
537
|
+
startTransition(async () => {
|
|
538
|
+
const result = await deleteEmailTemplateAction(template.id)
|
|
539
|
+
setOpen(false)
|
|
540
|
+
if (result.ok) onDone(`${template.name} was deleted.`)
|
|
541
|
+
else announce(result.error, true)
|
|
542
|
+
})
|
|
543
|
+
}}
|
|
544
|
+
>
|
|
545
|
+
{pending ? 'Deleting…' : 'Delete template'}
|
|
546
|
+
</Button>
|
|
547
|
+
</AlertDialogFooter>
|
|
548
|
+
</AlertDialogContent>
|
|
549
|
+
</AlertDialog>
|
|
550
|
+
)
|
|
551
|
+
}
|