From 769d6b64bbf73c67bd8777706449174032ebc9f4 Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Wed, 12 Mar 2025 18:11:16 -0500 Subject: [PATCH] Create admin recipe detail page --- app/admin/recipes/[recipe]/edit/page.tsx | 28 +++---- app/admin/tags/[tag]/edit/page.tsx | 6 +- src/admin/AdminRecipeForm.tsx | 74 +++++++++++++++++++ .../TagForm.tsx => admin/AdminTagForm.tsx} | 2 +- 4 files changed, 92 insertions(+), 18 deletions(-) create mode 100644 src/admin/AdminRecipeForm.tsx rename src/{tag/TagForm.tsx => admin/AdminTagForm.tsx} (97%) diff --git a/app/admin/recipes/[recipe]/edit/page.tsx b/app/admin/recipes/[recipe]/edit/page.tsx index 5cdfc425..dc289b03 100644 --- a/app/admin/recipes/[recipe]/edit/page.tsx +++ b/app/admin/recipes/[recipe]/edit/page.tsx @@ -1,31 +1,31 @@ import AdminChildPage from '@/components/AdminChildPage'; import { redirect } from 'next/navigation'; import { getPhotosCached } from '@/photo/cache'; -import TagForm from '@/tag/TagForm'; -import { PATH_ADMIN, PATH_ADMIN_TAGS, pathForTag } from '@/app/paths'; +import { PATH_ADMIN, PATH_ADMIN_TAGS, pathForRecipe } from '@/app/paths'; import PhotoLightbox from '@/photo/PhotoLightbox'; import { getPhotosMeta } from '@/photo/db/query'; -import AdminTagBadge from '@/admin/AdminTagBadge'; +import AdminRecipeBadge from '@/admin/AdminRecipeBadge'; +import AdminRecipeForm from '@/admin/AdminRecipeForm'; const MAX_PHOTO_TO_SHOW = 6; interface Props { - params: Promise<{ tag: string }> + params: Promise<{ recipe: string }> } -export default async function PhotoPageEdit({ +export default async function RecipePageEdit({ params, }: Props) { - const { tag: tagFromParams } = await params; + const { recipe: recipeFromParams } = await params; - const tag = decodeURIComponent(tagFromParams); + const recipe = decodeURIComponent(recipeFromParams); const [ { count }, photos, ] = await Promise.all([ - getPhotosMeta({ tag }), - getPhotosCached({ tag, limit: MAX_PHOTO_TO_SHOW }), + getPhotosMeta({ recipe }), + getPhotosCached({ recipe, limit: MAX_PHOTO_TO_SHOW }), ]); if (count === 0) { redirect(PATH_ADMIN); } @@ -34,15 +34,15 @@ export default async function PhotoPageEdit({ } + breadcrumb={} > - + - + ); }; diff --git a/app/admin/tags/[tag]/edit/page.tsx b/app/admin/tags/[tag]/edit/page.tsx index 5cdfc425..747dc180 100644 --- a/app/admin/tags/[tag]/edit/page.tsx +++ b/app/admin/tags/[tag]/edit/page.tsx @@ -1,7 +1,7 @@ import AdminChildPage from '@/components/AdminChildPage'; import { redirect } from 'next/navigation'; import { getPhotosCached } from '@/photo/cache'; -import TagForm from '@/tag/TagForm'; +import AdminTagForm from '@/admin/AdminTagForm'; import { PATH_ADMIN, PATH_ADMIN_TAGS, pathForTag } from '@/app/paths'; import PhotoLightbox from '@/photo/PhotoLightbox'; import { getPhotosMeta } from '@/photo/db/query'; @@ -36,13 +36,13 @@ export default async function PhotoPageEdit({ backLabel="Tags" breadcrumb={} > - + - + ); }; diff --git a/src/admin/AdminRecipeForm.tsx b/src/admin/AdminRecipeForm.tsx new file mode 100644 index 00000000..f423e44d --- /dev/null +++ b/src/admin/AdminRecipeForm.tsx @@ -0,0 +1,74 @@ +'use client'; + +import SubmitButtonWithStatus from '@/components/SubmitButtonWithStatus'; +import Link from 'next/link'; +import { PATH_ADMIN_RECIPES } from '@/app/paths'; +import FieldSetWithStatus from '@/components/FieldSetWithStatus'; +import { ReactNode, useMemo, useState } from 'react'; +import { renamePhotoTagGloballyAction } from '@/photo/actions'; +import { parameterize } from '@/utility/string'; +import { useAppState } from '@/state/AppState'; + +export default function AdminRecipeForm({ + recipe, + children, +}: { + recipe: string + children?: ReactNode +}) { + const { invalidateSwr } = useAppState(); + + const [updatedRecipeRaw, setUpdatedRecipeRaw] = useState(recipe); + + const updatedRecipe = useMemo(() => + parameterize(updatedRecipeRaw) + , [updatedRecipeRaw]); + + const isFormValid = ( + updatedRecipe && + updatedRecipe !== recipe + ); + + return ( +
+ + {/* Form data: tag to be replaced */} + + {/* Form data: updated tag */} + + {children} +
+ + Cancel + + + Update + +
+ + ); +} diff --git a/src/tag/TagForm.tsx b/src/admin/AdminTagForm.tsx similarity index 97% rename from src/tag/TagForm.tsx rename to src/admin/AdminTagForm.tsx index 9be11e8d..9023a30b 100644 --- a/src/tag/TagForm.tsx +++ b/src/admin/AdminTagForm.tsx @@ -9,7 +9,7 @@ import { renamePhotoTagGloballyAction } from '@/photo/actions'; import { parameterize } from '@/utility/string'; import { useAppState } from '@/state/AppState'; -export default function TagForm({ +export default function AdminTagForm({ tag, children, }: {