-
Notifications
You must be signed in to change notification settings - Fork 1
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
Lint Fix: Fix for new Phone numbers schema change #861
Conversation
@@ -261,7 +261,7 @@ export const PersonModal: React.FC<PersonModalProps> = ({ | |||
return { | |||
id: phoneNumber.id, | |||
primary: phoneNumber.primary, | |||
number: phoneNumber.number, | |||
number: phoneNumber?.number, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this will help. I believe it's number
that will be null, not phoneNumber
. And if phoneNumber
is null
, all the other property access calls with throw an exception too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know about this one, I added it just in case. I want to test with a Null number. I'll do that tomorrow
This pull request is automatically being deployed by Amplify Hosting (learn more). |
In staging there is an issue with deleting an existing null phone number. But this is due to the staging file. On production, it works fine. There have been a lot of changes to the PersonModal file with the new Preferences, so it's likely that causing it. In the Production personModal, it is working fine. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides the test and type suggestions I mentioned, the code looks pretty good!
Thanks to the schema tweak, invalid phone numbers shouldn't cause issues anymore, and the user can edit them if they open the Edit Person modal. I'm wondering if we need to show the user the error and should instead just show a blank number like the old MPDX. I guess my question is whether a missing phone number is important enough of an issue to warrant showing an error message like this.
...components/Contacts/ContactDetails/ContactDetailsTab/People/ContactDetailsTabPeople.test.tsx
Outdated
Show resolved
Hide resolved
...components/Contacts/ContactDetails/ContactDetailsTab/People/ContactDetailsTabPeople.test.tsx
Outdated
Show resolved
Hide resolved
...tails/ContactDetailsTab/People/Items/PersonModal/PersonPhoneNumber/PersonPhoneNumberItem.tsx
Outdated
Show resolved
Hide resolved
...ents/Contacts/ContactDetails/ContactDetailsTab/People/Items/PersonModal/PersonModal.test.tsx
Outdated
Show resolved
Hide resolved
…longer have to change the value of a null field.
@canac Sorry, I forgot to push up my changes. My changes are also in staging. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code seems to work well locally! I'm going to go ahead and approve since all my suggestions are just stylistic.
...components/Contacts/ContactDetails/ContactDetailsTab/People/ContactDetailsTabPeople.test.tsx
Show resolved
Hide resolved
src/components/Contacts/ContactDetails/ContactDetailsTab/People/ContactDetailsTabPeople.tsx
Outdated
Show resolved
Hide resolved
.string() | ||
.when('destroy', { | ||
is: true, | ||
then: yup.string().nullable(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could add otherwise: yup.string().required(t('This field is required')),
instead of a second .when
block.
@@ -69,6 +70,20 @@ export const PersonPhoneNumber: React.FC<PersonPhoneNumberProps> = ({ | |||
(phoneNumber) => phoneNumber.id === primaryPhoneNumber?.id, | |||
) ?? 0, | |||
); | |||
|
|||
const hasNullPhoneNumbers = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually variables that start with has
are booleans. Would it make sense to rename this to nullPhoneNumbers
?
|
||
const hasNullPhoneNumbers = | ||
phoneNumbers?.filter((phone) => phone.number === null) || []; | ||
hasNullPhoneNumbers.forEach((phoneNumber) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, it might make more sense to combine these .filter
and .forEach
loops.
if (!phoneNumbers) {
return;
}
phoneNumbers.forEach((phoneNumber) => {
const index = phoneNumbers.findIndex((phone) => phone.id === phoneNumber.id);
if (phoneNumber.number === null) {
setFieldError(`phoneNumbers.${index}.number`, t('Please enter a valid phone number'));
}
});
@dr-bizz Also the tests are failing because a mock sets a non-nullable phone number to |
Description
This PR is going to be for when this PR https://github.com/CruGlobal/mpdx_api/pull/2760/files goes live.
It fixes a lint issue and ensures a null phone number won't cause an error.
Checklist: