+
{children}
)
diff --git a/src/components/dashboard/delete-button/index.jsx b/src/components/dashboard/delete-button/index.jsx
new file mode 100644
index 0000000..171b0e0
--- /dev/null
+++ b/src/components/dashboard/delete-button/index.jsx
@@ -0,0 +1,7 @@
+function DeleteButton({setDeleteMenu,id}) {
+ return(
+
+ )
+}
+
+export default DeleteButton;
\ No newline at end of file
diff --git a/src/components/dashboard/delete-menu/index.jsx b/src/components/dashboard/delete-menu/index.jsx
new file mode 100644
index 0000000..537fda7
--- /dev/null
+++ b/src/components/dashboard/delete-menu/index.jsx
@@ -0,0 +1,48 @@
+import ModalContainer from "../modal-container";
+import { del } from "../../../modules/fetchManager";
+import { useState } from "react";
+
+function DeleteMenu({deleteMenu, setDeleteMenu, link, user, element}) {
+
+ const [loading, setLoading] = useState(false);
+ const [error, setError] = useState(null);
+
+ const onClick = () => {
+ if(deleteMenu <= 0) {
+ setError("L'élément sélectionné est invalide !");
+ return;
+ }
+ setLoading(true);
+ del(link+'/'+deleteMenu, user.token)
+ .then(data => {
+ setLoading(false);
+ if(data.status === 500) {
+ setError("Erreur serveur, veuillez réessayer plus tard");
+ return;
+ }
+
+ if(data.status >= 400) {
+ setError("Erreur lors de la suppression, veuillez réessayer plus tard");
+ return;
+ }
+
+ setDeleteMenu(false);
+ })
+ }
+
+ return(
+
+
+
Voulez-vous vraiment supprimer {element} ?
+ {loading ?
Chargement...
: null}
+ {error ?
{error}
: null}
+
+
+
+
+
+
+ )
+}
+
+export default DeleteMenu;
\ No newline at end of file
diff --git a/src/components/dashboard/doctor/appointment/index.jsx b/src/components/dashboard/doctor/appointment/index.jsx
new file mode 100644
index 0000000..e69de29
diff --git a/src/components/dashboard/doctor/home/hospitals/index.jsx b/src/components/dashboard/doctor/home/hospitals/index.jsx
new file mode 100644
index 0000000..dfa0321
--- /dev/null
+++ b/src/components/dashboard/doctor/home/hospitals/index.jsx
@@ -0,0 +1,42 @@
+import { get } from "../../../../../modules/fetchManager";
+import { useState, useEffect } from "react";
+import ListDisplay from "../../../list-display";
+import ItemList from "./item-list";
+
+function Hospitals({user}) {
+
+ const [data, setData] = useState(null);
+ const [error, setError] = useState(null);
+ const [loading, setLoading] = useState(true);
+
+ useEffect(() => {
+ get('doctors/'+user.doctor.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);
+ });
+ },[user]);
+
+ if(loading) return
Chargement...
;
+ if(error) return
{error}
;
+ return (
+
+ );
+
+}
+
+export default Hospitals;
\ No newline at end of file
diff --git a/src/components/dashboard/doctor/home/hospitals/item-list/index.jsx b/src/components/dashboard/doctor/home/hospitals/item-list/index.jsx
new file mode 100644
index 0000000..e80db8e
--- /dev/null
+++ b/src/components/dashboard/doctor/home/hospitals/item-list/index.jsx
@@ -0,0 +1,11 @@
+function ItemList({item}) {
+ 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/doctor/home/index.jsx b/src/components/dashboard/doctor/home/index.jsx
new file mode 100644
index 0000000..0b28818
--- /dev/null
+++ b/src/components/dashboard/doctor/home/index.jsx
@@ -0,0 +1,27 @@
+import HeadTitle from "../../head-title";
+import Services from "./services";
+import Hospitals from "./hospitals";
+
+function Home({user}) {
+ return(
+
+
+
+
+
+
Affectation
+
+
+
+
+
+
+
+
+
+
+
+ );
+}
+
+export default Home;
\ No newline at end of file
diff --git a/src/components/dashboard/doctor/home/services/index.jsx b/src/components/dashboard/doctor/home/services/index.jsx
new file mode 100644
index 0000000..8b62a6d
--- /dev/null
+++ b/src/components/dashboard/doctor/home/services/index.jsx
@@ -0,0 +1,42 @@
+import { get } from "../../../../../modules/fetchManager";
+import { useState, useEffect } from "react";
+import ListDisplay from "../../../list-display";
+import ItemList from "./item-list";
+
+function Services({user}) {
+
+ const [data, setData] = useState(null);
+ const [error, setError] = useState(null);
+ const [loading, setLoading] = useState(true);
+
+ useEffect(() => {
+ get('doctors/'+user.doctor.id+'/services', user.token)
+ .then((data) => {
+ setLoading(false);
+ if(data.status === 404) {
+ setError("Aucun service trouvé");
+ return;
+ }
+
+ if(data.status === 500) {
+ setError("Erreur serveur, veuillez réessayer plus tard");
+ return;
+ }
+ setData(data.JSON);
+ });
+ },[user]);
+
+ if(loading) return
Chargement...
;
+ if(error) return
{error}
;
+ return (
+
+ );
+
+}
+
+export default Services;
\ No newline at end of file
diff --git a/src/components/dashboard/doctor/home/services/item-list/index.jsx b/src/components/dashboard/doctor/home/services/item-list/index.jsx
new file mode 100644
index 0000000..d85dc40
--- /dev/null
+++ b/src/components/dashboard/doctor/home/services/item-list/index.jsx
@@ -0,0 +1,11 @@
+function ItemList({item}) {
+ return(
+
+
{item.name}
+
{item.price}€
+
{item.description}
+
+ )
+}
+
+export default ItemList;
\ No newline at end of file
diff --git a/src/components/dashboard/doctor/medical-file/index.jsx b/src/components/dashboard/doctor/medical-file/index.jsx
new file mode 100644
index 0000000..e69de29
diff --git a/src/components/dashboard/doctor/menu-handler/index.jsx b/src/components/dashboard/doctor/menu-handler/index.jsx
index ba73c50..5944cc5 100644
--- a/src/components/dashboard/doctor/menu-handler/index.jsx
+++ b/src/components/dashboard/doctor/menu-handler/index.jsx
@@ -1,10 +1,25 @@
-function MenuHandler({page, setPage, user}) {
- return (
-
-
MenuHandler
-
Current page: {page}
-
- )
+import Prescription from "../prescription";
+import MedicalFile from "../medical-file";
+import Appointment from "../appointment";
+import Profil from "../profil";
+import Home from "../home";
+import Patient from "../patient";
+
+function MenuHandler({page,user}) {
+ switch (page) {
+ case "prescription":
+ return
;
+ case "medical-file":
+ return
;
+ case "appointment":
+ return
;
+ case "patient":
+ return
;
+ case "profil":
+ return
;
+ default:
+ return
;
+ }
}
export default MenuHandler;
\ No newline at end of file
diff --git a/src/components/dashboard/doctor/patient/index.jsx b/src/components/dashboard/doctor/patient/index.jsx
new file mode 100644
index 0000000..e69de29
diff --git a/src/components/dashboard/doctor/prescription/index.jsx b/src/components/dashboard/doctor/prescription/index.jsx
new file mode 100644
index 0000000..e69de29
diff --git a/src/components/dashboard/doctor/profil/index.jsx b/src/components/dashboard/doctor/profil/index.jsx
new file mode 100644
index 0000000..e69de29
diff --git a/src/components/dashboard/head-title/index.jsx b/src/components/dashboard/head-title/index.jsx
index 2e7d5cb..2f4439b 100644
--- a/src/components/dashboard/head-title/index.jsx
+++ b/src/components/dashboard/head-title/index.jsx
@@ -1,6 +1,6 @@
function HeadTitle({title}) {
return(
-
+
{title}
)
diff --git a/src/components/dashboard/index.jsx b/src/components/dashboard/index.jsx
index b5793b4..9ac7a1d 100644
--- a/src/components/dashboard/index.jsx
+++ b/src/components/dashboard/index.jsx
@@ -1,5 +1,5 @@
import PageHandler from "./page-handler";
-import { useState, useEffect } from "react";
+import { useState } from "react";
import { getUserSession, setUserSession } from "../../modules/userManager";
import { get } from "../../modules/fetchManager";
import TypeUser from "./type-user";
@@ -12,10 +12,6 @@ function Dashboard() {
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';
}
@@ -23,6 +19,8 @@ function Dashboard() {
if(!type && loading === 0){
get('users/@me/roles', user.token).then((data) => {
+ console.log(data);
+
setLoading(loading + 1);
if(data.status === 403) {
@@ -30,22 +28,24 @@ function Dashboard() {
return;
}
- if(data.status === 404) {
+ if(data.status === 404 || data.JSON[0].name === "Doctor") {
setType(false);
- get('doctors/@me', user.token).then((data) => {
+ get('doctors/@me', user.token).then((dataDoc) => {
setLoading(loading + 1);
- if(data.status >= 400) {
+ if(dataDoc.status >= 400) {
return;
}
const newUser = {
token: user.token,
data: user.data,
- roles: user.roles,
- doctor: data.JSON,
+ roles: data.JSON,
+ doctor: dataDoc.JSON,
};
+ // console.log(newUser);
+
setUser(newUser);
setUserSession(newUser);
setType(true);
@@ -67,6 +67,9 @@ function Dashboard() {
// console.log(type);
}
+ // console.log(type);
+ // console.log(user);
+
return(
{
@@ -82,15 +85,15 @@ function Dashboard() {
null
}
{
- !type && loading < 2 ?
+ !type && loading === 2 ?
-
+
:
null
}
{
- !type && loading === 2 ?
+ !type && loading < 2 ?
diff --git a/src/components/dashboard/layout/index.jsx b/src/components/dashboard/layout/index.jsx
index 13c41ab..0fce7b0 100644
--- a/src/components/dashboard/layout/index.jsx
+++ b/src/components/dashboard/layout/index.jsx
@@ -1,6 +1,6 @@
function Layout({children}) {
return(
-
+
{children}
)
diff --git a/src/components/dashboard/list-display/index.jsx b/src/components/dashboard/list-display/index.jsx
index 20e4cd2..4fc56b4 100644
--- a/src/components/dashboard/list-display/index.jsx
+++ b/src/components/dashboard/list-display/index.jsx
@@ -1,14 +1,16 @@
-function ListDisplay({data,itemComponent,setCreateMenu,nameMenu}) {
+function ListDisplay({data, ItemComponent, height = true, setDeleteMenu = null, setModifyMenu = null, user = null, setDetailMenu = null}) {
+ const className = height ? "min-h-full h-fit py-5 w-full" : "h-fit py-5 w-full";
+ // const className = 'h-fit py-5 w-full';
+ console.log(className)
return(
-
-
+
{
- data.map((item) => {
+ data.map((item,index) =>
-
- {itemComponent(item)}
+ {}
- })
+ )
}
diff --git a/src/components/dashboard/logout-button/index.jsx b/src/components/dashboard/logout-button/index.jsx
new file mode 100644
index 0000000..6ac6fce
--- /dev/null
+++ b/src/components/dashboard/logout-button/index.jsx
@@ -0,0 +1,17 @@
+import { removeUserSession } from "../../../modules/userManager";
+
+function LogoutButton({setUser}) {
+
+ const handleClick = (e) => {
+ e.preventDefault();
+ setUser(null);
+ removeUserSession();
+ window.location.href = '/';
+ }
+
+ return(
+
+ );
+}
+
+export default LogoutButton;
\ No newline at end of file
diff --git a/src/components/dashboard/menu-display/index.jsx b/src/components/dashboard/menu-display/index.jsx
new file mode 100644
index 0000000..891dada
--- /dev/null
+++ b/src/components/dashboard/menu-display/index.jsx
@@ -0,0 +1,15 @@
+import Container from "../container"
+import Loader from "../loader"
+import ListDisplay from "../list-display"
+
+function MenuDisplay({loading, error, data, ItemList, setDeleteMenu, setModifyMenu,user = null,setDetailMenu = null}) {
+ return(
+
+ { loading ? : null }
+ { error ? {error}
: null }
+ { !error && !loading ? : null }
+
+ )
+}
+
+export default MenuDisplay;
\ No newline at end of file
diff --git a/src/components/dashboard/modal-container/index.jsx b/src/components/dashboard/modal-container/index.jsx
index b39f755..815fcb7 100644
--- a/src/components/dashboard/modal-container/index.jsx
+++ b/src/components/dashboard/modal-container/index.jsx
@@ -1,7 +1,10 @@
function ModalContainer({ children }) {
return (
-
+
+ {/*
setMenu(false)}>
+ X
+
*/}
{children}
diff --git a/src/components/dashboard/modify-button/index.jsx b/src/components/dashboard/modify-button/index.jsx
new file mode 100644
index 0000000..c9183dd
--- /dev/null
+++ b/src/components/dashboard/modify-button/index.jsx
@@ -0,0 +1,7 @@
+function ModifyButton({setModifyMenu,item}) {
+ return(
+
+ );
+}
+
+export default ModifyButton;
\ No newline at end of file
diff --git a/src/components/dashboard/navbarre/hero/index.jsx b/src/components/dashboard/navbarre/hero/index.jsx
index 05d2d11..98bfe2e 100644
--- a/src/components/dashboard/navbarre/hero/index.jsx
+++ b/src/components/dashboard/navbarre/hero/index.jsx
@@ -1,9 +1,9 @@
function Hero({user}) {
return(
-
+
-
-
{user.data.first_name + " " + user.data.last_name}
+
+
{user.data.first_name + " " + user.data.last_name}
)
diff --git a/src/components/dashboard/navbarre/index.jsx b/src/components/dashboard/navbarre/index.jsx
index f430b3a..63b399e 100644
--- a/src/components/dashboard/navbarre/index.jsx
+++ b/src/components/dashboard/navbarre/index.jsx
@@ -1,22 +1,15 @@
import Hero from "./hero";
import LinkMenu from "./link-menu";
-import { removeUserSession } from "../../../modules/userManager";
+import LogoutButton from "../logout-button";
function Navbarre({setPage, user, setUser, links}) {
- const handleClick = (e) => {
- e.preventDefault();
- setUser(null);
- removeUserSession();
- window.location.href = '/';
- }
-
return (
);
diff --git a/src/modules/fetchManager.js b/src/modules/fetchManager.js
index 0ef1c48..077e8ef 100644
--- a/src/modules/fetchManager.js
+++ b/src/modules/fetchManager.js
@@ -5,11 +5,12 @@ function selectUrl(url) {
return url.includes('http') ? url : `${config.api}/${url}`;
}
-async function get(url, token = 'none') {
+async function get(url, token = 'none',signal = null) {
const options = {
method: 'GET',
mode: 'cors',
headers: { 'Content-Type': 'application/json', authorization: `${token}` },
+ signal: signal,
};
return await fetch(selectUrl(url), options)
@@ -20,12 +21,13 @@ async function get(url, token = 'none') {
.catch(err => error(err));
}
-async function post(url, body, token = 'none') {
+async function post(url, body, token = 'none',signal = null) {
const options = {
method: 'POST',
mode: 'cors',
headers: { 'Content-Type': 'application/json', authorization: `${token}` },
body: JSON.stringify(body),
+ signal: signal,
};
return await fetch(selectUrl(url), options)
@@ -36,12 +38,13 @@ async function post(url, body, token = 'none') {
.catch(err => error(err));
}
-async function patch(url, body, token = 'none') {
+async function patch(url, body, token = 'none',signal = null) {
const options = {
method: 'PATCH',
mode: 'cors',
headers: { 'Content-Type': 'application/json', authorization: `${token}` },
body: JSON.stringify(body),
+ signal: signal,
};
return await fetch(selectUrl(url), options)
@@ -52,12 +55,29 @@ async function patch(url, body, token = 'none') {
.catch(err => error(err));
}
-async function put(url, body, token = 'none') {
+async function put(url, body, token = 'none',signal = null) {
const options = {
method: 'PUT',
mode: 'cors',
headers: { 'Content-Type': 'application/json', authorization: `${token}` },
body: JSON.stringify(body),
+ signal: signal,
+ };
+
+ return await fetch(selectUrl(url), options)
+ .then(res => res.json())
+ .then(json => {
+ return json;
+ })
+ .catch(err => error(err));
+}
+
+async function del(url, token = 'none',signal = null) {
+ const options = {
+ method: 'DELETE',
+ mode: 'cors',
+ headers: { 'Content-Type': 'application/json', authorization: `${token}` },
+ signal: signal,
};
return await fetch(selectUrl(url), options)
@@ -73,4 +93,5 @@ export {
post,
patch,
put,
+ del
};
\ No newline at end of file
diff --git a/src/modules/useAsync.js b/src/modules/useAsync.js
new file mode 100644
index 0000000..e34ca4d
--- /dev/null
+++ b/src/modules/useAsync.js
@@ -0,0 +1,42 @@
+import { useState, useCallback } from "react";
+const cache = new Map();
+const defaultOptions = {
+ cacheKey: "",
+ refetch: false,
+};
+export const useAsync = (defaultData) => {
+ const [data, setData] = useState({
+ data: defaultData ?? null,
+ error: null,
+ loading: false,
+ });
+ const run = useCallback(async (asyncFn, options = {}) => {
+ try {
+ // Merge the default options with the options passed in
+ const { cacheKey, refetch } = { ...defaultOptions, ...options };
+ const result = { data: null, error: null, loading: false };
+ // If we have a cache key and not requesting a new data, then return the cached data
+ if (!refetch && cacheKey && cache.has(cacheKey)) {
+ const res = cache.get(cacheKey);
+ result.data = res;
+ } else {
+ setData({ ...result, loading: true });
+ const res = await asyncFn();
+ result.data = res;
+ cacheKey && cache.set(cacheKey, res);
+ }
+ setData(result);
+ return result;
+ } catch (error) {
+ const result = { data: null, error: error, loading: false };
+ setData(result);
+ return result;
+ }
+ }, []);
+ return {
+ data : data.data,
+ error: data.error,
+ loading: data.loading,
+ run,
+ };
+};
\ No newline at end of file