plane/web/components/issues/delete-issue-modal.tsx
Aaryan Khandelwal 20e7dc68e6
[WEB-1127] style: create and delete modals' consistency (#4345)
* 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
2024-05-07 12:44:36 +05:30

78 lines
1.9 KiB
TypeScript

import { useEffect, useState } from "react";
// types
import { TIssue } from "@plane/types";
// ui
import { TOAST_TYPE, setToast } from "@plane/ui";
// components
import { AlertModalCore } from "@/components/core";
// hooks
import { useIssues, useProject } from "@/hooks/store";
type Props = {
isOpen: boolean;
handleClose: () => void;
dataId?: string | null | undefined;
data?: TIssue;
onSubmit?: () => Promise<void>;
};
export const DeleteIssueModal: React.FC<Props> = (props) => {
const { dataId, data, isOpen, handleClose, onSubmit } = props;
// states
const [isDeleting, setIsDeleting] = useState(false);
// store hooks
const { issueMap } = useIssues();
const { getProjectById } = useProject();
useEffect(() => {
setIsDeleting(false);
}, [isOpen]);
if (!dataId && !data) return null;
// derived values
const issue = data ? data : issueMap[dataId!];
const projectDetails = getProjectById(issue?.project_id);
const onClose = () => {
setIsDeleting(false);
handleClose();
};
const handleIssueDelete = async () => {
setIsDeleting(true);
if (onSubmit)
await onSubmit()
.then(() => {
onClose();
})
.catch(() => {
setToast({
title: "Error",
type: TOAST_TYPE.ERROR,
message: "Failed to delete issue",
});
})
.finally(() => setIsDeleting(false));
};
return (
<AlertModalCore
handleClose={onClose}
handleSubmit={handleIssueDelete}
isDeleting={isDeleting}
isOpen={isOpen}
title="Delete Issue"
content={
<>
Are you sure you want to delete issue{" "}
<span className="break-words font-medium text-custom-text-100">
{projectDetails?.identifier}-{issue?.sequence_id}
</span>
{""}? All of the data related to the issue will be permanently removed. This action cannot be undone.
</>
}
/>
);
};