diff --git a/.scannerwork/.sonar_lock b/.scannerwork/.sonar_lock new file mode 100644 index 0000000..e69de29 diff --git a/.scannerwork/report-task.txt b/.scannerwork/report-task.txt new file mode 100644 index 0000000..1953886 --- /dev/null +++ b/.scannerwork/report-task.txt @@ -0,0 +1,6 @@ +projectKey=jtt_crm +serverUrl=https://codefirst.iut.uca.fr/sonar +serverVersion=9.6.1.59531 +dashboardUrl=https://codefirst.iut.uca.fr/sonar/dashboard?id=jtt_crm +ceTaskId=AYSvDEjizKKB0GF_0uUi +ceTaskUrl=https://codefirst.iut.uca.fr/sonar/api/ce/task?id=AYSvDEjizKKB0GF_0uUi diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..980fd57 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "macos-clang-arm64", + "includePath": [ + "${workspaceFolder}/**" + ], + "compilerPath": "/usr/bin/clang", + "cStandard": "${default}", + "cppStandard": "${default}", + "intelliSenseMode": "macos-clang-arm64", + "compilerArgs": [ + "" + ] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..6053dbd --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,13 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "C/C++ Runner: Debug Session", + "type": "lldb", + "request": "launch", + "args": [], + "cwd": "/Users/malanone/JTT_Production/JTT_CrM", + "program": "/Users/malanone/JTT_Production/JTT_CrM/build/Debug/outDebug" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..50d1b0f --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,36 @@ +{ + "C_Cpp_Runner.cCompilerPath": "clang", + "C_Cpp_Runner.cppCompilerPath": "clang++", + "C_Cpp_Runner.debuggerPath": "lldb", + "C_Cpp_Runner.cStandard": "", + "C_Cpp_Runner.cppStandard": "", + "C_Cpp_Runner.msvcBatchPath": "", + "C_Cpp_Runner.useMsvc": false, + "C_Cpp_Runner.warnings": [ + "-Wall", + "-Wextra", + "-Wpedantic", + "-Wshadow", + "-Wformat=2", + "-Wconversion", + "-Wnull-dereference", + "-Wsign-conversion" + ], + "C_Cpp_Runner.enableWarnings": true, + "C_Cpp_Runner.warningsAsError": false, + "C_Cpp_Runner.compilerArgs": [], + "C_Cpp_Runner.linkerArgs": [], + "C_Cpp_Runner.includePaths": [], + "C_Cpp_Runner.includeSearch": [ + "*", + "**/*" + ], + "C_Cpp_Runner.excludeSearch": [ + "**/build", + "**/build/**", + "**/.*", + "**/.*/**", + "**/.vscode", + "**/.vscode/**" + ] +} \ No newline at end of file diff --git a/server-api/api.js b/server-api/api.js index f639d30..b0292a5 100644 --- a/server-api/api.js +++ b/server-api/api.js @@ -287,6 +287,41 @@ app.get('/Contact/AllWithCustomerName', (req, res) => { }); }); +app.get('/Entreprise/All', (req, res) => { + let sql = 'SELECT idcustomer,name FROM customers ORDER BY name'; + db.query(sql, (err, result) => { + if (err) throw err; + console.log(result); + res.send(result); + }); +}); + +app.get('/Contact/Exist/:phone', (req, res) => { + const phone = req.params.phone + let sql = 'SELECT idcontact FROM contacts WHERE phone = ?'; + + db.query(sql, [phone], (err, result) => { + if (err) throw err; + + console.log(result); + res.send(result); + }); +}); + +app.post('/Contact/Add', (req, res) => { + + let form = req.body; + + console.log("on est dans le form",form); + + const sql = `INSERT INTO contacts(firstname,lastname, mail, phone, iduser, idcustomer) VALUES ('${form.firstname}', '${form.lastname}', '${form.mail}', '${form.phone}', '${form.iduser}', '${form.idcustomer}' )`; + db.query(sql , (err, result) => { + if (err) throw err; + console.log(result); + res.send('Post added...' + result.insertId); + }); +}); + app.get('/Contact/:iduser', (req, res) => { const iduser = req.params.iduser; @@ -303,7 +338,7 @@ app.post('/Event/Add', (req, res) => { let form = req.body; - console.log(form); + console.log("on est dans le form d'un event ",form); const sql = `INSERT INTO events(date,starttime,endtime,comment,idusersend,iduserreceive,idcontact) VALUES ('${form.date}', '${form.starttime}', '${form.endtime}', '${form.comment}', '${form.idusersend}', '${form.iduserreceive}', '${form.idcontact}')`; db.query(sql , (err, result) => { @@ -325,4 +360,4 @@ app.get('/Event/:iduser', (req, res) => { console.log(result); res.send(result); }); -}); +}); \ No newline at end of file diff --git a/src/App.js b/src/App.js index 0a85a37..d84a7b5 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'; @@ -40,6 +41,7 @@ const App = () => { } /> } /> } /> + } /> ); diff --git a/src/components/Contact/AddContact.js b/src/components/Contact/AddContact.js index c9c0c60..8bf59aa 100644 --- a/src/components/Contact/AddContact.js +++ b/src/components/Contact/AddContact.js @@ -1,42 +1,102 @@ -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'; +import Session from 'react-session-api'; // HERE ABOVE useHistory IS REPLACED WITH useNavigate -function AddContact(props) { +const api = axios.create({ + baseURL: 'http://localhost:8080' + }) + +function AddContact() { + + const [loginError, setLoginError] = useState(false); + const [entreprises, setEntreprises] = useState([]); + const [selectedIdEntreprise, setSelectedIdEntreprise] = useState(1); + const [newContact, setNewContact] = useState([]); 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); + console.log(entreprises); + }); + }, []); + + function handleChangeEntreprise(event){ + setSelectedIdEntreprise(event.target.value); + console.log("je suis dans handleChangeEntreprise"); + }; + + function checkAdd(event){ + + event.preventDefault(); + + const formData = new FormData(event.currentTarget); + const values = Object.fromEntries(formData.entries()); + 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); + 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"); + }); + }; return ( -
-

Add Contact

-
-
- - setUser({...User, name: e.target.value})}/> -
-
- - setUser({...User, email: e.target.value})}/> +
+

Ajouter un nouveau contact

+
+ + + +
+

Nom :

+

Prénom :

+

Téléphone :

+

Email :

+

Entreprise :

+
+ + + + + + + + +
+

{loginError === true?"L'identifiant existe déja":''}

+
+ + Retour +
+
- -
) } -export default AddContact +export default AddContact; diff --git a/src/components/Menu.js b/src/components/Menu.js deleted file mode 100644 index 7c04e13..0000000 --- a/src/components/Menu.js +++ /dev/null @@ -1,11 +0,0 @@ -import React from 'react'; - -const Menu = () => { - return ( -
- -
- ); -}; - -export default Menu; \ No newline at end of file diff --git a/src/pages/Admin_create.js b/src/pages/Admin_create.js index e37ea9b..8fa3533 100644 --- a/src/pages/Admin_create.js +++ b/src/pages/Admin_create.js @@ -28,6 +28,7 @@ function Admin_create() { function handleChangeRole(event){ setSelectedIdRole(event.target.value); + console.log(event.target.value); }; function checkAdd(event){ diff --git a/src/pages/Calendrier.js b/src/pages/Calendrier.js index 4134078..dbbf680 100644 --- a/src/pages/Calendrier.js +++ b/src/pages/Calendrier.js @@ -39,7 +39,7 @@ function Calendrier(){ const apiString = '/Contact/' + Session.get("idUser"); api.get(apiString).then((response) => { setContacts(response.data); - setSelectedContact(response.data[0].idcontact) + setSelectedContact(response.data[0].idcontact) }); const apiStringEvent = '/Event/' + Session.get("idUser"); diff --git a/src/pages/Repertoire.js b/src/pages/Repertoire.js index 07b106f..8d34aab 100644 --- a/src/pages/Repertoire.js +++ b/src/pages/Repertoire.js @@ -4,7 +4,9 @@ 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'; - +import { NavLink } from 'react-router-dom'; +import { useNavigate } from 'react-router-dom'; +import Session from 'react-session-api'; const api = axios.create({ baseURL: 'http://localhost:8080' @@ -12,7 +14,7 @@ const api = axios.create({ function Repertoire() { - const [theme, setTheme] = useState("light"); + const [theme, setTheme] = useState("light"); if (localStorage.getItem('theme') && localStorage.getItem("theme") !== '' && localStorage.getItem("theme") !== theme) { setTheme(localStorage.getItem("theme")) } @@ -21,11 +23,13 @@ function Repertoire() { const [SearchTerm, setSearchTerm] = useState(""); const [SearchResults, setSearchResults] = useState([]); const [customers, setCustomers] = useState([]); - useEffect(() => { - api.get('/Contact/AllWithCustomerName').then((response) => { + const apiString = '/Contact/' + Session.get("idUser"); + api.get(apiString).then((response) => { + setContacts(response.data); + console.log("response.data", response.data); setSearchTerm(response.data[0].idcontact); }); }, []); @@ -56,7 +60,9 @@ function Repertoire() {
- + + + @@ -113,6 +119,44 @@ function Repertoire() { ); }; +function AddContact(props) { + + 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('/'); + } + return ( +
+

Add Contact

+
+
+ + setUser({ ...User, name: e.target.value })} /> +
+
+ + setUser({ ...User, email: e.target.value })} /> +
+ + +
+ ); +}; + + + // function Repertoire() { // // NOW WITH THE USE OF HOOKS WE WILL GET THE CONTACTS diff --git a/src/styles/components/_repertoire.scss b/src/styles/components/_repertoire.scss index 8ef8b6f..0cc9050 100644 --- a/src/styles/components/_repertoire.scss +++ b/src/styles/components/_repertoire.scss @@ -171,6 +171,8 @@ body { width: 100%; justify-content: space-between; + + .boutonAddContact { display: flex; justify-content: center; @@ -180,6 +182,7 @@ body { margin: 30px 30px; border-radius: 25px; box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37); + text-decoration-line: none; } .input_box { diff --git a/src/styles/components/contact/_addContact.scss b/src/styles/components/contact/_addContact.scss new file mode 100644 index 0000000..b79b38c --- /dev/null +++ b/src/styles/components/contact/_addContact.scss @@ -0,0 +1,8 @@ +.addContactPage{ + display: flex; + flex-direction: column; + justify-content: space-around; + align-items: center; + + +} \ No newline at end of file diff --git a/src/styles/index.scss b/src/styles/index.scss index ac6a812..eb40ba3 100644 --- a/src/styles/index.scss +++ b/src/styles/index.scss @@ -7,4 +7,5 @@ @import "./components/calendrier"; @import "./components/parametre"; @import "./components/repertoire"; -@import "./components/chargement" \ No newline at end of file +@import "./components/chargement"; +@import "./components/contact/addContact"; \ No newline at end of file