plane/web/components/pages/modals/delete-page-modal.tsx
Aaryan Khandelwal ff03c0b718 [WEB-1322] dev: conflict free pages collaboration (#4463)
* chore: pages realtime

* chore: empty binary response

* chore: added a ypy package

* feat: pages collaboration

* chore: update fetching logic

* chore: degrade ypy version

* chore: replace useEffect fetch logic with useSWR

* chore: move all the update logic to the page store

* refactor: remove react-hook-form

* chore: save description_html as well

* chore: migrate old data logic

* fix: added description_binary as field name

* fix: code cleanup

* refactor: create separate hook to handle page description

* fix: build errors

* chore: combine updates instead of using the whole document

* chore: removed ypy package

* chore: added conflict resolving logic to the client side

* chore: add a save changes button

* chore: add read-only validation

* chore: remove saving state information

* chore: added permission class

* chore: removed the migration file

* chore: corrected the model field

* chore: rename pageStore to page

* chore: update collaboration provider

* chore: add try catch to handle error

---------

Co-authored-by: NarayanBavisetti <narayan3119@gmail.com>
2024-05-28 13:10:03 +05:30

90 lines
2.2 KiB
TypeScript

import React, { useState } from "react";
import { observer } from "mobx-react";
// 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 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}
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.
</>
}
/>
);
});