diff --git a/server-api/api.js b/server-api/api.js
index bc4e8e6..a1cec21 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/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() {
) : (
);
}
diff --git a/src/pages/Repertoire.js b/src/pages/Repertoire.js
index 4770d8d..bcecdba 100644
--- a/src/pages/Repertoire.js
+++ b/src/pages/Repertoire.js
@@ -25,14 +25,19 @@ function Repertoire() {
const [SearchTerm, setSearchTerm] = useState("");
const [SearchResults, setSearchResults] = useState([]);
const [customers, setCustomers] = useState([]);
+
+
useEffect(() => {
+ console.log("useEffect appel api contact");
const apiString = '/Contact/' + Session.get("idUser");
api.get(apiString).then((response) => {
setContacts(response.data);
- setSearchTerm(response.data[0].idcontact);
+ setSearchResults(response.data);
+ console.log("response.data", response.data);
+
});
- }, [modifContact]);
+ }, [null,contactSelectionne]);
useEffect(() => {
api.get('/Customer/All').then((response) => {
@@ -40,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);
@@ -66,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);
};
@@ -118,7 +136,7 @@ function Repertoire() {
);
- }
+ }
return (
@@ -137,7 +155,7 @@ function Repertoire() {
{ contactSelectionne === "" ?
-
+
setSearchTerm(event.target.value)} />
@@ -145,9 +163,12 @@ function Repertoire() {
:
}
-
-
-
+ { contactSelectionne === "" ?
+
+
+
+
+ :
}
{ contactSelectionne === "" ?
@@ -157,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}
))}