Skip to content

Commit

Permalink
feat: remove usless code
Browse files Browse the repository at this point in the history
  • Loading branch information
gca-axelor committed Dec 17, 2024
1 parent 0b1c885 commit ac38201
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions packages/apps/purchase/src/screens/RequestCreationScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit ac38201

Please sign in to comment.