diff --git a/barkmanui/.env b/barkmanui/.env index c62e21a..29a2dbd 100644 --- a/barkmanui/.env +++ b/barkmanui/.env @@ -1 +1 @@ -VITE_API_URL=http://localhost:5145 \ No newline at end of file +VITE_API_URL=https://barkdev.ts.drewr.io \ No newline at end of file diff --git a/barkmanui/src/App.tsx b/barkmanui/src/App.tsx index e3753f9..9963f2d 100644 --- a/barkmanui/src/App.tsx +++ b/barkmanui/src/App.tsx @@ -7,6 +7,7 @@ import '@mantine/core/styles.css'; import ItemDetail from "./features/inventory/ItemDetail.tsx"; import EditItem from "./features/inventory/EditItem.tsx"; import {BarkHeader} from "./common/components/BarkHeader.tsx"; +import AddItem from "./features/inventory/AddItem.tsx"; // Create a client const queryClient = new QueryClient() @@ -40,6 +41,7 @@ function App() { }/> }/> }/> + }/> diff --git a/barkmanui/src/features/inventory/AddItem.tsx b/barkmanui/src/features/inventory/AddItem.tsx new file mode 100644 index 0000000..6fb76e7 --- /dev/null +++ b/barkmanui/src/features/inventory/AddItem.tsx @@ -0,0 +1,90 @@ +import {Button, Group, TextInput, Text, 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"; +import {InventoryItem} from "./types.ts"; +import {useEffect} from "react"; + +type EditableInventoryItem = Omit; + +function EditItem() { + const params = useParams(); + + const editItemForm = useForm({ + mode: 'uncontrolled', + initialValues: { + name: "", + brand: "", + statusId: "", + status: {name: "", id: ""}, + serialNumber: "", + rentalPrice: 0, + replacementCost: 0, + notes: "", + }, + + validate: {}, + }); + + + + + const updateItem = useMutation({ + mutationFn: async (values: EditableInventoryItem) => { + + const result = await fetch(import.meta.env.VITE_API_URL + '/inventory' , { + method: 'POST', + body: JSON.stringify(values), + headers: { + 'Content-Type': 'application/json' + } + }); + + if (!result.ok) { + throw new Error('Failed to update inventory item'); + } + + } + }) + + + return ( + <> +
await + updateItem.mutateAsync(values))}> + + + + Add Item + + + + + + + +