You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[HOLD for payment 2024-08-14] [$250] Tax-In tax name field, saving with code does not throw error #45887
Please re-state the problem that we are trying to solve in this issue.
Tax-In tax name field, saving with code does not throw error
What is the root cause of that problem?
The form validation runs when the input value changes because shouldValidateOnChange is true by default in FormProvider, but we only want to run validation when user submits the form and then after once form is submitted we want to validate on value changes.
We should also check at other places where TextPicker is used.
I found CreateReportFieldsPage component which also needs to be updated like this.
What alternative solutions did you explore? (Optional)
We can validate the value inside TextSelectorModal and AmountSelectorModal.
Code changes:
Introduce a new prop in TextPicker and TextSelectorModal, we can name it validate. The function will accept a value and should return an error or empty string if no issues are found.
We need to extract the validation for invalidCharacter and make it a util function so we can use it in the validation function for TextPicker & TextSelectorModal. We can also use invalidCharacter validation directly inside TextSelectorModal, this way we don't need to pass invalidCharacter validation when using TextSelectorModal.
Pass validation function for TextPicker. This will check for invalid character also.
validate={(value?: string)=>{if(!policy){return;}if(validateTaxName(policy,{[INPUT_IDS.NAME]: value??''})?.[INPUT_IDS.NAME]){returnvalidateTaxName(policy,{[INPUT_IDS.NAME]: value??''})?.[INPUT_IDS.NAME];}// This can also be directly used in `TextSelectorModal`, that way we don't need to pass this in validation callbackif(ValidationUtils.validateInvalidCharacter(value)){returnValidationUtils.validateInvalidCharacter(value);}return'';}}
Create state named isTouched & error. isTouched will be responsible for checking if the input is already blurred or not and if it is then we will validate on every keystroke and error will be used to store the error string.
Replace Button inside TextSelectorModal with FormAlertWithSubmitButton and validate the value before saving.
changed the title [-]Tax-In tax name field, saving with code does not throw error[/-][+][$250] Tax-In tax name field, saving with code does not throw error[/+]on Jul 22, 2024
Please re-state the problem that we are trying to solve in this issue.
In tax name field, saving with code throws error " invalid character " in android but error not shown in mweb.
What is the root cause of that problem?
We don't set shouldValidateOnBlur true for the form here, so when we come back from the TextPicker back to the WorkspaceCreateTaxPage, it does not validate the input but has to wait until the user clicks Save to see the issue with the input.
This is odd because the user comes all the way from clicking into the Name field, inputting the invalid name and come back, and do not see any error until they click Save, then they have to click all the way to the Name field again to edit it to the correct one. The feedback loop is too long.
What changes do you think we should make in order to solve the problem?
Then the user will see the error immediately after they come back from the Name TextPicker, in all platforms.
What alternative solutions did you explore? (Optional)
I think the best UX would be to validate right inside the Name input, so if the name is invalid, it the user will see it immediately after clicking Save or blurring in the NameTextPicker. This will make the feedback loop the shortest and takes the least amount of time for the user to correct any mistake they made.
We don't really need to duplicate the validation logic from FormProvider to TextPicker, we just need to use FormProvider itself inside TextSelectorModal, because TextSelectorModal itself can be considered a form (with proper validation logic, etc)
Because we don't want the Enter key press to trigger submission in the create tax form, if the name text picker is opened, because Enter should trigger submission in the text picker there instead because it's focused.
8. Below
We need to pass currentValue as value of the name form's input, also call setValue when the form name change
Test thoroughly the TextPicker used in other places to make sure it works well and no regression caused
Rather than isModalOpen check above, there could be other ways to check that the modal is opened on top of current screen (ie. Onyx's modal key like here) we can explore that to reduce changes needed.
Thanks for proposal everyone. @Krishna2323 Can you please explain why do we need to create a new state called shouldValidateOnChange instead using shouldValidateOnChange=true directly?
@dominictbshouldValidateOnBlur={true} will make the form validate and showed errors even when we didn't select any value for them, I don't think that's a good way to handle such cases. Please see the video below.
The solution for this issue has been 🚀 deployed to production 🚀 in version 9.0.17-2 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:
BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:
[@hungvu193] The PR that introduced the bug has been identified. Link to the PR:
[@hungvu193] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment:
[@hungvu193] A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion:
[@hungvu193] Determine if we should create a regression test for this bug.
[@hungvu193] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
[@RachCHopkins] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:
The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment: N/A
A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion: N/A
Regression test:
Login with any account.
Go to Profile => workspaces => Open any workspace that has Tax feature enable.
Go to tax => Add tax rate => Name.
Enter or any invalid character in the name input.
Press Save.
Verify that: the name input should show error "Invalid character" after clicking on save button.
Contributor has been paid, the contract has been completed, and the Upwork post has been closed. @hungvu193 please go ahead and raise your NewDot Request!
Activity
melvin-bot commentedon Jul 22, 2024
Triggered auto assignment to @RachCHopkins (
Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.izarutskaya commentedon Jul 22, 2024
We think this issue might be related to the #vip-vsb
Krishna2323 commentedon Jul 22, 2024
Proposal
Please re-state the problem that we are trying to solve in this issue.
Tax-In tax name field, saving with code does not throw error
What is the root cause of that problem?
shouldValidateOnChangeis true by default inFormProvider, but we only want to run validation when user submits the form and then after once form is submitted we want to validate on value changes.App/src/pages/workspace/taxes/WorkspaceCreateTaxPage.tsx
Lines 79 to 88 in e3ebeff
App/src/components/Form/FormProvider.tsx
Lines 65 to 66 in e3ebeff
What changes do you think we should make in order to solve the problem?
We need to create a state named
shouldValidateOnChange, initially value will be false.When
validateFormruns we need to updateshouldValidateOnChangeto true.App/src/pages/workspace/taxes/WorkspaceCreateTaxPage.tsx
Line 52 in e3ebeff
Then pass
shouldValidateOnChangestate toFormProviderthroughshouldValidateOnChangeprop.We are following the same approach in
BaseOnboardingPersonalDetails.tsxalso.App/src/pages/OnboardingPersonalDetails/BaseOnboardingPersonalDetails.tsx
Line 45 in e3ebeff
App/src/pages/OnboardingPersonalDetails/BaseOnboardingPersonalDetails.tsx
Lines 98 to 101 in e3ebeff
App/src/pages/OnboardingPersonalDetails/BaseOnboardingPersonalDetails.tsx
Line 154 in e3ebeff
We should also check at other places where
TextPickeris used.I found
CreateReportFieldsPagecomponent which also needs to be updated like this.What alternative solutions did you explore? (Optional)
We can validate the value inside
TextSelectorModalandAmountSelectorModal.Code changes:
TextPickerandTextSelectorModal, we can name itvalidate. The function will accept a value and should return an error or empty string if no issues are found.invalidCharacterand make it a util function so we can use it in the validation function forTextPicker&TextSelectorModal. We can also useinvalidCharactervalidation directly insideTextSelectorModal, this way we don't need to passinvalidCharactervalidation when usingTextSelectorModal.App/src/components/Form/FormProvider.tsx
Lines 117 to 149 in b0f810d
TextPicker. This will check for invalid character also.isTouched&error.isTouchedwill be responsible for checking if the input is already blurred or not and if it is then we will validate on every keystroke anderrorwill be used to store the error string.ButtoninsideTextSelectorModalwithFormAlertWithSubmitButtonand validate the value before saving.[-]Tax-In tax name field, saving with code does not throw error[/-][+][$250] Tax-In tax name field, saving with code does not throw error[/+]melvin-bot commentedon Jul 22, 2024
Job added to Upwork: https://www.upwork.com/jobs/~01e31e4849306c8612
melvin-bot commentedon Jul 22, 2024
Triggered auto assignment to Contributor-plus team member for initial proposal review - @hungvu193 (
External)dominictb commentedon Jul 23, 2024
Proposal
Please re-state the problem that we are trying to solve in this issue.
In tax name field, saving with code throws error " invalid character " in android but error not shown in mweb.
What is the root cause of that problem?
We don't set
shouldValidateOnBlurtrue for the form here, so when we come back from theTextPickerback to theWorkspaceCreateTaxPage, it does not validate the input but has to wait until the user clicksSaveto see the issue with the input.This is odd because the user comes all the way from clicking into the Name field, inputting the invalid name and come back, and do not see any error until they click
Save, then they have to click all the way to theNamefield again to edit it to the correct one. The feedback loop is too long.What changes do you think we should make in order to solve the problem?
Update
App/src/pages/workspace/taxes/WorkspaceCreateTaxPage.tsx
Line 86 in fd08a8f
Then the user will see the error immediately after they come back from the Name
TextPicker, in all platforms.What alternative solutions did you explore? (Optional)
I think the best UX would be to validate right inside the Name input, so if the name is invalid, it the user will see it immediately after clicking
Saveor blurring in theNameTextPicker. This will make the feedback loop the shortest and takes the least amount of time for the user to correct any mistake they made.We don't really need to duplicate the validation logic from
FormProvidertoTextPicker, we just need to useFormProvideritself insideTextSelectorModal, becauseTextSelectorModalitself can be considered a form (with proper validation logic, etc)General steps:
FormProviderinputCallbackRefabove can be defined here as:TEXT_PICKER_MODAL_FORMused above will be a new key inONYXKEYS.FORMSApp/src/components/TextPicker/index.tsx
Line 47 in 08bb00b
onCloseof the parent too (we'll need this later when we set the modal open state inWorkspaceCreateTaxPageonOpenhereApp/src/pages/workspace/taxes/WorkspaceCreateTaxPage.tsx
Line 64 in 08bb00b
isModalOpenApp/src/pages/workspace/taxes/WorkspaceCreateTaxPage.tsx
Line 87 in 08bb00b
Because we don't want the Enter key press to trigger submission in the create tax form, if the name text picker is opened, because Enter should trigger submission in the text picker there instead because it's focused.
8. Below
App/src/pages/workspace/taxes/WorkspaceCreateTaxPage.tsx
Line 99 in 08bb00b
With those minimal changes, it works well now:
https://github.com/user-attachments/assets/dc2ddac5-c366-4f8f-9cf9-37dec0420249
Some further enhancements that could be done:
currentValueasvalueof the name form's input, also callsetValuewhen the form name changeTextPickerused in other places to make sure it works well and no regression causedisModalOpencheck above, there could be other ways to check that the modal is opened on top of current screen (ie. Onyx's modal key like here) we can explore that to reduce changes needed.All those follow-ups can be done in the PR phase.
hungvu193 commentedon Jul 24, 2024
Thanks for proposal everyone.
@Krishna2323 Can you please explain why do we need to create a new state called
shouldValidateOnChangeinstead usingshouldValidateOnChange=truedirectly?@dominictb
shouldValidateOnBlur={true}will make the form validate and showed errors even when we didn't select any value for them, I don't think that's a good way to handle such cases. Please see the video below.Screen.Recording.2024-07-24.at.11.15.43.mov
44 remaining items
melvin-bot commentedon Aug 7, 2024
Reviewinglabel has been removed, please complete the "BugZero Checklist".melvin-bot commentedon Aug 7, 2024
The solution for this issue has been 🚀 deployed to production 🚀 in version 9.0.17-2 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:
If no regressions arise, payment will be issued on 2024-08-14. 🎊
For reference, here are some details about the assignees on this issue:
melvin-bot commentedon Aug 7, 2024
BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:
hungvu193 commentedon Aug 15, 2024
Regression test:
Do we 👍 or 👎 ?
hungvu193 commentedon Aug 16, 2024
little bump @RachCHopkins for the payment 😄
RachCHopkins commentedon Aug 19, 2024
Sorry @hungvu193 I've been a little tied up! I'll get this organised tomorrow!
RachCHopkins commentedon Aug 19, 2024
Payment Summary:
Contributor: @dominictb paid $250 via Upwork
Contributor+: @hungvu193 due $250 via NewDot
Upwork job here
RachCHopkins commentedon Aug 19, 2024
Contributor has been paid, the contract has been completed, and the Upwork post has been closed. @hungvu193 please go ahead and raise your NewDot Request!
JmillsExpensify commentedon Aug 23, 2024
$250 approved for @hungvu193