source: my-react-app/src/components/Customers.js@ cfc16a3

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

RetaurantServiceImpl problemi
isAvailable od tableEntity...

  • Property mode set to 100644
File size: 3.0 KB
Line 
1import 'bootstrap/dist/css/bootstrap.min.css';
2import React, {useEffect, useState} from "react";
3import axios from "axios";
4import { Link } from 'react-router-dom';
5import { useNavigate } from 'react-router-dom';
6
7
8const Customers = () => {
9 const [customers, setCustomers] = useState([]);
10 const navigate = useNavigate();
11
12 useEffect(() => {
13 const fetchCustomers = async () => {
14 try {
15 const response = await axios.get("http://localhost:8080/api/customers");
16 setCustomers(response.data);
17 } catch (error) {
18 console.error("Error fetching customers: ", error);
19 }
20 };
21
22 fetchCustomers()
23 }, []);
24
25 const handleDetailClick = (customerId) => {
26 navigate(`/customers/${customerId}`);
27 }
28
29 const handleEditClick = (customerId) => {
30 navigate(`/customers/edit/${customerId}`);
31 }
32
33 const handleDeleteClick = async (customerId) => {
34 try {
35 await axios.delete(`http://localhost:8080/api/customers/delete/${customerId}`);
36 setCustomers(customers.filter(customer => customer.customerID !== customerId));
37 window.location.reload();
38 } catch (error) {
39 console.error("Error + " + error);
40 }
41 }
42
43 return (
44 <div className="container mt-4">
45 <h1 className="mb-4">Customer List</h1>
46 <div className="row row-cols-1 row-cols-md-3 g-4">
47 {customers
48 .filter(customer => customer.role !== 'admin')
49 .map((customer) => (
50 <div className="col" key={customer.customerId}>
51 <div className="card h-100">
52 <div className="card-body">
53 <h5 className="card-title">{customer.fullName}</h5>
54 <p className="card-text"><strong>Email:</strong> {customer.email}</p>
55 <p className="card-text"><strong>Phone:</strong> {customer.phone}</p>
56 <p className="card-text"><strong>Address:</strong> {customer.address}</p>
57 <p className="card-text"><strong>Membership
58 Level:</strong> {customer.membershipLevel}</p>
59 <p className="card-text"><strong>Registration
60 Date:</strong> {new Date(customer.registrationDate).toLocaleString()}</p>
61 </div>
62 <button onClick={() => handleDetailClick(customer.customerId)}>View Details</button>
63 <button onClick={() => handleEditClick(customer.customerId)}>Edit</button>
64 <button onClick={() => handleDeleteClick(customer.customerId)}>DELETE</button>
65 </div>
66 </div>
67 ))}
68 </div>
69 </div>
70 );
71
72}
73
74export default Customers;
Note: See TracBrowser for help on using the repository browser.