diff --git a/apps/app/components/estimates/delete-estimate-modal.tsx b/apps/app/components/estimates/delete-estimate-modal.tsx new file mode 100644 index 000000000..6b5f4c512 --- /dev/null +++ b/apps/app/components/estimates/delete-estimate-modal.tsx @@ -0,0 +1,104 @@ +import React, { useEffect, useState } from "react"; + +// headless ui +import { Dialog, Transition } from "@headlessui/react"; +// types +import { IEstimate } from "types"; + +// icons +import { ExclamationTriangleIcon } from "@heroicons/react/24/outline"; +// ui +import { SecondaryButton, DangerButton } from "components/ui"; + +type Props = { + isOpen: boolean; + handleClose: () => void; + data: IEstimate; + handleDelete: () => void; +}; + +export const DeleteEstimateModal: React.FC = ({ + isOpen, + handleClose, + data, + handleDelete, +}) => { + const [isDeleteLoading, setIsDeleteLoading] = useState(false); + + useEffect(() => { + setIsDeleteLoading(false); + }, [isOpen]); + + const onClose = () => { + setIsDeleteLoading(false); + handleClose(); + }; + + return ( + + + +
+ + +
+
+ + +
+
+ + + +

Delete Estimate

+
+
+ +

+ Are you sure you want to delete estimate-{" "} + {data.name} + {""}? All of the data related to the estiamte will be permanently removed. + This action cannot be undone. +

+
+
+ Cancel + { + setIsDeleteLoading(true); + handleDelete(); + }} + loading={isDeleteLoading} + > + {isDeleteLoading ? "Deleting..." : "Delete Estimate"} + +
+
+
+
+
+
+
+
+ ); +}; diff --git a/apps/app/components/estimates/index.tsx b/apps/app/components/estimates/index.tsx index c537b8b3a..40248b525 100644 --- a/apps/app/components/estimates/index.tsx +++ b/apps/app/components/estimates/index.tsx @@ -1,3 +1,4 @@ export * from "./create-update-estimate-modal"; export * from "./single-estimate"; -export * from "./estimate-points-modal" \ No newline at end of file +export * from "./estimate-points-modal" +export * from "./delete-estimate-modal" diff --git a/apps/app/components/estimates/single-estimate.tsx b/apps/app/components/estimates/single-estimate.tsx index 1d626f5fd..005acb25d 100644 --- a/apps/app/components/estimates/single-estimate.tsx +++ b/apps/app/components/estimates/single-estimate.tsx @@ -11,7 +11,7 @@ import projectService from "services/project.service"; import useToast from "hooks/use-toast"; import useProjectDetails from "hooks/use-project-details"; // components -import { EstimatePointsModal } from "components/estimates"; +import { EstimatePointsModal, DeleteEstimateModal } from "components/estimates"; // ui import { CustomMenu } from "components/ui"; //icons @@ -39,6 +39,8 @@ export const SingleEstimate: React.FC = ({ handleEstimateDelete, }) => { const [isEstimatePointsModalOpen, setIsEstimatePointsModalOpen] = useState(false); + const [isDeleteEstimateModalOpen, setIsDeleteEstimateModalOpen] = useState(false); + const router = useRouter(); const { workspaceSlug, projectId } = router.query; @@ -138,7 +140,7 @@ export const SingleEstimate: React.FC = ({ {projectDetails?.estimate !== estimate.id && ( { - handleEstimateDelete(estimate.id); + setIsDeleteEstimateModalOpen(true); }} >
@@ -166,6 +168,16 @@ export const SingleEstimate: React.FC = ({
)} + + setIsDeleteEstimateModalOpen(false)} + data={estimate} + handleDelete={() => { + handleEstimateDelete(estimate.id); + setIsDeleteEstimateModalOpen(false); + }} + /> ); }; diff --git a/apps/app/pages/[workspaceSlug]/projects/[projectId]/settings/estimates.tsx b/apps/app/pages/[workspaceSlug]/projects/[projectId]/settings/estimates.tsx index c5b508e9c..aca79f964 100644 --- a/apps/app/pages/[workspaceSlug]/projects/[projectId]/settings/estimates.tsx +++ b/apps/app/pages/[workspaceSlug]/projects/[projectId]/settings/estimates.tsx @@ -61,6 +61,13 @@ const EstimatesSettings: NextPage = () => { estimatesService .deleteEstimate(workspaceSlug as string, projectId as string, estimateId) + .then(() => { + setToastAlert({ + type: "success", + title: "Success!", + message: "Estimate Deleted successfully.", + }); + }) .catch(() => { setToastAlert({ type: "error",