From faa8f13a421518a9b17086001498b087e9f92062 Mon Sep 17 00:00:00 2001 From: Drew Rautenberg Date: Mon, 3 Feb 2025 10:06:11 -0600 Subject: [PATCH 01/12] backed end add --- .../20250203160519_add-barcodes.Designer.cs | 108 ++++++++++++++++++ .../Migrations/20250203160519_add-barcodes.cs | 29 +++++ .../Migrations/BarkContextModelSnapshot.cs | 4 + barkmanAPI/Program.cs | 2 + barkmanAPI/barkDbModel.cs | 3 +- barkmanui/.env | 4 +- 6 files changed, 147 insertions(+), 3 deletions(-) create mode 100644 barkmanAPI/Migrations/20250203160519_add-barcodes.Designer.cs create mode 100644 barkmanAPI/Migrations/20250203160519_add-barcodes.cs diff --git a/barkmanAPI/Migrations/20250203160519_add-barcodes.Designer.cs b/barkmanAPI/Migrations/20250203160519_add-barcodes.Designer.cs new file mode 100644 index 0000000..5611d82 --- /dev/null +++ b/barkmanAPI/Migrations/20250203160519_add-barcodes.Designer.cs @@ -0,0 +1,108 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using barkmanapi; + +#nullable disable + +namespace barkmanapi.Migrations +{ + [DbContext(typeof(BarkContext))] + [Migration("20250203160519_add-barcodes")] + partial class addbarcodes + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("barkmanapi.InventoryItems", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Barcode") + .HasColumnType("integer") + .HasColumnName("barcode"); + + b.Property("Brand") + .IsRequired() + .HasColumnType("text") + .HasColumnName("brand"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text") + .HasColumnName("name"); + + b.Property("Notes") + .HasColumnType("text") + .HasColumnName("notes"); + + b.Property("RentalPrice") + .HasColumnType("real") + .HasColumnName("rental_price"); + + b.Property("ReplacementCost") + .HasColumnType("real") + .HasColumnName("replacement_cost"); + + b.Property("SerialNumber") + .HasColumnType("text") + .HasColumnName("serial_number"); + + b.Property("StatusId") + .HasColumnType("text") + .HasColumnName("status_id"); + + b.HasKey("Id") + .HasName("pk_inventory"); + + b.HasIndex("StatusId") + .HasDatabaseName("ix_inventory_status_id"); + + b.ToTable("inventory", (string)null); + }); + + modelBuilder.Entity("barkmanapi.ItemStatus", b => + { + b.Property("Id") + .HasColumnType("text") + .HasColumnName("id"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text") + .HasColumnName("name"); + + b.HasKey("Id") + .HasName("pk_item_status"); + + b.ToTable("item_status", (string)null); + }); + + modelBuilder.Entity("barkmanapi.InventoryItems", b => + { + b.HasOne("barkmanapi.ItemStatus", "Status") + .WithMany() + .HasForeignKey("StatusId") + .HasConstraintName("fk_inventory_item_status_status_id"); + + b.Navigation("Status"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/barkmanAPI/Migrations/20250203160519_add-barcodes.cs b/barkmanAPI/Migrations/20250203160519_add-barcodes.cs new file mode 100644 index 0000000..15424dc --- /dev/null +++ b/barkmanAPI/Migrations/20250203160519_add-barcodes.cs @@ -0,0 +1,29 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace barkmanapi.Migrations +{ + /// + public partial class addbarcodes : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "barcode", + table: "inventory", + type: "integer", + nullable: false, + defaultValue: 0); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "barcode", + table: "inventory"); + } + } +} diff --git a/barkmanAPI/Migrations/BarkContextModelSnapshot.cs b/barkmanAPI/Migrations/BarkContextModelSnapshot.cs index 10252f0..332a8b9 100644 --- a/barkmanAPI/Migrations/BarkContextModelSnapshot.cs +++ b/barkmanAPI/Migrations/BarkContextModelSnapshot.cs @@ -30,6 +30,10 @@ namespace barkmanapi.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + b.Property("Barcode") + .HasColumnType("integer") + .HasColumnName("barcode"); + b.Property("Brand") .IsRequired() .HasColumnType("text") diff --git a/barkmanAPI/Program.cs b/barkmanAPI/Program.cs index 5549237..0d3297c 100644 --- a/barkmanAPI/Program.cs +++ b/barkmanAPI/Program.cs @@ -73,6 +73,7 @@ inventoryGroup.MapPut("/{id}", async (int id, InventoryItems updatedItem, BarkCo } existingItem.Name = updatedItem.Name; + existingItem.Barcode = updatedItem.Barcode; existingItem.Brand = updatedItem.Brand; existingItem.SerialNumber = updatedItem.SerialNumber; existingItem.Status = updatedItem.Status; @@ -88,6 +89,7 @@ inventoryGroup.MapPost("", async (InventoryItems newItemInput, BarkContext db) = { var newItem = new InventoryItems(); newItem.Name = newItemInput.Name; + newItem.Barcode = newItemInput.Barcode; newItem.Brand = newItemInput.Brand; newItem.SerialNumber = newItemInput.SerialNumber; newItem.RentalPrice = newItemInput.RentalPrice; diff --git a/barkmanAPI/barkDbModel.cs b/barkmanAPI/barkDbModel.cs index 77cce27..1e283bb 100644 --- a/barkmanAPI/barkDbModel.cs +++ b/barkmanAPI/barkDbModel.cs @@ -10,7 +10,8 @@ public class BarkContext(DbContextOptions options) : DbContext(opti public class InventoryItems { - public int Id {get; set;} + public int Id {get; set;} + public int Barcode {get; set;} public string Name { get; set; } public string Brand { get; set; } public string? SerialNumber { get; set; } diff --git a/barkmanui/.env b/barkmanui/.env index 889752b..1104091 100644 --- a/barkmanui/.env +++ b/barkmanui/.env @@ -1,4 +1,4 @@ #Staging API -#VITE_API_URL=https://barkdev.ts.drewr.io +VITE_API_URL=https://barkdev.ts.drewr.io #Local Dev API -VITE_API_URL=http://localhost:5145 \ No newline at end of file +#VITE_API_URL=http://localhost:5145 \ No newline at end of file From ee4baa3d5039f18efd4168822b44aabe8dc70b56 Mon Sep 17 00:00:00 2001 From: Drew Rautenberg Date: Mon, 3 Feb 2025 10:18:43 -0600 Subject: [PATCH 02/12] ui updates --- barkmanui/.env | 4 ++-- barkmanui/src/features/inventory/EditItem.tsx | 6 ++++-- barkmanui/src/features/inventory/InventoryList.tsx | 4 ++-- barkmanui/src/features/inventory/ItemDetail.tsx | 2 +- barkmanui/src/features/inventory/types.ts | 1 + 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/barkmanui/.env b/barkmanui/.env index 1104091..889752b 100644 --- a/barkmanui/.env +++ b/barkmanui/.env @@ -1,4 +1,4 @@ #Staging API -VITE_API_URL=https://barkdev.ts.drewr.io +#VITE_API_URL=https://barkdev.ts.drewr.io #Local Dev API -#VITE_API_URL=http://localhost:5145 \ No newline at end of file +VITE_API_URL=http://localhost:5145 \ No newline at end of file diff --git a/barkmanui/src/features/inventory/EditItem.tsx b/barkmanui/src/features/inventory/EditItem.tsx index 5c34c6e..a3d9d67 100644 --- a/barkmanui/src/features/inventory/EditItem.tsx +++ b/barkmanui/src/features/inventory/EditItem.tsx @@ -1,4 +1,4 @@ -import {Button, Group, TextInput, Text, Textarea, NumberInput, Container, Title, Flex} from '@mantine/core'; +import {Button, Group, TextInput, Textarea, NumberInput, Container, Title, Flex} from '@mantine/core'; import {useForm} from '@mantine/form'; import {useParams} from "react-router"; import {useMutation, useQuery, useQueryClient} from "@tanstack/react-query"; @@ -13,6 +13,7 @@ function EditItem() { const editItemForm = useForm({ mode: 'uncontrolled', initialValues: { + barcode: 0, name: "", brand: "", statusId: "", @@ -90,7 +91,8 @@ function EditItem() {
{isFetching ? 'Updating...' : ''}
Edit Item - ID: {data.id} + - ID + Barcode Brand Item Status @@ -56,7 +56,7 @@ function InventoryList() { {data.map((data) => ( - {data.id} + {data.barcode} {data.brand} {data.name} {data.statusId} diff --git a/barkmanui/src/features/inventory/ItemDetail.tsx b/barkmanui/src/features/inventory/ItemDetail.tsx index 2d17c0b..eb0d5f5 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} diff --git a/barkmanui/src/features/inventory/types.ts b/barkmanui/src/features/inventory/types.ts index 21d4246..e3a75a5 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}, From 730cbc6733b2b17b9493b2df26f1bf9adc09dca8 Mon Sep 17 00:00:00 2001 From: Drew Rautenberg Date: Mon, 3 Feb 2025 10:29:50 -0600 Subject: [PATCH 03/12] added notifications and redirect to edit item page --- barkmanui/src/features/inventory/AddItem.tsx | 3 ++- barkmanui/src/features/inventory/EditItem.tsx | 24 ++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/barkmanui/src/features/inventory/AddItem.tsx b/barkmanui/src/features/inventory/AddItem.tsx index 581e430..33be18c 100644 --- a/barkmanui/src/features/inventory/AddItem.tsx +++ b/barkmanui/src/features/inventory/AddItem.tsx @@ -74,7 +74,8 @@ function AddItem() { wrap="wrap"> Add Item - + ; function EditItem() { const params = useParams(); + const navigate = useNavigate(); const editItemForm = useForm({ mode: 'uncontrolled', @@ -54,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'); } From 9f0d28d919699c0012ed6eea1662f43bba2f01db Mon Sep 17 00:00:00 2001 From: Drew Rautenberg Date: Mon, 3 Feb 2025 10:32:43 -0600 Subject: [PATCH 04/12] fixed incorrect update status map --- barkmanAPI/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/barkmanAPI/Program.cs b/barkmanAPI/Program.cs index 0d3297c..4284745 100644 --- a/barkmanAPI/Program.cs +++ b/barkmanAPI/Program.cs @@ -76,7 +76,7 @@ inventoryGroup.MapPut("/{id}", async (int id, InventoryItems updatedItem, BarkCo existingItem.Barcode = updatedItem.Barcode; existingItem.Brand = updatedItem.Brand; existingItem.SerialNumber = updatedItem.SerialNumber; - existingItem.Status = updatedItem.Status; + existingItem.StatusId = updatedItem.StatusId; existingItem.RentalPrice = updatedItem.RentalPrice; existingItem.ReplacementCost = updatedItem.ReplacementCost; existingItem.Notes = updatedItem.Notes; From eb17e4e68c25eb0a12c5175b9fe3a36fe8d55b83 Mon Sep 17 00:00:00 2001 From: Drew Rautenberg Date: Mon, 3 Feb 2025 10:33:55 -0600 Subject: [PATCH 05/12] changed get to return sorted by barcode --- barkmanAPI/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/barkmanAPI/Program.cs b/barkmanAPI/Program.cs index 4284745..5ede613 100644 --- a/barkmanAPI/Program.cs +++ b/barkmanAPI/Program.cs @@ -48,7 +48,7 @@ var itemStatusGroup = app.MapGroup(prefix: "/itemstatus") .WithDescription("Endpoints for managing item status"); inventoryGroup.MapGet("", async (BarkContext db) => - await db.Inventory.OrderBy(item => item.Id).ToListAsync()); + await db.Inventory.OrderBy(item => item.Barcode).ToListAsync()); inventoryGroup.MapGet("/{id}", async (int id, BarkContext db) => { From 571914ac0f5312b15778ddcfe2ba8d243d970b9a Mon Sep 17 00:00:00 2001 From: Drew Rautenberg Date: Mon, 3 Feb 2025 10:39:14 -0600 Subject: [PATCH 06/12] "Update inventory routes to include 'inventory' prefix. Adjusted routes and links throughout the inventory feature to include the 'inventory' prefix for improved path clarity and consistency. This change ensures better organization and aligns with routing standards across the application." --- barkmanui/src/App.tsx | 6 +++--- barkmanui/src/features/inventory/InventoryList.tsx | 4 ++-- barkmanui/src/features/inventory/ItemDetail.tsx | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/barkmanui/src/App.tsx b/barkmanui/src/App.tsx index b72505c..ac886f0 100644 --- a/barkmanui/src/App.tsx +++ b/barkmanui/src/App.tsx @@ -43,9 +43,9 @@ function App() { }/> }/> - }/> - }/> - }/> + }/> + }/> + }/> diff --git a/barkmanui/src/features/inventory/InventoryList.tsx b/barkmanui/src/features/inventory/InventoryList.tsx index 42e1512..4020b67 100644 --- a/barkmanui/src/features/inventory/InventoryList.tsx +++ b/barkmanui/src/features/inventory/InventoryList.tsx @@ -37,7 +37,7 @@ function InventoryList() {

ARFF ARFF BARK BARK

- Add Item + Add Item @@ -61,7 +61,7 @@ function InventoryList() { {data.name} {data.statusId} - Details + Details
))} diff --git a/barkmanui/src/features/inventory/ItemDetail.tsx b/barkmanui/src/features/inventory/ItemDetail.tsx index eb0d5f5..b1e7a44 100644 --- a/barkmanui/src/features/inventory/ItemDetail.tsx +++ b/barkmanui/src/features/inventory/ItemDetail.tsx @@ -38,7 +38,7 @@ function ItemDetail() { Replacement Cost: ${data.replacementCost} Notes: {data.notes} - Edit + Edit ) From 54adaa99ceb73e529de21ac65b983352ce3309bb Mon Sep 17 00:00:00 2001 From: Drew Rautenberg Date: Mon, 3 Feb 2025 11:23:16 -0600 Subject: [PATCH 07/12] added query to return last used barcode and autopoulate field --- barkmanui/src/features/inventory/AddItem.tsx | 24 +++++++++++++++++-- .../src/features/inventory/InventoryList.tsx | 1 - barkmanui/src/features/inventory/types.ts | 1 + 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/barkmanui/src/features/inventory/AddItem.tsx b/barkmanui/src/features/inventory/AddItem.tsx index 33be18c..f457a06 100644 --- a/barkmanui/src/features/inventory/AddItem.tsx +++ b/barkmanui/src/features/inventory/AddItem.tsx @@ -1,7 +1,7 @@ import {Button, Group, TextInput, NumberInput, Container, Title, Flex} from '@mantine/core'; import {useForm} from '@mantine/form'; -import {useMutation} from "@tanstack/react-query"; -import {NewItem} from "./types.ts"; +import {useMutation, useQuery} from "@tanstack/react-query"; +import {InventoryItem, NewItem} from "./types.ts"; import { useNavigate} from "react-router"; import { IconX, IconCheck } from '@tabler/icons-react'; import { notifications } from '@mantine/notifications'; @@ -10,9 +10,29 @@ function AddItem() { const navigate = useNavigate(); + const { isPending, error, data} = 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() + }, + }); + + if (isPending) return 'Loading...' + + if (error) return 'An error has occurred: ' + error.message + + const lastBarcode = data[data.length - 1].barcode; + const newItemForm = useForm({ mode: 'uncontrolled', initialValues: { + barcode: lastBarcode + 1, name: "", brand: "", serialNumber: "", diff --git a/barkmanui/src/features/inventory/InventoryList.tsx b/barkmanui/src/features/inventory/InventoryList.tsx index 4020b67..d97f18b 100644 --- a/barkmanui/src/features/inventory/InventoryList.tsx +++ b/barkmanui/src/features/inventory/InventoryList.tsx @@ -23,7 +23,6 @@ function InventoryList() { if (error) return 'An error has occurred: ' + error.message - return ( <> Date: Wed, 5 Feb 2025 10:57:08 -0600 Subject: [PATCH 08/12] maybe almost there --- .../src/features/inventory/InventoryList.tsx | 22 +++---------------- .../inventory/hooks/useInventoryList.tsx | 17 ++++++++++++++ 2 files changed, 20 insertions(+), 19 deletions(-) create mode 100644 barkmanui/src/features/inventory/hooks/useInventoryList.tsx diff --git a/barkmanui/src/features/inventory/InventoryList.tsx b/barkmanui/src/features/inventory/InventoryList.tsx index d97f18b..764293f 100644 --- a/barkmanui/src/features/inventory/InventoryList.tsx +++ b/barkmanui/src/features/inventory/InventoryList.tsx @@ -1,27 +1,13 @@ -import {useQuery} from "@tanstack/react-query"; -import {InventoryItem} from "./types"; import {Flex, Table} from '@mantine/core'; import BarkButton from "../../common/components/BarkButton.tsx"; import {Link, NavLink} from "react-router"; +import useInventoryList from "./hooks/useInventoryList.tsx"; function InventoryList() { - const { isPending, error, data, isFetching } = useQuery({ - queryKey: ['inventory'], - queryFn: async (): Promise => { - const response = await fetch( - import.meta.env.VITE_API_URL + '/inventory', - ) + const data = useInventoryList(); - if (!response.ok) throw new Error('Failed to fetch inventory ' + response.statusText) - return await response.json() - }, - }); - - if (isPending) return 'Loading...' - - if (error) return 'An error has occurred: ' + error.message return ( <> @@ -40,8 +26,6 @@ function InventoryList() { -
{isFetching ? 'Updating...' : ''}
- @@ -53,7 +37,7 @@ function InventoryList() { - {data.map((data) => ( + {data?.map((data) => ( {data.barcode} {data.brand} 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 From 15e5957ecf8a5f5d4636be28c8cc8f8ad712ae71 Mon Sep 17 00:00:00 2001 From: Drew Rautenberg Date: Wed, 5 Feb 2025 11:16:03 -0600 Subject: [PATCH 09/12] it works! --- barkmanui/src/features/inventory/InventoryList.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/barkmanui/src/features/inventory/InventoryList.tsx b/barkmanui/src/features/inventory/InventoryList.tsx index 764293f..5a6054c 100644 --- a/barkmanui/src/features/inventory/InventoryList.tsx +++ b/barkmanui/src/features/inventory/InventoryList.tsx @@ -3,11 +3,16 @@ import BarkButton from "../../common/components/BarkButton.tsx"; import {Link, NavLink} from "react-router"; import useInventoryList from "./hooks/useInventoryList.tsx"; + function InventoryList() { - const data = useInventoryList(); + const rawData = useInventoryList(); + if (rawData.isPending) return 'Loading...' + if (rawData.error) return 'An error has occurred: ' + rawData.error.message + + const data = rawData.data return ( <> @@ -25,7 +30,6 @@ function InventoryList() { Add Item -
From f5646fa6cf943f9634422723eacd58c47f16e011 Mon Sep 17 00:00:00 2001 From: Drew Rautenberg Date: Wed, 5 Feb 2025 11:42:06 -0600 Subject: [PATCH 10/12] sort works, barcode is weird --- barkmanui/src/features/inventory/AddItem.tsx | 54 +++++++++----------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/barkmanui/src/features/inventory/AddItem.tsx b/barkmanui/src/features/inventory/AddItem.tsx index f457a06..bff6b3a 100644 --- a/barkmanui/src/features/inventory/AddItem.tsx +++ b/barkmanui/src/features/inventory/AddItem.tsx @@ -1,38 +1,22 @@ import {Button, Group, TextInput, NumberInput, Container, Title, Flex} from '@mantine/core'; import {useForm} from '@mantine/form'; -import {useMutation, useQuery} from "@tanstack/react-query"; -import {InventoryItem, NewItem} from "./types.ts"; -import { useNavigate} from "react-router"; -import { IconX, IconCheck } from '@tabler/icons-react'; -import { notifications } from '@mantine/notifications'; +import {useMutation} from "@tanstack/react-query"; +import {NewItem} from "./types.ts"; +import {useNavigate} from "react-router"; +import {IconX, IconCheck} from '@tabler/icons-react'; +import {notifications} from '@mantine/notifications'; +import useInventoryList from "./hooks/useInventoryList.tsx"; function AddItem() { const navigate = useNavigate(); - const { isPending, error, data} = 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() - }, - }); - - if (isPending) return 'Loading...' - - if (error) return 'An error has occurred: ' + error.message - - const lastBarcode = data[data.length - 1].barcode; + const rawData = useInventoryList(); const newItemForm = useForm({ mode: 'uncontrolled', initialValues: { - barcode: lastBarcode + 1, + barcode: 0, name: "", brand: "", serialNumber: "", @@ -56,8 +40,8 @@ function AddItem() { if (result.ok) { notifications.show({ - icon: , - color:"teal", + icon: , + color: "teal", title: "All good!", message: "Item Created", position: 'top-center', @@ -68,8 +52,8 @@ function AddItem() { if (!result.ok) { notifications.show({ - icon: , - color:"red", + icon: , + color: "red", title: "Bummer!", message: "Something went wrong", position: 'top-center', @@ -77,9 +61,16 @@ function AddItem() { throw new Error('Failed to create inventory item'); } - } + }, + + }) + if (rawData.isPending) return 'Loading...' + if (rawData.error) return 'An error has occurred: ' + rawData.error.message + const data = rawData.data + const nextBarcode = data[data.length - 1].barcode + 1; + return ( <> @@ -94,8 +85,9 @@ function AddItem() { wrap="wrap"> Add Item - + Date: Wed, 5 Feb 2025 13:01:47 -0600 Subject: [PATCH 11/12] barcode works and populates next available --- barkmanui/src/features/inventory/AddItem.tsx | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/barkmanui/src/features/inventory/AddItem.tsx b/barkmanui/src/features/inventory/AddItem.tsx index bff6b3a..8ba7709 100644 --- a/barkmanui/src/features/inventory/AddItem.tsx +++ b/barkmanui/src/features/inventory/AddItem.tsx @@ -6,6 +6,8 @@ import {useNavigate} from "react-router"; import {IconX, IconCheck} from '@tabler/icons-react'; import {notifications} from '@mantine/notifications'; import useInventoryList from "./hooks/useInventoryList.tsx"; +import {useEffect} from "react"; + function AddItem() { @@ -66,10 +68,18 @@ function AddItem() { }) + useEffect(() => { + if (rawData.data) { + const data = rawData.data; + const nextBarcode = data[data.length - 1].barcode + 1; + newItemForm.setValues({barcode: nextBarcode}); + } + },[rawData.data]); + if (rawData.isPending) return 'Loading...' if (rawData.error) return 'An error has occurred: ' + rawData.error.message - const data = rawData.data - const nextBarcode = data[data.length - 1].barcode + 1; + + return ( @@ -86,8 +96,7 @@ function AddItem() { Add Item + placeholder="Barcode" {...newItemForm.getInputProps('barcode')}/> Date: Wed, 5 Feb 2025 13:06:36 -0600 Subject: [PATCH 12/12] refactored unneeded code --- barkmanui/src/features/inventory/AddItem.tsx | 13 ++++++------- barkmanui/src/features/inventory/InventoryList.tsx | 9 ++++----- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/barkmanui/src/features/inventory/AddItem.tsx b/barkmanui/src/features/inventory/AddItem.tsx index 8ba7709..a335528 100644 --- a/barkmanui/src/features/inventory/AddItem.tsx +++ b/barkmanui/src/features/inventory/AddItem.tsx @@ -13,7 +13,7 @@ function AddItem() { const navigate = useNavigate(); - const rawData = useInventoryList(); + const inventoryQuery = useInventoryList(); const newItemForm = useForm({ mode: 'uncontrolled', @@ -69,15 +69,14 @@ function AddItem() { }) useEffect(() => { - if (rawData.data) { - const data = rawData.data; - const nextBarcode = data[data.length - 1].barcode + 1; + if (inventoryQuery.data) { + const nextBarcode = inventoryQuery.data[inventoryQuery.data.length - 1].barcode + 1; newItemForm.setValues({barcode: nextBarcode}); } - },[rawData.data]); + },[inventoryQuery.data]); - if (rawData.isPending) return 'Loading...' - if (rawData.error) return 'An error has occurred: ' + rawData.error.message + if (inventoryQuery.isPending) return 'Loading...' + if (inventoryQuery.error) return 'An error has occurred: ' + inventoryQuery.error.message diff --git a/barkmanui/src/features/inventory/InventoryList.tsx b/barkmanui/src/features/inventory/InventoryList.tsx index 5a6054c..c6df33f 100644 --- a/barkmanui/src/features/inventory/InventoryList.tsx +++ b/barkmanui/src/features/inventory/InventoryList.tsx @@ -6,13 +6,12 @@ import useInventoryList from "./hooks/useInventoryList.tsx"; function InventoryList() { - const rawData = useInventoryList(); + const inventoryQuery = useInventoryList(); - if (rawData.isPending) return 'Loading...' + if (inventoryQuery.isPending) return 'Loading...' - if (rawData.error) return 'An error has occurred: ' + rawData.error.message + if (inventoryQuery.error) return 'An error has occurred: ' + inventoryQuery.error.message - const data = rawData.data return ( <> @@ -41,7 +40,7 @@ function InventoryList() { - {data?.map((data) => ( + {inventoryQuery.data?.map((data) => ( {data.barcode} {data.brand}