diff --git a/src/components/EditSections/EditUserInfo/EditUserInfo.js b/src/components/EditSections/EditUserInfo/EditUserInfo.js index 6d7392d8e..a4db5e7dd 100644 --- a/src/components/EditSections/EditUserInfo/EditUserInfo.js +++ b/src/components/EditSections/EditUserInfo/EditUserInfo.js @@ -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'; @@ -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: '', @@ -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); @@ -346,12 +354,12 @@ class EditUserInfo extends React.Component { } - name="type" - id="type" + label={} + name={USER_TYPE_FIELD} + id={USER_TYPE_FIELD} component={Select} fullWidth - disabled={isShadowUser} + disabled={isUserTypeDisabled} dataOptions={typeOptions} aria-required={isConsortium} required={isConsortium} diff --git a/src/components/EditSections/EditUserInfo/EditUserInfo.test.js b/src/components/EditSections/EditUserInfo/EditUserInfo.test.js index e1b1d434f..61ed877de 100644 --- a/src/components/EditSections/EditUserInfo/EditUserInfo.test.js +++ b/src/components/EditSections/EditUserInfo/EditUserInfo.test.js @@ -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); }); }); diff --git a/src/components/UserDetailSections/UserInfo/UserInfo.js b/src/components/UserDetailSections/UserInfo/UserInfo.js index 5bacc0c03..638206f7c 100644 --- a/src/components/UserDetailSections/UserInfo/UserInfo.js +++ b/src/components/UserDetailSections/UserInfo/UserInfo.js @@ -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 = { @@ -119,6 +120,14 @@ class UserInfo extends React.Component { /> + + + } + value={get(user, [USER_TYPE_FIELD], '')} + /> + + {hasProfilePicture === true && diff --git a/src/components/UserDetailSections/UserInfo/UserInfo.test.js b/src/components/UserDetailSections/UserInfo/UserInfo.test.js index 7484f1546..13a40430f 100644 --- a/src/components/UserDetailSections/UserInfo/UserInfo.test.js +++ b/src/components/UserDetailSections/UserInfo/UserInfo.test.js @@ -8,39 +8,6 @@ const toggleMock = jest.fn(); const renderUserInfo = (props) => renderWithRouter(); -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, @@ -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(); }); diff --git a/src/constants.js b/src/constants.js index e86dba5fe..6b0ac1496 100644 --- a/src/constants.js +++ b/src/constants.js @@ -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', }; diff --git a/src/views/UserEdit/UserEdit.js b/src/views/UserEdit/UserEdit.js index ec00ea935..852b4a655 100644 --- a/src/views/UserEdit/UserEdit.js +++ b/src/views/UserEdit/UserEdit.js @@ -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'; @@ -84,7 +83,7 @@ class UserEdit extends React.Component { defaultDeliveryAddressTypeId: null, }, username: '', - type: USER_TYPES.PATRON, + type: '', }; if (!match.params.id) return initialFormValues; diff --git a/translations/ui-users/en.json b/translations/ui-users/en.json index 4e621aeb6..9104eb377 100644 --- a/translations/ui-users/en.json +++ b/translations/ui-users/en.json @@ -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",