import { FC, useEffect, useMemo, useState } from "react"; import orderBy from "lodash/orderBy"; import { observer } from "mobx-react"; import { ChevronLeft } from "lucide-react"; import { TEstimatePointsObject, TEstimateUpdateStageKeys } from "@plane/types"; import { Button } from "@plane/ui"; // components import { EModalPosition, EModalWidth, ModalCore } from "@/components/core"; import { EstimateUpdateStageOne, EstimateUpdateStageTwo } from "@/components/estimates"; // hooks import { useEstimate, // useProjectEstimates } from "@/hooks/store"; type TUpdateEstimateModal = { workspaceSlug: string; projectId: string; estimateId: string | undefined; isOpen: boolean; handleClose: () => void; }; export const UpdateEstimateModal: FC = observer((props) => { // props const { workspaceSlug, projectId, estimateId, isOpen, handleClose } = props; // hooks const { asJson: currentEstimate } = useEstimate(estimateId); // states const [estimateEditType, setEstimateEditType] = useState(undefined); const [estimatePoints, setEstimatePoints] = useState(undefined); const handleEstimateEditType = (type: TEstimateUpdateStageKeys) => { if (currentEstimate?.points && currentEstimate?.points.length > 0) { let estimateValidatePoints: TEstimatePointsObject[] = []; currentEstimate?.points.map( (point) => point.key && point.value && estimateValidatePoints.push({ id: point.id, key: point.key, value: point.value }) ); estimateValidatePoints = orderBy(estimateValidatePoints, ["key"], ["asc"]); if (estimateValidatePoints.length > 0) { setEstimateEditType(type); setEstimatePoints(estimateValidatePoints); } } }; const handleUpdatePoints = (newPoints: TEstimatePointsObject[] | undefined) => setEstimatePoints(newPoints); useEffect(() => { if (!isOpen) { setEstimateEditType(undefined); setEstimatePoints(undefined); } }, [isOpen]); // derived values const renderEstimateStepsCount = useMemo(() => (estimatePoints ? "2" : "1"), [estimatePoints]); return (
{/* heading */}
{estimateEditType && (
{ setEstimateEditType(undefined); handleUpdatePoints(undefined); }} className="flex-shrink-0 cursor-pointer w-5 h-5 flex justify-center items-center" >
)}
Edit estimate system
Step {renderEstimateStepsCount}/2
{/* estimate steps */}
{!estimateEditType && } {estimateEditType && estimatePoints && ( )}
); });