diff --git a/CHANGELOG.md b/CHANGELOG.md index 202d53fea..a78348a8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## [10.1.0] IN PROGRESS * Also support `feesfines` interface version `19.0`. Refs UIU-2960. +* Disable validation for shadow user. Refs UIU-3000. ## [10.0.4](https://github.com/folio-org/ui-users/tree/v10.0.4) (2023-11-10) [Full Changelog](https://github.com/folio-org/ui-users/compare/v10.0.3...v10.0.4) diff --git a/src/components/EditSections/EditUserInfo/EditUserInfo.js b/src/components/EditSections/EditUserInfo/EditUserInfo.js index a78efdd04..b81c5919d 100644 --- a/src/components/EditSections/EditUserInfo/EditUserInfo.js +++ b/src/components/EditSections/EditUserInfo/EditUserInfo.js @@ -291,8 +291,7 @@ class EditUserInfo extends React.Component { dataOptions={patronGroupOptions} defaultValue={initialValues.patronGroup} aria-required="true" - required - disabled={disabled} + required={!disabled} /> {(selectedPatronGroup) => { diff --git a/src/views/UserEdit/UserEdit.js b/src/views/UserEdit/UserEdit.js index e885326f9..6698ff9c4 100644 --- a/src/views/UserEdit/UserEdit.js +++ b/src/views/UserEdit/UserEdit.js @@ -214,7 +214,7 @@ class UserEdit extends React.Component { } user.personal.addresses = toUserAddresses(user.personal.addresses); // eslint-disable-line no-param-reassign - user.personal.email = user.personal.email.trim(); + user.personal.email = user.personal.email?.trim(); user.departments = compact(user.departments); const { proxies, sponsors, permissions, servicePoints, preferredServicePoint } = user; diff --git a/src/views/UserEdit/UserForm.js b/src/views/UserEdit/UserForm.js index 648f62022..eb16cf854 100644 --- a/src/views/UserEdit/UserForm.js +++ b/src/views/UserEdit/UserForm.js @@ -26,6 +26,7 @@ import { import { EditCustomFieldsRecord } from '@folio/stripes/smart-components'; import stripesFinalForm from '@folio/stripes/final-form'; +import { USER_TYPES } from '../../constants'; import { EditUserInfo, EditExtendedInfo, @@ -40,10 +41,11 @@ import getProxySponsorWarning from '../../components/util/getProxySponsorWarning import TenantsPermissionsAccordion from './TenantsPermissionsAccordion'; import css from './UserForm.css'; -import { USER_TYPES } from '../../constants'; export function validate(values) { + const isShadowUser = values?.type === USER_TYPES.SHADOW; const errors = {}; + errors.personal = {}; if (!values.personal || !values.personal.lastName) { @@ -54,11 +56,11 @@ export function validate(values) { errors.username = ; } - if (!values.patronGroup) { + if (!isShadowUser && !values.patronGroup) { errors.patronGroup = ; } - if (!values.personal || !values.personal.preferredContactTypeId) { + if (!isShadowUser && (!values.personal || !values.personal.preferredContactTypeId)) { if (errors.personal) errors.personal.preferredContactTypeId = ; else errors.personal = { preferredContactTypeId: }; } diff --git a/src/views/UserEdit/UserForm.test.js b/src/views/UserEdit/UserForm.test.js index 9548bdfa0..47a948dc8 100644 --- a/src/views/UserEdit/UserForm.test.js +++ b/src/views/UserEdit/UserForm.test.js @@ -1,6 +1,8 @@ import React from 'react'; import { FormattedMessage } from 'react-intl'; +import { USER_TYPES } from '../../constants'; + import { validate } from './UserForm'; describe('UserForm', () => { @@ -43,6 +45,11 @@ describe('UserForm', () => { expect(result.personal.preferredContactTypeId).toMatchObject(); }); + it('not requires personal.preferredContactTypeId for shadow user', () => { + const result = validate({ personal: {}, type: USER_TYPES.SHADOW }); + expect(result.personal.preferredContactTypeId).not.toBeDefined(); + }); + it('requires username when password is present', () => { const result = validate({ creds: { password: 'thunder-chicken' } }); expect(result.username).toMatchObject(); @@ -53,6 +60,11 @@ describe('UserForm', () => { expect(result.patronGroup).toMatchObject(); }); + it('not requires patronGroup for shadow user', () => { + const result = validate({ type: USER_TYPES.SHADOW }); + expect(result.patronGroup).not.toBeDefined(); + }); + it('requires personal.addresses to have an addressType', () => { const result = validate({ personal: { addresses: [{ 'monkey': 'bagel' }] } }); expect(result.personal.addresses[0].addressType).toMatchObject();