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
80 lines
2.2 KiB
TypeScript
80 lines
2.2 KiB
TypeScript
import React, { useEffect, useState } from "react";
|
|
import { observer } from "mobx-react-lite";
|
|
import { useRouter } from "next/router";
|
|
// types
|
|
import { IEstimate } from "@plane/types";
|
|
// ui
|
|
import { TOAST_TYPE, setToast } from "@plane/ui";
|
|
// components
|
|
import { AlertModalCore } from "@/components/core";
|
|
// hooks
|
|
import { useEstimate } from "@/hooks/store";
|
|
|
|
type Props = {
|
|
isOpen: boolean;
|
|
data: IEstimate | null;
|
|
handleClose: () => void;
|
|
};
|
|
|
|
export const DeleteEstimateModal: React.FC<Props> = observer((props) => {
|
|
const { isOpen, handleClose, data } = props;
|
|
// states
|
|
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
|
|
// router
|
|
const router = useRouter();
|
|
const { workspaceSlug, projectId } = router.query;
|
|
// store hooks
|
|
const { deleteEstimate } = useEstimate();
|
|
|
|
const handleEstimateDelete = async () => {
|
|
if (!workspaceSlug || !projectId) return;
|
|
|
|
setIsDeleteLoading(true);
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
|
|
const estimateId = data?.id!;
|
|
|
|
await deleteEstimate(workspaceSlug.toString(), projectId.toString(), estimateId)
|
|
.then(() => {
|
|
handleClose();
|
|
})
|
|
.catch((err) => {
|
|
const error = err?.error;
|
|
const errorString = Array.isArray(error) ? error[0] : error;
|
|
|
|
setToast({
|
|
type: TOAST_TYPE.ERROR,
|
|
title: "Error!",
|
|
message: errorString ?? "Estimate could not be deleted. Please try again",
|
|
});
|
|
})
|
|
.finally(() => setIsDeleteLoading(false));
|
|
};
|
|
|
|
useEffect(() => {
|
|
setIsDeleteLoading(false);
|
|
}, [isOpen]);
|
|
|
|
const onClose = () => {
|
|
setIsDeleteLoading(false);
|
|
handleClose();
|
|
};
|
|
|
|
return (
|
|
<AlertModalCore
|
|
handleClose={onClose}
|
|
handleSubmit={handleEstimateDelete}
|
|
isDeleting={isDeleteLoading}
|
|
isOpen={isOpen}
|
|
title="Delete Estimate"
|
|
content={
|
|
<>
|
|
Are you sure you want to delete estimate-{" "}
|
|
<span className="break-words font-medium text-custom-text-100">{data?.name}</span>
|
|
{""}? All of the data related to the estiamte will be permanently removed. This action cannot be undone.
|
|
</>
|
|
}
|
|
/>
|
|
);
|
|
});
|