From 6ccb1533d22b11ed8d72ecaf39bc107f479de107 Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Sat, 20 Jul 2024 23:07:39 -0500 Subject: [PATCH] Dismiss form after successfully assigning tags --- src/admin/AdminBatchEditPanelClient.tsx | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/admin/AdminBatchEditPanelClient.tsx b/src/admin/AdminBatchEditPanelClient.tsx index 0bd5ac8b..f543e8e9 100644 --- a/src/admin/AdminBatchEditPanelClient.tsx +++ b/src/admin/AdminBatchEditPanelClient.tsx @@ -13,6 +13,7 @@ import { usePathname } from 'next/navigation'; import { PATH_GRID_INFERRED } from '@/site/paths'; import PhotoTagFieldset from './PhotoTagFieldset'; import { tagMultiplePhotosAction } from '@/photo/actions'; +import { toastSuccess } from '@/toast'; export default function AdminBatchEditPanelClient({ uniqueTags, @@ -33,6 +34,12 @@ export default function AdminBatchEditPanelClient({ const [tagErrorMessage, setTagErrorMessage] = useState(''); const isTagging = tags !== undefined; + const resetForm = () => { + setSelectedPhotoIds?.(undefined); + setTags(undefined); + setTagErrorMessage(''); + }; + const photosPlural = selectedPhotoIds?.length === 1 ? 'photo' : 'photos'; const renderPhotoText = () => selectedPhotoIds?.length === 0 @@ -61,9 +68,20 @@ export default function AdminBatchEditPanelClient({ tags, selectedPhotoIds ?? [], ) + .then(() => { + toastSuccess( + `Tags applied to ${selectedPhotoIds?.length} ${photosPlural}` + ); + resetForm(); + }) .finally(() => setIsLoading(false)); }} - disabled={!tags || Boolean(tagErrorMessage) || isLoading} + disabled={ + !tags || + Boolean(tagErrorMessage) || + (selectedPhotoIds?.length ?? 0) === 0 || + isLoading + } primary > Apply Tags