From e913d1178145ab706a4047c73a4f6bbd25ed9268 Mon Sep 17 00:00:00 2001
From: ankur prabhu <ankurprabhu0531@gmail.com>
Date: Fri, 12 Apr 2024 01:37:37 +0530
Subject: [PATCH 1/8] fix qrscanner on invalid id

---
 src/Components/Assets/AssetsList.tsx | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/Components/Assets/AssetsList.tsx b/src/Components/Assets/AssetsList.tsx
index 9e1469c91a5..a70712482c0 100644
--- a/src/Components/Assets/AssetsList.tsx
+++ b/src/Components/Assets/AssetsList.tsx
@@ -119,8 +119,12 @@ const AssetsList = () => {
         return data?.results[0].id;
       }
     } catch (err) {
-      console.log(err);
+      console.error(err);
+      Notification.Error({ msg: err });
     }
+    setIsLoading(false);
+    Notification.Error({ msg: "Invalid Asset Id" });
+    setIsScannerActive(false);
   };
 
   const checkValidAssetId = async (assetId: string) => {
@@ -161,7 +165,9 @@ const AssetsList = () => {
           onScan={async (value: string | null) => {
             if (value) {
               const assetId = await getAssetIdFromQR(value);
-              checkValidAssetId(assetId ?? value);
+              if (assetId) {
+                checkValidAssetId(assetId);
+              }
             }
           }}
           onError={(e) =>

From ffc40e3d4713e312fea2435093302f04b008ffe4 Mon Sep 17 00:00:00 2001
From: ankur prabhu <ankurprabhu0531@gmail.com>
Date: Fri, 12 Apr 2024 01:41:43 +0530
Subject: [PATCH 2/8] removing repeating code

---
 src/Components/Assets/AssetsList.tsx | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/Components/Assets/AssetsList.tsx b/src/Components/Assets/AssetsList.tsx
index a70712482c0..7e817b1aea4 100644
--- a/src/Components/Assets/AssetsList.tsx
+++ b/src/Components/Assets/AssetsList.tsx
@@ -124,7 +124,6 @@ const AssetsList = () => {
     }
     setIsLoading(false);
     Notification.Error({ msg: "Invalid Asset Id" });
-    setIsScannerActive(false);
   };
 
   const checkValidAssetId = async (assetId: string) => {

From 0231cd3c66fb686f49bbb5ba2169eddea3494285 Mon Sep 17 00:00:00 2001
From: ankur prabhu <ankurprabhu0531@gmail.com>
Date: Wed, 17 Apr 2024 19:31:00 +0530
Subject: [PATCH 3/8] using translation

---
 src/Components/Assets/AssetsList.tsx | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/src/Components/Assets/AssetsList.tsx b/src/Components/Assets/AssetsList.tsx
index 7e817b1aea4..ec3fcf7be72 100644
--- a/src/Components/Assets/AssetsList.tsx
+++ b/src/Components/Assets/AssetsList.tsx
@@ -123,7 +123,9 @@ const AssetsList = () => {
       Notification.Error({ msg: err });
     }
     setIsLoading(false);
-    Notification.Error({ msg: "Invalid Asset Id" });
+    Notification.Error({
+      msg: t("Oops! The asset ID you entered does not appear to be valid."),
+    });
   };
 
   const checkValidAssetId = async (assetId: string) => {
@@ -133,7 +135,7 @@ const AssetsList = () => {
     try {
       if (assetData) {
         navigate(
-          `/facility/${assetData.location_object.facility?.id}/assets/${assetId}`,
+          `/facility/${assetData.location_object.facility?.id}/assets/${assetId}`
         );
       }
     } catch (err) {
@@ -146,7 +148,7 @@ const AssetsList = () => {
   };
 
   const authorizedForImportExport = useIsAuthorized(
-    AuthorizeFor(["DistrictAdmin", "StateAdmin"]),
+    AuthorizeFor(["DistrictAdmin", "StateAdmin"])
   );
 
   if (isScannerActive)
@@ -395,7 +397,7 @@ const AssetsList = () => {
               value(
                 "Facility",
                 "facility",
-                qParams.facility && facilityObject?.name,
+                qParams.facility && facilityObject?.name
               ),
               badge("Name/Serial No./QR ID", "search"),
               value("Asset Class", "asset_class", asset_class ?? ""),
@@ -403,17 +405,17 @@ const AssetsList = () => {
               value(
                 "Location",
                 "location",
-                qParams.location && locationObject?.name,
+                qParams.location && locationObject?.name
               ),
               value(
                 "Warranty AMC End Of Validity Before",
                 "warranty_amc_end_of_validity_before",
-                qParams.warranty_amc_end_of_validity_before ?? "",
+                qParams.warranty_amc_end_of_validity_before ?? ""
               ),
               value(
                 "Warranty AMC End Of Validity After",
                 "warranty_amc_end_of_validity_after",
-                qParams.warranty_amc_end_of_validity_after ?? "",
+                qParams.warranty_amc_end_of_validity_after ?? ""
               ),
             ]}
           />
@@ -473,7 +475,7 @@ const AssetsList = () => {
 };
 
 export const warrantyAmcValidityChip = (
-  warranty_amc_end_of_validity: string,
+  warranty_amc_end_of_validity: string
 ) => {
   if (warranty_amc_end_of_validity === "" || !warranty_amc_end_of_validity)
     return;
@@ -481,8 +483,7 @@ export const warrantyAmcValidityChip = (
   const warrantyAmcEndDate = new Date(warranty_amc_end_of_validity);
 
   const days = Math.ceil(
-    Math.abs(Number(warrantyAmcEndDate) - Number(today)) /
-      (1000 * 60 * 60 * 24),
+    Math.abs(Number(warrantyAmcEndDate) - Number(today)) / (1000 * 60 * 60 * 24)
   );
 
   if (warrantyAmcEndDate < today) {

From 9ddcfd1c43cf9f6b74dcdc451a4b4f3be05b12df Mon Sep 17 00:00:00 2001
From: ankur prabhu <ankurprabhu0531@gmail.com>
Date: Wed, 17 Apr 2024 19:43:46 +0530
Subject: [PATCH 4/8] some code changes

---
 src/Components/Assets/AssetsList.tsx | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/Components/Assets/AssetsList.tsx b/src/Components/Assets/AssetsList.tsx
index ec3fcf7be72..d7a7e977429 100644
--- a/src/Components/Assets/AssetsList.tsx
+++ b/src/Components/Assets/AssetsList.tsx
@@ -117,15 +117,19 @@ const AssetsList = () => {
           query: { qr_code_id: assetId },
         });
         return data?.results[0].id;
+      } else {
+        Notification.Error({
+          msg: t("Oops! The asset ID you entered does not appear to be valid."),
+        });
       }
     } catch (err) {
       console.error(err);
-      Notification.Error({ msg: err });
+      Notification.Error({
+        msg: t("Oops! The asset ID you entered does not appear to be valid."),
+      });
+    } finally {
+      setIsLoading(false);
     }
-    setIsLoading(false);
-    Notification.Error({
-      msg: t("Oops! The asset ID you entered does not appear to be valid."),
-    });
   };
 
   const checkValidAssetId = async (assetId: string) => {

From 9548c380a774295b394a5a60969f2b6674b6dbab Mon Sep 17 00:00:00 2001
From: ankur prabhu <ankurprabhu0531@gmail.com>
Date: Wed, 17 Apr 2024 19:45:28 +0530
Subject: [PATCH 5/8] using console.log

---
 src/Components/Assets/AssetsList.tsx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Components/Assets/AssetsList.tsx b/src/Components/Assets/AssetsList.tsx
index d7a7e977429..2af713ec654 100644
--- a/src/Components/Assets/AssetsList.tsx
+++ b/src/Components/Assets/AssetsList.tsx
@@ -123,7 +123,7 @@ const AssetsList = () => {
         });
       }
     } catch (err) {
-      console.error(err);
+      console.log(err);
       Notification.Error({
         msg: t("Oops! The asset ID you entered does not appear to be valid."),
       });

From 5292ed98d1f8e8fc42927119771d0c4246fdd14f Mon Sep 17 00:00:00 2001
From: ankur prabhu <ankurprabhu0531@gmail.com>
Date: Sat, 4 May 2024 16:18:48 +0530
Subject: [PATCH 6/8] adding suggested changes

---
 src/Components/Assets/AssetsList.tsx | 21 +++++++++++----------
 src/Locale/en/Notifications.json     |  3 ++-
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/src/Components/Assets/AssetsList.tsx b/src/Components/Assets/AssetsList.tsx
index 2af713ec654..8ff5fe58db4 100644
--- a/src/Components/Assets/AssetsList.tsx
+++ b/src/Components/Assets/AssetsList.tsx
@@ -119,13 +119,13 @@ const AssetsList = () => {
         return data?.results[0].id;
       } else {
         Notification.Error({
-          msg: t("Oops! The asset ID you entered does not appear to be valid."),
+          msg: t("invalid_asset_id_msg"),
         });
       }
     } catch (err) {
       console.log(err);
       Notification.Error({
-        msg: t("Oops! The asset ID you entered does not appear to be valid."),
+        msg: t("invalid_asset_id_msg"),
       });
     } finally {
       setIsLoading(false);
@@ -139,7 +139,7 @@ const AssetsList = () => {
     try {
       if (assetData) {
         navigate(
-          `/facility/${assetData.location_object.facility?.id}/assets/${assetId}`
+          `/facility/${assetData.location_object.facility?.id}/assets/${assetId}`,
         );
       }
     } catch (err) {
@@ -152,7 +152,7 @@ const AssetsList = () => {
   };
 
   const authorizedForImportExport = useIsAuthorized(
-    AuthorizeFor(["DistrictAdmin", "StateAdmin"])
+    AuthorizeFor(["DistrictAdmin", "StateAdmin"]),
   );
 
   if (isScannerActive)
@@ -401,7 +401,7 @@ const AssetsList = () => {
               value(
                 "Facility",
                 "facility",
-                qParams.facility && facilityObject?.name
+                qParams.facility && facilityObject?.name,
               ),
               badge("Name/Serial No./QR ID", "search"),
               value("Asset Class", "asset_class", asset_class ?? ""),
@@ -409,17 +409,17 @@ const AssetsList = () => {
               value(
                 "Location",
                 "location",
-                qParams.location && locationObject?.name
+                qParams.location && locationObject?.name,
               ),
               value(
                 "Warranty AMC End Of Validity Before",
                 "warranty_amc_end_of_validity_before",
-                qParams.warranty_amc_end_of_validity_before ?? ""
+                qParams.warranty_amc_end_of_validity_before ?? "",
               ),
               value(
                 "Warranty AMC End Of Validity After",
                 "warranty_amc_end_of_validity_after",
-                qParams.warranty_amc_end_of_validity_after ?? ""
+                qParams.warranty_amc_end_of_validity_after ?? "",
               ),
             ]}
           />
@@ -479,7 +479,7 @@ const AssetsList = () => {
 };
 
 export const warrantyAmcValidityChip = (
-  warranty_amc_end_of_validity: string
+  warranty_amc_end_of_validity: string,
 ) => {
   if (warranty_amc_end_of_validity === "" || !warranty_amc_end_of_validity)
     return;
@@ -487,7 +487,8 @@ export const warrantyAmcValidityChip = (
   const warrantyAmcEndDate = new Date(warranty_amc_end_of_validity);
 
   const days = Math.ceil(
-    Math.abs(Number(warrantyAmcEndDate) - Number(today)) / (1000 * 60 * 60 * 24)
+    Math.abs(Number(warrantyAmcEndDate) - Number(today)) /
+      (1000 * 60 * 60 * 24),
   );
 
   if (warrantyAmcEndDate < today) {
diff --git a/src/Locale/en/Notifications.json b/src/Locale/en/Notifications.json
index 8c6255ca850..3de4257befb 100644
--- a/src/Locale/en/Notifications.json
+++ b/src/Locale/en/Notifications.json
@@ -15,5 +15,6 @@
   "unsubscribe_failed": "Unsubscribe failed.",
   "unsubscribe": "Unsubscribe",
   "escape": "Escape",
-  "loading": "Loading..."
+  "loading": "Loading...",
+  "invalid_asset_id_msg": "Oops! The asset ID you entered does not appear to be valid."
 }

From c055554d40575a38e249a51f8c13a00bb35edae2 Mon Sep 17 00:00:00 2001
From: ankur prabhu <ankurprabhu0531@gmail.com>
Date: Wed, 22 May 2024 19:36:27 +0530
Subject: [PATCH 7/8] fix multiple notifications on error

---
 src/Components/Assets/AssetsList.tsx | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/Components/Assets/AssetsList.tsx b/src/Components/Assets/AssetsList.tsx
index 0d81a740fa4..7f99e930ba0 100644
--- a/src/Components/Assets/AssetsList.tsx
+++ b/src/Components/Assets/AssetsList.tsx
@@ -169,7 +169,10 @@ const AssetsList = () => {
           onResult={async (text) => {
             if (text) {
               const assetId = await getAssetIdFromQR(text);
-              checkValidAssetId(assetId ?? text);
+
+              if (assetId !== undefined) {
+                checkValidAssetId(assetId);
+              }
             }
           }}
           onError={(e) => {

From 25ab42a25c3cbdb735ae98ff62fcf0e976b04f74 Mon Sep 17 00:00:00 2001
From: Khavin Shankar <khavinshankar@gmail.com>
Date: Wed, 31 Jul 2024 19:48:02 +0530
Subject: [PATCH 8/8] use more user friendly error messages

---
 src/Components/Assets/AssetsList.tsx | 8 ++++----
 src/Locale/en/Notifications.json     | 3 ++-
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/Components/Assets/AssetsList.tsx b/src/Components/Assets/AssetsList.tsx
index ee422205d16..fa609e0e3b8 100644
--- a/src/Components/Assets/AssetsList.tsx
+++ b/src/Components/Assets/AssetsList.tsx
@@ -121,7 +121,7 @@ const AssetsList = () => {
       if (!isValidURL(assetURL)) {
         setIsLoading(false);
         Notification.Error({
-          msg: "Invalid QR code scanned !!!",
+          msg: t("invalid_asset_id_msg"),
         });
         return;
       }
@@ -137,7 +137,7 @@ const AssetsList = () => {
         if (!data) {
           setIsLoading(false);
           Notification.Error({
-            msg: "Invalid QR code scanned !!!",
+            msg: t("invalid_asset_id_msg"),
           });
           return;
         }
@@ -151,13 +151,13 @@ const AssetsList = () => {
         } else {
           setIsLoading(false);
           Notification.Error({
-            msg: "Asset not found !!!",
+            msg: t("asset_not_found_msg"),
           });
         }
       } else {
         setIsLoading(false);
         Notification.Error({
-          msg: "Invalid QR code scanned !!!",
+          msg: t("invalid_asset_id_msg"),
         });
       }
     } catch (err) {
diff --git a/src/Locale/en/Notifications.json b/src/Locale/en/Notifications.json
index 0a49c5844a6..dac9c29730f 100644
--- a/src/Locale/en/Notifications.json
+++ b/src/Locale/en/Notifications.json
@@ -17,5 +17,6 @@
   "unsubscribe": "Unsubscribe",
   "escape": "Escape",
   "loading": "Loading...",
-  "invalid_asset_id_msg": "Oops! The asset ID you entered does not appear to be valid."
+  "invalid_asset_id_msg": "Oops! The asset ID you entered does not appear to be valid.",
+  "asset_not_found_msg": "Oops! The asset you are looking for does not exist. Please check the asset id."
 }