diff --git a/server-api/api.js b/server-api/api.js
index c95ec21..8117453 100644
--- a/server-api/api.js
+++ b/server-api/api.js
@@ -213,4 +213,40 @@ app.get('/Contact/AllWithCustomerName', (req, res) => {
console.log(result);
res.send(result);
});
-});
\ No newline at end of file
+});
+
+app.get('/Entreprise/All', (req, res) => {
+ let sql = 'SELECT * FROM customers ORDER BY name';
+ db.query(sql, (err, result) => {
+ if (err) throw err;
+ console.log(result);
+ res.send(result);
+ });
+});
+
+app.get('/Contact/Exist/:login', (req, res) => {
+
+ const login = req.params.login;
+ let sql = 'SELECT idContact FROM contact WHERE login = ?';
+
+ db.query(sql, [login], (err, result) => {
+ if (err) throw err;
+
+ console.log(result);
+ res.send(result);
+ });
+});
+
+app.post('/Contact/Add', (req, res) => {
+
+ let form = req.body;
+
+ console.log(form);
+
+ const sql = `INSERT INTO contact(name, firstname, mail, phone, idUser, idCustomer) VALUES ('${form.name}', '${form.firstname}', '${form.mail}', '${form.phone}' , '${form.idrole}', '${form.idUser}', '${form.idCustomer}' )`;
+ db.query(sql , (err, result) => {
+ if (err) throw err;
+ console.log(result);
+ res.send('Post added...' + result.insertId);
+ });
+});
diff --git a/src/App.js b/src/App.js
index f2910b2..552dbb7 100644
--- a/src/App.js
+++ b/src/App.js
@@ -13,6 +13,7 @@ import Calendrier from './pages/Calendrier';
import Repertoire from './pages/Repertoire';
import Parametres from './pages/Parametres';
import Chargement from './pages/Chargement';
+import AddContact from './components/Contact/AddContact'
import { Component } from 'fullcalendar';
import RestartPassword from './pages/RestartPassword';
@@ -38,6 +39,7 @@ const App = () => {
} />
} />
} />
+ } />
);
diff --git a/src/components/Contact/AddContact.js b/src/components/Contact/AddContact.js
index c9c0c60..26a6e71 100644
--- a/src/components/Contact/AddContact.js
+++ b/src/components/Contact/AddContact.js
@@ -1,40 +1,93 @@
-import React, {useState} from 'react'
-import {useNavigate} from 'react-router-dom';
+import React, { useState, useEffect } from 'react';
+import axios from 'axios'
+import NavigationDashboard from '../NavigationDashboard.js';
+import CryptoJS from 'crypto-js';
+import Select, { SelectChangeEvent } from '@mui/material/Select';
+import MenuItem from '@mui/material/MenuItem';
+import { NavLink } from 'react-router-dom';
+import { useNavigate } from "react-router-dom";
+import { Button } from '@mui/material';
// HERE ABOVE useHistory IS REPLACED WITH useNavigate
+const api = axios.create({
+ baseURL: 'http://localhost:8080'
+ })
+
function AddContact(props) {
+
+ const [loginError, setLoginError] = useState(false);
+ const [entreprises, setEntreprises] = useState([]);
+ const [selectedIdEntreprise, setSelectedIdEntreprise] = useState(1);
const navigate=useNavigate();
- const [User, setUser] = useState({name:"", email:""});
- let add = (e) => {
- e.preventDefault();
- if(User.name === "" || User.email === ""){
- alert("All fields are mandatory!!!");
- return
- }
- // THIS IS USED TO SHOW THE LIST DATA ON THE APP.JS FILE
- props.addContactHandler(User);
- // THIS IS USED FOR WHEN THE ADD BUTTON IS PRESSED THE INPUT FILED AGAIN GETS EMPTY
- setUser({name:"", email:""});
- //console.log(props);
- navigate('/');
- }
+ useEffect(() =>{
+ api.get('/Entreprise/All').then((response) => {
+ setEntreprises(response.data);
+ });
+ }, []);
+
+ function handleChangeEntreprise(event){
+ setSelectedIdEntreprise(event.target.value);
+ };
+
+ function checkAdd(event){
+
+ event.preventDefault();
+
+ const formData = new FormData(event.currentTarget);
+ const values = Object.fromEntries(formData.entries());
+ console.log(values.name);
+ api.get('/Contact/Exist/'+ values.login).then((response) => {
+ const login = response.data;
+ if (login.length > 0){
+ setLoginError(true);
+ }
+ else {
+ setLoginError(false);
+
+ api.post('/Contact/Add', values).then (function(response) {
+ console.log(response.data);
+ });
+
+ navigate("/Repertoire");
+ }
+ });
+ };
return (
-