source: my-react-app/src/components/CustomerDetails.js@ 8ca35dc

main
Last change on this file since 8ca35dc was 8ca35dc, checked in by Aleksandar Panovski <apano77@…>, 4 months ago

Done with stupid timeslots

  • Property mode set to 100644
File size: 1.3 KB
Line 
1import React, { useEffect, useState } from 'react';
2import axios from 'axios';
3import { useParams } from 'react-router-dom';
4
5const CustomerDetails = () => {
6 const { id } = useParams();
7 const [customer, setCustomer] = useState(null);
8
9 useEffect(() => {
10 const fetchCustomer = async () => {
11 try {
12 const response = await axios.get(`http://localhost:8081/api/customers/${id}`);
13 setCustomer(response.data);
14 } catch (error) {
15 console.error('Error fetching customer:', error);
16 }
17 };
18
19 fetchCustomer();
20 }, [id]);
21
22 if (!customer) {
23 return <div>Loading...</div>;
24 }
25
26 return (
27 <div>
28 <h2>Customer Details</h2>
29 <p className="card-text"><strong>Email:</strong> {customer.email}</p>
30 <p className="card-text"><strong>Phone:</strong> {customer.phone}</p>
31 <p className="card-text"><strong>Address:</strong> {customer.address}</p>
32 <p className="card-text"><strong>Membership
33 Level:</strong> {customer.membershipLevel}</p>
34 <p className="card-text"><strong>Registration
35 Date:</strong> {new Date(customer.registrationDate).toLocaleString()}</p>
36 </div>
37 );
38}
39
40export default CustomerDetails;
Note: See TracBrowser for help on using the repository browser.