Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UIU-2936: add user type for user info section #2551

Merged
merged 4 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions src/components/EditSections/EditUserInfo/EditUserInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
ModalFooter,
} from '@folio/stripes/components';

import { USER_TYPES } from '../../../constants';
import { USER_TYPES, USER_TYPE_FIELD } from '../../../constants';
import { isConsortiumEnabled } from '../../util';
import asyncValidateField from '../../validators/asyncValidateField';
import validateMinDate from '../../validators/validateMinDate';
Expand Down Expand Up @@ -169,6 +169,9 @@ class EditUserInfo extends React.Component {
];

const isShadowUser = initialValues.type === USER_TYPES.SHADOW;
const isSystemUser = initialValues.type === USER_TYPES.SYSTEM;
const isUserTypeDisabled = isShadowUser || isSystemUser;

const typeOptions = [
{
value: '',
Expand All @@ -177,18 +180,23 @@ class EditUserInfo extends React.Component {
},
{
value: USER_TYPES.PATRON,
label: intl.formatMessage({ id: 'ui-users.information.type.patron' }),
label: intl.formatMessage({ id: 'ui-users.information.userType.patron' }),
visible: !isShadowUser,
},
{
value: USER_TYPES.STAFF,
label: intl.formatMessage({ id: 'ui-users.information.type.staff' }),
label: intl.formatMessage({ id: 'ui-users.information.userType.staff' }),
visible: !isShadowUser,
},
{
value: USER_TYPES.SHADOW,
label: intl.formatMessage({ id: 'ui-users.information.type.shadow' }),
label: intl.formatMessage({ id: 'ui-users.information.userType.shadow' }),
visible: isShadowUser,
},
{
value: USER_TYPES.SYSTEM,
label: intl.formatMessage({ id: 'ui-users.information.userType.system' }),
visible: isSystemUser,
}
].filter(o => o.visible);

Expand Down Expand Up @@ -346,12 +354,12 @@ class EditUserInfo extends React.Component {
</Col>
<Col xs={12} md={3}>
<Field
label={<FormattedMessage id="ui-users.information.type" />}
name="type"
id="type"
label={<FormattedMessage id="ui-users.information.userType" />}
name={USER_TYPE_FIELD}
id={USER_TYPE_FIELD}
component={Select}
fullWidth
disabled={isShadowUser}
disabled={isUserTypeDisabled}
dataOptions={typeOptions}
aria-required={isConsortium}
required={isConsortium}
Expand Down
11 changes: 7 additions & 4 deletions src/components/EditSections/EditUserInfo/EditUserInfo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,21 +155,24 @@ describe('Render Edit User Information component', () => {
type
${USER_TYPES.PATRON}
${USER_TYPES.SHADOW}
${USER_TYPES.SYSTEM}
`('Should have user type $type', async ({ type }) => {
const isShadowUser = type === USER_TYPES.SHADOW;
const isSystemUser = type === USER_TYPES.SYSTEM;
const isUserTypeDisabled = isShadowUser || isSystemUser;
isConsortiumEnabled.mockClear().mockReturnValue(isShadowUser);
renderEditUserInfo({ ...props, initialValues: { ...props.initialValues, type } });

const selectElement = screen.getByRole('combobox', { name: /ui-users.information.type/i });
const selectElement = screen.getByRole('combobox', { name: /ui-users.information.userType/i });
expect(selectElement).toBeInTheDocument();

if (type !== USER_TYPES.SHADOW) {
if (!isUserTypeDisabled) {
expect(selectElement).toBeEnabled();
}

if (isShadowUser) {
if (isUserTypeDisabled) {
expect(selectElement).toBeDisabled();
}
expect(screen.getByRole('option', { name: `ui-users.information.type.${type}` })).toHaveValue(type);
expect(screen.getByRole('option', { name: `ui-users.information.userType.${type}` })).toHaveValue(type);
});
});
9 changes: 9 additions & 0 deletions src/components/UserDetailSections/UserInfo/UserInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import { ViewMetaData } from '@folio/stripes/smart-components';
import css from './UserInfo.css';
import appIcon from '../../../../icons/app.png';
import { USER_TYPE_FIELD } from '../../../constants';

class UserInfo extends React.Component {
static propTypes = {
Expand Down Expand Up @@ -119,6 +120,14 @@ class UserInfo extends React.Component {
/>
</Col>
</Row>
<Row>
<Col xs={3}>
<KeyValue
label={<FormattedMessage id="ui-users.information.userType" />}
value={get(user, [USER_TYPE_FIELD], '')}
/>
</Col>
</Row>
</Col>

{hasProfilePicture === true &&
Expand Down
41 changes: 4 additions & 37 deletions src/components/UserDetailSections/UserInfo/UserInfo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,6 @@ const toggleMock = jest.fn();

const renderUserInfo = (props) => renderWithRouter(<UserInfo {...props} />);

const propsData = {
expanded: true,
onToggle: toggleMock,
accordionId: 'userInformationSection',
stripes: {
connect: (Component) => Component,
},
patronGroup: {
desc: 'Staff Member',
expirationOffsetInDays: 730,
group: 'staff',
id: '3684a786-6671-4268-8ed0-9db82ebca60b'
},
user: {
active: false,
barcode: '1652148049552566548',
createdDate: '2022-05-10T02:00:49.576+00:00',
departments: [],
id: 'ec6d380d-bcdd-4ef6-bb65-15677ab7cb84',
patronGroup: '3684a786-6671-4268-8ed0-9db82ebca60b',
personal: { lastName: 'Admin', firstName: 'acq-admin', addresses: [] },
proxyFor: [],
type: 'patron',
updatedDate: '2022-05-10T02:00:49.576+00:00',
username: 'acq-admin'
},
settings: [
{
value: true
}
]
};

const props = {
expanded: true,
onToggle: toggleMock,
Expand All @@ -67,19 +34,19 @@ const props = {
updatedDate: '2022-05-10T02:00:49.576+00:00',
username: 'acq-admin'
},
settings: [{
value: true
}]
settings: [{ value: true }]
};

describe('Render userInfo component', () => {
describe('Check if user data are shown', () => {
it('Active Users', () => {
renderUserInfo(props);
expect(screen.getByText('acq-admin')).toBeInTheDocument();
expect(screen.getByText('patron')).toBeInTheDocument();
expect(screen.getByText('1652148049552566548')).toBeInTheDocument();
});
it('Inactive Users', () => {
renderUserInfo(propsData);
renderUserInfo({ ...props, user: { ...props.user, active: false } });
expect(screen.getByText('acq-admin')).toBeInTheDocument();
expect(screen.getByText('1652148049552566548')).toBeInTheDocument();
});
Expand Down
2 changes: 2 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,10 @@ export const RECORD_SOURCE = {
CONSORTIUM: 'consortium',
};

export const USER_TYPE_FIELD = 'type';
export const USER_TYPES = {
PATRON: 'patron',
SHADOW: 'shadow',
STAFF: 'staff',
SYSTEM: 'system',
};
3 changes: 1 addition & 2 deletions src/views/UserEdit/UserEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import { toUserAddresses, getFormAddressList } from '../../components/data/conve
import contactTypes from '../../components/data/static/contactTypes';
import {
OKAPI_TENANT_HEADER,
USER_TYPES,
deliveryFulfillmentValues,
} from '../../constants';
import { resourcesLoaded, showErrorCallout } from './UserEditHelpers';
Expand Down Expand Up @@ -84,7 +83,7 @@ class UserEdit extends React.Component {
defaultDeliveryAddressTypeId: null,
},
username: '',
type: USER_TYPES.PATRON,
type: '',
};

if (!match.params.id) return initialFormValues;
Expand Down
9 changes: 5 additions & 4 deletions translations/ui-users/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,11 @@
"information.middleName": "Middle name",
"information.barcode": "Barcode",
"information.selectUserType": "Select user type",
"information.type": "User type",
"information.type.patron": "Patron",
"information.type.staff": "Staff",
"information.type.shadow": "Shadow",
"information.userType": "User type",
"information.userType.patron": "Patron",
"information.userType.staff": "Staff",
"information.userType.shadow": "Shadow",
"information.userType.system": "System",
"information.patronGroup": "Patron group",
"information.patronGroups": "Patron groups",
"information.status": "Status",
Expand Down
Loading