chore: updating the new estinates in update modal

This commit is contained in:
guru_sainath 2024-05-27 11:52:54 +05:30
parent bdb0674d35
commit 0a9e16a98a
3 changed files with 17 additions and 13 deletions

View File

@ -56,14 +56,19 @@ export const UpdateEstimateModal: FC<TUpdateEstimateModal> = observer((props) =>
// derived values // derived values
const renderEstimateStepsCount = useMemo(() => (estimatePoints ? "2" : "1"), [estimatePoints]); const renderEstimateStepsCount = useMemo(() => (estimatePoints ? "2" : "1"), [estimatePoints]);
const isNewEstimatePointsToCreate =
(estimatePoints || []).filter((point) => point.id === undefined).length > 0 ? true : false;
const handleCreateEstimate = async () => { const handleUpdateEstimate = async () => {
try { try {
if (!workspaceSlug || !projectId || !estimateId || currentEstimate?.type === undefined) return; if (!workspaceSlug || !projectId || !estimateId || currentEstimate?.type === undefined) return;
const currentEstimatePoints = (estimatePoints || []).filter((point) => point.id === undefined);
const currentEstimationType: TEstimateSystemKeys = currentEstimate?.type; const currentEstimationType: TEstimateSystemKeys = currentEstimate?.type;
const validatedEstimatePoints: TEstimatePointsObject[] = []; const validatedEstimatePoints: TEstimatePointsObject[] = [];
if ([EEstimateSystem.POINTS, EEstimateSystem.TIME].includes(currentEstimationType)) { if ([EEstimateSystem.POINTS, EEstimateSystem.TIME].includes(currentEstimationType)) {
estimatePoints?.map((estimatePoint) => { currentEstimatePoints?.map((estimatePoint) => {
if ( if (
estimatePoint.value && estimatePoint.value &&
((estimatePoint.value != "0" && Number(estimatePoint.value)) || estimatePoint.value === "0") ((estimatePoint.value != "0" && Number(estimatePoint.value)) || estimatePoint.value === "0")
@ -71,15 +76,13 @@ export const UpdateEstimateModal: FC<TUpdateEstimateModal> = observer((props) =>
validatedEstimatePoints.push(estimatePoint); validatedEstimatePoints.push(estimatePoint);
}); });
} else { } else {
estimatePoints?.map((estimatePoint) => { currentEstimatePoints?.map((estimatePoint) => {
if (estimatePoint.value) validatedEstimatePoints.push(estimatePoint); if (estimatePoint.value) validatedEstimatePoints.push(estimatePoint);
}); });
} }
if (validatedEstimatePoints.length === estimatePoints?.length) {
if (validatedEstimatePoints.length === currentEstimatePoints?.length) {
const payload: IEstimateFormData = { const payload: IEstimateFormData = {
estimate: {
type: "points",
},
estimate_points: validatedEstimatePoints, estimate_points: validatedEstimatePoints,
}; };
await updateEstimate(payload); await updateEstimate(payload);
@ -144,9 +147,9 @@ export const UpdateEstimateModal: FC<TUpdateEstimateModal> = observer((props) =>
<Button variant="neutral-primary" size="sm" onClick={handleClose}> <Button variant="neutral-primary" size="sm" onClick={handleClose}>
Cancel Cancel
</Button> </Button>
{estimatePoints && ( {isNewEstimatePointsToCreate && (
<Button variant="primary" size="sm" onClick={handleCreateEstimate}> <Button variant="primary" size="sm" onClick={handleUpdateEstimate}>
Create Estimate Update Estimate
</Button> </Button>
)} )}
</div> </div>

View File

@ -1,4 +1,5 @@
import { FC } from "react"; import { FC } from "react";
import { observer } from "mobx-react";
import { Plus } from "lucide-react"; import { Plus } from "lucide-react";
import { IEstimate, TEstimatePointsObject, TEstimateUpdateStageKeys } from "@plane/types"; import { IEstimate, TEstimatePointsObject, TEstimateUpdateStageKeys } from "@plane/types";
import { Button, Sortable } from "@plane/ui"; import { Button, Sortable } from "@plane/ui";
@ -14,7 +15,7 @@ type TEstimateUpdateStageTwo = {
handleEstimatePoints: (value: TEstimatePointsObject[]) => void; handleEstimatePoints: (value: TEstimatePointsObject[]) => void;
}; };
export const EstimateUpdateStageTwo: FC<TEstimateUpdateStageTwo> = (props) => { export const EstimateUpdateStageTwo: FC<TEstimateUpdateStageTwo> = observer((props) => {
const { estimate, estimateEditType, estimatePoints, handleEstimatePoints } = props; const { estimate, estimateEditType, estimatePoints, handleEstimatePoints } = props;
const currentEstimateSystem = estimate || undefined; const currentEstimateSystem = estimate || undefined;
@ -85,4 +86,4 @@ export const EstimateUpdateStageTwo: FC<TEstimateUpdateStageTwo> = (props) => {
</div> </div>
</div> </div>
); );
}; });

View File

@ -148,7 +148,7 @@ export class Estimate implements IEstimate {
const { workspaceSlug, projectId } = this.store.router; const { workspaceSlug, projectId } = this.store.router;
if (!workspaceSlug || !projectId || !this.id || !payload) return; if (!workspaceSlug || !projectId || !this.id || !payload) return;
// make update estimation request await this.service.updateEstimate(workspaceSlug, projectId, this.id, payload);
// runInAction(() => { // runInAction(() => {
// this.points = payload.estimate_points; // this.points = payload.estimate_points;