Skip to content
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

Merged
merged 12 commits into from
Jan 25, 2024
Merged

Conversation

dr-bizz
Copy link
Contributor

@dr-bizz dr-bizz commented Jan 18, 2024

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:

  • I have given my PR a title with the format "MPDX-(JIRA#) (summary sentence max 80 chars)"
  • I have applied the appropriate labels. (Add the label "On Staging" to get the branch automatically merged into staging.)
  • I have requested a review from another person on the project

@dr-bizz dr-bizz requested a review from canac January 18, 2024 20:54
@dr-bizz dr-bizz added the On Staging Will be merged to the staging branch by Github Actions label Jan 18, 2024
@@ -261,7 +261,7 @@ export const PersonModal: React.FC<PersonModalProps> = ({
return {
id: phoneNumber.id,
primary: phoneNumber.primary,
number: phoneNumber.number,
number: phoneNumber?.number,
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-861.d3dytjb8adxkk5.amplifyapp.com

@dr-bizz
Copy link
Contributor Author

dr-bizz commented Jan 19, 2024

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.

Copy link
Contributor

@canac canac left a 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.

@dr-bizz dr-bizz requested a review from canac January 22, 2024 20:22
@dr-bizz
Copy link
Contributor Author

dr-bizz commented Jan 23, 2024

@canac Sorry, I forgot to push up my changes. My changes are also in staging.

Copy link
Contributor

@canac canac left a 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.

.string()
.when('destroy', {
is: true,
then: yup.string().nullable(),
Copy link
Contributor

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 =
Copy link
Contributor

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) => {
Copy link
Contributor

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'));
  }
});

@canac
Copy link
Contributor

canac commented Jan 23, 2024

@dr-bizz Also the tests are failing because a mock sets a non-nullable phone number to null, but that test will pass once Shelby's PR gets merged. I'm not sure which PR we plan to merge first, but I'm OK with merging this one first despite the failure if you do it that way. Just make sure to rerun the tests on main after the API PR gets merged to make sure that the tests all pass then.

@dr-bizz dr-bizz enabled auto-merge (squash) January 24, 2024 18:11
@dr-bizz dr-bizz disabled auto-merge January 24, 2024 18:11
@dr-bizz dr-bizz merged commit 3f178c5 into main Jan 25, 2024
17 of 18 checks passed
@dr-bizz dr-bizz deleted the fix-phone-numbers branch January 25, 2024 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
On Staging Will be merged to the staging branch by Github Actions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants