Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(OH2-283): admin exams list #581

Merged
merged 15 commits into from
May 13, 2024
7 changes: 7 additions & 0 deletions src/components/accessories/admin/exams/Exams.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from "react";

import ExamsTable from "./examsTable";

export const Exams = () => {
return <ExamsTable />;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.table {
display: grid;
margin-top: 50px;
}
80 changes: 80 additions & 0 deletions src/components/accessories/admin/exams/examsTable/ExamsTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import React, { useEffect } from "react";
import Table from "../../../table/Table";
import { useTranslation } from "react-i18next";
import InfoBox from "../../../infoBox/InfoBox";
import { CircularProgress } from "@material-ui/core";
import { useDispatch, useSelector } from "react-redux";
import { getExams } from "../../../../../state/exams/actions";
import { IState } from "../../../../../types";
import { ExamDTO } from "../../../../../generated";
import { IApiResponse } from "../../../../../state/types";
import classes from "./ExamsTable.module.scss";

export const ExamsTable = () => {
const dispatch = useDispatch();
const { t } = useTranslation();

useEffect(() => {
dispatch(getExams());
}, [dispatch]);

const header = ["code", "type", "description", "procedure", "defaultResult"];

const label = {
code: t("exam.code"),
type: t("exam.examtype"),
description: t("exam.description"),
procedure: t("exam.procedure"),
defaultResult: t("exam.defaultResult"),
};
const order = ["code", "type", "description", "procedure", "defaultResult"];

const { data, status, error } = useSelector<IState, IApiResponse<ExamDTO[]>>(
(state) => state.exams.examList
);

const formatDataToDisplay = (data: ExamDTO[]) => {
return data.map((item) => {
return {
code: item.code ?? "",
type: item.examtype?.description ?? "",
description: item.description ?? "",
procedure: item.procedure ?? "",
defaultResult: item.defaultResult ?? "",
};
});
};

return (
<div className={classes.table}>
{(() => {
switch (status) {
case "FAIL":
return <InfoBox type="error" message={error?.message} />;
case "LOADING":
return (
<CircularProgress
style={{ marginLeft: "50%", position: "relative" }}
/>
);

case "SUCCESS":
return (
<Table
rowData={formatDataToDisplay(data ?? [])}
tableHeader={header}
labelData={label}
columnsOrder={order}
rowsPerPage={10}
isCollapsabile={false}
/>
);
case "SUCCESS_EMPTY":
return <InfoBox type="info" message={t("common.emptydata")} />;
default:
return;
}
})()}
</div>
);
};
3 changes: 3 additions & 0 deletions src/components/accessories/admin/exams/examsTable/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { ExamsTable } from "./ExamsTable";

export default ExamsTable;
1 change: 1 addition & 0 deletions src/components/accessories/admin/exams/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./Exams";
12 changes: 7 additions & 5 deletions src/components/accessories/table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,13 @@ const Table: FunctionComponent<IProps> = ({

return (
<>
<div className="header">
<Button type="button" onClick={handleExpand}>
{expanded ? t("common.collapse_all") : t("common.expand_all")}
</Button>
</div>
{isCollapsabile ?? (
<div className="header">
<Button type="button" onClick={handleExpand}>
{expanded ? t("common.collapse_all") : t("common.expand_all")}
</Button>
</div>
)}
gasp marked this conversation as resolved.
Show resolved Hide resolved
<TableContainer component={Paper}>
<MaterialComponent className="table" aria-label="simple table">
<TableHead className="table_header">
Expand Down
1 change: 1 addition & 0 deletions src/components/accessories/table/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export interface IProps {
labelData: Record<string, any>;
tableHeader: Array<string>;
dateFields?: string[];
/** allow the table to expand & collapse */
isCollapsabile?: boolean;
rowsPerPage: number;
initialOrderBy?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
box-shadow: 0 4px 8px 0 rgba(48, 49, 51, 0.1);
border-radius: 8px;
flex-grow: 1;
align-self: center;
margin: 30px 160px;
align-self: center;
@include susy-media($medium-down) {
flex-direction: column;
margin: 20px 20px;
Expand Down
7 changes: 7 additions & 0 deletions src/resources/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,13 @@
"urine": { "txt": "Urine" }
}
},
"exam": {
"code": "Code",
"examtype": "Exam Type",
"description": "Name",
"procedure": "Procedure",
"defaultResult": "Default value"
},
"ward": {
"code": "Code",
"description": "Description",
Expand Down
3 changes: 2 additions & 1 deletion src/routes/Admin/AdminRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import AdminActivity, {
AdminActivityContent,
} from "../../components/activities/adminActivity";
import { Wards, NewWard, EditWard } from "../../components/accessories/admin";
import { Exams } from "../../components/accessories/admin/exams";

export const AdminRoutes = () => {
const { t } = useTranslation();
Expand Down Expand Up @@ -47,7 +48,7 @@ export const AdminRoutes = () => {
{
path: "exams",
element: (
<AdminActivityContent title={t("nav.exams")} children={<Wards />} />
<AdminActivityContent title={t("nav.exams")} children={<Exams />} />
),
},
{
Expand Down