|
|
|
@ -7,6 +7,7 @@ import MenuItem from '@mui/material/MenuItem';
|
|
|
|
|
import { NavLink } from 'react-router-dom';
|
|
|
|
|
import { useNavigate } from "react-router-dom";
|
|
|
|
|
import { Button } from '@mui/material';
|
|
|
|
|
import Session from 'react-session-api';
|
|
|
|
|
// HERE ABOVE useHistory IS REPLACED WITH useNavigate
|
|
|
|
|
|
|
|
|
|
const api = axios.create({
|
|
|
|
@ -18,6 +19,7 @@ function AddContact() {
|
|
|
|
|
const [loginError, setLoginError] = useState(false);
|
|
|
|
|
const [entreprises, setEntreprises] = useState([]);
|
|
|
|
|
const [selectedIdEntreprise, setSelectedIdEntreprise] = useState(1);
|
|
|
|
|
const [newContact, setNewContact] = useState([]);
|
|
|
|
|
|
|
|
|
|
const navigate=useNavigate();
|
|
|
|
|
|
|
|
|
@ -39,21 +41,24 @@ function AddContact() {
|
|
|
|
|
|
|
|
|
|
const formData = new FormData(event.currentTarget);
|
|
|
|
|
const values = Object.fromEntries(formData.entries());
|
|
|
|
|
console.log(values.name);
|
|
|
|
|
api.get('/Contact/Exist/'+ values.idcontact).then((response) => {
|
|
|
|
|
setNewContact(values);
|
|
|
|
|
setNewContact(newContact => [...newContact, Session.get('idUser')]);
|
|
|
|
|
console.log("c'est le new contact " ,newContact);
|
|
|
|
|
api.get('/Contact/Exist/'+ values.phone).then((response) => {
|
|
|
|
|
const login = response.data;
|
|
|
|
|
if (login.length > 0){
|
|
|
|
|
setLoginError(true);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
setLoginError(false);
|
|
|
|
|
|
|
|
|
|
api.post('/Contact/Add', values).then (function(response) {
|
|
|
|
|
const newContact = [firstname:values.firstname, lastname:values.lastname, phone:values.phone, mail:values.email, iduser:Session.get('idUser'), idcustomer:values.selectedIdEntreprise];
|
|
|
|
|
api.post('/Contact/Add', newContact).then (function(response) {
|
|
|
|
|
console.log(response.data);
|
|
|
|
|
});
|
|
|
|
|
console.log("c'est le new contact " ,newContact);
|
|
|
|
|
|
|
|
|
|
navigate("/Repertoire");
|
|
|
|
|
}
|
|
|
|
|
navigate("/Repertoire");
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -73,8 +78,8 @@ function AddContact() {
|
|
|
|
|
</div>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<input id="nom" name='name' className="texte_zone" type="text" placeholder="Nom..." required/>
|
|
|
|
|
<input id="prenom" name='firstname' className="texte_zone" type="text" placeholder="Prénom..." required/>
|
|
|
|
|
<input id="nom" name='firstname' className="texte_zone" type="text" placeholder="Nom..." required/>
|
|
|
|
|
<input id="prenom" name='lastname' className="texte_zone" type="text" placeholder="Prénom..." required/>
|
|
|
|
|
<input id="phone" name='phone' className="texte_zone" type="tel"
|
|
|
|
|
placeholder="Téléphone..." pattern="[0-9]{10}" required/>
|
|
|
|
|
<input id="email" name='mail' className="texte_zone" type="email" placeholder="Email..." required/>
|
|
|
|
|