mirror of
https://github.com/makeplane/plane.git
synced 2026-07-13 14:01:45 +02:00
[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.
This commit is contained in:
@@ -107,6 +107,7 @@ export const EstimatePointItemPreview: FC<TEstimatePointItemPreview> = observer(
|
||||
projectId={projectId}
|
||||
estimateId={estimateId}
|
||||
estimatePointId={estimatePointId}
|
||||
estimatePoints={estimatePoints}
|
||||
callback={() => estimateId && setEstimatePointDeleteToggle(false)}
|
||||
estimatePointError={estimatePointError}
|
||||
handleEstimatePointError={handleEstimatePointError}
|
||||
|
||||
@@ -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<TEstimatePointDelete> = observer((props) =>
|
||||
projectId,
|
||||
estimateId,
|
||||
estimatePointId,
|
||||
estimatePoints,
|
||||
callback,
|
||||
estimatePointError,
|
||||
handleEstimatePointError,
|
||||
@@ -46,6 +50,15 @@ export const EstimatePointDelete: FC<TEstimatePointDelete> = 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)
|
||||
|
||||
@@ -34,6 +34,7 @@ export const EstimatePointSwitchRoot: FC<TEstimatePointSwitchRoot> = observer((p
|
||||
// states
|
||||
const [estimatePoints, setEstimatePoints] = useState<TEstimatePointsObject[] | undefined>(undefined);
|
||||
const [estimatePointError, setEstimatePointError] = useState<TEstimateTypeError>(undefined);
|
||||
const [switchLoader, setSwitchLoader] = useState(false);
|
||||
|
||||
const handleEstimatePointError = (
|
||||
key: number,
|
||||
@@ -141,6 +142,7 @@ export const EstimatePointSwitchRoot: FC<TEstimatePointSwitchRoot> = 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<TEstimatePointSwitchRoot> = observer((p
|
||||
message: "Created and Enabled successfully",
|
||||
});
|
||||
handleClose();
|
||||
setSwitchLoader(false);
|
||||
}
|
||||
} catch (error) {
|
||||
setToast({
|
||||
@@ -172,6 +175,7 @@ export const EstimatePointSwitchRoot: FC<TEstimatePointSwitchRoot> = observer((p
|
||||
title: "Error!",
|
||||
message: "something went wrong",
|
||||
});
|
||||
setSwitchLoader(false);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -215,8 +219,8 @@ export const EstimatePointSwitchRoot: FC<TEstimatePointSwitchRoot> = observer((p
|
||||
Cancel
|
||||
</Button>
|
||||
|
||||
<Button variant="primary" size="sm" onClick={handleSwitchEstimate}>
|
||||
Update
|
||||
<Button variant="primary" size="sm" onClick={handleSwitchEstimate} disabled={switchLoader}>
|
||||
{switchLoader ? "Updating..." : "Update"}
|
||||
</Button>
|
||||
</div>
|
||||
</>
|
||||
|
||||
Reference in New Issue
Block a user