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 { useNavigate} from "react-router"; import { IconX, IconCheck } from '@tabler/icons-react'; import { notifications } from '@mantine/notifications'; function AddItem() { const navigate = useNavigate(); const newItemForm = useForm({ mode: 'uncontrolled', initialValues: { name: "", brand: "", serialNumber: "", rentalPrice: 0, replacementCost: 0, }, validate: {}, }); const updateItem = useMutation({ mutationFn: async (values: NewItem) => { 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) { notifications.show({ icon: , color:"teal", title: "All good!", message: "Item Created", 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 create inventory item'); } } }) return ( <>
await updateItem.mutateAsync(values))}> Add Item
); } export default AddItem;