import NavigationDashboard from '../components/NavigationDashboard';
import React, { useState, useEffect } from 'react';
import axios from 'axios';
import user from '../images/user.jpg';
import { TableContainer, Table, TableHead, TableBody, TableRow, TableCell } from '@mui/material';
import { Paper } from '@mui/material';
const api = axios.create({
baseURL: 'http://localhost:8080'
})
function Repertoire() {
const [theme, setTheme] = useState("light");
if (localStorage.getItem('theme') && localStorage.getItem("theme") !== '' && localStorage.getItem("theme") !== theme) {
setTheme(localStorage.getItem("theme"))
}
const [contacts, setContacts] = useState([]);
const [SearchTerm, setSearchTerm] = useState("");
const [SearchResults, setSearchResults] = useState([]);
const [customers, setCustomers] = useState([]);
useEffect(() => {
api.get('/Contact/AllWithCustomerName').then((response) => {
setContacts(response.data);
setSearchTerm(response.data[0].idcontact);
});
}, []);
useEffect(() => {
api.get('/Customer/All').then((response) => {
setCustomers(response.data);
});
}, []);
return (
{/* Create an account page */}
{/*
Entreprise
Nom
Prénom
{contacts.map((contact) => (
handleClick(event, contact.idcontact)}
// selected={contact.idcontact === selectedIdcontact}
>
{contact.idcustomer.name}
{contact.lastname}
{contact.firstname}
))}
*/}
);
};
// function Repertoire() {
// // NOW WITH THE USE OF HOOKS WE WILL GET THE CONTACTS
// const LOCAL_STORAGE_KEY = "contacts"
// const [contacts, setContacts] = useState([]);
// const [SearchTerm, setSearchTerm] = useState("");
// const [SearchResults, setSearchResults] = useState([]);
// const addContactHandler = async (contact) => {
// const request = {
// id: uuid(),
// ...contact
// }
// const response = await api.post("/contacts", request)
// setContacts([...contacts, response.data]);
// }
// // UPDATE CONTACT
// const updateContactHandler = async (contact) => {
// const response = await api.put(`/contacts/${contact.id}`, contact);
// const { id, name, email } = response.data;
// setContacts(contacts.map(contact => {
// return contact.id === id ? { ...response.data } : contact;
// }))
// }
// // FOR DELETING THE ITEMS
// const removeContactHandler = async (id) => {
// await api.delete(`/contacts/${id}`);
// const newContactList = contacts.filter((contact) => {
// return contact.id !== id;
// });
// setContacts(newContactList);
// }
// // SEARCHING THE CONTACTS
// const searchHandler = (searchTerm) => {
// setSearchTerm(searchTerm);
// if (searchTerm !== "") {
// const newContactList = contacts.filter((contact) => {
// return Object.values(contact).join(" ").toLowerCase().includes(searchTerm.toLowerCase());
// });
// setSearchResults(newContactList);
// } else {
// setSearchResults(contacts);
// }
// }
// useEffect(() => {
// const retrieveContacts = JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY));
// if (retrieveContacts) setContacts(retrieveContacts);
// }
// , []);
// useEffect(() => {
// localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(contacts));
// }
// , [contacts]);
// return (
//