Redirect to photo detail after editing
This commit is contained in:
parent
d2cca5ec9e
commit
51be78e597
@ -3,6 +3,7 @@
|
||||
import { ComponentProps, useMemo, useRef } from 'react';
|
||||
import {
|
||||
getPathComponents,
|
||||
PARAM_REDIRECT,
|
||||
PATH_ROOT,
|
||||
pathForAdminPhotoEdit,
|
||||
pathForTag,
|
||||
@ -81,7 +82,8 @@ export default function AdminPhotoMenu({
|
||||
size={14}
|
||||
className="translate-x-[1px] translate-y-[-0.5px]"
|
||||
/>,
|
||||
href: pathForAdminPhotoEdit(photo.id),
|
||||
href: pathForAdminPhotoEdit(photo.id) +
|
||||
`?${PARAM_REDIRECT}=${encodeURIComponent(path)}`,
|
||||
...showKeyCommands && { keyCommand: KEY_COMMANDS.edit },
|
||||
}];
|
||||
if (includeFavorite) {
|
||||
@ -184,6 +186,7 @@ export default function AdminPhotoMenu({
|
||||
|
||||
return { items };
|
||||
}, [
|
||||
path,
|
||||
appText,
|
||||
photo,
|
||||
showKeyCommands,
|
||||
|
||||
@ -88,8 +88,11 @@ export const PATH_API_PRESIGNED_URL = `${PATH_API_STORAGE}/presigned-url`;
|
||||
// Modifiers
|
||||
const EDIT = 'edit';
|
||||
const IMAGE = 'image';
|
||||
|
||||
// Parameters
|
||||
export const PARAM_UPLOAD_TITLE = 'title';
|
||||
export const PARAM_SELECT = 'select';
|
||||
export const PARAM_REDIRECT = 'redirect';
|
||||
|
||||
// Special characters
|
||||
export const MISSING_FIELD = '-';
|
||||
|
||||
@ -40,7 +40,6 @@ import {
|
||||
} from '@/cache';
|
||||
import { revalidatePhoto, getPhotosCached } from './cache';
|
||||
import {
|
||||
PATH_ADMIN_PHOTOS,
|
||||
PATH_ADMIN_RECIPES,
|
||||
PATH_ADMIN_TAGS,
|
||||
PATH_ROOT,
|
||||
@ -108,7 +107,6 @@ export const createPhotoAction = async (formData: FormData) =>
|
||||
await addAlbumTitlesToPhoto(albumTitles, photo.id, false);
|
||||
await propagateRecipeTitleIfNecessary(formData, photo);
|
||||
revalidateAllKeysAndPaths();
|
||||
redirect(PATH_ADMIN_PHOTOS);
|
||||
}
|
||||
});
|
||||
|
||||
@ -343,8 +341,6 @@ export const updatePhotoAction = async (formData: FormData) =>
|
||||
});
|
||||
|
||||
revalidateAllKeysAndPaths();
|
||||
|
||||
redirect(PATH_ADMIN_PHOTOS);
|
||||
});
|
||||
|
||||
export const toggleFavoritePhotoAction = async (
|
||||
|
||||
@ -26,7 +26,11 @@ import { createPhotoAction, updatePhotoAction } from '../actions';
|
||||
import SubmitButtonWithStatus from '@/components/SubmitButtonWithStatus';
|
||||
import Link from 'next/link';
|
||||
import { clsx } from 'clsx/lite';
|
||||
import { PATH_ADMIN_PHOTOS, PATH_ADMIN_UPLOADS } from '@/app/path';
|
||||
import {
|
||||
PARAM_REDIRECT,
|
||||
PATH_ADMIN_PHOTOS,
|
||||
PATH_ADMIN_UPLOADS,
|
||||
} from '@/app/path';
|
||||
import { toastSuccess, toastWarning } from '@/toast';
|
||||
import { getDimensionsFromSize } from '@/utility/size';
|
||||
import ImageWithFallback from '@/components/image/ImageWithFallback';
|
||||
@ -66,6 +70,7 @@ import { TbPhoto } from 'react-icons/tb';
|
||||
import { Albums } from '@/album';
|
||||
import FieldsetAlbum from '@/album/FieldsetAlbum';
|
||||
import Form from 'next/form';
|
||||
import { useRouter, useSearchParams } from 'next/navigation';
|
||||
|
||||
const THUMBNAIL_SIZE = 300;
|
||||
|
||||
@ -102,6 +107,10 @@ export default function PhotoForm({
|
||||
onFormDataChange?: (formData: Partial<PhotoFormData>) => void,
|
||||
onFormStatusChange?: (pending: boolean) => void
|
||||
}) {
|
||||
const router = useRouter();
|
||||
|
||||
const redirectParam = useSearchParams().get(PARAM_REDIRECT);
|
||||
|
||||
const [formData, setFormData] =
|
||||
useState<Partial<PhotoFormData>>(initialPhotoForm);
|
||||
const [formErrors, setFormErrors] =
|
||||
@ -481,6 +490,9 @@ export default function PhotoForm({
|
||||
? createPhotoAction
|
||||
: updatePhotoAction
|
||||
)(data)
|
||||
.then(() => {
|
||||
router.push(redirectParam ?? PATH_ADMIN_PHOTOS);
|
||||
})
|
||||
.catch(e => {
|
||||
if (e.message !== 'NEXT_REDIRECT') {
|
||||
setFormActionErrorMessage(e.message);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user