diff --git a/barkmanui/src/features/customers/CustomerList.tsx b/barkmanui/src/features/customers/CustomerList.tsx new file mode 100644 index 0000000..3a8f9e4 --- /dev/null +++ b/barkmanui/src/features/customers/CustomerList.tsx @@ -0,0 +1,54 @@ +import {Flex, Table} from '@mantine/core'; +import BarkButton from "../../common/components/BarkButton.tsx"; +import {Link, NavLink} from "react-router"; +import useCustomerList from "./hooks/useCustomerList.tsx"; + + +function CustomerList() { + + const customerQuery = useCustomerList(); + + if (customerQuery.isPending) return 'Loading...' + + if (customerQuery.error) return 'An error has occurred: ' + customerQuery.error.message + + + return ( + <> + +

+ ARFF ARFF BARK BARK +

+ Add Item +
+ + + + + Name + Company + + + + {customerQuery.data?.map((data) => ( + + {data.name} + {data.company} + + Details + + + ))} + +
+ + ) +} +export default CustomerList; \ No newline at end of file diff --git a/barkmanui/src/features/customers/hooks/useCustomerList.tsx b/barkmanui/src/features/customers/hooks/useCustomerList.tsx new file mode 100644 index 0000000..0cbae87 --- /dev/null +++ b/barkmanui/src/features/customers/hooks/useCustomerList.tsx @@ -0,0 +1,17 @@ +import {useQuery} from "@tanstack/react-query"; +import {Customer} from "../types.ts"; + + const useCustomerList = () => useQuery({ + queryKey: ['customer'], + queryFn: async (): Promise => { + const response = await fetch( + import.meta.env.VITE_API_URL + '/custmoers', + ) + + if (!response.ok) throw new Error('Failed to fetch customers ' + response.statusText) + + return await response.json() + }, + }); + +export default useCustomerList; \ No newline at end of file diff --git a/barkmanui/src/features/customers/types.ts b/barkmanui/src/features/customers/types.ts new file mode 100644 index 0000000..7029951 --- /dev/null +++ b/barkmanui/src/features/customers/types.ts @@ -0,0 +1,10 @@ +export interface Customer { + id: number, + name: string, + company: string, + email: string, + phone: string, + address: string, + billingTerms: string, + notes: string, +} \ No newline at end of file