diff --git a/apps/app/components/estimates/create-update-estimate-modal.tsx b/apps/app/components/estimates/create-update-estimate-modal.tsx index 98a5a430b..3b9660e9d 100644 --- a/apps/app/components/estimates/create-update-estimate-modal.tsx +++ b/apps/app/components/estimates/create-update-estimate-modal.tsx @@ -184,67 +184,23 @@ export const CreateUpdateEstimateModal: React.FC = ({ handleClose, data, name: formData.name, description: formData.description, }, - estimate_points: data - ? [ - { - id: data.points[0].id, - key: 0, - value: formData.value1, - }, - { - id: data.points[1].id, - key: 1, - value: formData.value2, - }, - { - id: data.points[2].id, - key: 2, - value: formData.value3, - }, - { - id: data.points[3].id, - key: 3, - value: formData.value4, - }, - { - id: data.points[4].id, - key: 4, - value: formData.value5, - }, - { - id: data.points[5].id, - key: 5, - value: formData.value6, - }, - ] - : [ - { - key: 0, - value: formData.value1, - }, - { - key: 1, - value: formData.value2, - }, - { - key: 2, - value: formData.value3, - }, - { - key: 3, - value: formData.value4, - }, - { - key: 4, - value: formData.value5, - }, - { - key: 5, - value: formData.value6, - }, - ], + estimate_points: [], }; + for (let i = 0; i < 6; i++) { + const point = { + key: i, + value: formData[`value${i + 1}` as keyof FormValues], + }; + + if (data) + payload.estimate_points.push({ + id: data.points[i].id, + ...point, + }); + else payload.estimate_points.push({ ...point }); + } + if (data) await updateEstimate(payload); else await createEstimate(payload); }; @@ -277,7 +233,7 @@ export const CreateUpdateEstimateModal: React.FC = ({ handleClose, data, leaveFrom="opacity-100" leaveTo="opacity-0" > -
+
@@ -291,7 +247,7 @@ export const CreateUpdateEstimateModal: React.FC = ({ handleClose, data, leaveFrom="opacity-100 translate-y-0 sm:scale-100" leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95" > - +