This repository was archived by the owner on Feb 9, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 753
Expand file tree
/
Copy pathCustomerProfile.js
More file actions
61 lines (55 loc) · 1.53 KB
/
CustomerProfile.js
File metadata and controls
61 lines (55 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { useState, useEffect } from "react";
const CustomerProfile = ({ id }) => {
const [allCustomerData, setAllCustomerData] = useState();
const [isLoading, setIsLoading] = useState(true);
const [errorMessage, setErrorMessage] = useState(null);
function doFetchForCustomerProf() {
fetch(`https://cyf-react.glitch.me/customers/${id}`)
.then((response) => {
if (!response.ok) {
throw new Error("Failed to fetch customer data.");
}
return response.json();
})
.then((data) => {
setAllCustomerData(data);
setIsLoading(false);
setErrorMessage(null);
})
.catch((error) => {
setIsLoading(false);
setErrorMessage(error.message);
});
}
useEffect(() => {
if (id) {
doFetchForCustomerProf();
}
}, [id]);
if (isLoading) {
return <p>Please wait while the customer information is loading...</p>;
}
if (errorMessage) {
return <p>{errorMessage}</p>;
}
return (
<div className="customer-card">
<h2>Customer Profile Card</h2>
<p>
<b>Customer ID:</b> {allCustomerData.id}
</p>
<p>
<b>Customer Name:</b> {allCustomerData.title}{" "}
{allCustomerData.firstName} {allCustomerData.surname}
</p>
<p>
<b>Customer email:</b> {allCustomerData.email}
</p>
<p>
<b>Customer Phone Number:</b> {allCustomerData.phoneNumber}
</p>
<p>{allCustomerData.vip ? "vip" : "not vip"}</p>
</div>
);
};
export default CustomerProfile;