Dismiss form after successfully assigning tags
This commit is contained in:
parent
38d372dd72
commit
6ccb1533d2
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user