mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
244986554c
* chore: move modal core components to the UI package * fix: build errors
89 lines
2.1 KiB
TypeScript
89 lines
2.1 KiB
TypeScript
"use client";
|
|
|
|
import React, { useState } from "react";
|
|
import { observer } from "mobx-react";
|
|
// ui
|
|
import { AlertModalCore, TOAST_TYPE, setToast } from "@plane/ui";
|
|
// constants
|
|
import { PAGE_DELETED } from "@/constants/event-tracker";
|
|
// hooks
|
|
import { useEventTracker, usePage, useProjectPages } from "@/hooks/store";
|
|
|
|
type TConfirmPageDeletionProps = {
|
|
isOpen: boolean;
|
|
onClose: () => void;
|
|
pageId: string;
|
|
};
|
|
|
|
export const DeletePageModal: React.FC<TConfirmPageDeletionProps> = observer((props) => {
|
|
const { pageId, isOpen, onClose } = props;
|
|
// states
|
|
const [isDeleting, setIsDeleting] = useState(false);
|
|
// store hooks
|
|
const { removePage } = useProjectPages();
|
|
const { capturePageEvent } = useEventTracker();
|
|
const page = usePage(pageId);
|
|
|
|
if (!page) return null;
|
|
|
|
const { name } = page;
|
|
|
|
const handleClose = () => {
|
|
setIsDeleting(false);
|
|
onClose();
|
|
};
|
|
|
|
const handleDelete = async () => {
|
|
setIsDeleting(true);
|
|
await removePage(pageId)
|
|
.then(() => {
|
|
capturePageEvent({
|
|
eventName: PAGE_DELETED,
|
|
payload: {
|
|
...page,
|
|
state: "SUCCESS",
|
|
},
|
|
});
|
|
handleClose();
|
|
setToast({
|
|
type: TOAST_TYPE.SUCCESS,
|
|
title: "Success!",
|
|
message: "Page deleted successfully.",
|
|
});
|
|
})
|
|
.catch(() => {
|
|
capturePageEvent({
|
|
eventName: PAGE_DELETED,
|
|
payload: {
|
|
...page,
|
|
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}
|
|
isSubmitting={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.
|
|
</>
|
|
}
|
|
/>
|
|
);
|
|
});
|