From d610f0a02a4ccff792bf03029c6a0f40d6154bb1 Mon Sep 17 00:00:00 2001 From: Gregory <117281520+gca-axelor@users.noreply.github.com> Date: Mon, 16 Dec 2024 11:06:01 +0100 Subject: [PATCH] feat: remove usless code --- .../src/screens/RequestCreationScreen.tsx | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/packages/apps/purchase/src/screens/RequestCreationScreen.tsx b/packages/apps/purchase/src/screens/RequestCreationScreen.tsx index cb00b6c0c..eaa72d198 100644 --- a/packages/apps/purchase/src/screens/RequestCreationScreen.tsx +++ b/packages/apps/purchase/src/screens/RequestCreationScreen.tsx @@ -85,31 +85,28 @@ const RequestCreationScreen = () => { const handleAddLine = () => { setLines(prevLines => { const newLines = [...prevLines]; - const newProduct = isCustomProduct - ? {name: productTitle, id: `custom-${Date.now()}`} - : newLine; - const indexLine = newLines.findIndex(line => line.id === newProduct?.id); + const existingLine = newLines.find(line => line.id === newLine?.id); - if (indexLine >= 0) { - if (isEditionMode) { - newLines[indexLine].realQty = movedQty; - } else { - newLines[indexLine].realQty += movedQty; - } + if (existingLine) { + existingLine.realQty = isEditionMode + ? movedQty + : existingLine.realQty + movedQty; } else { newLines.push({ - product: newProduct, - trackingNumber: newProduct?.trackingNumber, + product: isCustomProduct + ? {name: productTitle, id: `custom-${Date.now()}`} + : newLine, + trackingNumber: newLine?.trackingNumber, realQty: movedQty, - currentQty: newProduct?.currentQty, + currentQty: newLine?.currentQty, unit: unit, - id: newProduct?.id, + id: newLine?.id || `custom-${Date.now()}`, }); } return newLines; }); - handleReset(RequestCreation.step.addLine); + handleReset(); }; const isEditionMode = useMemo(