import 'bootstrap/dist/css/bootstrap.min.css'; import React, {useContext, useEffect, useState} from "react"; import axios from "axios"; import { Link } from 'react-router-dom'; import { useNavigate } from 'react-router-dom'; import {CustomerContext} from "./CustomerContext"; const Customers = () => { const [customers, setCustomers] = useState([]); const navigate = useNavigate(); const customersContext = useContext(CustomerContext); useEffect(() => { setCustomers(customersContext.customers) }, [customersContext]); const handleDetailClick = (customerId) => { navigate(`/customers/${customerId}`); } const handleEditClick = (customerId) => { navigate(`/customers/edit/${customerId}`); } const handleDeleteClick = async (customerId) => { try { await axios.delete(`http://localhost:8080/api/customers/delete/${customerId}`); setCustomers(customers.filter(customer => customer.customerID !== customerId)); window.location.reload(); } catch (error) { console.error("Error + " + error); } } return (

Customer List

{customers .filter(customer => customer.role !== 'admin') .map((customer) => (
{customer.firstName + " " + customer.lastName}

Email: {customer.email}

Phone: {customer.phone}

Address: {customer.address}

Membership Level: {customer.membershipLevel}

{/*

Registration*/} {/* Date: {new Date(customer.registrationDate).toLocaleString()}

*/}
))}
); } export default Customers;