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

View File

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

View File

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