From 630cd76f682eeb625bd89f2def8dd751ea5283f0 Mon Sep 17 00:00:00 2001 From: Shahzaib Ahmad <31288329+Shahzaibahmad97@users.noreply.github.com> Date: Mon, 26 Aug 2024 18:25:43 +0500 Subject: [PATCH] hide some components from admin user management that were specific to a particular module (#107) --- src/components/UserFilter.js | 59 +++++++++++++++++-------------- src/components/UserForm.js | 4 +-- src/components/UserMasterPanel.js | 27 +++++++------- 3 files changed, 50 insertions(+), 40 deletions(-) diff --git a/src/components/UserFilter.js b/src/components/UserFilter.js index b852fee..ba71309 100644 --- a/src/components/UserFilter.js +++ b/src/components/UserFilter.js @@ -1,5 +1,6 @@ import React, { Component } from "react"; import _debounce from "lodash/debounce"; +import { connect } from "react-redux"; import { withTheme, withStyles } from "@material-ui/core/styles"; import { injectIntl } from "react-intl"; @@ -13,7 +14,7 @@ import { TextInput, formatMessage, } from "@openimis/fe-core"; -import { DEFAULT } from "../constants"; +import { DEFAULT, RIGHT_HEALTHFACILITIES } from "../constants"; const styles = (theme) => ({ dialogTitle: theme.dialog.title, @@ -222,7 +223,7 @@ class UserFilter extends Component { ); render() { - const { classes, filters, onChangeFilters, intl } = this.props; + const { classes, filters, onChangeFilters, intl, rights } = this.props; const { locationFilters, currentUserType, currentUserRoles, selectedDistrict } = this.state; return (
@@ -253,29 +254,30 @@ class UserFilter extends Component { } /> - - { - onChangeFilters([ - { - id: "healthFacility", - value: v, - filter: v ? `healthFacilityId: ${decodeId(v.id)}` : null, - }, - ]); - }} - /> - - } - /> + { rights.includes(RIGHT_HEALTHFACILITIES) && ( + { + onChangeFilters([ + { + id: "healthFacility", + value: v, + filter: v ? `healthFacilityId: ${decodeId(v.id)}` : null, + }, + ]); + }} + /> + + } + /> + )} @@ -439,4 +441,9 @@ class UserFilter extends Component { } } -export default withModulesManager(injectIntl(withTheme(withStyles(styles)(UserFilter)))); +const mapStateToProps = (state) => ({ + rights: state.core?.user?.i_user?.rights ?? [], + module: state.core?.savedPagination?.module, +}); + +export default withModulesManager(connect(mapStateToProps)(injectIntl(withTheme(withStyles(styles)(UserFilter))))); diff --git a/src/components/UserForm.js b/src/components/UserForm.js index 53d2146..67c250d 100644 --- a/src/components/UserForm.js +++ b/src/components/UserForm.js @@ -18,7 +18,7 @@ import { coreConfirm, parseData, } from "@openimis/fe-core"; -import { CLAIM_ADMIN_USER_TYPE, ENROLMENT_OFFICER_USER_TYPE, INTERACTIVE_USER_TYPE, RIGHT_USERS } from "../constants"; +import { CLAIM_ADMIN_USER_TYPE, ENROLMENT_OFFICER_USER_TYPE, INTERACTIVE_USER_TYPE, RIGHT_USERS, RIGHT_CLAIMADMINISTRATOR } from "../constants"; import EnrolmentOfficerFormPanel from "./EnrolmentOfficerFormPanel"; import ClaimAdministratorFormPanel from "./ClaimAdministratorFormPanel"; import { @@ -251,7 +251,7 @@ class UserForm extends Component { readOnly={readOnly || isInMutation || user?.validityTo} actions={actions} HeadPanel={UserMasterPanel} - Panels={[EnrolmentOfficerFormPanel, ClaimAdministratorFormPanel]} + Panels={[EnrolmentOfficerFormPanel, ...(rights.includes(RIGHT_CLAIMADMINISTRATOR) ? [ClaimAdministratorFormPanel] : []) ]} user={user} onEditedChanged={this.onEditedChanged} canSave={!user.validityTo && this.canSave} diff --git a/src/components/UserMasterPanel.js b/src/components/UserMasterPanel.js index 68b10b4..785af25 100644 --- a/src/components/UserMasterPanel.js +++ b/src/components/UserMasterPanel.js @@ -16,7 +16,7 @@ import { passwordGenerator, validatePassword, } from "@openimis/fe-core"; -import { CLAIM_ADMIN_USER_TYPE, ENROLMENT_OFFICER_USER_TYPE, EMAIL_REGEX_PATTERN, DEFAULT } from "../constants"; +import { CLAIM_ADMIN_USER_TYPE, ENROLMENT_OFFICER_USER_TYPE, EMAIL_REGEX_PATTERN, DEFAULT, RIGHT_HEALTHFACILITIES } from "../constants"; import { usernameValidationCheck, usernameValidationClear, @@ -62,6 +62,7 @@ const UserMasterPanel = (props) => { savedUserEmail, usernameLength, passwordPolicy, + rights, } = props; const { formatMessage, formatMessageWithValues } = useTranslations("admin", modulesManager); const dispatch = useDispatch(); @@ -240,17 +241,18 @@ const UserMasterPanel = (props) => { /> )} - - onEditedChanged({ ...edited, healthFacility })} - /> - + { rights.includes(RIGHT_HEALTHFACILITIES) && ( + onEditedChanged({ ...edited, healthFacility })} + /> + + )} { }; const mapStateToProps = (state) => ({ + rights: state.core?.user?.i_user?.rights ?? [], isUsernameValid: state.admin.validationFields?.username?.isValid, isUsernameValidating: state.admin.validationFields?.username?.isValidating, usernameValidationError: state.admin.validationFields?.username?.validationError,