new item works

This commit is contained in:
2025-01-29 14:38:27 -06:00
parent 451f108a3f
commit aa4ff86d3e
2 changed files with 43 additions and 51 deletions
+18 -33
View File
@@ -1,36 +1,25 @@
import {Button, Group, TextInput, Text, Textarea, NumberInput, Container, Title, Flex} from '@mantine/core';
import {Button, Group, TextInput, 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";
import {useMutation} from "@tanstack/react-query";
import {NewItem} from "./types.ts";
type EditableInventoryItem = Omit<InventoryItem, 'id'>;
function AddItem() {
function EditItem() {
const params = useParams();
const editItemForm = useForm<EditableInventoryItem>({
const newItemForm = useForm<NewItem>({
mode: 'uncontrolled',
initialValues: {
name: "",
brand: "",
statusId: "",
status: {name: "", id: ""},
serialNumber: "",
rentalPrice: 0,
replacementCost: 0,
notes: "",
},
validate: {},
});
const updateItem = useMutation({
mutationFn: async (values: EditableInventoryItem) => {
mutationFn: async (values: NewItem) => {
const result = await fetch(import.meta.env.VITE_API_URL + '/inventory', {
method: 'POST',
@@ -50,7 +39,7 @@ function EditItem() {
return (
<>
<form onSubmit={editItemForm.onSubmit(async (values) => await
<form onSubmit={newItemForm.onSubmit(async (values) => await
updateItem.mutateAsync(values))}>
<Container m="lg">
<Flex mih={50}
@@ -62,20 +51,16 @@ function EditItem() {
<Title order={1}>Add Item</Title>
<TextInput withAsterisk key={editItemForm.key('brand')} size="md" label="Brand"
placeholder="Brand" {...editItemForm.getInputProps('brand')}/>
<TextInput withAsterisk key={editItemForm.key('name')} size="md" label="Name"
placeholder="Name" {...editItemForm.getInputProps('name')}/>
<TextInput size="md" key={editItemForm.key('statusId')} label="Status"
placeholder="Status" {...editItemForm.getInputProps('statusId')}/>
<TextInput size="md" key={editItemForm.key('serialNumber')} label="Serial Number"
placeholder="Serial Number"{...editItemForm.getInputProps('serialNumber')}/>
<NumberInput size="md" key={editItemForm.key('rentalPrice')} label="Rental Price"
placeholder="Rental Price" {...editItemForm.getInputProps('rentalPrice')}/>
<NumberInput size="md" key={editItemForm.key('replacementCost')} label="Replacement Cost"
placeholder="Replacement Cost" {...editItemForm.getInputProps('replacementCost')}/>
<Textarea label="Notes" key={editItemForm.key('notes')}
placeholder="Notes" {...editItemForm.getInputProps('notes')}/>
<TextInput withAsterisk key={newItemForm.key('brand')} size="md" label="Brand"
placeholder="Brand" {...newItemForm.getInputProps('brand')}/>
<TextInput withAsterisk key={newItemForm.key('name')} size="md" label="Name"
placeholder="Name" {...newItemForm.getInputProps('name')}/>
<TextInput size="md" key={newItemForm.key('serialNumber')} label="Serial Number"
placeholder="Serial Number"{...newItemForm.getInputProps('serialNumber')}/>
<NumberInput size="md" key={newItemForm.key('rentalPrice')} label="Rental Price"
placeholder="Rental Price" {...newItemForm.getInputProps('rentalPrice')}/>
<NumberInput size="md" key={newItemForm.key('replacementCost')} label="Replacement Cost"
placeholder="Replacement Cost" {...newItemForm.getInputProps('replacementCost')}/>
<Group justify="flex-end" mt="md">
<Button type="submit">Submit</Button>
@@ -87,4 +72,4 @@ function EditItem() {
);
}
export default EditItem;
export default AddItem;
+8 -1
View File
@@ -8,5 +8,12 @@ export interface InventoryItem {
rentalPrice: number,
replacementCost: number,
notes: string,
}
export interface NewItem {
brand: string,
name: string,
serialNumber: string,
rentalPrice: number,
replacementCost: number,
}