Skip to content

Commit

Permalink
Merge branch 'develop' into update/OH2-399-group-permissions-select-rows
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveGT96 committed Oct 29, 2024
2 parents f4ae4ab + f15d23c commit f26bde8
Show file tree
Hide file tree
Showing 18 changed files with 2,477 additions and 2,353 deletions.
4,651 changes: 2,330 additions & 2,321 deletions api/oh.yaml

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion src/components/accessories/admin/users/Users.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Tab, Tabs } from "@mui/material";
import React from "react";
import React, { useCallback } from "react";
import { useTranslation } from "react-i18next";
import { useLocation, useNavigate } from "react-router";

import Button from "../../button/Button";
import UserGroupsTable from "./userGroupsTable";
import UsersTable from "./usersTable";

import { useAppDispatch } from "libraries/hooks/redux";
import { deleteUser } from "state/users";
import { PATHS } from "../../../../consts";
import { UserDTO, UserGroupDTO } from "../../../../generated";

Expand All @@ -18,6 +20,7 @@ export enum TabOptions {
export const Users = () => {
const navigate = useNavigate();
const { t } = useTranslation();
const dispatch = useAppDispatch();

const { state }: { state: { tab?: TabOptions } } = useLocation();
const setTab = (tab: TabOptions) =>
Expand All @@ -33,6 +36,13 @@ export const Users = () => {
state: row,
});

const handleDeleteUser = useCallback(
(row: UserDTO) => {
dispatch(deleteUser(row.userName ?? ""));
},
[dispatch]
);

return (
<>
<Tabs
Expand All @@ -58,6 +68,7 @@ export const Users = () => {
</Button>
}
onEdit={handleEditUser}
onDelete={handleDeleteUser}
/>
) : (
<UserGroupsTable
Expand Down
85 changes: 63 additions & 22 deletions src/components/accessories/admin/users/usersTable/UsersTable.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,57 @@
import { CircularProgress } from "@mui/material";
import React, { ReactNode, useEffect } from "react";
import React, { ReactNode, useEffect, useRef } from "react";
import { useTranslation } from "react-i18next";

import { useAppDispatch, useAppSelector } from "libraries/hooks/redux";
import { usePermission } from "libraries/permissionUtils/usePermission";
import checkIcon from "../../../../../assets/check-icon.png";
import { UserDTO } from "../../../../../generated";
import { getUsers } from "../../../../../state/users";
import { deleteUserReset, getUsers } from "../../../../../state/users";
import ConfirmationDialog from "../../../confirmationDialog/ConfirmationDialog";
import InfoBox from "../../../infoBox/InfoBox";
import Table from "../../../table/Table";
import { TFilterField } from "../../../table/filter/types";

import { scrollToElement } from "libraries/uiUtils/scrollToElement";
import { getUserGroups } from "state/usergroups";
import classes from "./UsersTable.module.scss";

interface IOwnProps {
headerActions: ReactNode;
onEdit: (row: UserDTO) => void;
onDelete: (row: UserDTO) => void;
}

export const UsersTable = ({ headerActions, onEdit }: IOwnProps) => {
export const UsersTable = ({ headerActions, onEdit, onDelete }: IOwnProps) => {
const dispatch = useAppDispatch();
const { t } = useTranslation();
const infoBoxRef = useRef<HTMLDivElement>(null);

const canUpdate = usePermission("users.update");
const canDelete = usePermission("users.update");

const deleteUser = useAppSelector((state) => state.users.delete);

useEffect(() => {
dispatch(getUsers({}));
dispatch(getUserGroups());

return () => {
dispatch(deleteUserReset());
};
}, [dispatch]);

const header = ["userName", "userGroupName", "desc"];
useEffect(() => {
if (deleteUser.status === "FAIL") {
scrollToElement(infoBoxRef.current);
}

if (deleteUser.hasSucceeded) {
dispatch(getUsers({}));
}
}, [deleteUser.status, dispatch]);

const header = ["userName", "userGroupName", "desc"];
const label = {
userName: t("user.username"),
userGroupName: t("user.groups"),
Expand Down Expand Up @@ -65,7 +87,7 @@ export const UsersTable = ({ headerActions, onEdit }: IOwnProps) => {
userGroupName:
item.userGroupName?.desc ?? item.userGroupName?.code ?? "",
desc: item.desc ?? "",
passwd: item.passwd ?? ""
passwd: item.passwd ?? "",
};
});
};
Expand All @@ -85,23 +107,42 @@ export const UsersTable = ({ headerActions, onEdit }: IOwnProps) => {

case "SUCCESS":
return (
<Table
rowData={formatDataToDisplay(data ?? [])}
tableHeader={header}
labelData={label}
columnsOrder={order}
rowsPerPage={10}
filterColumns={filters}
manualFilter={false}
isCollapsabile={false}
rawData={(data ?? []).map((user) => ({
...user,
userGroupName: user.userGroupName?.code,
}))}
rowKey="userName"
headerActions={headerActions}
onEdit={canUpdate ? onEdit: undefined}
/>
<>
{deleteUser.status === "FAIL" && (
<div ref={infoBoxRef} className="info-box-container">
<InfoBox type="error" message={deleteUser.error?.message} />
</div>
)}
<Table
rowData={formatDataToDisplay(data ?? [])}
tableHeader={header}
labelData={label}
columnsOrder={order}
rowsPerPage={10}
filterColumns={filters}
manualFilter={false}
isCollapsabile={false}
rawData={(data ?? []).map((user) => ({
...user,
userGroupName: user.userGroupName?.code,
}))}
rowKey="userName"
headerActions={headerActions}
onEdit={canUpdate ? onEdit : undefined}
onDelete={canDelete ? onDelete : undefined}
/>
<ConfirmationDialog
isOpen={!!deleteUser.hasSucceeded}
title={t("user.deleted")}
icon={checkIcon}
info={t("user.deleteSuccess")}
primaryButtonLabel="Ok"
handlePrimaryButtonClick={() => {
dispatch(deleteUserReset());
}}
handleSecondaryButtonClick={() => ({})}
/>
</>
);
case "SUCCESS_EMPTY":
return <InfoBox type="info" message={t("common.emptydata")} />;
Expand Down
1 change: 0 additions & 1 deletion src/generated/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ index.ts
models\AdmissionDTO.ts
models\AdmissionTypeDTO.ts
models\AdmittedPatientDTO.ts
models\AgeType.ts
models\AgeTypeDTO.ts
models\BillDTO.ts
models\BillItemsDTO.ts
Expand Down
9 changes: 4 additions & 5 deletions src/generated/apis/AgeTypesApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import { Observable } from 'rxjs';
import { BaseAPI, HttpHeaders, HttpQuery, throwIfNullOrUndefined, encodeURI, OperationOpts, RawAjaxResponse } from '../runtime';
import {
AgeType,
AgeTypeDTO,
} from '../models';

Expand All @@ -37,16 +36,16 @@ export class AgeTypesApi extends BaseAPI {

/**
*/
getAgeTypeByIndex({ index }: GetAgeTypeByIndexRequest): Observable<AgeType>
getAgeTypeByIndex({ index }: GetAgeTypeByIndexRequest, opts?: OperationOpts): Observable<RawAjaxResponse<AgeType>>
getAgeTypeByIndex({ index }: GetAgeTypeByIndexRequest, opts?: OperationOpts): Observable<AgeType | RawAjaxResponse<AgeType>> {
getAgeTypeByIndex({ index }: GetAgeTypeByIndexRequest): Observable<AgeTypeDTO>
getAgeTypeByIndex({ index }: GetAgeTypeByIndexRequest, opts?: OperationOpts): Observable<RawAjaxResponse<AgeTypeDTO>>
getAgeTypeByIndex({ index }: GetAgeTypeByIndexRequest, opts?: OperationOpts): Observable<AgeTypeDTO | RawAjaxResponse<AgeTypeDTO>> {
throwIfNullOrUndefined(index, 'index', 'getAgeTypeByIndex');

const headers: HttpHeaders = {
...(this.configuration.username != null && this.configuration.password != null ? { Authorization: `Basic ${btoa(this.configuration.username + ':' + this.configuration.password)}` } : undefined),
};

return this.request<AgeType>({
return this.request<AgeTypeDTO>({
url: '/agetypes/{index}'.replace('{index}', encodeURI(index)),
method: 'GET',
headers,
Expand Down
6 changes: 6 additions & 0 deletions src/generated/models/AgeTypeDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ export interface AgeTypeDTO {
* @memberof AgeTypeDTO
*/
from: number;
/**
* Lock
* @type {number}
* @memberof AgeTypeDTO
*/
lock?: number;
/**
* The maximum value of the range
* @type {number}
Expand Down
6 changes: 6 additions & 0 deletions src/generated/models/BillDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ export interface BillDTO {
* @memberof BillDTO
*/
user: string;
/**
* Lock
* @type {number}
* @memberof BillDTO
*/
lock?: number;
/**
* @type {boolean}
* @memberof BillDTO
Expand Down
6 changes: 6 additions & 0 deletions src/generated/models/PatientExaminationDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ export interface PatientExaminationDTO {
* @memberof PatientExaminationDTO
*/
pex_bowel_desc?: PatientExaminationDTOPexBowelDescEnum;
/**
* Lock
* @type {number}
* @memberof PatientExaminationDTO
*/
lock?: number;
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/generated/models/PriceDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ export interface PriceDTO {
* @memberof PriceDTO
*/
price: number;
/**
* Lock
* @type {number}
* @memberof PriceDTO
*/
lock?: number;
/**
* @type {boolean}
* @memberof PriceDTO
Expand Down
6 changes: 6 additions & 0 deletions src/generated/models/PriceListDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ export interface PriceListDTO {
* @memberof PriceListDTO
*/
currency?: string;
/**
* Lock
* @type {number}
* @memberof PriceListDTO
*/
lock?: number;
/**
* @type {number}
* @memberof PriceListDTO
Expand Down
6 changes: 6 additions & 0 deletions src/generated/models/PricesOthersDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ export interface PricesOthersDTO {
* @memberof PricesOthersDTO
*/
description: string;
/**
* Lock
* @type {number}
* @memberof PricesOthersDTO
*/
lock?: number;
/**
* @type {boolean}
* @memberof PricesOthersDTO
Expand Down
6 changes: 6 additions & 0 deletions src/generated/models/SupplierDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,10 @@ export interface SupplierDTO {
* @memberof SupplierDTO
*/
supNote?: string;
/**
* Lock
* @type {number}
* @memberof SupplierDTO
*/
lock?: number;
}
6 changes: 6 additions & 0 deletions src/generated/models/UserSettingDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,10 @@ export interface UserSettingDTO {
* @memberof UserSettingDTO
*/
configValue: string;
/**
* Lock
* @type {number}
* @memberof UserSettingDTO
*/
lock?: number;
}
6 changes: 6 additions & 0 deletions src/generated/models/VisitDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,10 @@ export interface VisitDTO {
* @memberof VisitDTO
*/
service?: string;
/**
* Lock
* @type {number}
* @memberof VisitDTO
*/
lock?: number;
}
1 change: 0 additions & 1 deletion src/generated/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export * from './AdmissionDTO';
export * from './AdmissionTypeDTO';
export * from './AdmittedPatientDTO';
export * from './AgeType';
export * from './AgeTypeDTO';
export * from './BillDTO';
export * from './BillItemsDTO';
Expand Down
10 changes: 10 additions & 0 deletions src/mockServer/routes/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ export const userRoutes = (server) => {
server.put("/:username").intercept((_req, res) => {
res.status(200).json(_req.jsonBody());
});
server.delete("/:username").intercept((req, res) => {
const username = req.params.username;
switch (username) {
case "FAIL":
res.status(400).json({ message: "Fail to delete user" });
break;
default:
res.status(204);
}
});
server.get("/:username/settings/dashboard").intercept((req, res) => {
res.status(200).json(dashboardSettingDTO);
});
Expand Down
4 changes: 2 additions & 2 deletions src/mockServer/routes/wards.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ export const wardsRoutes = (server) => {
const code = req.params.code;
switch (code) {
case "FAIL":
res.status(400).json({ message: "Fail to update ward" });
res.status(400).json({ message: "Fail to delete ward" });
break;
default:
res.status(200);
res.status(204);
}
});
});
Expand Down
2 changes: 2 additions & 0 deletions src/resources/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"editGroup": "Edit group",
"description": "Description",
"lastlogin": "Last login",
"deleted": "User deleted",
"groupCreated": "Group created",
"groupDeleted": "Group deleted",
"groupUpdated": "Group updated",
Expand All @@ -41,6 +42,7 @@
"createdSuccessTitle": "User created",
"createdSuccessMessage": "User has been created successfully!",
"updatedSuccessTitle": "User updated",
"deleteSuccess": "User has been deleted successfully!",
"updatedSuccessMessage": "User has been updated successfully!",
"validateUserNeedsGroup": "Each user should belong to a group",
"validatePasswordNeeded": "No password provided.",
Expand Down

0 comments on commit f26bde8

Please sign in to comment.