diff --git a/package.json b/package.json index 3fc72d6..d433aa2 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "web-vitals": "^2.1.4" }, "scripts": { - "start": "react-scripts start", + "start": "set PORT=8080 && react-scripts start", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject" diff --git a/services.sql b/services.sql new file mode 100644 index 0000000..7502f28 --- /dev/null +++ b/services.sql @@ -0,0 +1,7 @@ +INSERT INTO services (name,description,price) VALUES +('Chirurgie','Service de visio',100), +('Médecine', 'Service de laboratoire',50), +('Cancérologie', 'Service de cancérologie',75), +('Maternité', 'Service de maternité',150), +('Imagerie médical', "Service d'imagerie",75), +('Urgences', "Service d'urgences", 25); \ No newline at end of file diff --git a/src/components/auth/login/index.jsx b/src/components/auth/login/index.jsx index 26cf41b..212488c 100644 --- a/src/components/auth/login/index.jsx +++ b/src/components/auth/login/index.jsx @@ -1,20 +1,55 @@ +import { useForm } from 'react-hook-form'; +import { useState, useEffect } from 'react'; +import { post } from '../../../modules/fetchManager.js'; +import { getUserSession, setUserSession } from '../../../modules/userManager.js'; + function Login() { + + const [error, setError] = useState(null); + const [user, setUser] = useState(getUserSession()); + + useEffect(() => { + if(user.token && user.data){ + setUserSession(user); + window.location.href = '/dashboard'; + } + }, [user]); + + const { register, handleSubmit} = useForm(); + const onSubmit = (e) => { + post('users/login', e) + .then(data => { + if(data.JSON.token){ + setUser({ + token: data.JSON.token, + data: data.JSON.user + }); + } + else{ + setError("Email ou mot de passe incorrect"); + } + }); + } + return (
-
+

Connexion

+
+ {error ?

{error}

: null} +
- +
- - + +
diff --git a/src/components/auth/register/index.jsx b/src/components/auth/register/index.jsx index fac655c..5b229d7 100644 --- a/src/components/auth/register/index.jsx +++ b/src/components/auth/register/index.jsx @@ -13,10 +13,10 @@ function Register() { } post('users/register', e) .then(data => { - if(data.error){ - setError(data.error); + if(data.status === 200){ + window.location.href = '/login'; } - console.log(data); + setError(data.error); }); } diff --git a/src/components/auth/verifyEmail/index.jsx b/src/components/auth/verifyEmail/index.jsx new file mode 100644 index 0000000..efdee4e --- /dev/null +++ b/src/components/auth/verifyEmail/index.jsx @@ -0,0 +1,63 @@ +import { useState, useEffect } from 'react'; +import { get } from '../../../modules/fetchManager.js'; +import { getUserSession, setUserSession } from '../../../modules/userManager.js'; + +function VerifyEmail() { + const queryParameters = new URLSearchParams(window.location.search); + const code = queryParameters.get('code'); + const user = getUserSession(); + const [verified,setVerified] =useState(null); + const [error, setError] = useState(null); + + if(!user || !user.token || !user.data){ + console.log(user); + window.location.href = '/login'; + } + + get('users/email/verify?code='+code, user.token) + .then(data => { + if(data.status !== 200){ + if(data.status === 400){ + setError("Le code de vérification est invalide"); + } + if(data.status === 500){ + setError("Erreur serveur, veuillez réessayer plus tard"); + } + return; + } + setVerified("Votre email a bien été vérifié"); + setUserSession({ + token: user.token, + data: user.data, + }); + }) + + const handleClick = (e) => { + e.preventDefault(); + get('users/email/request', user.token) + .then(data => { + if(data.status !== 200){ + setError("Erreur serveur, veuillez réessayer plus tard"); + return; + } + setVerified("Email envoyé"); + }) + } + + return ( +
+
+ {code ?

Vérification de l'email en cours...

:

Veuillez vérifiez votre boîte mail, un mail de vérification vous a été envoyé

} + {verified ?

{verified}

: null} + {error ?
+

{error}

+ +
: null} +
+
+ ); +} + +export default VerifyEmail; \ No newline at end of file diff --git a/src/components/dashboard/admin/appointment/index.jsx b/src/components/dashboard/admin/appointment/index.jsx new file mode 100644 index 0000000..8fe1514 --- /dev/null +++ b/src/components/dashboard/admin/appointment/index.jsx @@ -0,0 +1,11 @@ +import HeadTitle from "../../head-title"; + +function Appointment({user}) { + return( +
+ +
+ ) +} + +export default Appointment; \ 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 new file mode 100644 index 0000000..09d449c --- /dev/null +++ b/src/components/dashboard/admin/hospital/create/index.jsx @@ -0,0 +1,53 @@ +import ModalContainer from '../../../modal-container'; +import { useForm } from 'react-hook-form'; +import { post } from '../../../../../modules/fetchManager'; + +function CreateHospital({setCreateMenu,user}) { + + const { register, handleSubmit } = useForm(); + + const onSubmit = (data) => { + data.company_id = 1; + data.country = "France"; + post('hospitals', data, user.token) + .then(data => { + console.log(data); + }) + } + + return( + + +
+

Création d'un Hôpital

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+ ) +} + +export default CreateHospital; \ No newline at end of file diff --git a/src/components/dashboard/admin/hospital/index.jsx b/src/components/dashboard/admin/hospital/index.jsx new file mode 100644 index 0000000..090391c --- /dev/null +++ b/src/components/dashboard/admin/hospital/index.jsx @@ -0,0 +1,11 @@ +import HeadTitle from "../../head-title"; + +function Hospital({user}) { + return( +
+ +
+ ) +} + +export default Hospital; \ No newline at end of file diff --git a/src/components/dashboard/admin/index.jsx b/src/components/dashboard/admin/index.jsx new file mode 100644 index 0000000..f952097 --- /dev/null +++ b/src/components/dashboard/admin/index.jsx @@ -0,0 +1,26 @@ +import { useState } from 'react'; +import PageContainer from '../page-container'; +import config from '../../../config'; +import MenuHandler from './menu-handler'; + +function Admin({user,setUser}) { + + const [page, setPage] = useState("home"); + const links = [ + {page:"home",name:"Accueil"}, + {page:"appointment",name:"Rendez-vous"}, + config.prescriptionOn ? {page:"prescription",name:"Préscriptions"} : null, + {page:"medical-file",name:"Dossier Médical"}, + {page:"user",name:"Utilisateurs"}, + {page:"hospital",name:"Hôpitaux"}, + {page:"profil",name:"Profil"} + ] + + return( + + + + ) +} + +export default Admin; \ No newline at end of file diff --git a/src/components/dashboard/admin/medical-file/index.jsx b/src/components/dashboard/admin/medical-file/index.jsx new file mode 100644 index 0000000..809f6f8 --- /dev/null +++ b/src/components/dashboard/admin/medical-file/index.jsx @@ -0,0 +1,11 @@ +import HeadTitle from "../../head-title"; + +function MedicalFile({user}) { + return( +
+ +
+ ) +} + +export default MedicalFile; \ No newline at end of file diff --git a/src/components/dashboard/admin/menu-handler/index.jsx b/src/components/dashboard/admin/menu-handler/index.jsx new file mode 100644 index 0000000..489220d --- /dev/null +++ b/src/components/dashboard/admin/menu-handler/index.jsx @@ -0,0 +1,28 @@ +import Prescription from "../prescription"; +import MedicalFile from "../medical-file"; +import Appointment from "../appointment"; +import User from "../user"; +import Hospital from "../hospital"; +import Profil from "../profil"; +import Home from "../../home"; + +function MenuHandler({page,user}) { + switch (page) { + case "prescription": + return ; + case "medical-file": + return ; + case "appointment": + return ; + case "user": + return ; + case "hospital": + return ; + case "profil": + return ; + default: + return ; + } +} + +export default MenuHandler; \ No newline at end of file diff --git a/src/components/dashboard/admin/prescription/index.jsx b/src/components/dashboard/admin/prescription/index.jsx new file mode 100644 index 0000000..0477a42 --- /dev/null +++ b/src/components/dashboard/admin/prescription/index.jsx @@ -0,0 +1,11 @@ +import HeadTitle from "../../head-title"; + +function Prescription({user}) { + return ( +
+ +
+ ); +} + +export default Prescription; \ No newline at end of file diff --git a/src/components/dashboard/admin/profil/index.jsx b/src/components/dashboard/admin/profil/index.jsx new file mode 100644 index 0000000..1906037 --- /dev/null +++ b/src/components/dashboard/admin/profil/index.jsx @@ -0,0 +1,11 @@ +import HeadTitle from "../../head-title"; + +function Profil({user}) { + return( +
+ +
+ ) +} + +export default Profil; \ No newline at end of file diff --git a/src/components/dashboard/admin/user/index.jsx b/src/components/dashboard/admin/user/index.jsx new file mode 100644 index 0000000..e60fa2d --- /dev/null +++ b/src/components/dashboard/admin/user/index.jsx @@ -0,0 +1,11 @@ +import HeadTitle from "../../head-title"; + +function User({user}) { + return( +
+ +
+ ) +} + +export default User; \ No newline at end of file diff --git a/src/components/dashboard/appointment/index.jsx b/src/components/dashboard/appointment/index.jsx deleted file mode 100644 index 3ca2a4d..0000000 --- a/src/components/dashboard/appointment/index.jsx +++ /dev/null @@ -1,11 +0,0 @@ -import HeadTitle from "../head-title"; - -function Appointment() { - return ( -
- -
- ); -} - -export default Appointment; \ No newline at end of file diff --git a/src/components/dashboard/back-button/index.jsx b/src/components/dashboard/back-button/index.jsx new file mode 100644 index 0000000..7716c04 --- /dev/null +++ b/src/components/dashboard/back-button/index.jsx @@ -0,0 +1,12 @@ +function BackButton({setMenu,value}) { + + const val = value ? value : null; + + return( + + ); +} + +export default BackButton; \ No newline at end of file diff --git a/src/components/dashboard/container/index.jsx b/src/components/dashboard/container/index.jsx new file mode 100644 index 0000000..7d31c88 --- /dev/null +++ b/src/components/dashboard/container/index.jsx @@ -0,0 +1,9 @@ +function Container({children}) { + return( +
+ {children} +
+ ) +} + +export default Container; \ No newline at end of file diff --git a/src/components/dashboard/createButton/index.jsx b/src/components/dashboard/createButton/index.jsx new file mode 100644 index 0000000..a3c7920 --- /dev/null +++ b/src/components/dashboard/createButton/index.jsx @@ -0,0 +1,9 @@ +function CreateButton({setCreateMenu, nameMenu}) { + return( + + ) +} + +export default CreateButton; \ No newline at end of file diff --git a/src/components/dashboard/doctor/index.jsx b/src/components/dashboard/doctor/index.jsx new file mode 100644 index 0000000..55064ce --- /dev/null +++ b/src/components/dashboard/doctor/index.jsx @@ -0,0 +1,23 @@ +import { useState } from 'react'; +import PageContainer from '../page-container'; +import config from '../../../config'; +import MenuHandler from './menu-handler'; + +function Doctor({user, setUser}) { + const [page, setPage] = useState("home"); + const links = [ + {page:"home",name:"Accueil"}, + {page:"appointment",name:"Rendez-vous"}, + config.prescriptionOn ? {page:"prescription",name:"Préscriptions"} : null, + {page:"medical-file",name:"Dossier Médical"}, + {page:"profil",name:"Profil"} + ]; + + return ( + + + + ) +} + +export default Doctor; \ No newline at end of file diff --git a/src/components/dashboard/doctor/menu-handler/index.jsx b/src/components/dashboard/doctor/menu-handler/index.jsx new file mode 100644 index 0000000..ba73c50 --- /dev/null +++ b/src/components/dashboard/doctor/menu-handler/index.jsx @@ -0,0 +1,10 @@ +function MenuHandler({page, setPage, user}) { + return ( +
+

MenuHandler

+

Current page: {page}

+
+ ) +} + +export default MenuHandler; \ No newline at end of file diff --git a/src/components/dashboard/home/index.jsx b/src/components/dashboard/home/index.jsx index 341cf85..f886396 100644 --- a/src/components/dashboard/home/index.jsx +++ b/src/components/dashboard/home/index.jsx @@ -2,7 +2,7 @@ import HeadTitle from "../head-title" function Home() { return( -
+
) diff --git a/src/components/dashboard/index.jsx b/src/components/dashboard/index.jsx index b94e8ed..b5793b4 100644 --- a/src/components/dashboard/index.jsx +++ b/src/components/dashboard/index.jsx @@ -1,17 +1,102 @@ -import Navbarre from "./navbarre"; -import Layout from "./layout"; import PageHandler from "./page-handler"; -import { useState } from "react"; +import { useState, useEffect } from "react"; +import { getUserSession, setUserSession } from "../../modules/userManager"; +import { get } from "../../modules/fetchManager"; +import TypeUser from "./type-user"; +import Loader from "./loader"; +import SecondMenuBg from "./second-menu-bg"; +import NotVerified from "./notVerified"; function Dashboard() { - const [page, setPage] = useState("home"); + const [user, setUser] = useState(getUserSession()); + const [type, setType] = useState((user.roles) ? true : false); + const [loading, setLoading] = useState(0); + + // useEffect(() => { + // setUserSession(user); + // }, [user]); + + if(!user.token || !user.data){ + window.location.href = '/login'; + } + + if(!type && loading === 0){ + get('users/@me/roles', user.token).then((data) => { + + setLoading(loading + 1); + + if(data.status === 403) { + window.location.href = '/login'; + return; + } + + if(data.status === 404) { + setType(false); + get('doctors/@me', user.token).then((data) => { + setLoading(loading + 1); + + if(data.status >= 400) { + return; + } + + const newUser = { + token: user.token, + data: user.data, + roles: user.roles, + doctor: data.JSON, + }; + + setUser(newUser); + setUserSession(newUser); + setType(true); + }); + return; + } + + const newUser = { + token: user.token, + data: user.data, + roles: data.JSON, + }; + + setUser(newUser); + setUserSession(newUser); + setType(true); + }); + + // console.log(type); + } return(
- - - - + { + type && (!user.doctor || user.doctor.is_verified) ? + + : + null + } + { + type && user.doctor && !user.doctor.is_verified ? + + : + null + } + { + !type && loading < 2 ? +
+ +
+ : + null + } + { + !type && loading === 2 ? + + + + : + null + }
); } diff --git a/src/components/dashboard/list-display/index.jsx b/src/components/dashboard/list-display/index.jsx new file mode 100644 index 0000000..20e4cd2 --- /dev/null +++ b/src/components/dashboard/list-display/index.jsx @@ -0,0 +1,18 @@ +function ListDisplay({data,itemComponent,setCreateMenu,nameMenu}) { + return( +
+ +
    + { + data.map((item) => { +
  • + {itemComponent(item)} +
  • + }) + } +
+
+ ) +} + +export default ListDisplay; \ No newline at end of file diff --git a/src/components/dashboard/loader/index.jsx b/src/components/dashboard/loader/index.jsx new file mode 100644 index 0000000..6c6cfed --- /dev/null +++ b/src/components/dashboard/loader/index.jsx @@ -0,0 +1,15 @@ +import './loader.css'; +import SecondMenuBg from '../second-menu-bg'; + +function Loader({color}) { + let cssColor = 'loader' + if(color) { + cssColor += ' cyan'; + } + + return( + + ); +} + +export default Loader; \ No newline at end of file diff --git a/src/components/dashboard/loader/loader.css b/src/components/dashboard/loader/loader.css new file mode 100644 index 0000000..9d29eb0 --- /dev/null +++ b/src/components/dashboard/loader/loader.css @@ -0,0 +1,24 @@ +.loader { + width: 48px; + height: 48px; + border: 5px solid #FFF; + border-bottom-color: transparent; + border-radius: 50%; + display: inline-block; + box-sizing: border-box; + animation: rotation 1s linear infinite; +} + +.cyan { + border: 5px solid rgb(22,78,99); + border-bottom-color: transparent; +} + +@keyframes rotation { + 0% { + transform: rotate(0deg); + } + 100% { + transform: rotate(360deg); + } +} \ No newline at end of file diff --git a/src/components/dashboard/modal-container/index.jsx b/src/components/dashboard/modal-container/index.jsx new file mode 100644 index 0000000..b39f755 --- /dev/null +++ b/src/components/dashboard/modal-container/index.jsx @@ -0,0 +1,11 @@ +function ModalContainer({ children }) { + return ( +
+
+ {children} +
+
+ ); +} + +export default ModalContainer; \ No newline at end of file diff --git a/src/components/dashboard/navbarre/hero/index.jsx b/src/components/dashboard/navbarre/hero/index.jsx new file mode 100644 index 0000000..05d2d11 --- /dev/null +++ b/src/components/dashboard/navbarre/hero/index.jsx @@ -0,0 +1,12 @@ +function Hero({user}) { + return( +
+
+
+

{user.data.first_name + " " + user.data.last_name}

+
+
+ ) +} + +export default Hero; \ No newline at end of file diff --git a/src/components/dashboard/navbarre/index.jsx b/src/components/dashboard/navbarre/index.jsx index e53cfa6..f430b3a 100644 --- a/src/components/dashboard/navbarre/index.jsx +++ b/src/components/dashboard/navbarre/index.jsx @@ -1,45 +1,22 @@ -function Navbarre({setPage}) { +import Hero from "./hero"; +import LinkMenu from "./link-menu"; +import { removeUserSession } from "../../../modules/userManager"; + +function Navbarre({setPage, user, setUser, links}) { + const handleClick = (e) => { - // e.preventDefault(); - setPage(e.target.getAttribute("id")); - }; + e.preventDefault(); + setUser(null); + removeUserSession(); + window.location.href = '/'; + } return ( ) diff --git a/src/components/dashboard/navbarre/link-menu/index.jsx b/src/components/dashboard/navbarre/link-menu/index.jsx new file mode 100644 index 0000000..9b0f45c --- /dev/null +++ b/src/components/dashboard/navbarre/link-menu/index.jsx @@ -0,0 +1,18 @@ +import LinkNav from "../link-nav"; + +function LinkMenu({setPage, links}) { + + const items = links.map((link,index) => + link ? : null + ); + + return ( +
+
    + {items} +
+
+ ) +} + +export default LinkMenu; \ No newline at end of file diff --git a/src/components/dashboard/navbarre/link-nav/index.jsx b/src/components/dashboard/navbarre/link-nav/index.jsx new file mode 100644 index 0000000..4af6b23 --- /dev/null +++ b/src/components/dashboard/navbarre/link-nav/index.jsx @@ -0,0 +1,17 @@ +function LinkNav({setPage,link}) { + + const handleClick = (e) => { + // e.preventDefault(); + setPage(e.target.getAttribute("id")); + }; + + return( +
  • +

    {link.name}

    +
    +
    +
  • + ) +} + +export default LinkNav; \ No newline at end of file diff --git a/src/components/dashboard/notVerified/index.jsx b/src/components/dashboard/notVerified/index.jsx new file mode 100644 index 0000000..b96a29c --- /dev/null +++ b/src/components/dashboard/notVerified/index.jsx @@ -0,0 +1,24 @@ +import { removeUserSession } from "../../../modules/userManager"; +import SecondMenuBg from "../second-menu-bg"; + +function NotVerified({setUser}) { + const handleClick = (e) => { + e.preventDefault(); + removeUserSession(); + setUser(null); + window.location.href = '/'; + } + + return( +
    + +
    +

    Votre compte est en cours de vérification,
    Un mail vous sera envoyé une fois votre compte validé

    + +
    +
    +
    + ) +} + +export default NotVerified; \ No newline at end of file diff --git a/src/components/dashboard/page-container/index.jsx b/src/components/dashboard/page-container/index.jsx new file mode 100644 index 0000000..eb38b4f --- /dev/null +++ b/src/components/dashboard/page-container/index.jsx @@ -0,0 +1,15 @@ +import Navbarre from "../navbarre" +import Layout from "../layout" + +function PageContainer({children,links,setPage,setUser, user}) { + return( +
    + + + {children} + +
    + ) +} + +export default PageContainer; \ No newline at end of file diff --git a/src/components/dashboard/page-handler/index.jsx b/src/components/dashboard/page-handler/index.jsx index a103805..d48eda6 100644 --- a/src/components/dashboard/page-handler/index.jsx +++ b/src/components/dashboard/page-handler/index.jsx @@ -1,22 +1,21 @@ -import Home from "../home"; -import Prescription from "../prescription"; -import MedicalFile from "../medical-file"; -import Appointment from "../appointment"; +import { removeUserSession } from "../../../modules/userManager"; +import Patient from "../patient"; +import Admin from "../admin"; -function PageHandler({page}) { - switch (page) { - case "home": - return ; - case "prescription": - return ; - case "medical-file": - return ; - case "appointment": - return ; +function PageHandler({user,setUser}) { + switch (user.roles[0].name) { + case "Patient" : + return ; + case "Doctor" : + return null; + case "Admin" : + return ; default: - return ; + setUser(null); + removeUserSession(); + window.location.href = "/login"; + return null; } - } export default PageHandler; \ No newline at end of file diff --git a/src/components/dashboard/patient/appointment/create/index.jsx b/src/components/dashboard/patient/appointment/create/index.jsx new file mode 100644 index 0000000..4ef4cb1 --- /dev/null +++ b/src/components/dashboard/patient/appointment/create/index.jsx @@ -0,0 +1,24 @@ +import ModalContainer from "../../../modal-container"; +import SubmitButton from "../../../submit-button"; +import BackButton from "../../../back-button"; + +function Create({setCreateMenu, user}) { + return ( + +
    +

    Prendre Rendez-Vous

    +
    +
    +
    + +
    +
    + + +
    +
    +
    + ) +} + +export default Create; \ No newline at end of file diff --git a/src/components/dashboard/patient/appointment/index.jsx b/src/components/dashboard/patient/appointment/index.jsx new file mode 100644 index 0000000..0bf966e --- /dev/null +++ b/src/components/dashboard/patient/appointment/index.jsx @@ -0,0 +1,51 @@ +import HeadTitle from "../../head-title"; +import { get } from "../../../../modules/fetchManager"; +import { useState } from "react"; +import Loader from "../../loader"; +import Container from "../../container"; +import ListDisplay from "../../list-display"; +import ItemList from "./item-list"; +import Create from "./create"; +import CreateButton from "../../createButton"; + +function Appointment({user}) { + const [loading, setLoading] = useState(true); + const [error, setError] = useState(null); + const [appointments, setAppointments] = useState([]); + const [createMenu, setCreateMenu] = useState(false); + + if(loading && !error && appointments.length === 0){ + get('patients/@me/appointments', user.token) + .then((data) => { + setLoading(false); + if(data.status === 404) { + setError("Aucun rendez-vous trouvé"); + return; + } + + if(data.status === 500) { + setError("Erreur serveur, veuillez réessayer plus tard"); + return; + } + + setAppointments(data.JSON); + }); + } + + return ( +
    + +
    + +
    + + { loading ? : null } + { error ?

    {error}

    : null } + { !error && !loading ? : null } + { createMenu ? : null } +
    +
    + ); +} + +export default Appointment; \ No newline at end of file diff --git a/src/components/dashboard/patient/appointment/item-list/index.jsx b/src/components/dashboard/patient/appointment/item-list/index.jsx new file mode 100644 index 0000000..d023950 --- /dev/null +++ b/src/components/dashboard/patient/appointment/item-list/index.jsx @@ -0,0 +1,11 @@ +function ItemList({item}) { + return ( +
    +

    {item.date}

    +

    {item.doctor}

    +

    {item.reason}

    +
    + ); +} + +export default ItemList; \ No newline at end of file diff --git a/src/components/dashboard/patient/index.jsx b/src/components/dashboard/patient/index.jsx new file mode 100644 index 0000000..d6b159d --- /dev/null +++ b/src/components/dashboard/patient/index.jsx @@ -0,0 +1,23 @@ +import { useState } from 'react'; +import PageContainer from '../page-container'; +import config from '../../../config'; +import MenuHandler from './menu-handler'; + +function Patient({user,setUser}) { + const [page, setPage] = useState("home"); + const links = [ + {page:"home",name:"Accueil"}, + {page:"appointment",name:"Rendez-vous"}, + config.prescriptionOn ? {page:"prescription",name:"Préscriptions"} : null, + {page:"medical-file",name:"Dossier Médical"}, + {page:"profil",name:"Profil"} + ] + + return ( + + + + ) +} + +export default Patient; \ No newline at end of file diff --git a/src/components/dashboard/medical-file/index.jsx b/src/components/dashboard/patient/medical-file/index.jsx similarity index 78% rename from src/components/dashboard/medical-file/index.jsx rename to src/components/dashboard/patient/medical-file/index.jsx index 0f98d42..848ee65 100644 --- a/src/components/dashboard/medical-file/index.jsx +++ b/src/components/dashboard/patient/medical-file/index.jsx @@ -1,4 +1,4 @@ -import HeadTitle from "../head-title"; +import HeadTitle from "../../head-title"; function MedicalFile() { return ( diff --git a/src/components/dashboard/patient/menu-handler/index.jsx b/src/components/dashboard/patient/menu-handler/index.jsx new file mode 100644 index 0000000..c9b70d0 --- /dev/null +++ b/src/components/dashboard/patient/menu-handler/index.jsx @@ -0,0 +1,23 @@ +import Home from "../../home"; +import Prescription from "../prescription"; +import MedicalFile from "../medical-file"; +import Appointment from "../appointment"; +import Profil from "../profil"; + +function MenuHandler({setPage,page,user}) { + switch (page) { + case "prescription": + return ; + case "medical-file": + return ; + case "appointment": + return ; + case "profil": + return ; + default: + return ; + } + +} + +export default MenuHandler; \ No newline at end of file diff --git a/src/components/dashboard/prescription/index.jsx b/src/components/dashboard/patient/prescription/index.jsx similarity index 78% rename from src/components/dashboard/prescription/index.jsx rename to src/components/dashboard/patient/prescription/index.jsx index e220512..98c2492 100644 --- a/src/components/dashboard/prescription/index.jsx +++ b/src/components/dashboard/patient/prescription/index.jsx @@ -1,4 +1,4 @@ -import HeadTitle from "../head-title"; +import HeadTitle from "../../head-title"; function Prescription() { return ( diff --git a/src/components/dashboard/patient/profil/index.jsx b/src/components/dashboard/patient/profil/index.jsx new file mode 100644 index 0000000..bb9b669 --- /dev/null +++ b/src/components/dashboard/patient/profil/index.jsx @@ -0,0 +1,11 @@ +import HeadTitle from "../../head-title"; + +function Profil() { + return ( +
    + +
    + ); +} + +export default Profil; \ No newline at end of file diff --git a/src/components/dashboard/second-menu-bg/index.jsx b/src/components/dashboard/second-menu-bg/index.jsx new file mode 100644 index 0000000..0dc56ba --- /dev/null +++ b/src/components/dashboard/second-menu-bg/index.jsx @@ -0,0 +1,9 @@ +function SecondMenuBg({children}) { + return( +
    + {children} +
    + ) +} + +export default SecondMenuBg; \ No newline at end of file diff --git a/src/components/dashboard/submit-button/index.jsx b/src/components/dashboard/submit-button/index.jsx new file mode 100644 index 0000000..fe766d8 --- /dev/null +++ b/src/components/dashboard/submit-button/index.jsx @@ -0,0 +1,9 @@ +function SubmitButton() { + return ( + + ); +} + +export default SubmitButton; \ No newline at end of file diff --git a/src/components/dashboard/type-user/container/index.jsx b/src/components/dashboard/type-user/container/index.jsx new file mode 100644 index 0000000..7ccfef6 --- /dev/null +++ b/src/components/dashboard/type-user/container/index.jsx @@ -0,0 +1,9 @@ +function Container({children}) { + return ( +
    + {children} +
    + ); +} + +export default Container; \ No newline at end of file diff --git a/src/components/dashboard/type-user/doctor-type-user/index.jsx b/src/components/dashboard/type-user/doctor-type-user/index.jsx new file mode 100644 index 0000000..910e878 --- /dev/null +++ b/src/components/dashboard/type-user/doctor-type-user/index.jsx @@ -0,0 +1,58 @@ +import Container from "../container"; +import BackButton from "../../back-button"; +import SubmitButton from "../../submit-button"; +import { useForm } from 'react-hook-form'; +import { getUserSession, setUserSession } from "../../../../modules/userManager"; +import { post, get } from "../../../../modules/fetchManager"; + +function DoctorTypeUser({setMenu}) { + + const { register, handleSubmit } = useForm(); + + const onSubmit = (data) => { + const user = getUserSession(); + post('doctors/register', data, user.token) + .then(data => { + if(data.status !== 200) { + alert("Erreur lors de la création du compte médecin"); + } + window.location.href = '/dashboard'; + }); + } + + return ( + +
    +
    +

    Création d'un compte Patient

    +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    +
    + ); +} + +export default DoctorTypeUser; \ No newline at end of file diff --git a/src/components/dashboard/type-user/index.jsx b/src/components/dashboard/type-user/index.jsx new file mode 100644 index 0000000..d221d04 --- /dev/null +++ b/src/components/dashboard/type-user/index.jsx @@ -0,0 +1,21 @@ +import { useState } from "react"; +import SelectTypeUser from "./select-type-user"; +import DoctorTypeUser from "./doctor-type-user"; +import PatientTypeUser from "./patient-type-user"; +import SecondMenuBg from "../second-menu-bg"; + +function TypeUser() { + const [menu, setMenu] = useState(null); + + return ( + +
    + {menu === "patient" ? : null} + {menu === "doctor" ? : null} + {(menu !== "patient" && menu !== "doctor") ? : null} +
    +
    + ); +} + +export default TypeUser; \ No newline at end of file diff --git a/src/components/dashboard/type-user/patient-type-user/index.jsx b/src/components/dashboard/type-user/patient-type-user/index.jsx new file mode 100644 index 0000000..4680991 --- /dev/null +++ b/src/components/dashboard/type-user/patient-type-user/index.jsx @@ -0,0 +1,63 @@ +import Container from "../container"; +import BackButton from "../../back-button"; +import SubmitButton from "../../submit-button"; +import { useForm } from 'react-hook-form'; +import { getUserSession, setUserSession } from "../../../../modules/userManager"; +import { post, get } from "../../../../modules/fetchManager"; + +function PatientTypeUser({setMenu}) { + + const { register, handleSubmit } = useForm(); + + const onSubmit = (data) => { + const user = getUserSession(); + post('patients/register', data, user.token) + .then(data => { + console.log(data); + if(data.status !== 200) { + alert("Erreur lors de la création du compte patient"); + } + window.location.href = '/dashboard'; + }); + } + + return( + +
    +
    +

    Création d'un compte Patient

    +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    +
    + ); +} + +export default PatientTypeUser; \ No newline at end of file diff --git a/src/components/dashboard/type-user/select-type-user/index.jsx b/src/components/dashboard/type-user/select-type-user/index.jsx new file mode 100644 index 0000000..4f61204 --- /dev/null +++ b/src/components/dashboard/type-user/select-type-user/index.jsx @@ -0,0 +1,33 @@ +import Container from "../container"; + +function SelectTypeUser({setMenu}) { + + const handleClick = (e) => { + e.preventDefault(); + const type = e.target.id; + if (type !== "patient" && type !== "doctor") { + setMenu(null); + return; + } + setMenu(type); + } + + return( + +
    +

    Type d'utilisateur

    +

    Choisissez le type de compte que vous souhaitez créer

    +
    +
    + + +
    +
    + ); +} + +export default SelectTypeUser; \ No newline at end of file diff --git a/src/index.js b/src/index.js index ac045a5..bfe64c5 100644 --- a/src/index.js +++ b/src/index.js @@ -9,6 +9,7 @@ import Home from './components/vitrine/home'; import Login from './components/auth/login'; import Register from './components/auth/register'; import Dashboard from './components/dashboard'; +import VerifyEmail from './components/auth/verifyEmail'; const router = createBrowserRouter([ { @@ -26,6 +27,10 @@ const router = createBrowserRouter([ { path: "dashboard", element: , + }, + { + path: "email/verify", + element: , } ]); diff --git a/src/modules/fetchManager.js b/src/modules/fetchManager.js index 92385ce..0ef1c48 100644 --- a/src/modules/fetchManager.js +++ b/src/modules/fetchManager.js @@ -8,6 +8,7 @@ function selectUrl(url) { async function get(url, token = 'none') { const options = { method: 'GET', + mode: 'cors', headers: { 'Content-Type': 'application/json', authorization: `${token}` }, }; @@ -27,8 +28,6 @@ async function post(url, body, token = 'none') { body: JSON.stringify(body), }; - console.log(body); - return await fetch(selectUrl(url), options) .then(res => res.json()) .then(json => { diff --git a/src/modules/userManager.js b/src/modules/userManager.js new file mode 100644 index 0000000..d98ad0c --- /dev/null +++ b/src/modules/userManager.js @@ -0,0 +1,21 @@ +function getUserSession() { + const user = JSON.parse(window.sessionStorage.getItem('user')); + if (!user) { + return false; + } + return user; + +} + +function setUserSession(user) { + if(!user || !user.token || !user.data) return false; + window.sessionStorage.setItem('user', JSON.stringify(user)); + return true; +} + +function removeUserSession() { + window.sessionStorage.removeItem('user'); + return true; +} + +export { getUserSession, setUserSession, removeUserSession }; \ No newline at end of file