MCPcopy Create free account
hub / github.com/amigoscode/full-stack-professional / Customer

Function Customer

frontend/react/src/Customer.jsx:14–93  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12import {errorNotification} from "./services/notification.js";
13
14const Customer = () => {
15
16 const [customers, setCustomers] = useState([]);
17 const [loading, setLoading] = useState(false);
18 const [err, setError] = useState("");
19
20 const fetchCustomers = () => {
21 setLoading(true);
22 getCustomers().then(res => {
23 setCustomers(res.data)
24 }).catch(err => {
25 setError(err.response.data.message)
26 errorNotification(
27 err.code,
28 err.response.data.message
29 )
30 }).finally(() => {
31 setLoading(false)
32 })
33 }
34
35 useEffect(() => {
36 fetchCustomers();
37 }, [])
38
39 if (loading) {
40 return (
41 <SidebarWithHeader>
42 <Spinner
43 thickness='4px'
44 speed='0.65s'
45 emptyColor='gray.200'
46 color='blue.500'
47 size='xl'
48 />
49 </SidebarWithHeader>
50 )
51 }
52
53 if (err) {
54 return (
55 <SidebarWithHeader>
56 <CreateCustomerDrawer
57 fetchCustomers={fetchCustomers}
58 />
59 <Text mt={5}>Ooops there was an error</Text>
60 </SidebarWithHeader>
61 )
62 }
63
64 if(customers.length <= 0) {
65 return (
66 <SidebarWithHeader>
67 <CreateCustomerDrawer
68 fetchCustomers={fetchCustomers}
69 />
70 <Text mt={5}>No customers available</Text>
71 </SidebarWithHeader>

Callers

nothing calls this directly

Calls 1

fetchCustomersFunction · 0.85

Tested by

no test coverage detected