Skip to content

Commit

Permalink
OP-363 | Check permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
alefalezza committed Apr 2, 2021
1 parent b494260 commit 0be38d8
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 20 deletions.
13 changes: 9 additions & 4 deletions src/components/accessories/patientOPD/patientOPD.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import React, { FunctionComponent } from 'react';
import React, { FunctionComponent } from "react";
import { usePermission } from "../../../libraries/permissionUtils/usePermission";
import { PermissionDenied } from "../permissionDenied/PermissionDenied";
import { initialFields } from "./consts";
import PatientOPDForm from "./patientOPDForm/PatientOPDForm";

const PatientOPD: FunctionComponent = () => {
const canRead = usePermission("odp.read");

const onSubmit = (opd: any) => {
console.log(opd);
};

return (
return canRead ? (
<div className="patientSummary">
<PatientOPDForm
fields={initialFields}
Expand All @@ -18,7 +21,9 @@ const PatientOPD: FunctionComponent = () => {
isLoading={false}
/>
</div>
) : (
<PermissionDenied />
);
}
};

export default PatientOPD;
export default PatientOPD;
17 changes: 11 additions & 6 deletions src/components/accessories/patientSummary/PatientSummary.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import React, { FunctionComponent } from 'react';
import { patientSummaryTabs } from "./tabsConfig";
import Tabs from '../tabs/Tabs';
import React, { FunctionComponent } from "react";
import { usePermission } from "../../../libraries/permissionUtils/usePermission";
import { PermissionDenied } from "../permissionDenied/PermissionDenied";
import Tabs from "../tabs/Tabs";
import "./styles.scss";
import { patientSummaryTabs } from "./tabsConfig";

const PatientSummary: FunctionComponent = () => {
const canRead = usePermission("summary.read");

return (
return canRead ? (
<div className="patientSummary">
<Tabs config={patientSummaryTabs} />
</div>
) : (
<PermissionDenied />
);
}
};

export default PatientSummary;
export default PatientSummary;
25 changes: 15 additions & 10 deletions src/components/accessories/patientTriage/PatientTriage.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import React, { FunctionComponent } from 'react';
import PatientTriageForm from './patientTriageForm/PatientTriageForm';
import PatientTriageTable from './patientTriageTable/PatientTriageTable';
import React, { FunctionComponent } from "react";
import PatientTriageForm from "./patientTriageForm/PatientTriageForm";
import PatientTriageTable from "./patientTriageTable/PatientTriageTable";
import { initialFields } from "./consts";
import "./styles.scss";
import { usePermission } from "../../../libraries/permissionUtils/usePermission";
import { PermissionDenied } from "../permissionDenied/PermissionDenied";

const PatientTriage: FunctionComponent = () => {
const canRead = usePermission("examination.read");

const onSubmit = (triage: any) => {
console.log(triage);

/* TODO:
* 1. Save Triage using Redux
* 2. Reset the form
* 3. Update the table
*/
* 1. Save Triage using Redux
* 2. Reset the form
* 3. Update the table
*/
};

return (
return canRead ? (
<div className="patientTriage">
<PatientTriageForm
fields={initialFields}
Expand All @@ -27,7 +30,9 @@ const PatientTriage: FunctionComponent = () => {
/>
<PatientTriageTable />
</div>
) : (
<PermissionDenied />
);
}
};

export default PatientTriage;
export default PatientTriage;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import React, { FunctionComponent } from "react";

// TODO: Add style and a proper message
export const PermissionDenied: FunctionComponent = () => <>Permission denied</>;
10 changes: 10 additions & 0 deletions src/libraries/permissionUtils/usePermission.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { useSelector } from "react-redux";
import { IState, TPermission } from "../../types";

export const usePermission = (name: TPermission): boolean => {
const permissions = useSelector<IState, string[]>(
(state) => state.main.me?.data?.permission || []
);

return Boolean(permissions.find((permission: string) => permission === name));
};

0 comments on commit 0be38d8

Please sign in to comment.