From 9ea3d5844dc055b362be585172aa0124b3e3038e Mon Sep 17 00:00:00 2001
From: Maxime Princelle <maxime@princelle.org>
Date: Fri, 17 Dec 2021 15:19:50 +0100
Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20bug=20in=20edit=20mode=20o?=
 =?UTF-8?q?f=20stock?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/pages/stock.tsx | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/pages/stock.tsx b/src/pages/stock.tsx
index 6be785d..52e89c8 100644
--- a/src/pages/stock.tsx
+++ b/src/pages/stock.tsx
@@ -37,13 +37,16 @@ const Stock = () => {
   const toggleEditMode = (productId) => {
     let productsTemp = productsList;
     let product = productsTemp[productId];
-
+    product.edit = product.edit === true ? false : true;
+    
     // Set all product.edit in productsTemp to false
-    productsTemp.forEach((p) => {
-      p.edit = false;
+    productsTemp.forEach((p, idx) => {
+      if (p.edit && p.edit === true && idx !== productId) {
+        p.edit = false;
+      }
     });
 
-    product.edit = product.edit === true ? false : true;
+    productsTemp[productId] = product;
     setProductsList([...productsTemp]);
 
     if (product.edit === false) {
-- 
GitLab