Skip to content

Commit

Permalink
Merge pull request #4552 from stairaku/PSP-9471
Browse files Browse the repository at this point in the history
PSP-9471: UI UX Clean Up - Contact – Manage Contacts: Allow to save contacts that are set as Inactive without Contact Methods
  • Loading branch information
stairaku authored Dec 30, 2024
2 parents a084d97 + 6da46e7 commit 102f2f4
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -201,7 +201,7 @@ describe('UpdateOrganizationForm', () => {
const save = getSaveButton();
await act(async () => userEvent.click(save));

expect(updateOrganization).toBeCalledWith(newValues);
expect(updateOrganization).toHaveBeenCalledWith(newValues);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,16 @@ const UpdateOrganization: React.FC<FormikProps<IEditableOrganizationForm>> = ({

const organizationId = getIn(values, 'id');
const persons = getIn(values, 'persons') as Partial<ApiGen_Concepts_Person>[];
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 &&
Expand All @@ -97,7 +101,7 @@ const UpdateOrganization: React.FC<FormikProps<IEditableOrganizationForm>> = ({
!!touched.billingAddress?.streetAddress1) &&
getIn(errors, 'needsContactMethod')
);
}, [touched, errors]);
}, [touched, errors, isOrganizationDisabled]);

const checkState = useCallback(() => {
return dirty && !isSubmitting;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -90,6 +91,9 @@ const UpdatePersonComponent: React.FC<
};

const isContactMethodInvalid = useMemo(() => {
if (isPersonDisabled === true) {
return false;
}
return (
!!touched.phoneContactMethods &&
!!touched.emailContactMethods &&
Expand All @@ -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(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 });

Expand Down
13 changes: 7 additions & 6 deletions source/frontend/src/features/contacts/formModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -33,15 +34,15 @@ export class IEditablePersonForm {
useOrganizationAddress = false;
personOrganizationId?: number;
personOrganizationRowVersion?: number;
isDisabled: string | boolean = false;
isDisabled: string;
emailContactMethods: IEditableContactMethodForm[];
phoneContactMethods: IEditableContactMethodForm[];
mailingAddress: IEditablePersonAddressForm;
propertyAddress: IEditablePersonAddressForm;
billingAddress: IEditablePersonAddressForm;

constructor() {
this.isDisabled = false;
this.isDisabled = 'false';
this.firstName = '';
this.middleNames = '';
this.surname = '';
Expand Down Expand Up @@ -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) ??
Expand Down Expand Up @@ -183,7 +184,7 @@ export class IEditableOrganizationForm {
alias?: string;
incorporationNumber?: string;
comment?: string;
isDisabled: boolean;
isDisabled: string;
persons: Partial<ApiGen_Concepts_Person>[];
emailContactMethods: IEditableContactMethodForm[];
phoneContactMethods: IEditableContactMethodForm[];
Expand All @@ -192,7 +193,7 @@ export class IEditableOrganizationForm {
billingAddress: IEditableOrganizationAddressForm;

constructor() {
this.isDisabled = false;
this.isDisabled = 'false';
this.name = '';
this.alias = '';
this.incorporationNumber = '';
Expand Down Expand Up @@ -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 =
Expand Down

0 comments on commit 102f2f4

Please sign in to comment.