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,16 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useSWRConfig } from 'swr'
|
|
4
|
+
|
|
5
|
+
/** First entry of every SWR key that holds media library data: ["media", search, page, perPage]. */
|
|
6
|
+
export const MEDIA_CACHE_KEY = 'media'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Marks every cached library page as out of date and refetches the ones on screen. Call it after
|
|
10
|
+
* anything that changes images from the client (upload, rename, delete): SWR's cache lives in the
|
|
11
|
+
* browser, so the server's `revalidatePath` does not reach it. Same idea as `useInvalidatePets`.
|
|
12
|
+
*/
|
|
13
|
+
export function useInvalidateMedia() {
|
|
14
|
+
const { mutate } = useSWRConfig()
|
|
15
|
+
return () => mutate((key) => Array.isArray(key) && key[0] === MEDIA_CACHE_KEY)
|
|
16
|
+
}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { labelFor, PetStatus, SPECIES } from "@/lib/options";
|
|
2
|
+
import { isRichTextEmpty } from "@/lib/rich-text";
|
|
3
|
+
import type { PetFormMedia, PetFormValues } from "@/lib/zod-schema/pet";
|
|
4
|
+
import type { MediaItem, Pet } from "@/server/types";
|
|
5
|
+
|
|
6
|
+
// Glue between the pet form and `savePetAction`: the starting values, the payload, and which tab
|
|
7
|
+
// each field lives in (so an error can open the right tab).
|
|
8
|
+
|
|
9
|
+
export const TABS = [
|
|
10
|
+
{ id: "basics", label: "Basics" },
|
|
11
|
+
{ id: "health", label: "Health and behaviour" },
|
|
12
|
+
{ id: "photos", label: "Photos and story" },
|
|
13
|
+
{ id: "adoption", label: "Adoption" },
|
|
14
|
+
{ id: "seo", label: "Search and sharing" },
|
|
15
|
+
] as const;
|
|
16
|
+
|
|
17
|
+
export type TabId = (typeof TABS)[number]["id"];
|
|
18
|
+
|
|
19
|
+
type FieldName = keyof PetFormValues;
|
|
20
|
+
|
|
21
|
+
// The tab of every field, in the order the form shows them (the error summary follows this order).
|
|
22
|
+
// `null` is the sidebar, which is always on screen.
|
|
23
|
+
export const FIELD_TAB: Record<FieldName, TabId | null> = {
|
|
24
|
+
name: "basics",
|
|
25
|
+
species: "basics",
|
|
26
|
+
sex: "basics",
|
|
27
|
+
size: "basics",
|
|
28
|
+
breed: "basics",
|
|
29
|
+
color: "basics",
|
|
30
|
+
ageMode: "basics",
|
|
31
|
+
birthDate: "basics",
|
|
32
|
+
ageValue: "basics",
|
|
33
|
+
ageUnit: "basics",
|
|
34
|
+
ageDescription: "basics",
|
|
35
|
+
ageGroup: "basics",
|
|
36
|
+
city: "basics",
|
|
37
|
+
state: "basics",
|
|
38
|
+
country: "basics",
|
|
39
|
+
location: "basics",
|
|
40
|
+
vaccinated: "health",
|
|
41
|
+
neutered: "health",
|
|
42
|
+
microchipped: "health",
|
|
43
|
+
houseTrained: "health",
|
|
44
|
+
specialNeeds: "health",
|
|
45
|
+
healthNotes: "health",
|
|
46
|
+
temperament: "health",
|
|
47
|
+
goodWith: "health",
|
|
48
|
+
personalityNotes: "health",
|
|
49
|
+
photos: "photos",
|
|
50
|
+
description: "photos",
|
|
51
|
+
videoUrl: "photos",
|
|
52
|
+
adoptionFee: "adoption",
|
|
53
|
+
rescuedAt: "adoption",
|
|
54
|
+
contactWhatsApp: "adoption",
|
|
55
|
+
seoTitle: "seo",
|
|
56
|
+
seoDescription: "seo",
|
|
57
|
+
seoImage: "seo",
|
|
58
|
+
status: null,
|
|
59
|
+
featured: null,
|
|
60
|
+
unlisted: null,
|
|
61
|
+
urgent: null,
|
|
62
|
+
slug: null,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const FIELD_ORDER = Object.keys(FIELD_TAB) as FieldName[];
|
|
66
|
+
|
|
67
|
+
/** What an error is called in the summary at the top of the form. */
|
|
68
|
+
export const FIELD_LABELS: Record<FieldName, string> = {
|
|
69
|
+
name: "Name",
|
|
70
|
+
species: "Species",
|
|
71
|
+
sex: "Sex",
|
|
72
|
+
size: "Size",
|
|
73
|
+
breed: "Breed",
|
|
74
|
+
color: "Colour",
|
|
75
|
+
ageMode: "Age",
|
|
76
|
+
birthDate: "Birth date",
|
|
77
|
+
ageValue: "Age",
|
|
78
|
+
ageUnit: "Age unit",
|
|
79
|
+
ageDescription: "Age description",
|
|
80
|
+
ageGroup: "Age group",
|
|
81
|
+
city: "City",
|
|
82
|
+
state: "State",
|
|
83
|
+
country: "Country",
|
|
84
|
+
location: "Location",
|
|
85
|
+
vaccinated: "Vaccinated",
|
|
86
|
+
neutered: "Neutered",
|
|
87
|
+
microchipped: "Microchipped",
|
|
88
|
+
houseTrained: "House trained",
|
|
89
|
+
specialNeeds: "Special needs",
|
|
90
|
+
healthNotes: "Health notes",
|
|
91
|
+
temperament: "Temperament",
|
|
92
|
+
goodWith: "Good with",
|
|
93
|
+
personalityNotes: "Personality notes",
|
|
94
|
+
photos: "Photos",
|
|
95
|
+
description: "Description",
|
|
96
|
+
videoUrl: "Video link",
|
|
97
|
+
adoptionFee: "Adoption fee",
|
|
98
|
+
rescuedAt: "Rescue date",
|
|
99
|
+
contactWhatsApp: "WhatsApp number",
|
|
100
|
+
seoTitle: "Search title",
|
|
101
|
+
seoDescription: "Search description",
|
|
102
|
+
seoImage: "Share image",
|
|
103
|
+
status: "Status",
|
|
104
|
+
featured: "Featured",
|
|
105
|
+
unlisted: "Link only",
|
|
106
|
+
urgent: "Urgent",
|
|
107
|
+
slug: "Address",
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/** The form field a name from the server's `fieldErrors` belongs to, or null if the form has none. */
|
|
111
|
+
export function formFieldFor(serverField: string): FieldName | null {
|
|
112
|
+
if (serverField === "photoIds") return "photos";
|
|
113
|
+
if (serverField === "seoImageId") return "seoImage";
|
|
114
|
+
return serverField in FIELD_TAB ? (serverField as FieldName) : null;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const toRef = (media: MediaItem): PetFormMedia => ({
|
|
118
|
+
id: media.id,
|
|
119
|
+
url: media.url,
|
|
120
|
+
thumbnailUrl: media.thumbnailUrl,
|
|
121
|
+
alt: media.alt,
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The values the form starts with: a new pet, or the pet being edited. `defaultCountry` is the
|
|
126
|
+
* site's country (ISO code), which a pet without one starts with.
|
|
127
|
+
*/
|
|
128
|
+
export function petToFormValues(pet: Pet | null, defaultCountry: string): PetFormValues {
|
|
129
|
+
// A pet with a birth date keeps its age unless the owner picks another way; one without it
|
|
130
|
+
// shows the typed description and picked group. (`ageDescription` and `ageGroup` on a pet with a
|
|
131
|
+
// birth date are worked out live, so they are not put in the form.)
|
|
132
|
+
const dated = Boolean(pet?.birthDate);
|
|
133
|
+
|
|
134
|
+
return {
|
|
135
|
+
name: pet?.name ?? "",
|
|
136
|
+
species: pet ? labelFor(SPECIES, pet.species) : "",
|
|
137
|
+
sex: (pet?.sex as PetFormValues["sex"] | null) ?? "",
|
|
138
|
+
size: (pet?.size as PetFormValues["size"] | null) ?? "",
|
|
139
|
+
breed: pet?.breed ?? "",
|
|
140
|
+
color: pet?.color ?? "",
|
|
141
|
+
city: pet?.city ?? "",
|
|
142
|
+
state: pet?.state ?? "",
|
|
143
|
+
// A new pet, and one saved before countries were kept, starts as the site's country.
|
|
144
|
+
country: pet?.country ?? defaultCountry,
|
|
145
|
+
location: pet?.location ?? "",
|
|
146
|
+
|
|
147
|
+
ageMode: dated ? "keep" : pet ? "none" : "estimate",
|
|
148
|
+
birthDate: pet?.birthDate ?? "",
|
|
149
|
+
ageValue: "",
|
|
150
|
+
ageUnit: "months",
|
|
151
|
+
ageDescription: dated ? "" : (pet?.ageDescription ?? ""),
|
|
152
|
+
ageGroup: dated ? "" : ((pet?.ageGroup as PetFormValues["ageGroup"] | null) ?? ""),
|
|
153
|
+
|
|
154
|
+
vaccinated: pet?.vaccinated ?? false,
|
|
155
|
+
neutered: pet?.neutered ?? false,
|
|
156
|
+
microchipped: pet?.microchipped ?? false,
|
|
157
|
+
houseTrained: pet?.houseTrained ?? false,
|
|
158
|
+
specialNeeds: pet?.specialNeeds ?? false,
|
|
159
|
+
healthNotes: pet?.healthNotes ?? null,
|
|
160
|
+
temperament: (pet?.temperament ?? []) as PetFormValues["temperament"],
|
|
161
|
+
goodWith: (pet?.goodWith ?? []) as PetFormValues["goodWith"],
|
|
162
|
+
personalityNotes: pet?.personalityNotes ?? null,
|
|
163
|
+
|
|
164
|
+
photos: pet?.photos.map(toRef) ?? [],
|
|
165
|
+
description: pet?.description ?? null,
|
|
166
|
+
videoUrl: pet?.videoUrl ?? "",
|
|
167
|
+
|
|
168
|
+
adoptionFee: pet?.adoptionFee == null ? "" : String(pet.adoptionFee),
|
|
169
|
+
rescuedAt: pet?.rescuedAt ?? "",
|
|
170
|
+
contactWhatsApp: pet?.contactWhatsApp ?? "",
|
|
171
|
+
|
|
172
|
+
seoTitle: pet?.seo.title ?? "",
|
|
173
|
+
seoDescription: pet?.seo.description ?? "",
|
|
174
|
+
seoImage: pet?.seo.image ? toRef(pet.seo.image) : null,
|
|
175
|
+
|
|
176
|
+
status: pet?.status ?? PetStatus.Available,
|
|
177
|
+
featured: pet?.featured ?? false,
|
|
178
|
+
unlisted: pet?.unlisted ?? false,
|
|
179
|
+
urgent: pet?.urgent ?? false,
|
|
180
|
+
slug: pet?.slug ?? "",
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const blank = (value: string) => (value === "" ? null : value);
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* The payload for `savePetAction`. A blank field is sent as null, which clears it. The age fields
|
|
188
|
+
* depend on how the age was entered, and are left out when it was not changed: sending `ageValue`
|
|
189
|
+
* again would work "about 8 months" out from today and move the pet's age.
|
|
190
|
+
*/
|
|
191
|
+
export function toPetInput(values: PetFormValues): Record<string, unknown> {
|
|
192
|
+
const input: Record<string, unknown> = {
|
|
193
|
+
name: values.name,
|
|
194
|
+
status: values.status,
|
|
195
|
+
species: values.species,
|
|
196
|
+
sex: blank(values.sex),
|
|
197
|
+
size: blank(values.size),
|
|
198
|
+
breed: blank(values.breed),
|
|
199
|
+
color: blank(values.color),
|
|
200
|
+
city: blank(values.city),
|
|
201
|
+
state: blank(values.state),
|
|
202
|
+
country: blank(values.country),
|
|
203
|
+
location: blank(values.location),
|
|
204
|
+
vaccinated: values.vaccinated,
|
|
205
|
+
neutered: values.neutered,
|
|
206
|
+
microchipped: values.microchipped,
|
|
207
|
+
houseTrained: values.houseTrained,
|
|
208
|
+
specialNeeds: values.specialNeeds,
|
|
209
|
+
healthNotes: isRichTextEmpty(values.healthNotes) ? null : values.healthNotes,
|
|
210
|
+
temperament: values.temperament,
|
|
211
|
+
goodWith: values.goodWith,
|
|
212
|
+
personalityNotes: isRichTextEmpty(values.personalityNotes) ? null : values.personalityNotes,
|
|
213
|
+
photoIds: values.photos.map((photo) => photo.id),
|
|
214
|
+
description: isRichTextEmpty(values.description) ? null : values.description,
|
|
215
|
+
videoUrl: blank(values.videoUrl),
|
|
216
|
+
adoptionFee: values.adoptionFee === "" ? null : Number(values.adoptionFee),
|
|
217
|
+
rescuedAt: blank(values.rescuedAt),
|
|
218
|
+
contactWhatsApp: blank(values.contactWhatsApp),
|
|
219
|
+
seoTitle: blank(values.seoTitle),
|
|
220
|
+
seoDescription: blank(values.seoDescription),
|
|
221
|
+
seoImageId: values.seoImage?.id ?? null,
|
|
222
|
+
featured: values.featured,
|
|
223
|
+
unlisted: values.unlisted,
|
|
224
|
+
urgent: values.urgent,
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
// A blank address on an edit keeps the current one, and on a new pet it is made from the name.
|
|
228
|
+
if (values.slug !== "") input.slug = values.slug;
|
|
229
|
+
|
|
230
|
+
if (values.ageMode === "date" && values.birthDate !== "") {
|
|
231
|
+
input.birthDate = values.birthDate;
|
|
232
|
+
} else if (values.ageMode === "estimate" && values.ageValue !== "") {
|
|
233
|
+
input.ageValue = Number(values.ageValue);
|
|
234
|
+
input.ageUnit = values.ageUnit;
|
|
235
|
+
} else if (values.ageMode === "none") {
|
|
236
|
+
input.birthDate = null;
|
|
237
|
+
input.ageDescription = blank(values.ageDescription);
|
|
238
|
+
input.ageGroup = blank(values.ageGroup);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return input;
|
|
242
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useSWRConfig } from "swr";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* First entry of every SWR key that holds pet data: the list is ["pets", search, status, species, page]
|
|
7
|
+
* and the species dropdown is ["pets", "species"]. One matcher (below) covers both.
|
|
8
|
+
*/
|
|
9
|
+
export const PETS_CACHE_KEY = "pets";
|
|
10
|
+
|
|
11
|
+
/** The species the dropdowns offer (built-in and custom). A save can add one, so it is invalidated with the lists. */
|
|
12
|
+
export const SPECIES_CACHE_KEY = [PETS_CACHE_KEY, "species"] as const;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Marks every cached pet list, and the species dropdown, as out of date and refetches the ones on screen. Call it after
|
|
16
|
+
* anything that changes pets from the client (save, delete): SWR's cache lives in the browser, so
|
|
17
|
+
* the server's `revalidatePath` does not reach it.
|
|
18
|
+
*/
|
|
19
|
+
export function useInvalidatePets() {
|
|
20
|
+
const { mutate } = useSWRConfig();
|
|
21
|
+
return () => mutate((key) => Array.isArray(key) && key[0] === PETS_CACHE_KEY);
|
|
22
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ActionResult } from "@/server/result";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* For client components and SWR fetchers: the data of a successful action, or throw so the error
|
|
5
|
+
* lands in SWR's `error`. Actions return `{ ok: false }` instead of throwing, which SWR cannot see.
|
|
6
|
+
* (`unwrap` in ./unwrap.ts is for server components: it imports server-only code.)
|
|
7
|
+
*/
|
|
8
|
+
export function unwrapResult<T>(result: ActionResult<T>): T {
|
|
9
|
+
if (!result.ok) throw new Error(result.error);
|
|
10
|
+
return result.data;
|
|
11
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { can, type Permission } from '@pet-adopt/plugin-sdk'
|
|
2
|
+
import { notFound, redirect } from 'next/navigation'
|
|
3
|
+
|
|
4
|
+
import type { ActionResult } from '@/server/result'
|
|
5
|
+
import { getSessionUser } from '@/server/session'
|
|
6
|
+
import { needsTwoFactorSetup } from '@/server/two-factor'
|
|
7
|
+
import type { SessionUser } from '@/server/types'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* For server components: the data of a successful action, or throw so the nearest `error.tsx`
|
|
11
|
+
* shows the message. (Client components handle `ok: false` themselves, with toasts and field errors.)
|
|
12
|
+
*/
|
|
13
|
+
export function unwrap<T>(result: ActionResult<T>): T {
|
|
14
|
+
if (!result.ok) throw new Error(result.error)
|
|
15
|
+
return result.data
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Like `unwrap`, for a lookup by id: a missing record becomes the 404 page. */
|
|
19
|
+
export function unwrapOrNotFound<T>(result: ActionResult<T | null>): T {
|
|
20
|
+
const data = unwrap(result)
|
|
21
|
+
if (data == null) notFound()
|
|
22
|
+
return data
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Page ids come from the URL. Anything that is not a whole number is a 404. */
|
|
26
|
+
export function parseId(value: string): number {
|
|
27
|
+
if (!/^\d{1,10}$/.test(value)) notFound()
|
|
28
|
+
return Number(value)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** A screen that needs `permission` (`pets:view`, `users:view`...). Others go back to the dashboard. */
|
|
32
|
+
export async function requirePermissionPage(permission: Permission): Promise<SessionUser> {
|
|
33
|
+
const user = await getSessionUser()
|
|
34
|
+
if (!user) redirect('/admin/login')
|
|
35
|
+
// Two-factor still to set up (their role requires it): the admin layout shows that screen.
|
|
36
|
+
if (!can(user.role, permission) || (await needsTwoFactorSetup(user))) redirect('/admin')
|
|
37
|
+
return user
|
|
38
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useSearchParams } from 'next/navigation'
|
|
4
|
+
import type { inferParserType } from 'nuqs/server'
|
|
5
|
+
import useSWR from 'swr'
|
|
6
|
+
|
|
7
|
+
import { loadMediaSearchParams, mediaSearchParsers } from '@/app/(admin)/admin/media/search-params'
|
|
8
|
+
import { listMediaAction } from '@/server/actions/media'
|
|
9
|
+
import type { listMedia } from '@/server/media'
|
|
10
|
+
|
|
11
|
+
import { MEDIA_CACHE_KEY } from './media-cache'
|
|
12
|
+
import { unwrapResult } from './unwrap-client'
|
|
13
|
+
|
|
14
|
+
export type MediaListFilters = inferParserType<typeof mediaSearchParsers>
|
|
15
|
+
export type MediaListPage = Awaited<ReturnType<typeof listMedia>>
|
|
16
|
+
|
|
17
|
+
/** What the server page loaded for the URL it was opened with: the first render's view and data. */
|
|
18
|
+
export type MediaListSeed = { initialFilters: MediaListFilters; initialData: MediaListPage }
|
|
19
|
+
|
|
20
|
+
// One entry per part of the view, so every search, page and size is cached on its own.
|
|
21
|
+
const keyOf = (f: MediaListFilters) => [MEDIA_CACHE_KEY, f.search, f.page, f.perPage] as const
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The media library for the URL as it is now (the search box writes it, debounced), fetched and
|
|
25
|
+
* cached with SWR, like `usePetList`. The server's data only seeds the key it was rendered for.
|
|
26
|
+
* `keepPreviousData` keeps the last page on screen while the next one loads, so paging and typing
|
|
27
|
+
* do not flash an empty grid.
|
|
28
|
+
*/
|
|
29
|
+
export function useMediaList({ initialFilters, initialData }: MediaListSeed) {
|
|
30
|
+
const filters = loadMediaSearchParams(useSearchParams())
|
|
31
|
+
const key = keyOf(filters)
|
|
32
|
+
const isInitial = JSON.stringify(key) === JSON.stringify(keyOf(initialFilters))
|
|
33
|
+
|
|
34
|
+
const result = useSWR(
|
|
35
|
+
key,
|
|
36
|
+
async ([, search, page, perPage]) => unwrapResult(await listMediaAction({ search: search || undefined, page, limit: perPage })),
|
|
37
|
+
{ fallbackData: isInitial ? initialData : undefined, keepPreviousData: true },
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
return { filters, ...result }
|
|
41
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useSearchParams } from "next/navigation";
|
|
4
|
+
import useSWR from "swr";
|
|
5
|
+
import type { inferParserType } from "nuqs/server";
|
|
6
|
+
import {
|
|
7
|
+
loadPetSearchParams,
|
|
8
|
+
petSearchParsers,
|
|
9
|
+
} from "@/app/(admin)/admin/pets/search-params";
|
|
10
|
+
import { listPetsAction } from "@/server/actions/pets";
|
|
11
|
+
import type { PetPage } from "@/server/types";
|
|
12
|
+
import { PETS_CACHE_KEY } from "./pets-cache";
|
|
13
|
+
import { unwrapResult } from "./unwrap-client";
|
|
14
|
+
|
|
15
|
+
export type PetListFilters = inferParserType<typeof petSearchParsers>;
|
|
16
|
+
|
|
17
|
+
/** What the server page loaded for the URL it was opened with: the first render's filters and rows. */
|
|
18
|
+
export type PetListSeed = {
|
|
19
|
+
initialFilters: PetListFilters;
|
|
20
|
+
initialData: PetPage;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// The SWR key: one entry per filter, so every combination is cached on its own.
|
|
24
|
+
const keyOf = (f: PetListFilters) =>
|
|
25
|
+
[PETS_CACHE_KEY, f.search, f.status, f.species, f.page] as const;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The admin pet list for the URL as it is now (FilterBar writes the filters, debounced), fetched
|
|
29
|
+
* and cached with SWR. PetList and FilterBar's pager both call it: SWR sees the same key and makes
|
|
30
|
+
* one request. `keepPreviousData` keeps the last rows while a new key loads; PetList leaves it off
|
|
31
|
+
* so it can show a skeleton, the pager turns it on so the page count does not blink out.
|
|
32
|
+
*/
|
|
33
|
+
export function usePetList({
|
|
34
|
+
initialFilters,
|
|
35
|
+
initialData,
|
|
36
|
+
keepPreviousData = false,
|
|
37
|
+
}: PetListSeed & { keepPreviousData?: boolean }) {
|
|
38
|
+
const filters = loadPetSearchParams(useSearchParams());
|
|
39
|
+
const key = keyOf(filters);
|
|
40
|
+
// The server's data is only right for the URL it was rendered for, so it only seeds that key.
|
|
41
|
+
const isInitial = JSON.stringify(key) === JSON.stringify(keyOf(initialFilters));
|
|
42
|
+
|
|
43
|
+
const result = useSWR(
|
|
44
|
+
key,
|
|
45
|
+
async ([, search, status, species, page]) =>
|
|
46
|
+
unwrapResult(
|
|
47
|
+
await listPetsAction({
|
|
48
|
+
search,
|
|
49
|
+
status: status ?? undefined,
|
|
50
|
+
species: species ?? undefined,
|
|
51
|
+
page,
|
|
52
|
+
}),
|
|
53
|
+
),
|
|
54
|
+
{ fallbackData: isInitial ? initialData : undefined, keepPreviousData },
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
return { filters, ...result };
|
|
58
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// A pet's age, worked out from its birth date every time it is shown, so it keeps up with the
|
|
2
|
+
// calendar without anyone editing it. Dates are plain `YYYY-MM-DD` strings (they sort as dates, on
|
|
3
|
+
// SQLite and PostgreSQL alike). Everything takes `today` as a parameter, so tests can move time.
|
|
4
|
+
// No imports: the schema files and scripts load this too.
|
|
5
|
+
|
|
6
|
+
export type AgeUnit = 'weeks' | 'months' | 'years'
|
|
7
|
+
export type AgeGroup = 'baby' | 'young' | 'adult' | 'senior'
|
|
8
|
+
|
|
9
|
+
const DAY_MS = 86_400_000
|
|
10
|
+
|
|
11
|
+
/** Today as YYYY-MM-DD (UTC). */
|
|
12
|
+
export function todayISO(now: Date = new Date()): string {
|
|
13
|
+
return now.toISOString().slice(0, 10)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const pad = (n: number, width = 2) => String(n).padStart(width, '0')
|
|
17
|
+
const toISO = (y: number, m: number, d: number) => `${pad(y, 4)}-${pad(m)}-${pad(d)}`
|
|
18
|
+
|
|
19
|
+
function parse(iso: string) {
|
|
20
|
+
const [y, m, d] = iso.split('-').map(Number)
|
|
21
|
+
return { y, m, d }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const daysInMonth = (y: number, m: number) => new Date(Date.UTC(y, m, 0)).getUTCDate()
|
|
25
|
+
|
|
26
|
+
/** `iso` minus whole months. The day is kept unless that month is shorter (31 March - 1 month = 28 February). */
|
|
27
|
+
export function subtractMonths(iso: string, months: number): string {
|
|
28
|
+
const { y, m, d } = parse(iso)
|
|
29
|
+
const index = y * 12 + (m - 1) - months
|
|
30
|
+
const year = Math.floor(index / 12)
|
|
31
|
+
const month = (((index % 12) + 12) % 12) + 1
|
|
32
|
+
return toISO(year, month, Math.min(d, daysInMonth(year, month)))
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function subtractDays(iso: string, days: number): string {
|
|
36
|
+
const { y, m, d } = parse(iso)
|
|
37
|
+
return new Date(Date.UTC(y, m - 1, d) - days * DAY_MS).toISOString().slice(0, 10)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** "About 8 months old" as a birth date: the day that many weeks, months or years before `today`. */
|
|
41
|
+
export function estimateBirthDate(value: number, unit: AgeUnit, today: string = todayISO()): string {
|
|
42
|
+
if (unit === 'weeks') return subtractDays(today, value * 7)
|
|
43
|
+
return subtractMonths(today, unit === 'years' ? value * 12 : value)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function elapsed(birthDate: string, today: string) {
|
|
47
|
+
const b = parse(birthDate)
|
|
48
|
+
const t = parse(today)
|
|
49
|
+
const days = Math.round((Date.UTC(t.y, t.m - 1, t.d) - Date.UTC(b.y, b.m - 1, b.d)) / DAY_MS)
|
|
50
|
+
const months = t.y * 12 + t.m - (b.y * 12 + b.m) - (t.d < b.d ? 1 : 0)
|
|
51
|
+
return { days, months }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const plural = (n: number, word: string) => `${n} ${word}${n === 1 ? '' : 's'}`
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* "3 weeks", "8 months", "1 year 4 months", "5 years". An estimated birth date gets "About ".
|
|
58
|
+
* Returns null for a birth date in the future.
|
|
59
|
+
*/
|
|
60
|
+
export function formatAge(birthDate: string, opts: { estimated?: boolean; today?: string } = {}): string | null {
|
|
61
|
+
const { days, months } = elapsed(birthDate, opts.today ?? todayISO())
|
|
62
|
+
if (days < 0) return null
|
|
63
|
+
if (days < 7) return 'Under 1 week'
|
|
64
|
+
|
|
65
|
+
let label: string
|
|
66
|
+
if (days < 56) label = plural(Math.floor(days / 7), 'week')
|
|
67
|
+
else if (months < 12) label = plural(months, 'month')
|
|
68
|
+
else {
|
|
69
|
+
const years = Math.floor(months / 12)
|
|
70
|
+
const rest = months % 12
|
|
71
|
+
label = years < 3 && rest > 0 ? `${plural(years, 'year')} ${plural(rest, 'month')}` : plural(years, 'year')
|
|
72
|
+
}
|
|
73
|
+
return opts.estimated ? `About ${label}` : label
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// How many months old a pet can be and still be in each group. Older than the last is "senior".
|
|
77
|
+
// One table feeds both the label (ageGroupOf) and the catalog filter (ageGroupRange), so they agree.
|
|
78
|
+
const GROUP_LIMITS: ReadonlyArray<readonly [AgeGroup, number]> = [
|
|
79
|
+
['baby', 6],
|
|
80
|
+
['young', 24],
|
|
81
|
+
['adult', 96],
|
|
82
|
+
]
|
|
83
|
+
|
|
84
|
+
export function ageGroupOf(birthDate: string, today: string = todayISO()): AgeGroup {
|
|
85
|
+
for (const [group, months] of GROUP_LIMITS) {
|
|
86
|
+
if (birthDate > subtractMonths(today, months)) return group
|
|
87
|
+
}
|
|
88
|
+
return 'senior'
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* The birth dates that fall in a group, for a SQL filter: born after `after` and on or before
|
|
93
|
+
* `onOrBefore` (either can be missing). Null for a group that does not exist.
|
|
94
|
+
*/
|
|
95
|
+
export function ageGroupRange(group: string, today: string = todayISO()): { after?: string; onOrBefore?: string } | null {
|
|
96
|
+
if (group === 'senior') return { onOrBefore: subtractMonths(today, GROUP_LIMITS[GROUP_LIMITS.length - 1][1]) }
|
|
97
|
+
const index = GROUP_LIMITS.findIndex(([name]) => name === group)
|
|
98
|
+
if (index < 0) return null
|
|
99
|
+
return {
|
|
100
|
+
after: subtractMonths(today, GROUP_LIMITS[index][1]),
|
|
101
|
+
onOrBefore: index > 0 ? subtractMonths(today, GROUP_LIMITS[index - 1][1]) : undefined,
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** What to show as the age: worked out from the birth date when there is one, else the typed text. */
|
|
106
|
+
export function displayAge(
|
|
107
|
+
row: { birthDate: string | null; birthDateEstimated: boolean; ageDescription: string | null },
|
|
108
|
+
today?: string,
|
|
109
|
+
): string | null {
|
|
110
|
+
const live = row.birthDate ? formatAge(row.birthDate, { estimated: row.birthDateEstimated, today }) : null
|
|
111
|
+
return live ?? row.ageDescription
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** The age group: worked out from the birth date when there is one, else the one that was picked. */
|
|
115
|
+
export function displayAgeGroup(row: { birthDate: string | null; ageGroup: string | null }, today?: string): string | null {
|
|
116
|
+
return row.birthDate ? ageGroupOf(row.birthDate, today) : row.ageGroup
|
|
117
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// What a sign-in provider's callback error code (?error=<code>, from Better Auth) means for people,
|
|
2
|
+
// on the sign-in page and the Account page. Codes we do not know get a general message: the code
|
|
3
|
+
// itself is shown, so an admin can look it up.
|
|
4
|
+
|
|
5
|
+
/** The message for a failed sign-in with a provider. */
|
|
6
|
+
export function providerSignInError(code: string): string {
|
|
7
|
+
switch (code) {
|
|
8
|
+
case 'account_not_linked':
|
|
9
|
+
case 'signup_disabled':
|
|
10
|
+
return 'That account is not connected to an account here. Sign in with your password, then connect it on your Account page.'
|
|
11
|
+
case 'ACCOUNT_ARCHIVED':
|
|
12
|
+
return 'This account is archived. Ask an admin to restore it.'
|
|
13
|
+
case 'access_denied':
|
|
14
|
+
return 'Signing in was cancelled at the provider.'
|
|
15
|
+
case 'email_not_found':
|
|
16
|
+
return 'The provider did not share an email address. Ask an admin to check its scopes.'
|
|
17
|
+
default:
|
|
18
|
+
return `Signing in with the provider did not work (${code}). Try again, or sign in with your password.`
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** The message for a failed attempt to connect a provider on the Account page. */
|
|
23
|
+
export function providerConnectError(code: string): string {
|
|
24
|
+
switch (code) {
|
|
25
|
+
case 'account_already_linked_to_different_user':
|
|
26
|
+
return 'That provider account is already connected to someone else here.'
|
|
27
|
+
case 'access_denied':
|
|
28
|
+
return 'Connecting was cancelled at the provider.'
|
|
29
|
+
default:
|
|
30
|
+
return `Connecting the provider did not work (${code}). Try again, or ask an admin.`
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** A code from the address bar, only if it looks like one (it is shown on the page). */
|
|
35
|
+
export function errorCode(value: unknown): string | null {
|
|
36
|
+
const code = Array.isArray(value) ? value[0] : value
|
|
37
|
+
return typeof code === 'string' && /^[A-Za-z0-9_]{1,64}$/.test(code) ? code : null
|
|
38
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// The pieces the public read layer (src/lib/queries.ts) uses inside its 'use cache' functions: the
|
|
2
|
+
// tag names, the lifetimes and the tagging call. Mutations expire the same tags through
|
|
3
|
+
// safeRevalidate (src/lib/revalidate.ts).
|
|
4
|
+
//
|
|
5
|
+
// Every helper does nothing outside a cache scope. The cached functions also run under tsx (seed,
|
|
6
|
+
// migrate, check:backend) and from instrumentation.ts, where 'use cache' is inert and Next's
|
|
7
|
+
// cacheLife() / cacheTag() throw. A try/catch is the only guard that works in all of those places
|
|
8
|
+
// (process.env.NEXT_RUNTIME does not: it is set in instrumentation too).
|
|
9
|
+
import { cacheLife, cacheTag } from 'next/cache'
|
|
10
|
+
|
|
11
|
+
/** Cache tags, one name per kind of public data. */
|
|
12
|
+
export const TAGS = {
|
|
13
|
+
/** The site settings as getSettings returns them (the active theme, logo and icon included). */
|
|
14
|
+
settings: 'settings',
|
|
15
|
+
/** Which pages are live, under which address and title. */
|
|
16
|
+
pages: 'pages',
|
|
17
|
+
/** One address's published page, a miss included. By slug, not id: system pages can swap ids. */
|
|
18
|
+
page: (slug: string) => `page:${slug}`,
|
|
19
|
+
/** Every list of pets (grids, the catalogue, species, "more pets like this", the sitemap). */
|
|
20
|
+
pets: 'pets',
|
|
21
|
+
/** One pet as its own page shows it (row, photos, timeline). Pet ids are never reused. */
|
|
22
|
+
pet: (id: number) => `pet:${id}`,
|
|
23
|
+
/** Whatever plugin block loaders returned (one tag: `host().revalidateSite()` cannot say which plugin). */
|
|
24
|
+
pluginBlocks: 'plugin-blocks',
|
|
25
|
+
} as const
|
|
26
|
+
|
|
27
|
+
/** Next ignores (and warns about) longer tags; a slug from a visitor's URL can be any length. */
|
|
28
|
+
const MAX_TAG_LENGTH = 256
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Runs a cacheLife()/cacheTag() call; outside a cache scope (tsx, instrumentation) it does nothing.
|
|
32
|
+
* Only those two refusals are swallowed. Anything else (an unknown profile, a rejected option) is a
|
|
33
|
+
* mistake that would leave entries untagged or with the wrong lifetime, so it surfaces.
|
|
34
|
+
*/
|
|
35
|
+
function inCacheScope(call: () => void) {
|
|
36
|
+
try {
|
|
37
|
+
call()
|
|
38
|
+
} catch (error) {
|
|
39
|
+
const message = error instanceof Error ? error.message : ''
|
|
40
|
+
// Next's wording: "`cacheTag()` can only be called inside a `"use cache"` ... function" inside
|
|
41
|
+
// Next, and "... is only available with the `cacheComponents` config" under tsx.
|
|
42
|
+
if (/can only be called inside a|is only available with the `cacheComponents` config/.test(message)) return
|
|
43
|
+
throw error
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Public data: refreshed in the background after a minute, gone after an hour (as `revalidate = 60` was). */
|
|
48
|
+
export function publicLife() {
|
|
49
|
+
inCacheScope(() => cacheLife('minutes'))
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The build's empty fallback (no database during `next build`): the page stays static and is
|
|
54
|
+
* rebuilt on the first request after the server starts, instead of serving empty content for a minute.
|
|
55
|
+
*/
|
|
56
|
+
export function fallbackLife() {
|
|
57
|
+
inCacheScope(() => cacheLife({ revalidate: 1, expire: 3600 }))
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** The sitemap's entries: refreshed at most every 10 minutes unless a pet or page changes. */
|
|
61
|
+
export function sitemapLife() {
|
|
62
|
+
inCacheScope(() => cacheLife({ stale: 300, revalidate: 600, expire: 3600 }))
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Tags the cache entry being filled. */
|
|
66
|
+
export function tag(...tags: string[]) {
|
|
67
|
+
const usable = tags.filter((name) => name.length <= MAX_TAG_LENGTH)
|
|
68
|
+
if (usable.length) inCacheScope(() => cacheTag(...usable))
|
|
69
|
+
}
|