diff --git a/apps/app/components/project/issues/BoardView/state/confirm-state-delete.tsx b/apps/app/components/project/issues/BoardView/state/confirm-state-delete.tsx index d39962ca1..ae1d2d4d1 100644 --- a/apps/app/components/project/issues/BoardView/state/confirm-state-delete.tsx +++ b/apps/app/components/project/issues/BoardView/state/confirm-state-delete.tsx @@ -9,6 +9,8 @@ import stateServices from "lib/services/state.service"; import { STATE_LIST } from "constants/fetch-keys"; // hooks import useUser from "lib/hooks/useUser"; +// common +import { groupBy } from "constants/common"; // icons import { ExclamationTriangleIcon } from "@heroicons/react/24/outline"; // ui @@ -25,7 +27,9 @@ type Props = { const ConfirmStateDeletion: React.FC = ({ isOpen, onClose, data }) => { const [isDeleteLoading, setIsDeleteLoading] = useState(false); - const { activeWorkspace } = useUser(); + const [issuesWithThisStateExist, setIssuesWithThisStateExist] = useState(true); + + const { activeWorkspace, issues } = useUser(); const cancelButtonRef = useRef(null); @@ -36,7 +40,7 @@ const ConfirmStateDeletion: React.FC = ({ isOpen, onClose, data }) => { const handleDeletion = async () => { setIsDeleteLoading(true); - if (!data || !activeWorkspace) return; + if (!data || !activeWorkspace || issuesWithThisStateExist) return; await stateServices .deleteState(activeWorkspace.slug, data.project, data.id) .then(() => { @@ -53,6 +57,12 @@ const ConfirmStateDeletion: React.FC = ({ isOpen, onClose, data }) => { }); }; + const groupedIssues = groupBy(issues?.results ?? [], "state"); + + useEffect(() => { + if (data) setIssuesWithThisStateExist(!!groupedIssues[data.id]); + }, [groupedIssues]); + return ( = ({ isOpen, onClose, data }) => { This action cannot be undone.

+
+ {issuesWithThisStateExist && ( +

+ There are issues with this state. Please move them to another state + before deleting this state. +

+ )} +
@@ -113,7 +131,7 @@ const ConfirmStateDeletion: React.FC = ({ isOpen, onClose, data }) => { type="button" onClick={handleDeletion} theme="danger" - disabled={isDeleteLoading} + disabled={isDeleteLoading || issuesWithThisStateExist} className="inline-flex sm:ml-3" > {isDeleteLoading ? "Deleting..." : "Delete"}