From 78e0c54a27a5760e1b4c3e3e41d79e650d9dce95 Mon Sep 17 00:00:00 2001 From: Tristan Barlet Date: Wed, 11 Jan 2023 09:50:11 -0500 Subject: [PATCH 1/2] Barre de recherche dans les contacts selon : nom prenom du contact numero de tel entreprise --- server-api/api.js | 8 ++++---- src/pages/Repertoire.js | 41 +++++++++++++++++++++++++++++++---------- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/server-api/api.js b/server-api/api.js index 283f1e9..2a4086d 100644 --- a/server-api/api.js +++ b/server-api/api.js @@ -454,15 +454,15 @@ app.get('/Contact/:iduser', (req, res) => { }); }); -app.put('/Contact/Update/:phone', (req, res) => { +app.put('/Contact/Update/:idcontact', (req, res) => { - const phone = req.params.phone; + const idcontact = req.params.idcontact; let form = req.body; - const sql = `UPDATE contacts SET firstname = ?, lastname = ?, mail = ?, phone = ? WHERE (phone = ?)`; + const sql = `UPDATE contacts SET firstname = ?, lastname = ?, mail = ?, phone = ? WHERE (idcontact = ?)`; - db.query(sql, [form.firstname, form.lastname, form.mail, form.phone, phone], (err, result) => { + db.query(sql, [form.firstname, form.lastname, form.mail, form.phone, idcontact], (err, result) => { if (err) throw err; console.log(result); }); diff --git a/src/pages/Repertoire.js b/src/pages/Repertoire.js index a8463b7..bcecdba 100644 --- a/src/pages/Repertoire.js +++ b/src/pages/Repertoire.js @@ -25,16 +25,19 @@ function Repertoire() { const [SearchTerm, setSearchTerm] = useState(""); const [SearchResults, setSearchResults] = useState([]); const [customers, setCustomers] = useState([]); - console.log("contacts", contacts); + + useEffect(() => { + console.log("useEffect appel api contact"); const apiString = '/Contact/' + Session.get("idUser"); api.get(apiString).then((response) => { setContacts(response.data); + setSearchResults(response.data); console.log("response.data", response.data); - setSearchTerm(response.data[0].idcontact); + }); - }, [modifContact]); + }, [null,contactSelectionne]); useEffect(() => { api.get('/Customer/All').then((response) => { @@ -42,6 +45,19 @@ function Repertoire() { }); }, []); + useEffect(() => { + + const results = contacts.filter(contact => + contact.lastname.toLowerCase().includes(SearchTerm.toLowerCase()) + || contact.firstname.toLowerCase().includes(SearchTerm.toLowerCase()) + || contact.mail.toLowerCase().includes(SearchTerm.toLowerCase()) + || contact.phone.toLowerCase().startsWith(SearchTerm.toLowerCase()) + || contact.name.toLowerCase().includes(SearchTerm.toLowerCase()) + || SearchTerm.trim().length === 0 + ); + setSearchResults(results); + }, [null, SearchTerm, modifContact]); + function handleDeleteClick(contact) { api.delete('/Contact/Delete/' + contact.idcontact).then((response) => { const newContacts = contacts.filter((c) => c.idcontact !== contact.idcontact); @@ -68,7 +84,7 @@ function Repertoire() { phone: phone, idcontact: props.contact.idcontact, }; - api.put('/Contact/Update/' + props.contact.phone, contact).then((response) => {}); + api.put('/Contact/Update/' + props.contact.idcontact, contact).then((response) => {}); setModifContact(false); setContactSelectionne(contact); }; @@ -120,7 +136,7 @@ function Repertoire() { ); - } + } return ( @@ -139,7 +155,7 @@ function Repertoire() { { contactSelectionne === "" ?
- + setSearchTerm(event.target.value)} /> @@ -147,9 +163,12 @@ function Repertoire() { : } - - - + { contactSelectionne === "" ? + + + + + :} { contactSelectionne === "" ? @@ -159,15 +178,17 @@ function Repertoire() { Photo Nom Prénom + Téléphone Entreprise - {contacts.map((contact) => ( + {SearchResults.map((contact) => ( setContactSelectionne(contact)}> {contact.lastname} {contact.firstname} + {contact.phone} {contact.name} ))} From ef043a468c1408aa05c87e7cf7cfc71641599dd1 Mon Sep 17 00:00:00 2001 From: Tristan Barlet Date: Wed, 11 Jan 2023 10:19:42 -0500 Subject: [PATCH 2/2] mdp oublie mise en place --- src/pages/Connexion.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/pages/Connexion.js b/src/pages/Connexion.js index f912584..2e0dfca 100644 --- a/src/pages/Connexion.js +++ b/src/pages/Connexion.js @@ -24,6 +24,7 @@ function Connexion() { const [login, setLogin] = useState(""); const [password, setPassword] = useState(""); const [roleUser, setRole] = useState(""); + const [mdpOublie, setMdpOublie] = useState(false); function changeLogin(event) { setLogin(event.target.value); @@ -98,6 +99,15 @@ function Connexion() { ) : (
+ { mdpOublie ? +
+ +

Contactez votre administrateur système afin qu'il vérifie votre identité et vous regénére un mot de passe

+ +
+ :
); }