From 99e8426e3b7db05846aae81dab28fec79f01d99b Mon Sep 17 00:00:00 2001 From: guru_sainath Date: Wed, 3 Jul 2024 13:18:52 +0530 Subject: [PATCH] [WEB-522] chore: Estimate validation on estimate delete and switch (#553) * fix: validating and showing proper alert estimate point has to be taken greater than 0 in create and update * chore: implemented form submission loader on estimate switch. * chore: handled estimate delete vlaidation when we have minimum estimate points. --- web/core/components/estimates/points/preview.tsx | 1 + web/ee/components/estimates/points/delete.tsx | 13 +++++++++++++ web/ee/components/estimates/points/switch/root.tsx | 8 ++++++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/web/core/components/estimates/points/preview.tsx b/web/core/components/estimates/points/preview.tsx index 7f8f410bb0..53b04fd5fd 100644 --- a/web/core/components/estimates/points/preview.tsx +++ b/web/core/components/estimates/points/preview.tsx @@ -107,6 +107,7 @@ export const EstimatePointItemPreview: FC = observer( projectId={projectId} estimateId={estimateId} estimatePointId={estimatePointId} + estimatePoints={estimatePoints} callback={() => estimateId && setEstimatePointDeleteToggle(false)} estimatePointError={estimatePointError} handleEstimatePointError={handleEstimatePointError} diff --git a/web/ee/components/estimates/points/delete.tsx b/web/ee/components/estimates/points/delete.tsx index c61554f318..637bcdf302 100644 --- a/web/ee/components/estimates/points/delete.tsx +++ b/web/ee/components/estimates/points/delete.tsx @@ -9,12 +9,15 @@ import { Spinner, TOAST_TYPE, setToast } from "@plane/ui"; import { useEstimate, useEstimatePoint } from "@/hooks/store"; // plane web components import { EstimatePointDropdown } from "@/plane-web/components/estimates"; +// plane web constants +import { estimateCount } from "@/plane-web/constants/estimates"; type TEstimatePointDelete = { workspaceSlug: string; projectId: string; estimateId: string; estimatePointId: string; + estimatePoints: TEstimatePointsObject[]; callback: () => void; estimatePointError?: TEstimateTypeErrorObject | undefined; handleEstimatePointError?: (newValue: string, message: string | undefined, mode?: "add" | "delete") => void; @@ -26,6 +29,7 @@ export const EstimatePointDelete: FC = observer((props) => projectId, estimateId, estimatePointId, + estimatePoints, callback, estimatePointError, handleEstimatePointError, @@ -46,6 +50,15 @@ export const EstimatePointDelete: FC = observer((props) => const handleDelete = async () => { if (!workspaceSlug || !projectId || !projectId) return; + if (estimatePoints.length <= estimateCount.min) { + setToast({ + type: TOAST_TYPE.WARNING, + title: "Estimate can't be deleted", + message: `Estimate must have at least ${estimateCount.min} points.`, + }); + return; + } + handleEstimatePointError && handleEstimatePointError(estimateId, undefined, "delete"); if (estimateInputValue) diff --git a/web/ee/components/estimates/points/switch/root.tsx b/web/ee/components/estimates/points/switch/root.tsx index f88640e841..424248e628 100644 --- a/web/ee/components/estimates/points/switch/root.tsx +++ b/web/ee/components/estimates/points/switch/root.tsx @@ -34,6 +34,7 @@ export const EstimatePointSwitchRoot: FC = observer((p // states const [estimatePoints, setEstimatePoints] = useState(undefined); const [estimatePointError, setEstimatePointError] = useState(undefined); + const [switchLoader, setSwitchLoader] = useState(false); const handleEstimatePointError = ( key: number, @@ -141,6 +142,7 @@ export const EstimatePointSwitchRoot: FC = observer((p const handleSwitchEstimate = async () => { try { if (!workspaceSlug || !projectId) return; + setSwitchLoader(true); const isEstimatesValid = estimateSystemSwitchType && isValidEstimatePoints(estimateSystemSwitchType); @@ -165,6 +167,7 @@ export const EstimatePointSwitchRoot: FC = observer((p message: "Created and Enabled successfully", }); handleClose(); + setSwitchLoader(false); } } catch (error) { setToast({ @@ -172,6 +175,7 @@ export const EstimatePointSwitchRoot: FC = observer((p title: "Error!", message: "something went wrong", }); + setSwitchLoader(false); } }; @@ -215,8 +219,8 @@ export const EstimatePointSwitchRoot: FC = observer((p Cancel -