From 3ada9ea9229ba76d25932708f916844a5a51c7d0 Mon Sep 17 00:00:00 2001 From: Sibunnayak Date: Fri, 16 Aug 2024 16:39:42 +0530 Subject: [PATCH] Inventory --- src/views/Inventory/Inventory.js | 350 +++++++++++++++++++++++++------ 1 file changed, 286 insertions(+), 64 deletions(-) diff --git a/src/views/Inventory/Inventory.js b/src/views/Inventory/Inventory.js index c86fcf3..d899253 100644 --- a/src/views/Inventory/Inventory.js +++ b/src/views/Inventory/Inventory.js @@ -8,8 +8,7 @@ import debounce from "lodash.debounce"; const Inventory = () => { const token = isAutheticated(); const [loading, setLoading] = useState(false); - // const [inventoryData, setInventoryData] = useState([]); - const [filteredData, setFilteredData] = useState([]); + const [inventoryData, setInventoryData] = useState([]); const nameRef = useRef(); const startDateRef = useRef(); @@ -31,12 +30,14 @@ const Inventory = () => { show: itemPerPage, startDate: startDateRef.current?.value || "", endDate: endDateRef.current?.value || "", + name: nameRef.current?.value || "", }, }); const transformedData = response.data?.inventories?.map((entry) => ({ id: entry._id, + uniqueId: entry.uniqueId, tradeName: entry.addedForData?.shippingAddress?.tradeName || entry.addedForData?.trade_name || @@ -51,13 +52,9 @@ const Inventory = () => { createdAt: entry.createdAt, updatedAt: entry.updatedAt, })) || []; - - // setInventoryData(transformedData); + + setInventoryData(transformedData); setTotalData(response.data?.total_data || 0); - - // Apply the filter after data is fetched - filterData(transformedData); - } catch (err) { const msg = err?.response?.data?.msg || "Something went wrong!"; swal({ @@ -72,14 +69,6 @@ const Inventory = () => { } }; - const filterData = (data) => { - const tradeName = nameRef.current?.value || ""; - const filtered = data.filter((entry) => - entry.tradeName.toLowerCase().includes(tradeName.toLowerCase()) - ); - setFilteredData(filtered); - }; - const debouncedSearch = useCallback( debounce(() => { setCurrentPage(1); @@ -177,7 +166,7 @@ const Inventory = () => {
- @@ -206,11 +195,11 @@ const Inventory = () => { Loading... - ) : filteredData.length > 0 ? ( - filteredData.map((entry, i) => + ) : inventoryData.length > 0 ? ( + inventoryData.map((entry, i) => entry.products.map((product, j) => ( - + -
{entry.id}{entry.uniqueId} {new Date(entry.createdAt).toLocaleString( "en-IN", @@ -282,9 +271,215 @@ const Inventory = () => { ) )}
-
+ */} + + + + + + + + + + + + + + + + + + {loading ? ( + + + + ) : inventoryData.length > 0 ? ( + inventoryData.map((entry, i) => + entry.products.map((product, j) => ( + + {/* Only show ID, Date, Time, Trade Name, PD/RD, and Actions on the first row of each entry */} + {j === 0 && ( + <> + + + + + + + )} + {/* Product details */} + + + + + {/* Actions: only show on the first row of each entry */} + {j === 0 && ( + + )} + + )) + ) + ) : ( + + + + )} + +
+ ID + + Date + + Time + + Trade Name + + PD/RD + + Product SKU + + Product Name + + Sale + + Inventory + + Actions +
+ Loading... +
+ {entry.uniqueId} + + {new Date(entry.createdAt).toLocaleString( + "en-IN", + { + month: "short", + day: "numeric", + year: "numeric", + } + )} + + {new Date(entry.createdAt).toLocaleString( + "en-IN", + { + hour: "numeric", + minute: "numeric", + hour12: true, + } + )} + + {entry.tradeName} + + {entry.designation} + + {product.SKU} + + {product.ProductName} + + {product.Sale} + + {product.Inventory} + + + + +
+
No Data Available...
+
+ +
{ role="status" aria-live="polite" > - Showing {Math.min(itemPerPage * currentPage, totalData)} of {totalData} entries + Showing {currentPage * itemPerPage - itemPerPage + 1} to{" "} + {Math.min(currentPage * itemPerPage, totalData)} of{" "} + {totalData} entries
-
-
-