-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix(patient): Validation input for email and phone number #1983
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/hospitalrun/hospitalrun-frontend/yapgry5vv |
expect(wrapper.find(GeneralInformation).prop('feedbackFields').phoneNumber).toMatch( | ||
'patient.errors.patientPhoneNumberFeedback', | ||
) | ||
expect(wrapper.update.isInvalid === true) |
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.
this can be written as expect(wrapper.prop('isInvalid)).toBeTruthy()
to more closely align to how other tests have been written
expect(wrapper.find(GeneralInformation).prop('feedbackFields').email).toMatch( | ||
'patient.errors.patientEmailFeedback', | ||
) | ||
expect(wrapper.update.isInvalid === true) |
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.
same as other comment
expect(wrapper.find(GeneralInformation).prop('feedbackFields').phoneNumber).toMatch( | ||
'patient.errors.patientPhoneNumberFeedback', | ||
) | ||
expect(wrapper.update.isInvalid === true) |
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.
same as other comment
expect(wrapper.find(GeneralInformation).prop('feedbackFields').email).toMatch( | ||
'patient.errors.patientEmailFeedback', | ||
) | ||
expect(wrapper.update.isInvalid === true) |
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.
same as other comment
if (patient.phoneNumber) { | ||
if (!patient.phoneNumber.match(/^\d+/)) { | ||
inputIsValid = false | ||
setErrorMessage(t('patient.errors.updatePatientError')) | ||
setInvalidFields({ | ||
...invalidFields, | ||
phoneNumber: true, | ||
}) | ||
setFeedbackFields({ | ||
...feedbackFields, | ||
phoneNumber: t('patient.errors.patientPhoneNumberFeedback'), | ||
}) | ||
} | ||
} | ||
if (patient.email) { | ||
if (!patient.email.match(/^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/)) { | ||
inputIsValid = false | ||
setErrorMessage(t('patient.errors.updatePatientError')) | ||
setInvalidFields({ | ||
...invalidFields, | ||
email: true, | ||
}) | ||
setFeedbackFields({ | ||
...feedbackFields, | ||
email: t('patient.errors.patientEmailFeedback'), | ||
}) |
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 we may want to use https://www.npmjs.com/package/validator (or equivalent library if there is a different one).
I fear that there are edge cases that we have not considered. For example, phone numbers can have (, ), -, / in some cases.
This library seems comprehensive in the validations it performs.
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.
@fox1t thoughts here?
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.
Yes, we absolutely need to relay on some external library to do this properly. However I don't have any preference.
Deployment failed with the following error:
|
Any news about this? |
closing in favor of #2030 |
Fixes parts of #1976
Changes proposed in this pull request: