diff --git a/barkmanui/src/App.tsx b/barkmanui/src/App.tsx index f9b327e..c262ba4 100644 --- a/barkmanui/src/App.tsx +++ b/barkmanui/src/App.tsx @@ -11,6 +11,7 @@ import AddItem from "./features/inventory/AddItem.tsx"; import { Notifications } from '@mantine/notifications'; import '@mantine/notifications/styles.css'; import CustomerList from "@/features/customers/CustomerList.tsx"; +import AddCustomer from "@/features/customers/AddCustomer.tsx"; // Create a client const queryClient = new QueryClient() @@ -48,6 +49,7 @@ function App() { }/> }/> }/> + }/> diff --git a/barkmanui/src/features/customers/AddCustomer.tsx b/barkmanui/src/features/customers/AddCustomer.tsx new file mode 100644 index 0000000..825a40f --- /dev/null +++ b/barkmanui/src/features/customers/AddCustomer.tsx @@ -0,0 +1,109 @@ +import {Button, Group, TextInput, NumberInput, Container, Title, Flex} from '@mantine/core'; +import {useForm} from '@mantine/form'; +import {useMutation} from "@tanstack/react-query"; +import {NewCustomer} from "./types.ts"; +import {useNavigate} from "react-router"; +import {IconX, IconCheck} from '@tabler/icons-react'; +import {notifications} from '@mantine/notifications'; +import useCustomerList from "./hooks/useCustomerList.tsx"; + + +function AddCustomer() { + + const navigate = useNavigate(); + + const customerQuery = useCustomerList(); + + const newCustomerForm = useForm({ + mode: 'uncontrolled', + initialValues: { + name: "", + company: "", + email: "", + phone: "", + address: "", + }, + + validate: {}, + }); + + const updateCustomer = useMutation({ + mutationFn: async (values: NewCustomer) => { + + const result = await fetch(import.meta.env.VITE_API_URL + '/customers', { + method: 'POST', + body: JSON.stringify(values), + headers: { + 'Content-Type': 'application/json' + } + }); + + if (result.ok) { + notifications.show({ + icon: , + color: "teal", + title: "All good!", + message: "Customer Created", + position: 'top-center', + }); + navigate("/customers"); + + } + + if (!result.ok) { + notifications.show({ + icon: , + color: "red", + title: "Bummer!", + message: "Something went wrong", + position: 'top-center', + }); + throw new Error('Failed to create customer'); + } + + }, + + + }) + + if (customerQuery.isPending) return 'Loading...' + if (customerQuery.error) return 'An error has occurred: ' + customerQuery.error.message + + + + + return ( + <> +
await + updateCustomer.mutateAsync(values))}> + + + + Add Item + + + + + + + + + + + +
+ + ); +} + +export default AddCustomer; \ No newline at end of file diff --git a/barkmanui/src/features/customers/CustomerList.tsx b/barkmanui/src/features/customers/CustomerList.tsx index 3a8f9e4..7e4cd0f 100644 --- a/barkmanui/src/features/customers/CustomerList.tsx +++ b/barkmanui/src/features/customers/CustomerList.tsx @@ -26,7 +26,7 @@ function CustomerList() {

ARFF ARFF BARK BARK

- Add Item + Add Customer diff --git a/barkmanui/src/features/customers/types.ts b/barkmanui/src/features/customers/types.ts index 7a1023d..6451203 100644 --- a/barkmanui/src/features/customers/types.ts +++ b/barkmanui/src/features/customers/types.ts @@ -11,7 +11,7 @@ export interface Customer { export interface NewCustomer { name: string, company: string, - email: number, - phone: number, + email: string, + phone: string, address: string, } \ No newline at end of file