mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
chore: updated alerts
This commit is contained in:
parent
ec228ad02c
commit
0a72adc2a6
@ -8,8 +8,6 @@ import { EModalPosition, EModalWidth, ModalCore } from "@/components/core";
|
||||
import { EstimateCreateStageOne, EstimatePointCreateRoot } from "@/components/estimates";
|
||||
// constants
|
||||
import { EEstimateSystem, ESTIMATE_SYSTEMS } from "@/constants/estimates";
|
||||
// helpers
|
||||
import { isEstimatePointValuesRepeated } from "@/helpers/estimates";
|
||||
// hooks
|
||||
import { useProjectEstimates } from "@/hooks/store";
|
||||
|
||||
@ -40,63 +38,29 @@ export const CreateEstimateModal: FC<TCreateEstimateModal> = observer((props) =>
|
||||
|
||||
const handleCreateEstimate = async () => {
|
||||
try {
|
||||
if (!workspaceSlug || !projectId) return;
|
||||
if (!workspaceSlug || !projectId || !estimatePoints) return;
|
||||
|
||||
const validatedEstimatePoints: TEstimatePointsObject[] = [];
|
||||
if ([EEstimateSystem.POINTS, EEstimateSystem.TIME].includes(estimateSystem)) {
|
||||
estimatePoints?.map((estimatePoint) => {
|
||||
if (
|
||||
estimatePoint.value &&
|
||||
((estimatePoint.value != "0" && Number(estimatePoint.value)) || estimatePoint.value === "0")
|
||||
)
|
||||
validatedEstimatePoints.push(estimatePoint);
|
||||
});
|
||||
} else {
|
||||
estimatePoints?.map((estimatePoint) => {
|
||||
if (estimatePoint.value) validatedEstimatePoints.push(estimatePoint);
|
||||
});
|
||||
}
|
||||
const payload: IEstimateFormData = {
|
||||
estimate: {
|
||||
name: ESTIMATE_SYSTEMS[estimateSystem]?.name,
|
||||
type: estimateSystem,
|
||||
last_used: true,
|
||||
},
|
||||
estimate_points: estimatePoints,
|
||||
};
|
||||
await createEstimate(workspaceSlug, projectId, payload);
|
||||
|
||||
if (validatedEstimatePoints.length === estimatePoints?.length) {
|
||||
const isRepeated = isEstimatePointValuesRepeated(
|
||||
estimatePoints.map((point) => point.value),
|
||||
estimateSystem
|
||||
);
|
||||
if (!isRepeated) {
|
||||
const payload: IEstimateFormData = {
|
||||
estimate: {
|
||||
name: ESTIMATE_SYSTEMS[estimateSystem]?.name,
|
||||
type: estimateSystem,
|
||||
last_used: true,
|
||||
},
|
||||
estimate_points: validatedEstimatePoints,
|
||||
};
|
||||
await createEstimate(workspaceSlug, projectId, payload);
|
||||
setToast({
|
||||
type: TOAST_TYPE.SUCCESS,
|
||||
title: "Estimate system created",
|
||||
message: "Created and Enabled successfully",
|
||||
});
|
||||
handleClose();
|
||||
} else {
|
||||
setToast({
|
||||
type: TOAST_TYPE.ERROR,
|
||||
title: "Error!",
|
||||
message: "Estimate point values cannot be repeated",
|
||||
});
|
||||
}
|
||||
} else {
|
||||
setToast({
|
||||
type: TOAST_TYPE.ERROR,
|
||||
title: "Error!",
|
||||
message: "something went wrong",
|
||||
});
|
||||
}
|
||||
setToast({
|
||||
type: TOAST_TYPE.SUCCESS,
|
||||
title: "Estimate created",
|
||||
message: "Created and Enabled successfully",
|
||||
});
|
||||
handleClose();
|
||||
} catch (error) {
|
||||
setToast({
|
||||
type: TOAST_TYPE.ERROR,
|
||||
title: "Error!",
|
||||
message: "something went wrong",
|
||||
title: "Estimate creation failed",
|
||||
message: "We were unable to create the new estimate, please try again.",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@ -93,8 +93,8 @@ export const EstimatePointCreate: FC<TEstimatePointCreate> = observer((props) =>
|
||||
setError(undefined);
|
||||
setToast({
|
||||
type: TOAST_TYPE.SUCCESS,
|
||||
title: "Estimate point updated",
|
||||
message: "The estimate point has been updated successfully.",
|
||||
title: "Estimate point created",
|
||||
message: "The estimate point has been created successfully.",
|
||||
});
|
||||
handleClose();
|
||||
} catch {
|
||||
@ -102,8 +102,8 @@ export const EstimatePointCreate: FC<TEstimatePointCreate> = observer((props) =>
|
||||
setError("We are unable to process your request, please try again.");
|
||||
setToast({
|
||||
type: TOAST_TYPE.ERROR,
|
||||
title: "Estimate point failed to updated",
|
||||
message: "We are unable to process your request, please try again.",
|
||||
title: "Estimate point creation failed",
|
||||
message: "We were unable to create the new estimate point, please try again.",
|
||||
});
|
||||
}
|
||||
} else {
|
||||
|
@ -2,7 +2,7 @@ import { FC, useState } from "react";
|
||||
import { observer } from "mobx-react";
|
||||
import { Plus } from "lucide-react";
|
||||
import { TEstimatePointsObject } from "@plane/types";
|
||||
import { Button, Draggable, Sortable } from "@plane/ui";
|
||||
import { Button, Draggable, Sortable, TOAST_TYPE, setToast } from "@plane/ui";
|
||||
// components
|
||||
import { EstimatePointItemPreview, EstimatePointCreate } from "@/components/estimates/points";
|
||||
// constants
|
||||
@ -52,9 +52,22 @@ export const EstimatePointEditRoot: FC<TEstimatePointEditRoot> = observer((props
|
||||
}
|
||||
};
|
||||
|
||||
const handleDragEstimatePoints = (updatedEstimatedOrder: TEstimatePointsObject[]) => {
|
||||
const updatedEstimateKeysOrder = updatedEstimatedOrder.map((item, index) => ({ ...item, key: index + 1 }));
|
||||
updateEstimateSortOrder(workspaceSlug, projectId, updatedEstimateKeysOrder);
|
||||
const handleDragEstimatePoints = async (updatedEstimatedOrder: TEstimatePointsObject[]) => {
|
||||
try {
|
||||
const updatedEstimateKeysOrder = updatedEstimatedOrder.map((item, index) => ({ ...item, key: index + 1 }));
|
||||
await updateEstimateSortOrder(workspaceSlug, projectId, updatedEstimateKeysOrder);
|
||||
setToast({
|
||||
type: TOAST_TYPE.SUCCESS,
|
||||
title: "Estimates re-ordered",
|
||||
message: "Estimates have been re-ordered in your project.",
|
||||
});
|
||||
} catch {
|
||||
setToast({
|
||||
type: TOAST_TYPE.ERROR,
|
||||
title: "Estimate re-order failed",
|
||||
message: "We were unable to re-order the estimates, please try again",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
if (!workspaceSlug || !projectId || !estimateId) return <></>;
|
||||
|
@ -88,31 +88,36 @@ export const EstimatePointUpdate: FC<TEstimatePointUpdate> = observer((props) =>
|
||||
|
||||
if (isEstimateValid) {
|
||||
if (estimateId != undefined) {
|
||||
try {
|
||||
setLoader(true);
|
||||
|
||||
const payload = {
|
||||
value: estimateInputValue,
|
||||
};
|
||||
await updateEstimatePoint(workspaceSlug, projectId, payload);
|
||||
|
||||
if (estimateInputValue === estimatePoint.value) {
|
||||
setLoader(false);
|
||||
setError(undefined);
|
||||
handleClose();
|
||||
setToast({
|
||||
type: TOAST_TYPE.SUCCESS,
|
||||
title: "Estimate point updated",
|
||||
message: "The estimate point has been updated successfully.",
|
||||
});
|
||||
} catch {
|
||||
setLoader(false);
|
||||
setError("We are unable to process your request, please try again.");
|
||||
setToast({
|
||||
type: TOAST_TYPE.ERROR,
|
||||
title: "Estimate point failed to updated",
|
||||
message: "We are unable to process your request, please try again.",
|
||||
});
|
||||
}
|
||||
} else
|
||||
try {
|
||||
setLoader(true);
|
||||
|
||||
const payload = {
|
||||
value: estimateInputValue,
|
||||
};
|
||||
await updateEstimatePoint(workspaceSlug, projectId, payload);
|
||||
|
||||
setLoader(false);
|
||||
setError(undefined);
|
||||
handleClose();
|
||||
setToast({
|
||||
type: TOAST_TYPE.SUCCESS,
|
||||
title: "Estimate modified",
|
||||
message: "The estimate point has been updated in your project.",
|
||||
});
|
||||
} catch {
|
||||
setLoader(false);
|
||||
setError("We are unable to process your request, please try again.");
|
||||
setToast({
|
||||
type: TOAST_TYPE.ERROR,
|
||||
title: "Estimate modification failed",
|
||||
message: "We were unable to modify the estimate, please try again",
|
||||
});
|
||||
}
|
||||
} else {
|
||||
handleSuccess(estimateInputValue);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user