"use client"; import { FC, useState } from "react"; import { observer } from "mobx-react"; import { MoveRight, Trash2, X } from "lucide-react"; import { TEstimatePointsObject } from "@plane/types"; import { Spinner, TOAST_TYPE, setToast } from "@plane/ui"; // components import { EstimatePointDropdown } from "@/components/estimates/points"; // hooks import { useEstimate, useEstimatePoint } from "@/hooks/store"; type TEstimatePointDelete = { workspaceSlug: string; projectId: string; estimateId: string; estimatePointId: string; callback: () => void; }; export const EstimatePointDelete: FC = observer((props) => { const { workspaceSlug, projectId, estimateId, estimatePointId, callback } = props; // hooks const { estimatePointIds, estimatePointById, deleteEstimatePoint } = useEstimate(estimateId); const { asJson: estimatePoint } = useEstimatePoint(estimateId, estimatePointId); // states const [loader, setLoader] = useState(false); const [estimateInputValue, setEstimateInputValue] = useState(undefined); const [error, setError] = useState(undefined); const handleClose = () => { setEstimateInputValue(""); callback(); }; const handleDelete = async () => { if (!workspaceSlug || !projectId || !projectId) return; setError(undefined); if (estimateInputValue) try { setLoader(true); await deleteEstimatePoint( workspaceSlug, projectId, estimatePointId, estimateInputValue === "none" ? undefined : estimateInputValue ); setLoader(false); setError(undefined); setToast({ type: TOAST_TYPE.SUCCESS, title: "Estimate point updated", message: "The estimate point has been updated successfully.", }); handleClose(); } catch { setLoader(false); setError("something went wrong. please try again later"); setToast({ type: TOAST_TYPE.ERROR, title: "Estimate point failed to updated", message: "We are unable to process your request, please try again.", }); } else setError("please select option"); }; // derived values const selectDropdownOptionIds = estimatePointIds?.filter((pointId) => pointId != estimatePointId) as string[]; const selectDropdownOptions = (selectDropdownOptionIds || []) ?.map((pointId) => { const estimatePoint = estimatePointById(pointId); if (estimatePoint && estimatePoint?.id) return { id: estimatePoint.id, key: estimatePoint.key, value: estimatePoint.value }; }) .filter((estimatePoint) => estimatePoint != undefined) as TEstimatePointsObject[]; return (
{estimatePoint?.value}
Mark as
{ setEstimateInputValue(estimateId); setError(undefined); }} />
{loader ? (
) : (
)}
); });