diff --git a/barkmanui/src/features/inventory/EditItem.tsx b/barkmanui/src/features/inventory/EditItem.tsx index 2755408..3859a82 100644 --- a/barkmanui/src/features/inventory/EditItem.tsx +++ b/barkmanui/src/features/inventory/EditItem.tsx @@ -3,6 +3,7 @@ import { useForm } from '@mantine/form'; import {useParams} from "react-router"; import {useQuery} from "@tanstack/react-query"; import {InventoryItem} from "./types.ts"; +import {useEffect} from "react"; function EditItem() { const params = useParams(); @@ -10,14 +11,20 @@ function EditItem() { const form = useForm({ mode: 'uncontrolled', initialValues: { - email: '', - termsOfService: false, + name: "", + brand: "", + status: "", + serialNumber: "", + rentalPrice: 0, + replacementCost: 0, + notes: "", }, validate: { }, }); + const { isPending, error, data, isFetching } = useQuery({ queryKey: ['inventory', params.itemId], queryFn: async (): Promise => { @@ -31,22 +38,28 @@ function EditItem() { }, }); + useEffect(() => { + if (data) { + // Even if query.data changes, form will be initialized only once + form.initialize(data); + } + }, [data, form]); + if (isPending) return 'Loading...' if (error) return 'An error has occurred: ' + error.message - return (
console.log(values))}>
{isFetching ? 'Updating...' : ''}
ID: {data.id} - - - - - - -