) => void;
}
diff --git a/src/components/accessories/menuItem/MenuItem.tsx b/src/components/accessories/menuItem/MenuItem.tsx
index 3e5177cdd..6347ca63d 100644
--- a/src/components/accessories/menuItem/MenuItem.tsx
+++ b/src/components/accessories/menuItem/MenuItem.tsx
@@ -14,6 +14,7 @@ interface IOwnProps {
label: string;
selected?: boolean;
expandedContent?: ReactNode;
+ dataCy?: string;
onClick: () => void;
}
@@ -23,11 +24,13 @@ export const MenuItem = ({
label,
selected,
expandedContent,
+ dataCy,
onClick,
}: IOwnProps) => {
const [expanded, setExpanded] = useState(false);
const menu = (
diff --git a/src/components/activities/adminActivity/SideMenu/SideMenu.module.scss b/src/components/activities/adminActivity/SideMenu/SideMenu.module.scss
index 7f9c69479..d002276a1 100644
--- a/src/components/activities/adminActivity/SideMenu/SideMenu.module.scss
+++ b/src/components/activities/adminActivity/SideMenu/SideMenu.module.scss
@@ -20,6 +20,14 @@
gap: 8px;
}
+.editButton {
+ color: black !important;
+ background-color: white !important;
+ &:hover {
+ background-color: gray !important;
+ }
+}
+
.item {
display: flex;
flex-direction: column;
diff --git a/src/components/activities/adminActivity/SideMenu/SideMenu.tsx b/src/components/activities/adminActivity/SideMenu/SideMenu.tsx
index a3b6e55f6..81c8b9806 100644
--- a/src/components/activities/adminActivity/SideMenu/SideMenu.tsx
+++ b/src/components/activities/adminActivity/SideMenu/SideMenu.tsx
@@ -10,10 +10,12 @@ import {
People,
SupervisedUserCircle,
} from "@mui/icons-material";
+import { PATHS } from "consts";
import React, { ReactNode, useCallback } from "react";
import { useTranslation } from "react-i18next";
import { useLocation, useNavigate } from "react-router";
import { useAppSelector } from "../../../../libraries/hooks/redux";
+import Button from "../../../accessories/button/Button";
import { MenuItem } from "../../../accessories/menuItem";
import { IAdminSection } from "../types";
import classes from "./SideMenu.module.scss";
@@ -86,6 +88,7 @@ const SideMenu = () => {
))}
{t("nav.hospital")}
}
label={t(`nav.hospitalInfo`)}
onClick={() => {}}
@@ -102,6 +105,17 @@ const SideMenu = () => {
{entry[1] ?? "---"}
))}
+
}
/>
diff --git a/src/consts.ts b/src/consts.ts
index 91fe44272..ccda8c1ad 100644
--- a/src/consts.ts
+++ b/src/consts.ts
@@ -72,4 +72,5 @@ export const PATHS = {
admin_admissions_types: "/admin/types/admissions",
admin_admissions_types_new: "/admin/types/admissions/new",
admin_admissions_types_edit: "/admin/types/admissions/:code/edit",
+ admin_hospital_edit: "/admin/hospital/edit",
};
diff --git a/src/mockServer/routes/hospital.js b/src/mockServer/routes/hospital.js
index 09083c8c6..e5e3704a9 100644
--- a/src/mockServer/routes/hospital.js
+++ b/src/mockServer/routes/hospital.js
@@ -19,5 +19,15 @@ export const hospitalRoutes = (server) => {
res.status(200).json(hospitalDTO);
}
});
+ server.put("/:code").intercept((req, res) => {
+ const body = req.jsonBody();
+ switch (body.description) {
+ case "FAIL":
+ res.status(400).json({ message: "Invalid payload" });
+ break;
+ default:
+ res.status(200).json(body);
+ }
+ });
});
};
diff --git a/src/resources/i18n/en.json b/src/resources/i18n/en.json
index d897b0658..f743ad2aa 100644
--- a/src/resources/i18n/en.json
+++ b/src/resources/i18n/en.json
@@ -45,7 +45,13 @@
"telephone": "Telephone",
"fax": "Fax",
"email": "Email Address",
- "currencyCod": "Currency Code"
+ "currencyCod": "Currency Code",
+ "editHospital": "Edit hospital infos",
+ "updateHospital": "Save changes",
+ "saveHospital": "Save",
+ "updated": "Hospital infos updated",
+ "updateSuccess": "Hospital infos have been updated successfully!",
+ "discardChanges": "Changes will be lost. Do you want to discard anyway ?"
},
"login": {
"username": "Username",
diff --git a/src/routes/Admin/AdminRoutes.tsx b/src/routes/Admin/AdminRoutes.tsx
index 2e092a382..ceddc2a48 100644
--- a/src/routes/Admin/AdminRoutes.tsx
+++ b/src/routes/Admin/AdminRoutes.tsx
@@ -1,3 +1,4 @@
+import { EditHospital } from "components/accessories/admin/hospital";
import React, { ReactNode, useMemo } from "react";
import { useTranslation } from "react-i18next";
import { Navigate, Route, Routes } from "react-router";
@@ -6,7 +7,11 @@ import {
EditDisease,
NewDisease,
} from "../../components/accessories/admin/diseases";
-import { EditExam, Exams, NewExam } from "../../components/accessories/admin/exams";
+import {
+ EditExam,
+ Exams,
+ NewExam,
+} from "../../components/accessories/admin/exams";
import {
EditOperation,
NewOperation,
@@ -100,13 +105,19 @@ export const AdminRoutes = () => {
{
path: getPath(PATHS.admin_exams_new),
element: (
- } />
+ }
+ />
),
},
{
path: getPath(PATHS.admin_exams_edit),
element: (
- } />
+ }
+ />
),
},
{
@@ -211,6 +222,15 @@ export const AdminRoutes = () => {
/>
),
},
+ {
+ path: getPath(PATHS.admin_hospital_edit),
+ element: (
+ }
+ />
+ ),
+ },
],
[t]
);
diff --git a/src/state/hospital/initial.ts b/src/state/hospital/initial.ts
index 83501116d..afff62c89 100644
--- a/src/state/hospital/initial.ts
+++ b/src/state/hospital/initial.ts
@@ -1,6 +1,7 @@
-import { IHospitalState } from "./types";
import { ApiResponse } from "../types";
+import { IHospitalState } from "./types";
export const initial: IHospitalState = {
getHospital: new ApiResponse({ status: "IDLE" }),
+ updateHospital: new ApiResponse({ status: "IDLE" }),
};
diff --git a/src/state/hospital/slice.ts b/src/state/hospital/slice.ts
index 31306fa90..b011df253 100644
--- a/src/state/hospital/slice.ts
+++ b/src/state/hospital/slice.ts
@@ -6,7 +6,11 @@ import * as thunks from "./thunk";
export const hospitalSlice = createSlice({
name: "hospitals",
initialState: initial,
- reducers: {},
+ reducers: {
+ updateHospitalReset: (state) => {
+ state.updateHospital = initial.updateHospital;
+ },
+ },
extraReducers: (builder) =>
builder
// Get Hospital
@@ -18,5 +22,19 @@ export const hospitalSlice = createSlice({
})
.addCase(thunks.getHospital.rejected, (state, action) => {
state.getHospital = ApiResponse.error(action.payload);
+ })
+ // Update Hospital
+ .addCase(thunks.updateHospital.pending, (state) => {
+ state.updateHospital = ApiResponse.loading();
+ })
+ .addCase(thunks.updateHospital.fulfilled, (state, action) => {
+ state.updateHospital = state.getHospital = ApiResponse.value(
+ action.payload
+ );
+ })
+ .addCase(thunks.updateHospital.rejected, (state, action) => {
+ state.updateHospital = ApiResponse.error(action.payload);
}),
});
+
+export const { updateHospitalReset } = hospitalSlice.actions;
diff --git a/src/state/hospital/thunk.ts b/src/state/hospital/thunk.ts
index b16279824..5bc077173 100644
--- a/src/state/hospital/thunk.ts
+++ b/src/state/hospital/thunk.ts
@@ -1,9 +1,11 @@
import { createAsyncThunk } from "@reduxjs/toolkit";
-import { HospitalsApi } from "../../generated";
+import { HospitalDTO, HospitalsApi } from "../../generated";
import { customConfiguration } from "../../libraries/apiUtils/configuration";
const api = new HospitalsApi(customConfiguration(false));
+const securedApi = new HospitalsApi(customConfiguration());
+
export const getHospital = createAsyncThunk(
"hospitals/getHospital",
async (_, thunkApi) =>
@@ -12,3 +14,12 @@ export const getHospital = createAsyncThunk(
.toPromise()
.catch((error) => thunkApi.rejectWithValue(error.response))
);
+
+export const updateHospital = createAsyncThunk(
+ "hospitals/updateHospital",
+ async (payload: { code: string; hospitalDTO: HospitalDTO }, thunkApi) =>
+ securedApi
+ .updateHospital(payload)
+ .toPromise()
+ .catch((error) => thunkApi.rejectWithValue(error.response))
+);
diff --git a/src/state/hospital/types.ts b/src/state/hospital/types.ts
index a3e5810fe..0b0f26c78 100644
--- a/src/state/hospital/types.ts
+++ b/src/state/hospital/types.ts
@@ -3,4 +3,5 @@ import { ApiResponse } from "../types";
export type IHospitalState = {
getHospital: ApiResponse;
+ updateHospital: ApiResponse;
};