diff --git a/package-lock.json b/package-lock.json index cb62827..9203621 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,7 @@ "node-fetch": "^3.3.2", "pino": "^8.19.0", "react": "^18.2.0", + "react-async": "^10.0.1", "react-dom": "^18.2.0", "react-hook-form": "^7.51.0", "react-router": "^6.22.2", @@ -15113,6 +15114,14 @@ "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz", "integrity": "sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==" }, + "node_modules/react-async": { + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/react-async/-/react-async-10.0.1.tgz", + "integrity": "sha512-ORUz5ca0B57QgBIzEZM5SuhJ6xFjkvEEs0gylLNlWf06vuVcLZsjIw3wx58jJkZG38p+0nUAxRgFW2b7mnVZzA==", + "peerDependencies": { + "react": ">=16.3.1" + } + }, "node_modules/react-dev-utils": { "version": "12.0.1", "resolved": "https://registry.npmjs.org/react-dev-utils/-/react-dev-utils-12.0.1.tgz", diff --git a/package.json b/package.json index d433aa2..9751229 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "node-fetch": "^3.3.2", "pino": "^8.19.0", "react": "^18.2.0", + "react-async": "^10.0.1", "react-dom": "^18.2.0", "react-hook-form": "^7.51.0", "react-router": "^6.22.2", diff --git a/src/components/dashboard/admin/doctor/detail/index.jsx b/src/components/dashboard/admin/doctor/detail/index.jsx new file mode 100644 index 0000000..f472bb3 --- /dev/null +++ b/src/components/dashboard/admin/doctor/detail/index.jsx @@ -0,0 +1,45 @@ +import ModalContainer from '../../../modal-container'; +import { get } from '../../../../../modules/fetchManager'; +import { useState } from 'react'; +import BackButton from '../../../back-button'; + +function DetailMenu({user,detail,setDetail}) { + + const [data, setData] = useState([]); + + + if(data.length === 0) { + get('users/'+detail.user_id, user.token) + .then((data) => { + setData(data.JSON); + }); + } + + return( + + { + data.length === 0 ?

Chargement...

: +
+

Détails

+
+
+

Nom: {data.first_name}

+

Prénom: {data.last_name}

+

Email Perso: {data.email}

+

Téléphone Perso: {data.phone}

+

Email Perso: {detail.email}

+

Téléphone Perso: {detail.phone}

+

Spécialité: {detail.speciality}

+

Statut: {detail.status}

+

Vérifié: {detail.is_verified ? "Oui" : "Non"}

+
+ +
+
+ } +
+ ) + +} + +export default DetailMenu; \ No newline at end of file diff --git a/src/components/dashboard/admin/doctor/index.jsx b/src/components/dashboard/admin/doctor/index.jsx new file mode 100644 index 0000000..8db32de --- /dev/null +++ b/src/components/dashboard/admin/doctor/index.jsx @@ -0,0 +1,50 @@ +import HeadTitle from "../../head-title"; +import Container from "../../container"; +import { useState } from "react"; +import ItemList from "./item-list"; +import MenuDisplay from "../../menu-display"; +import ModifyMenu from "./modify"; +import DeleteMenu from "../../delete-menu"; +import { get } from "../../../../modules/fetchManager"; +import DetailMenu from "./detail"; + +function Docteur({user}) { + + const [docteurs, setDocteurs] = useState([]); + const [loading, setLoading] = useState(true); + const [error, setError] = useState(null); + const [modifyMenu, setModifyMenu] = useState(false); + const [deleteMenu, setDeleteMenu] = useState(false); + const [detailMenu, setDetailMenu] = useState(false); + + if(loading && !error && docteurs.length === 0){ + get('doctors', user.token) + .then((data) => { + setLoading(false); + if(data.status === 404) { + setError("Aucun docteur trouvé"); + return; + } + + if(data.status === 500) { + setError("Erreur serveur, veuillez réessayer plus tard"); + return; + } + setDocteurs(data.JSON); + }); + } + + return( +
+ + + + { modifyMenu ? : null } + { deleteMenu ? : null } + { detailMenu ? : null } + +
+ ) +} + +export default Docteur; \ No newline at end of file diff --git a/src/components/dashboard/admin/doctor/item-list/index.jsx b/src/components/dashboard/admin/doctor/item-list/index.jsx new file mode 100644 index 0000000..8f8b362 --- /dev/null +++ b/src/components/dashboard/admin/doctor/item-list/index.jsx @@ -0,0 +1,38 @@ +import { post } from "../../../../../modules/fetchManager"; +import ModifyButton from "../../../modify-button"; +import DeleteButton from "../../../delete-button"; + +export function ItemList({ item, setDeleteMenu, setModifyMenu, user, setDetailMenu }) { + + const onClick = () => { + post('doctors/'+item.id+'/validate', {doctor_id: item.id}, user.token) + .then((data) => { + console.log(data); + if(data.status === 500) alert("Erreur serveur, veuillez réessayer plus tard"); + + if(data.status === 400) alert("Docteur non trouvé ou erreur dans la requête"); + + if(data.status === 200) alert("Docteur vérifié"); + }); + } + return ( +
+
+

{item.email}

+

{item.phone}, {item.speciality}, {item.status}, {item.is_verified ? "Vérifié" : "Non vérifié"}

+
+
+
+ {!item.is_verified ? : null} + +
+
+ + +
+
+
+ ); +} + +export default ItemList; \ No newline at end of file diff --git a/src/components/dashboard/admin/doctor/modify/hospitals.jsx b/src/components/dashboard/admin/doctor/modify/hospitals.jsx new file mode 100644 index 0000000..26bc509 --- /dev/null +++ b/src/components/dashboard/admin/doctor/modify/hospitals.jsx @@ -0,0 +1,63 @@ +import { useState, useEffect } from "react"; +import { useForm } from "react-hook-form"; +import { get,post } from "../../../../../modules/fetchManager"; +import SubmitButton from "../../../submit-button"; + +function Hospitals({user,item}) { + + const {register, handleSubmit} = useForm(); + + const [data, setData] = useState(null); + const [error, setError] = useState(null); + const [loading, setLoading] = useState(true); + + useEffect(() => { + get('hospitals', user.token) + .then((data) => { + setLoading(false); + if(data.status === 404) { + setError("Aucun hôpital trouvé"); + return; + } + + if(data.status === 500) { + setError("Erreur serveur, veuillez réessayer plus tard"); + return; + } + setData(data.JSON); + }); + },[]); + + const onSubmit = (dataForm) => { + post('hospitals/'+dataForm.hospital_id+'/doctors',{doctor_id: item.id},user.token) + .then((data) => { + if(data.status === 200) { + alert("Hôpital ajouté"); + return; + } + alert(data.message); + }) + } + + if(error) return

{error}

; + return( +
+ { + loading ?

Chargement...

: +
+
+ + +
+ +
+ } +
+ ); +} + +export default Hospitals; \ No newline at end of file diff --git a/src/components/dashboard/admin/doctor/modify/hospitalsDoctor.jsx b/src/components/dashboard/admin/doctor/modify/hospitalsDoctor.jsx new file mode 100644 index 0000000..754b97f --- /dev/null +++ b/src/components/dashboard/admin/doctor/modify/hospitalsDoctor.jsx @@ -0,0 +1,62 @@ +import { useEffect, useState } from "react"; +import { useForm } from "react-hook-form"; +import { get, del } from "../../../../../modules/fetchManager"; + +function HospitalsDoctor({user,item}) { + + const {register, handleSubmit} = useForm(); + + const [data, setData] = useState(null); + const [error, setError] = useState(null); + const [loading, setLoading] = useState(true); + + useEffect(() => { + get('doctors/'+item.id+'/hospitals', user.token) + .then((data) => { + setLoading(false); + if(data.status === 404) { + setError("Aucun hôpital trouvé"); + return; + } + + if(data.status === 500) { + setError("Erreur serveur, veuillez réessayer plus tard"); + return; + } + setData(data.JSON); + }); + },[]); + + const onSubmit = (dataForm) => { + del('hospitals/'+dataForm.hospital_id+'/doctors/'+item.id, user.token) + .then((data) => { + if(data.status === 200) { + alert("Hôpital retiré"); + return; + } + alert(data.message); + }) + }; + + if(error) return

{error}

; + return( +
+ { + loading ?

Chargement...

: +
+
+ + +
+ +
+ } +
+ ); +} + +export default HospitalsDoctor; \ No newline at end of file diff --git a/src/components/dashboard/admin/doctor/modify/index.jsx b/src/components/dashboard/admin/doctor/modify/index.jsx new file mode 100644 index 0000000..d8aa7f5 --- /dev/null +++ b/src/components/dashboard/admin/doctor/modify/index.jsx @@ -0,0 +1,21 @@ +import ModalContainer from '../../../modal-container'; +import Hospitals from './hospitals'; +import Services from './services'; +import HospitalsDoctor from './hospitalsDoctor'; +import ServicesDoctor from './servicesDoctor'; +import BackButton from '../../../back-button'; + +function ModifyMenu({item, setModifyMenu,user}) { + return ( + + + + + + + + ); + +} + +export default ModifyMenu; \ No newline at end of file diff --git a/src/components/dashboard/admin/doctor/modify/services.jsx b/src/components/dashboard/admin/doctor/modify/services.jsx new file mode 100644 index 0000000..3cb2c89 --- /dev/null +++ b/src/components/dashboard/admin/doctor/modify/services.jsx @@ -0,0 +1,63 @@ +import { useState, useEffect } from "react"; +import { useForm } from "react-hook-form"; +import { get,post } from "../../../../../modules/fetchManager"; +import SubmitButton from "../../../submit-button"; + +function Services({user,item}) { + + const {register, handleSubmit} = useForm(); + + const [data, setData] = useState(null); + const [error, setError] = useState(null); + const [loading, setLoading] = useState(true); + + useEffect(() => { + get('services', user.token) + .then((data) => { + setLoading(false); + if(data.status === 404) { + setError("Aucun hôpital trouvé"); + return; + } + + if(data.status === 500) { + setError("Erreur serveur, veuillez réessayer plus tard"); + return; + } + setData(data.JSON); + }); + },[]); + + const onSubmit = (dataForm) => { + post('doctors/'+item.id+'/services',dataForm,user.token) + .then((data) => { + if(data.status === 200) { + alert("Service ajouté"); + return; + } + alert(data.message); + }) + } + + if(error) return

{error}

; + return( +
+ { + loading ?

Chargement...

: +
+
+ + +
+ +
+ } +
+ ); +} + +export default Services; \ No newline at end of file diff --git a/src/components/dashboard/admin/doctor/modify/servicesDoctor.jsx b/src/components/dashboard/admin/doctor/modify/servicesDoctor.jsx new file mode 100644 index 0000000..9f54a22 --- /dev/null +++ b/src/components/dashboard/admin/doctor/modify/servicesDoctor.jsx @@ -0,0 +1,62 @@ +import { useEffect, useState } from "react"; +import { useForm } from "react-hook-form"; +import { get, del } from "../../../../../modules/fetchManager"; + +function ServicesDoctor({user,item}) { + + const {register, handleSubmit} = useForm(); + + const [data, setData] = useState(null); + const [error, setError] = useState(null); + const [loading, setLoading] = useState(true); + + useEffect(() => { + get('doctors/'+item.id+'/services', user.token) + .then((data) => { + setLoading(false); + if(data.status === 404) { + setError("Aucun hôpital trouvé"); + return; + } + + if(data.status === 500) { + setError("Erreur serveur, veuillez réessayer plus tard"); + return; + } + setData(data.JSON); + }); + },[]); + + const onSubmit = (dataForm) => { + del('doctors/'+item.id+'/services/'+dataForm.service_id, user.token) + .then((data) => { + if(data.status === 200) { + alert("Service retiré"); + return; + } + alert(data.message); + }) + }; + + if(error) return

{error}

; + return( +
+ { + loading ?

Chargement...

: +
+
+ + +
+ +
+ } +
+ ); +} + +export default ServicesDoctor; \ No newline at end of file diff --git a/src/components/dashboard/admin/hospital/create/index.jsx b/src/components/dashboard/admin/hospital/create/index.jsx index 09d449c..9619498 100644 --- a/src/components/dashboard/admin/hospital/create/index.jsx +++ b/src/components/dashboard/admin/hospital/create/index.jsx @@ -1,26 +1,45 @@ import ModalContainer from '../../../modal-container'; import { useForm } from 'react-hook-form'; +import { useState } from 'react'; import { post } from '../../../../../modules/fetchManager'; +import BackButton from '../../../back-button'; +import SubmitButton from '../../../submit-button'; function CreateHospital({setCreateMenu,user}) { const { register, handleSubmit } = useForm(); + const [loading, setLoading] = useState(false); + const [error, setError] = useState(null); const onSubmit = (data) => { + setLoading(true); data.company_id = 1; data.country = "France"; post('hospitals', data, user.token) .then(data => { - console.log(data); + setLoading(false); + if(data.status === 400) { + setError("Des champs n'ont pas été remplis correctement"); + return; + } + if(data.status !== 200) { + setError("Erreur lors de la création de l'hôpital"); + return; + } + + setError("N"); }) } return( - +

Création d'un Hôpital

+ {loading ?
Chargement...
: null} + {error && error !== "N" ?
{error}
: null} + {error === "N" && !loading ?
Hôpital créé avec succès
: null}
@@ -38,11 +57,11 @@ function CreateHospital({setCreateMenu,user}) {
- +
- +
diff --git a/src/components/dashboard/admin/hospital/index.jsx b/src/components/dashboard/admin/hospital/index.jsx index 090391c..cb604e3 100644 --- a/src/components/dashboard/admin/hospital/index.jsx +++ b/src/components/dashboard/admin/hospital/index.jsx @@ -1,9 +1,49 @@ import HeadTitle from "../../head-title"; +import { get } from "../../../../modules/fetchManager"; +import { useState } from "react"; +import ItemList from "./item-list"; +import Create from "./create"; +import CreateButton from "../../createButton"; +import MenuDisplay from "../../menu-display"; +import ModifyMenu from "./modify"; +import DeleteMenu from "../../delete-menu"; function Hospital({user}) { + + const [hospitals, setHospitals] = useState([]); + const [loading, setLoading] = useState(true); + const [error, setError] = useState(null); + const [createMenu, setCreateMenu] = useState(false); + const [modifyMenu, setModifyMenu] = useState(false); + const [deleteMenu, setDeleteMenu] = useState(false); + + if(loading && !error && hospitals.length === 0){ + get('hospitals', user.token) + .then((data) => { + setLoading(false); + if(data.status === 404) { + setError("Aucun hôpital trouvé"); + return; + } + + if(data.status === 500) { + setError("Erreur serveur, veuillez réessayer plus tard"); + return; + } + setHospitals(data.JSON); + }); + } + return(
+
+ +
+ + { createMenu ? : null } + { modifyMenu ? : null } + { deleteMenu ? : null }
) } diff --git a/src/components/dashboard/admin/hospital/item-list/index.jsx b/src/components/dashboard/admin/hospital/item-list/index.jsx new file mode 100644 index 0000000..c6bee4c --- /dev/null +++ b/src/components/dashboard/admin/hospital/item-list/index.jsx @@ -0,0 +1,19 @@ +import ModifyButton from "../../../modify-button"; +import DeleteButton from "../../../delete-button"; + +function ItemList({item, setDeleteMenu, setModifyMenu}) { + return( +
+
+

{item.name} - {item.code}

+

{item.address}, {item.city}, {item.region}, {item.country}

+
+
+ + +
+
+ ); +} + +export default ItemList; \ No newline at end of file diff --git a/src/components/dashboard/admin/hospital/modify/index.jsx b/src/components/dashboard/admin/hospital/modify/index.jsx new file mode 100644 index 0000000..f3b9b49 --- /dev/null +++ b/src/components/dashboard/admin/hospital/modify/index.jsx @@ -0,0 +1,72 @@ +import ModalContainer from "../../../modal-container"; +import { useForm } from 'react-hook-form'; +import { useState } from 'react'; +import { put } from '../../../../../modules/fetchManager'; +import BackButton from "../../../back-button"; +import SubmitButton from "../../../submit-button"; + +function ModifyMenu({setModifyMenu,user,item}) { + + const { register, handleSubmit } = useForm(); + const [loading, setLoading] = useState(false); + const [error, setError] = useState(null); + + const onSubmit = (data) => { + setLoading(true); + data.country = "France"; + data.company_id = 1; + put('hospitals/'+item.id, data, user.token) + .then(data => { + setLoading(false); + if(data.status === 400) { + setError("Des champs n'ont pas été remplis correctement"); + return; + } + if(data.status !== 200) { + setError("Erreur lors de la modification de l'hôpital"); + return; + } + + setError("N"); + }); + } + + return( + +
+
+

Modification d'un Hôpital

+
+ {loading ?
Chargement...
: null} + {error && error !== "N" ?
{error}
: null} + {error === "N" && !loading ?
Hôpital modifié avec succès
: null} +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ ) +} + +export default ModifyMenu; \ No newline at end of file diff --git a/src/components/dashboard/admin/index.jsx b/src/components/dashboard/admin/index.jsx index f952097..a089f3e 100644 --- a/src/components/dashboard/admin/index.jsx +++ b/src/components/dashboard/admin/index.jsx @@ -12,9 +12,12 @@ function Admin({user,setUser}) { config.prescriptionOn ? {page:"prescription",name:"Préscriptions"} : null, {page:"medical-file",name:"Dossier Médical"}, {page:"user",name:"Utilisateurs"}, + {page:"doctor",name:"Docteurs"}, + {page:"patient",name:"Patients"}, {page:"hospital",name:"Hôpitaux"}, + {page:"service",name:"Services"}, {page:"profil",name:"Profil"} - ] + ]; return( diff --git a/src/components/dashboard/admin/menu-handler/index.jsx b/src/components/dashboard/admin/menu-handler/index.jsx index 489220d..7f9845a 100644 --- a/src/components/dashboard/admin/menu-handler/index.jsx +++ b/src/components/dashboard/admin/menu-handler/index.jsx @@ -5,6 +5,9 @@ import User from "../user"; import Hospital from "../hospital"; import Profil from "../profil"; import Home from "../../home"; +import Doctor from "../doctor"; +import Patient from "../patient"; +import Service from "../services"; function MenuHandler({page,user}) { switch (page) { @@ -16,6 +19,12 @@ function MenuHandler({page,user}) { return ; case "user": return ; + case "doctor": + return ; + case "patient": + return ; + case "service": + return ; case "hospital": return ; case "profil": diff --git a/src/components/dashboard/admin/patient/index.jsx b/src/components/dashboard/admin/patient/index.jsx new file mode 100644 index 0000000..8564d0d --- /dev/null +++ b/src/components/dashboard/admin/patient/index.jsx @@ -0,0 +1,11 @@ +import HeadTitle from "../../head-title"; + +function Patient({user}) { + return( +
+ +
+ ) +} + +export default Patient; \ No newline at end of file diff --git a/src/components/dashboard/admin/services/create/index.jsx b/src/components/dashboard/admin/services/create/index.jsx new file mode 100644 index 0000000..5bbba04 --- /dev/null +++ b/src/components/dashboard/admin/services/create/index.jsx @@ -0,0 +1,63 @@ +import ModalContainer from "../../../modal-container"; +import { useForm } from 'react-hook-form'; +import { useState } from 'react'; +import { post } from '../../../../../modules/fetchManager'; +import SubmitButton from "../../../submit-button"; +import BackButton from "../../../back-button"; + +function CreateMenu({setCreateMenu,user}) { + + const { register, handleSubmit } = useForm(); + + const [loading, setLoading] = useState(false); + const [error, setError] = useState(null); + + const onSubmit = (data) => { + setLoading(true); + post('services', data, user.token) + .then(data => { + setLoading(false); + if(data.status === 400) { + setError("Des champs n'ont pas été remplis correctement"); + return; + } + if(data.status !== 200) { + setError("Erreur lors de la création du service"); + return; + } + + setError("N"); + }) + }; + + return( + +
+
+

Création d'un Service

+
+ {loading ?
Chargement...
: null} + {error && error !== "N" ?
{error}
: null} + {error === "N" && !loading ?
Service créé avec succès
: null} +
+ + +
+
+ +