|
@@ -5,10 +5,13 @@ import { format } from 'date-fns';
|
|
|
import { useRouter } from 'next/router';
|
|
import { useRouter } from 'next/router';
|
|
|
import { useTranslation } from 'react-i18next';
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
|
|
|
|
|
|
+import { toastError } from '~/client/util/apiNotification';
|
|
|
import { usePageDeleteModal, usePutBackPageModal } from '~/stores/modal';
|
|
import { usePageDeleteModal, usePutBackPageModal } from '~/stores/modal';
|
|
|
import { useSWRxPageInfo, useSWRxCurrentPage, useIsTrashPage } from '~/stores/page';
|
|
import { useSWRxPageInfo, useSWRxCurrentPage, useIsTrashPage } from '~/stores/page';
|
|
|
|
|
+import { useRedirectFrom } from '~/stores/page-redirect';
|
|
|
import { useIsAbleToShowTrashPageManagementButtons } from '~/stores/ui';
|
|
import { useIsAbleToShowTrashPageManagementButtons } from '~/stores/ui';
|
|
|
|
|
|
|
|
|
|
+
|
|
|
const onDeletedHandler = (pathOrPathsToDelete) => {
|
|
const onDeletedHandler = (pathOrPathsToDelete) => {
|
|
|
if (typeof pathOrPathsToDelete !== 'string') {
|
|
if (typeof pathOrPathsToDelete !== 'string') {
|
|
|
return;
|
|
return;
|
|
@@ -31,6 +34,7 @@ export const TrashPageAlert = (): JSX.Element => {
|
|
|
|
|
|
|
|
const { open: openDeleteModal } = usePageDeleteModal();
|
|
const { open: openDeleteModal } = usePageDeleteModal();
|
|
|
const { open: openPutBackPageModal } = usePutBackPageModal();
|
|
const { open: openPutBackPageModal } = usePutBackPageModal();
|
|
|
|
|
+ const { unlink } = useRedirectFrom();
|
|
|
|
|
|
|
|
|
|
|
|
|
const deleteUser = pageData?.deleteUser;
|
|
const deleteUser = pageData?.deleteUser;
|
|
@@ -43,12 +47,18 @@ export const TrashPageAlert = (): JSX.Element => {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
const putBackedHandler = () => {
|
|
const putBackedHandler = () => {
|
|
|
- // Do not use "router.push(`/${pageId}`)" to avoid `Error: Invariant: attempted to hard navigate to the same URL`
|
|
|
|
|
- // See: https://github.com/weseek/growi/pull/7054
|
|
|
|
|
- router.reload();
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ unlink();
|
|
|
|
|
+ // Do not use "router.push(`/${pageId}`)" to avoid `Error: Invariant: attempted to hard navigate to the same URL`
|
|
|
|
|
+ // See: https://github.com/weseek/growi/pull/7054
|
|
|
|
|
+ router.reload();
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (err) {
|
|
|
|
|
+ toastError(err);
|
|
|
|
|
+ }
|
|
|
};
|
|
};
|
|
|
openPutBackPageModal({ pageId, path: pagePath }, { onPutBacked: putBackedHandler });
|
|
openPutBackPageModal({ pageId, path: pagePath }, { onPutBacked: putBackedHandler });
|
|
|
- }, [openPutBackPageModal, pageId, pagePath, router]);
|
|
|
|
|
|
|
+ }, [openPutBackPageModal, pageId, pagePath, router, unlink]);
|
|
|
|
|
|
|
|
const openPageDeleteModalHandler = useCallback(() => {
|
|
const openPageDeleteModalHandler = useCallback(() => {
|
|
|
if (pageId === undefined || revisionId === undefined || pagePath === undefined) {
|
|
if (pageId === undefined || revisionId === undefined || pagePath === undefined) {
|