Skip to content

Commit

Permalink
hide some components from admin user management that were specific to…
Browse files Browse the repository at this point in the history
… a particular module (#107)
  • Loading branch information
Shahzaibahmad97 authored Aug 26, 2024
1 parent e8afc4c commit 630cd76
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 40 deletions.
59 changes: 33 additions & 26 deletions src/components/UserFilter.js
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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,
Expand Down Expand Up @@ -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 (
<section className={classes.form}>
Expand Down Expand Up @@ -253,29 +254,30 @@ class UserFilter extends Component {
</Grid>
}
/>
<ControlledField
module="admin"
id="userFilter.healthFacility"
field={
<Grid item xs={3} className={classes.item}>
<PublishedComponent
pubRef="location.HealthFacilityPicker"
withNull={true}
value={this.filterValue("healthFacilityId") || ""}
district={selectedDistrict}
onChange={(v) => {
onChangeFilters([
{
id: "healthFacility",
value: v,
filter: v ? `healthFacilityId: ${decodeId(v.id)}` : null,
},
]);
}}
/>
</Grid>
}
/>
{ rights.includes(RIGHT_HEALTHFACILITIES) && (<ControlledField
module="admin"
id="userFilter.healthFacility"
field={
<Grid item xs={3} className={classes.item}>
<PublishedComponent
pubRef="location.HealthFacilityPicker"
withNull={true}
value={this.filterValue("healthFacilityId") || ""}
district={selectedDistrict}
onChange={(v) => {
onChangeFilters([
{
id: "healthFacility",
value: v,
filter: v ? `healthFacilityId: ${decodeId(v.id)}` : null,
},
]);
}}
/>
</Grid>
}
/>
)}
</Grid>
<Grid container>
<Grid item xs={12}>
Expand Down Expand Up @@ -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)))));
4 changes: 2 additions & 2 deletions src/components/UserForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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}
Expand Down
27 changes: 15 additions & 12 deletions src/components/UserMasterPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -62,6 +62,7 @@ const UserMasterPanel = (props) => {
savedUserEmail,
usernameLength,
passwordPolicy,
rights,
} = props;
const { formatMessage, formatMessageWithValues } = useTranslations("admin", modulesManager);
const dispatch = useDispatch();
Expand Down Expand Up @@ -240,17 +241,18 @@ const UserMasterPanel = (props) => {
/>
</Grid>
)}
<Grid item xs={4} className={classes.item}>
<PublishedComponent
pubRef="location.HealthFacilityPicker"
value={edited?.healthFacility}
district={edited.districts}
module="admin"
readOnly={readOnly}
required={edited.userTypes.includes(CLAIM_ADMIN_USER_TYPE)}
onChange={(healthFacility) => onEditedChanged({ ...edited, healthFacility })}
/>
</Grid>
{ rights.includes(RIGHT_HEALTHFACILITIES) && (<Grid item xs={4} className={classes.item}>
<PublishedComponent
pubRef="location.HealthFacilityPicker"
value={edited?.healthFacility}
district={edited.districts}
module="admin"
readOnly={readOnly}
required={edited.userTypes.includes(CLAIM_ADMIN_USER_TYPE)}
onChange={(healthFacility) => onEditedChanged({ ...edited, healthFacility })}
/>
</Grid>
)}
<Grid item xs={6} className={classes.item}>
<PublishedComponent
pubRef="admin.UserRolesPicker"
Expand Down Expand Up @@ -366,6 +368,7 @@ const UserMasterPanel = (props) => {
};

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,
Expand Down

0 comments on commit 630cd76

Please sign in to comment.