({
mode: 'uncontrolled',
initialValues: {
+ barcode: 0,
name: "",
brand: "",
statusId: "",
@@ -53,7 +57,26 @@ function EditItem() {
}
});
+ if (result.ok) {
+ notifications.show({
+ icon: ,
+ color:"teal",
+ title: "All good!",
+ message: "Item Updated",
+ position: 'top-center',
+ });
+ navigate("/inventory");
+
+ }
+
if (!result.ok) {
+ notifications.show({
+ icon: ,
+ color:"red",
+ title: "Bummer!",
+ message: "Something went wrong",
+ position: 'top-center',
+ });
throw new Error('Failed to update inventory item');
}
@@ -90,7 +113,8 @@ function EditItem() {
{isFetching ? 'Updating...' : ''}
Edit Item
- ID: {data.id}
+
=> {
- const response = await fetch(
- import.meta.env.VITE_API_URL + '/inventory',
- )
+ const inventoryQuery = useInventoryList();
- if (!response.ok) throw new Error('Failed to fetch inventory ' + response.statusText)
+ if (inventoryQuery.isPending) return 'Loading...'
- return await response.json()
- },
- });
-
- if (isPending) return 'Loading...'
-
- if (error) return 'An error has occurred: ' + error.message
+ if (inventoryQuery.error) return 'An error has occurred: ' + inventoryQuery.error.message
return (
@@ -37,16 +26,13 @@ function InventoryList() {
ARFF ARFF BARK BARK
- Add Item
+ Add Item
-
- {isFetching ? 'Updating...' : ''}
-
- ID
+ Barcode
Brand
Item
Status
@@ -54,14 +40,14 @@ function InventoryList() {
- {data.map((data) => (
+ {inventoryQuery.data?.map((data) => (
- {data.id}
+ {data.barcode}
{data.brand}
{data.name}
{data.statusId}
- Details
+ Details
))}
diff --git a/barkmanui/src/features/inventory/ItemDetail.tsx b/barkmanui/src/features/inventory/ItemDetail.tsx
index 2d17c0b..b1e7a44 100644
--- a/barkmanui/src/features/inventory/ItemDetail.tsx
+++ b/barkmanui/src/features/inventory/ItemDetail.tsx
@@ -29,7 +29,7 @@ function ItemDetail() {
Item Detail
{isFetching ? 'Updating...' : ''}
- ID: {data.id}
+ Barcode: {data.barcode}
Brand: {data.brand}
Name: {data.name}
Status: {data.status.name}
@@ -38,7 +38,7 @@ function ItemDetail() {
Replacement Cost: ${data.replacementCost}
Notes: {data.notes}
- Edit
+ Edit
>
)
diff --git a/barkmanui/src/features/inventory/hooks/useInventoryList.tsx b/barkmanui/src/features/inventory/hooks/useInventoryList.tsx
new file mode 100644
index 0000000..6c1ab01
--- /dev/null
+++ b/barkmanui/src/features/inventory/hooks/useInventoryList.tsx
@@ -0,0 +1,17 @@
+import {useQuery} from "@tanstack/react-query";
+import {InventoryItem} from "../types.js";
+
+ const useInventoryList = () => useQuery({
+ queryKey: ['inventory'],
+ queryFn: async (): Promise => {
+ const response = await fetch(
+ import.meta.env.VITE_API_URL + '/inventory',
+ )
+
+ if (!response.ok) throw new Error('Failed to fetch inventory ' + response.statusText)
+
+ return await response.json()
+ },
+ });
+
+export default useInventoryList;
\ No newline at end of file
diff --git a/barkmanui/src/features/inventory/types.ts b/barkmanui/src/features/inventory/types.ts
index 21d4246..4f1c7c4 100644
--- a/barkmanui/src/features/inventory/types.ts
+++ b/barkmanui/src/features/inventory/types.ts
@@ -1,5 +1,6 @@
export interface InventoryItem {
id: number,
+ barcode: number,
brand: string,
name: string,
status: {id: string; name: string},
@@ -11,6 +12,7 @@ export interface InventoryItem {
}
export interface NewItem {
+ barcode: number,
brand: string,
name: string,
serialNumber: string,