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 da94fc8..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) => { @@ -317,7 +352,7 @@ app.get('/Event/:iduser', (req, res) => { const iduser = req.params.iduser; - let sql = 'SELECT * FROM events e where e.iduserreceive = ?'; + let sql = 'SELECT e.date,e.starttime,e.endtime,e.comment FROM events e where e.iduserreceive = ?'; db.query(sql,[iduser], (err, result) => { if (err) throw err; @@ -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..156e9ae 100644 --- a/src/components/Contact/AddContact.js +++ b/src/components/Contact/AddContact.js @@ -1,42 +1,97 @@ -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 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('/'); - } - +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 navigate = useNavigate(); + + useEffect(() => { + api.get('/Entreprise/All').then((response) => { + setEntreprises(response.data); + }); + }, []); + + 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()); + 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.mail, iduser: Session.get('idUser'), idcustomer: selectedIdEntreprise }; + api.post('/Contact/Add', newContact).then(function (response) { + console.log(response.data); + }); + 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 ? "Le contact 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/Analyse.js b/src/pages/Analyse.js index 2572fa5..1480ef5 100644 --- a/src/pages/Analyse.js +++ b/src/pages/Analyse.js @@ -132,7 +132,6 @@ const Analyse = () => { for(let i = 0; i < lineDatas.length; i++) { - console.log(lineDatas); dataH.labels[i] = lineDatas[i].month +"/" +lineDatas[i].year; dataH.datasets[0].data[i] = lineDatas[i].total; } diff --git a/src/pages/Calendrier.js b/src/pages/Calendrier.js index bef41d7..dbbf680 100644 --- a/src/pages/Calendrier.js +++ b/src/pages/Calendrier.js @@ -32,40 +32,37 @@ const localizer = dateFnsLocalizer({ function Calendrier(){ const [contacts, setContacts] = useState([]); - const [events, setEvents] = useState([]); const [selectedContact, setSelectedContact] = useState(1); + const [allEvents, setAllEvents] = useState([]); -useEffect(() =>{ - const apiString = '/Contact/' + Session.get("idUser"); - api.get(apiString).then((response) => { - setContacts(response.data); + useEffect(() =>{ + const apiString = '/Contact/' + Session.get("idUser"); + api.get(apiString).then((response) => { + setContacts(response.data); setSelectedContact(response.data[0].idcontact) - }); - - const apiStringEvent = '/Event/' + Session.get("idUser"); - api.get(apiStringEvent).then((response) => { - setEvents(response.data); - }); + }); - events.forEach(event => { - const newEvent = { title: event.comment, start: new Date(event.date+" "+event.starttime), end: new Date(event.date+" "+event.endtime) }; - setAllEvents([...allEvents, newEvent]); - console.log("here"); - }); -}, []); + const apiStringEvent = '/Event/' + Session.get("idUser"); + api.get(apiStringEvent).then((response) => { + setAllEvents([]); + response.data.forEach(event => { + const newEvent = { title: event.comment, start: new Date(event.date+" "+event.starttime), end: new Date(event.date+" "+event.endtime) }; + setAllEvents(allEvents => [...allEvents, newEvent]); + }); + }); + }, []); const [theme, setTheme] = useState("light"); if (localStorage.getItem('theme') && localStorage.getItem("theme") !== '' && localStorage.getItem("theme") !== theme) { setTheme(localStorage.getItem("theme")) } + const [titre, setTitre] = useState(""); const [jour , setJour] = useState(new Date()); const [heureDebut, setHeureDebut] = useState(new Date()); const [heureFin, setHeureFin] = useState(new Date()); - const [allEvents, setAllEvents] = useState(events); - function handleAddEvent() { const newEvent = { title: titre, start: new Date(jour+" "+heureDebut), end: new Date(jour+" "+heureFin) }; const newEventBD = { date: jour,starttime: heureDebut,endtime: heureFin,comment: titre, idusersend: Session.get("idUser"),iduserreceive: Session.get("idUser"), idcontact: selectedContact}; 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 78846ac..819a16b 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