import React, { Fragment, useState } from "react"; import { observer } from "mobx-react"; // types import { ChevronLeft, Plus } from "lucide-react"; import { IEstimate, IEstimateFormData } from "@plane/types"; // ui import { SubHeading, TOAST_TYPE, setToast } from "@plane/ui"; // components import { EModalPosition, EModalWidth, ModalCore } from "@/components/core"; import { RadioInput } from "@/components/radio-group"; import { Sortable } from "@/components/sortable/sortable"; import { EstimateItem } from "./estimate-item"; import { useEstimate } from "@/hooks/store"; import { useRouter } from "next/router"; // helpers // hooks type Props = { isOpen: boolean; handleClose: () => void; data?: IEstimate; }; const ESTIMATE_SYSTEMS = { Points: { name: "Points", templates: { Fibonacci: [1, 2, 3, 5, 8, 13, 21], Linear: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], Squares: [1, 4, 9, 16, 25, 36], }, }, Categories: { name: "Categories", templates: { "T-Shirt Sizes": ["XS", "S", "M", "L", "XL", "XXL"], "Easy to hard": ["Easy", "Medium", "Hard", "Very Hard"], }, }, Time: { name: "Time", templates: { Hours: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }, }, }; type EstimatePoint = { id?: string; key: number; value: string; }; export const UpdateEstimateModal: React.FC = observer((props) => { const { handleClose, isOpen, data } = props; const router = useRouter(); const { workspaceSlug, projectId } = router.query; const { createEstimate, updateEstimate } = useEstimate(); console.log({ data }); const [estimateSystem, setEstimateSystem] = useState("Points"); const [points, setPoints] = useState(data.points); const currentEstimateSystem = ESTIMATE_SYSTEMS[estimateSystem]; const deleteItem = (index: number) => { points.splice(index, 1); setPoints([...points]); }; const saveEstimate = async () => { if (!workspaceSlug || !projectId || !data) return; console.log({ points }); const payload: IEstimateFormData = { estimate_points: points?.map((point, index) => { point.key = index; return point; }), estimate: { name: data.name, description: data.description, }, }; console.log({ payload }); await updateEstimate(workspaceSlug.toString(), projectId.toString(), data.id, payload) .then(() => { // onClose(); }) .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 updated. Please try again.", }); }); }; return (
{!points && (
New Estimate System
Step 2/2
console.log("Submitted")}>
({ label: name, value: name }))} label="Choose an estimate system" selected={estimateSystem} onChange={(value) => setEstimateSystem(value)} className="mb-4" />
Choose a template
{Object.keys(currentEstimateSystem.templates).map((name) => ( ))}
{/* Add modal footer */}
)} {points && (
New Estimate System
Step 2/2
( deleteItem(index)} /> )} onChange={(data: number[]) => setPoints(data)} keyExtractor={(value: number) => value} />
)}
{points && ( )}
); });