diff --git a/source/frontend/src/features/contacts/contact/edit/Organization/UpdateOrganizationForm.test.tsx b/source/frontend/src/features/contacts/contact/edit/Organization/UpdateOrganizationForm.test.tsx index 57490784d2..601b9b2d6a 100644 --- a/source/frontend/src/features/contacts/contact/edit/Organization/UpdateOrganizationForm.test.tsx +++ b/source/frontend/src/features/contacts/contact/edit/Organization/UpdateOrganizationForm.test.tsx @@ -115,7 +115,7 @@ describe('UpdateOrganizationForm', () => { const { getSaveButton } = setup({ id: 1 }); const save = getSaveButton(); await act(async () => userEvent.click(save)); - expect(updateOrganization).toBeCalledWith(mockOrganization); + expect(updateOrganization).toHaveBeenCalledWith(mockOrganization); }); it('should save the organization with new values', async () => { @@ -154,7 +154,7 @@ describe('UpdateOrganizationForm', () => { const save = getSaveButton(); await act(async () => userEvent.click(save)); - expect(updateOrganization).toBeCalledWith(newValues); + expect(updateOrganization).toHaveBeenCalledWith(newValues); }); it(`should save the form with address information when 'Other' country selected and no province is supplied`, async () => { @@ -201,7 +201,7 @@ describe('UpdateOrganizationForm', () => { const save = getSaveButton(); await act(async () => userEvent.click(save)); - expect(updateOrganization).toBeCalledWith(newValues); + expect(updateOrganization).toHaveBeenCalledWith(newValues); }); }); }); diff --git a/source/frontend/src/features/contacts/contact/edit/Organization/UpdateOrganizationForm.tsx b/source/frontend/src/features/contacts/contact/edit/Organization/UpdateOrganizationForm.tsx index 771c17c1a0..a977cbedbb 100644 --- a/source/frontend/src/features/contacts/contact/edit/Organization/UpdateOrganizationForm.tsx +++ b/source/frontend/src/features/contacts/contact/edit/Organization/UpdateOrganizationForm.tsx @@ -83,12 +83,16 @@ const UpdateOrganization: React.FC> = ({ const organizationId = getIn(values, 'id'); const persons = getIn(values, 'persons') as Partial[]; + const isOrganizationDisabled = getIn(values, 'isDisabled'); const onCancel = () => { history.push(`/contact/O${organizationId}`); }; const isContactMethodInvalid = useMemo(() => { + if (isOrganizationDisabled === true) { + return false; + } return ( !!touched.phoneContactMethods && !!touched.emailContactMethods && @@ -97,7 +101,7 @@ const UpdateOrganization: React.FC> = ({ !!touched.billingAddress?.streetAddress1) && getIn(errors, 'needsContactMethod') ); - }, [touched, errors]); + }, [touched, errors, isOrganizationDisabled]); const checkState = useCallback(() => { return dirty && !isSubmitting; diff --git a/source/frontend/src/features/contacts/contact/edit/Person/UpdatePersonForm.test.tsx b/source/frontend/src/features/contacts/contact/edit/Person/UpdatePersonForm.test.tsx index 88f4cb38cb..8b4094b454 100644 --- a/source/frontend/src/features/contacts/contact/edit/Person/UpdatePersonForm.test.tsx +++ b/source/frontend/src/features/contacts/contact/edit/Person/UpdatePersonForm.test.tsx @@ -241,7 +241,7 @@ describe('UpdatePersonForm', () => { const expectedPerson = { ...mockPerson }; expectedPerson!.personOrganizations![0].organization = null; - expect(updatePerson).toBeCalledWith(expectedPerson); + expect(updatePerson).toHaveBeenCalledWith(expectedPerson); }); it('should save the form with updated values', async () => { @@ -287,7 +287,7 @@ describe('UpdatePersonForm', () => { const save = getSaveButton(); await act(async () => userEvent.click(save)); - expect(updatePerson).toBeCalledWith(newValues); + expect(updatePerson).toHaveBeenCalledWith(newValues); }); it(`should save the form with address information when 'Other' country selected and no province is supplied`, async () => { diff --git a/source/frontend/src/features/contacts/contact/edit/Person/UpdatePersonForm.tsx b/source/frontend/src/features/contacts/contact/edit/Person/UpdatePersonForm.tsx index cf948ecca1..e55d553a15 100644 --- a/source/frontend/src/features/contacts/contact/edit/Person/UpdatePersonForm.tsx +++ b/source/frontend/src/features/contacts/contact/edit/Person/UpdatePersonForm.tsx @@ -79,6 +79,7 @@ const UpdatePersonComponent: React.FC< > = ({ values, errors, touched, dirty, submitForm, setFieldValue, isSubmitting }) => { const history = useHistory(); const { getOrganization } = useApiContacts(); + const isPersonDisabled = getIn(values, 'isDisabled'); const personId = getIn(values, 'id'); const organizationId = getIn(values, 'organization.id'); @@ -90,6 +91,9 @@ const UpdatePersonComponent: React.FC< }; const isContactMethodInvalid = useMemo(() => { + if (isPersonDisabled === true) { + return false; + } return ( !!touched.phoneContactMethods && !!touched.emailContactMethods && @@ -98,7 +102,7 @@ const UpdatePersonComponent: React.FC< !!touched.billingAddress?.streetAddress1) && getIn(errors, 'needsContactMethod') ); - }, [touched, errors]); + }, [touched, errors, isPersonDisabled]); // update mailing address sub-form when "useOrganizationAddress" checkbox is toggled useEffect(() => { diff --git a/source/frontend/src/features/contacts/contact/utils/contactUtils.ts b/source/frontend/src/features/contacts/contact/utils/contactUtils.ts index a5a20cba2b..54690d0090 100644 --- a/source/frontend/src/features/contacts/contact/utils/contactUtils.ts +++ b/source/frontend/src/features/contacts/contact/utils/contactUtils.ts @@ -23,9 +23,14 @@ export const onValidateOrganization = ( const errors = {} as any; try { // combine yup schema validation with custom rules - if (!hasEmail(values) && !hasPhoneNumber(values) && !hasAddress(values)) { + if ( + !hasEmail(values) && + !hasPhoneNumber(values) && + !hasAddress(values) && + values.isDisabled === 'false' + ) { errors.needsContactMethod = - 'Contacts must have a minimum of one method of contact to be saved. (ex: email,phone or address)'; + 'Contacts must have a minimum of one method of contact to be saved. (ex: email, phone or address)'; } validateYupSchema(values, OrganizationValidationSchema, true, { otherCountry: otherCountryId, @@ -40,9 +45,14 @@ export const onValidatePerson = (values: IEditablePersonForm, otherCountryId?: s const errors = {} as any; try { // combine yup schema validation with custom rules - if (!hasEmail(values) && !hasPhoneNumber(values) && !hasAddress(values)) { + if ( + !hasEmail(values) && + !hasPhoneNumber(values) && + !hasAddress(values) && + values.isDisabled === 'false' + ) { errors.needsContactMethod = - 'Contacts must have a minimum of one method of contact to be saved. (ex: email,phone or address)'; + 'Contacts must have a minimum of one method of contact to be saved. (ex: email, phone or address)'; } validateYupSchema(values, PersonValidationSchema, true, { otherCountry: otherCountryId }); diff --git a/source/frontend/src/features/contacts/formModels.ts b/source/frontend/src/features/contacts/formModels.ts index b521e096c5..d467f03c32 100644 --- a/source/frontend/src/features/contacts/formModels.ts +++ b/source/frontend/src/features/contacts/formModels.ts @@ -9,6 +9,7 @@ import { ApiGen_Concepts_PersonOrganization } from '@/models/api/generated/ApiGe import { NumberFieldValue } from '@/typings/NumberFieldValue'; import { exists, isValidId } from '@/utils'; import { + booleanToString, emptyStringtoNullable, fromTypeCode, stringToBoolean, @@ -33,7 +34,7 @@ export class IEditablePersonForm { useOrganizationAddress = false; personOrganizationId?: number; personOrganizationRowVersion?: number; - isDisabled: string | boolean = false; + isDisabled: string; emailContactMethods: IEditableContactMethodForm[]; phoneContactMethods: IEditableContactMethodForm[]; mailingAddress: IEditablePersonAddressForm; @@ -41,7 +42,7 @@ export class IEditablePersonForm { billingAddress: IEditablePersonAddressForm; constructor() { - this.isDisabled = false; + this.isDisabled = 'false'; this.firstName = ''; this.middleNames = ''; this.surname = ''; @@ -103,7 +104,7 @@ export class IEditablePersonForm { formPerson.useOrganizationAddress = person.useOrganizationAddress ?? false; - formPerson.isDisabled = person.isDisabled; + formPerson.isDisabled = booleanToString(person.isDisabled); formPerson.mailingAddress = formAddresses.find(a => a.addressTypeId === ApiGen_CodeTypes_AddressUsageTypes.MAILING) ?? @@ -183,7 +184,7 @@ export class IEditableOrganizationForm { alias?: string; incorporationNumber?: string; comment?: string; - isDisabled: boolean; + isDisabled: string; persons: Partial[]; emailContactMethods: IEditableContactMethodForm[]; phoneContactMethods: IEditableContactMethodForm[]; @@ -192,7 +193,7 @@ export class IEditableOrganizationForm { billingAddress: IEditableOrganizationAddressForm; constructor() { - this.isDisabled = false; + this.isDisabled = 'false'; this.name = ''; this.alias = ''; this.incorporationNumber = ''; @@ -249,7 +250,7 @@ export class IEditableOrganizationForm { newForm.alias = organization.alias ?? ''; newForm.incorporationNumber = organization.incorporationNumber ?? undefined; newForm.comment = organization.comment ?? undefined; - newForm.isDisabled = organization.isDisabled; + newForm.isDisabled = booleanToString(organization.isDisabled); newForm.persons = formPersonList; newForm.mailingAddress =