Skip to content

Commit

Permalink
ONI-164: add setting to enable displaying first name before second name
Browse files Browse the repository at this point in the history
  • Loading branch information
olewandowski1 committed Feb 8, 2024
1 parent b785ebe commit ad0c66c
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 131 deletions.
127 changes: 74 additions & 53 deletions src/components/UserFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
TextInput,
formatMessage,
} from "@openimis/fe-core";
import { DEFAULT } from "../constants";

const styles = (theme) => ({
dialogTitle: theme.dialog.title,
Expand All @@ -35,7 +36,6 @@ const extractLocations = (locations) => {
const village = municipality && locationsArray.find((l) => l.parent && l.parent.id === municipality.id);

return { region, district, municipality, village };

};

const getParentLocation = (locations) => {
Expand Down Expand Up @@ -71,10 +71,18 @@ const getParentLocation = (locations) => {
};
}
return newLocation;

};

class UserFilter extends Component {
constructor(props) {
super(props);
this.renderLastNameFirst = props.modulesManager.getConf(
"fe-insuree",
"renderLastNameFirst",
DEFAULT.RENDER_LAST_NAME_FIRST,
);
}

state = {
locationFilters: {},
selectedDistrict: {},
Expand All @@ -90,7 +98,6 @@ class UserFilter extends Component {
return !!filters && !!filters[k] ? filters[k].value : null;
};


filterTextFieldValue = (k) => {
const { filters } = this.props;
return !!filters && !!filters[k] ? filters[k].value : "";
Expand All @@ -103,7 +110,6 @@ class UserFilter extends Component {
return district;
};


onChangeCheckbox = (key, value) => {
const filters = [
{
Expand Down Expand Up @@ -163,8 +169,60 @@ class UserFilter extends Component {
onChangeFilters(filters);
};

renderLastNameField = (classes) => (
<ControlledField
module="admin"
id="userFilter.LastName"
field={
<Grid item xs={3} className={classes.item}>
<TextInput
module="user"
label="admin.user.lastName"
name="lastName"
value={this.filterTextFieldValue("lastName")}
onChange={(v) =>
this.debouncedOnChangeFilter([
{
id: "lastName",
value: v,
filter: `lastName: "${v}"`,
},
])
}
/>
</Grid>
}
/>
);

renderGivenNameField = (classes) => (
<ControlledField
module="admin"
id="userFilter.OtherNames"
field={
<Grid item xs={3} className={classes.item}>
<TextInput
module="user"
label="admin.user.otherNames"
name="otherNames"
value={this.filterTextFieldValue("otherNames")}
onChange={(v) =>
this.debouncedOnChangeFilter([
{
id: "otherNames",
value: v,
filter: `otherNames: "${v}"`,
},
])
}
/>
</Grid>
}
/>
);

render() {
const { classes, filters, onChangeFilters , intl} = this.props;
const { classes, filters, onChangeFilters, intl } = this.props;
const { locationFilters, currentUserType, currentUserRoles, selectedDistrict } = this.state;
return (
<section className={classes.form}>
Expand Down Expand Up @@ -204,7 +262,6 @@ class UserFilter extends Component {
pubRef="location.HealthFacilityPicker"
withNull={true}
value={this.filterValue("healthFacilityId") || ""}

district={selectedDistrict}
onChange={(v) => {
onChangeFilters([
Expand Down Expand Up @@ -255,52 +312,17 @@ class UserFilter extends Component {
</Grid>
}
/>
<ControlledField
module="admin"
id="userFilter.LastName"
field={
<Grid item xs={3} className={classes.item}>
<TextInput
module="user"
label="admin.user.lastName"
name="lastName"
value={this.filterTextFieldValue("lastName")}
onChange={(v) =>
this.debouncedOnChangeFilter([
{
id: "lastName",
value: v,
filter: `lastName: "${v}"`,
},
])
}
/>
</Grid>
}
/>
<ControlledField
module="admin"
id="userFilter.OtherNames"
field={
<Grid item xs={3} className={classes.item}>
<TextInput
module="user"
label="admin.user.otherNames"
name="otherNames"
value={this.filterTextFieldValue("otherNames")}
onChange={(v) =>
this.debouncedOnChangeFilter([
{
id: "otherNames",
value: v,
filter: `otherNames: "${v}"`,
},
])
}
/>
</Grid>
}
/>
{this.renderLastNameFirst ? (
<>
{this.renderLastNameField(classes)}
{this.renderGivenNameField(classes)}
</>
) : (
<>
{this.renderGivenNameField(classes)}
{this.renderLastNameField(classes)}
</>
)}
<ControlledField
module="admin"
id="userFilter.Email"
Expand Down Expand Up @@ -407,7 +429,6 @@ class UserFilter extends Component {
/>
}
label={formatMessage(intl, "admin", "UserFilter.showDeleted")}

/>
</Grid>
}
Expand Down
66 changes: 44 additions & 22 deletions src/components/UserMasterPanel.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-shadow */
import React, { useEffect, useState } from "react";
import { connect, useDispatch } from "react-redux";

Expand All @@ -13,7 +14,7 @@ import {
PublishedComponent,
ValidatedTextInput,
} from "@openimis/fe-core";
import { CLAIM_ADMIN_USER_TYPE, ENROLMENT_OFFICER_USER_TYPE, EMAIL_REGEX_PATTERN } from "../constants";
import { CLAIM_ADMIN_USER_TYPE, ENROLMENT_OFFICER_USER_TYPE, EMAIL_REGEX_PATTERN, DEFAULT } from "../constants";
import {
usernameValidationCheck,
usernameValidationClear,
Expand Down Expand Up @@ -61,6 +62,11 @@ const UserMasterPanel = (props) => {
} = props;
const { formatMessage } = useTranslations("admin", modulesManager);
const dispatch = useDispatch();
const renderLastNameFirst = modulesManager.getConf(
"fe-insuree",
"renderLastNameFirst",
DEFAULT.RENDER_LAST_NAME_FIRST,
);

const shouldValidateUsername = (inputValue) => {
const shouldBeValidated = inputValue !== savedUsername;
Expand Down Expand Up @@ -91,7 +97,6 @@ const UserMasterPanel = (props) => {
handleEmailChange(edited?.email);
}, []);


const [showPassword, setShowPassword] = useState(false);
const handleClickShowPassword = () => setShowPassword((show) => !show);

Expand All @@ -111,6 +116,32 @@ const UserMasterPanel = (props) => {
onEditedChanged({ ...edited, password: generatedPassword, confirmPassword: generatedPassword });
};

const renderLastNameField = (edited, classes, readOnly) => (
<Grid item xs={4} className={classes.item}>
<TextInput
module="admin"
label="user.lastName"
required
readOnly={readOnly}
value={edited?.lastName ?? ""}
onChange={(lastName) => onEditedChanged({ ...edited, lastName })}
/>
</Grid>
);

const renderGivenNameField = (edited, classes, readOnly) => (
<Grid item xs={4} className={classes.item}>
<TextInput
module="admin"
label="user.givenNames"
required
readOnly={readOnly}
value={edited?.otherNames ?? ""}
onChange={(otherNames) => onEditedChanged({ ...edited, otherNames })}
/>
</Grid>
);

return (
<Grid container direction="row">
<Grid item xs={4} className={classes.item}>
Expand All @@ -135,26 +166,17 @@ const UserMasterPanel = (props) => {
}}
/>
</Grid>
<Grid item xs={4} className={classes.item}>
<TextInput
module="admin"
label="user.givenNames"
required
readOnly={readOnly}
value={edited?.otherNames ?? ""}
onChange={(otherNames) => onEditedChanged({ ...edited, otherNames })}
/>
</Grid>
<Grid item xs={4} className={classes.item}>
<TextInput
module="admin"
label="user.lastName"
required
readOnly={readOnly}
value={edited?.lastName ?? ""}
onChange={(lastName) => onEditedChanged({ ...edited, lastName })}
/>
</Grid>
{renderLastNameFirst ? (
<>
{renderLastNameField(edited, classes, readOnly)}
{renderGivenNameField(edited, classes, readOnly)}
</>
) : (
<>
{renderGivenNameField(edited, classes, readOnly)}
{renderLastNameField(edited, classes, readOnly)}
</>
)}
{!(
obligatoryUserFields?.email == "H" ||
(edited.userTypes?.includes(ENROLMENT_OFFICER_USER_TYPE) && obligatoryEOFields?.email == "H")
Expand Down
Loading

0 comments on commit ad0c66c

Please sign in to comment.