mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
20e7dc68e6
* style: update modals typography, alignment * style: made the modal separator full width * style: delete modals consistency * style: update the remaining delete modals * chore: delete modal secondary button text * style: update the remaining create modals * chore: update cancel button text * chore: created modal core * style: modals responsiveness
90 lines
2.2 KiB
TypeScript
90 lines
2.2 KiB
TypeScript
import React, { useState } from "react";
|
|
import { observer } from "mobx-react-lite";
|
|
// ui
|
|
import { TOAST_TYPE, setToast } from "@plane/ui";
|
|
// components
|
|
import { AlertModalCore } from "@/components/core";
|
|
// constants
|
|
import { PAGE_DELETED } from "@/constants/event-tracker";
|
|
// hooks
|
|
import { useEventTracker, usePage, useProjectPages } from "@/hooks/store";
|
|
|
|
type TConfirmPageDeletionProps = {
|
|
isOpen: boolean;
|
|
onClose: () => void;
|
|
pageId: string;
|
|
projectId: string;
|
|
};
|
|
|
|
export const DeletePageModal: React.FC<TConfirmPageDeletionProps> = observer((props) => {
|
|
const { pageId, projectId, isOpen, onClose } = props;
|
|
// states
|
|
const [isDeleting, setIsDeleting] = useState(false);
|
|
// store hooks
|
|
const { removePage } = useProjectPages(projectId);
|
|
const { capturePageEvent } = useEventTracker();
|
|
const pageStore = usePage(pageId);
|
|
|
|
if (!pageStore) return null;
|
|
|
|
const { name } = pageStore;
|
|
|
|
const handleClose = () => {
|
|
setIsDeleting(false);
|
|
onClose();
|
|
};
|
|
|
|
const handleDelete = async () => {
|
|
setIsDeleting(true);
|
|
await removePage(pageId)
|
|
.then(() => {
|
|
capturePageEvent({
|
|
eventName: PAGE_DELETED,
|
|
payload: {
|
|
...pageStore,
|
|
state: "SUCCESS",
|
|
},
|
|
});
|
|
handleClose();
|
|
setToast({
|
|
type: TOAST_TYPE.SUCCESS,
|
|
title: "Success!",
|
|
message: "Page deleted successfully.",
|
|
});
|
|
})
|
|
.catch(() => {
|
|
capturePageEvent({
|
|
eventName: PAGE_DELETED,
|
|
payload: {
|
|
...pageStore,
|
|
state: "FAILED",
|
|
},
|
|
});
|
|
setToast({
|
|
type: TOAST_TYPE.ERROR,
|
|
title: "Error!",
|
|
message: "Page could not be deleted. Please try again.",
|
|
});
|
|
});
|
|
|
|
setIsDeleting(false);
|
|
};
|
|
|
|
return (
|
|
<AlertModalCore
|
|
handleClose={handleClose}
|
|
handleSubmit={handleDelete}
|
|
isDeleting={isDeleting}
|
|
isOpen={isOpen}
|
|
title="Delete Page"
|
|
content={
|
|
<>
|
|
Are you sure you want to delete page-{" "}
|
|
<span className="break-words font-medium text-custom-text-100">{name}</span>? The Page will be deleted
|
|
permanently. This action cannot be undone.
|
|
</>
|
|
}
|
|
/>
|
|
);
|
|
});
|