[HOLD for payment 2021-11-04] Fake growl about changes being made in profile is displayed when saving a name that's over 50 characters long
If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!
Action Performed:
- Navigate to settings > Profile
- Change the first or last name to something over 50 characters
- Save the changes
- Refresh the page
Expected Result:
User should be informed that there's a maximum of 50 characters in the first and last name inputs.
Actual Result:
There's a growl saying that the changes were "saved". After reload the name is back to previous name. More info from @vitHoracek
The response of the API call is 666 so we should not handle it as success.
{"code":666,"jsonCode":666,"type":"Expensify\\Libs\\Error\\ExpError","UUID":"05f93e83-41a5-42a6-ad9c-471d43afae2e","message":"Last name shouldn't be longer than 50 characters","title":"","data":[],"htmlMessage":"","requestID":"2P7skf"}
Workaround:
Don't save a name over 50 characters (?)
Platform:
Where is this issue occurring?
- Web
- iOS
- Android
- Desktop App
- Mobile Web
Version Number: 1.0.93-0
Logs: https://stackoverflow.com/c/expensify/questions/4856
Notes/Photos/Videos: Any additional supporting documentation
https://user-images.githubusercontent.com/44479856/132076454-ea43da97-ae6a-42ec-9139-e09bf6c321bd.mp4
Expensify/Expensify Issue URL:
From @vitHoracek https://expensify.slack.com/archives/C01GTK53T8Q/p1630687779397100
When you update your first OR last name with very long name, we present successful growl message and optimistically change the name on front end. After reload the name is back to previous name. Based on the API call response, the limit is 50 characters, but we do not handle the response correctly. Details in
Triggered auto assignment to @Beamanator (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.
Here is my suggestion,
Within ProfilePage.js file we have to add firstname lastname max chars validation within updatePersonalDetails() function before line 170 (i.e. before setPersonalDetails call ). If firstname, lastname max chars. validation failed then we will show growl message with Error and return. i.e. We will not proceed to call setPersonalDetails api in this case. So this way it will also save api call in case of firstname or lastname max length more than allowed chars.
Below is the Current Code: https://github.com/Expensify/App/blob/6cd518e81fb60415ba8d4d4a659fdc5dfa95b6fd/src/pages/settings/Profile/ProfilePage.js#L160-L183
Code will look like as under after First name, last name validation added.
updatePersonalDetails() {
const {
firstName,
lastName,
pronouns,
selfSelectedPronouns,
selectedTimezone,
isAutomaticTimezone,
} = this.state;
// Below code added to validate firstname, lastname max. length.
if (firstName.trim().length > 50) {
Growl.show(this.props.translate('profilePage.maxCharsAllowFirstname', {maxValue: 50}), CONST.GROWL.ERROR, 3000);
return;
}
if (lastName.trim().length > 50) {
Growl.show(this.props.translate('profilePage.maxCharsAllowLastname', {maxValue: 50}), CONST.GROWL.ERROR, 3000);
return;
}
setPersonalDetails({
firstName: firstName.trim(),
lastName: lastName.trim(),
pronouns: pronouns === this.props.translate('pronouns.selfSelect')
? selfSelectedPronouns
: pronouns,
timezone: {
automatic: isAutomaticTimezone,
selected: selectedTimezone,
},
});
Growl.show(this.props.translate('profilePage.growlMessageOnSave'), CONST.GROWL.SUCCESS, 3000);
}
Also we have to add constants within src/languages/en.js file.
profilePage: {
...,
maxCharsAllowFirstname: ({maxValue}) => `First name shouldn't be longer than ${maxValue} characters`,
maxCharsAllowLastname: ({maxValue}) => `Last name shouldn't be longer than ${maxValue} characters`,
},
Also We have to add constants within src/languages/es.js file.
profilePage: {
...,
maxCharsAllowFirstname: ({maxValue}) => `El nombre no debe tener más de ${maxValue} caracteres`,
maxCharsAllowLastname: ({maxValue}) => `El apellido no debe tener más de ${maxValue} caracteres`,
},
Please also suggest me proper grammar for English and Spanish if need any changes in message.
Here is the screen record how it works once code updated as per my suggestion.
https://user-images.githubusercontent.com/7823358/132083813-4ff6583b-f6ee-45af-9022-524dc579b1ca.mov
At present External label not set with this issue, so just giving suggestion. It might be helpful for someone if handled internally.
If this issue consider as External and my solution accepted then kindly invite me on Upwork project. Here is my Upwork profile: https://www.upwork.com/freelancers/~01c718889ed7821f82
Thank you.
Hi there, the above proposal looks great and working as expected. But just in case if we want a different solution. I'm adding mine.
Inside setPersonalDetails function, instead of optimistically updating the profile details, we can wait for the API completion and show success & error growl based on the jsonCode that we get from response.
It will look like this:
/**
* Sets the personal details object for the current user
*
* @param {Object} details
*/
function setPersonalDetails(details) {
API.PersonalDetails_Update({details: JSON.stringify(details)})
.then((response) => {
if (response.jsonCode === 200) {
Growl.show(translateLocal('profilePage.growlMessageOnSave'), CONST.GROWL.SUCCESS, 3000);
} else {
Growl.error(response.message, 3000);
return;
}
if (details.timezone) {
NameValuePair.set(CONST.NVP.TIMEZONE, details.timezone);
}
mergeLocalPersonalDetails(details);
}).catch((error) => {
console.debug('Error while setting personal details', error);
});
}
Then we can remove the additional success Growl on ProfilePage.js
Demo:
https://user-images.githubusercontent.com/83179295/132084447-868bc858-aceb-4506-bd5e-0c8bb053c06e.mp4
Hi @thesahindia , your solution also looks good, but some confusion from my side as under:
if (response.jsonCode === 200) { Growl.show(translateLocal('profilePage.growlMessageOnSave'), CONST.GROWL.SUCCESS, 3000); } else { Growl.error(response.message, 3000); return; }
If api will not return response.message in localised language then in case of error it will show error message in english, I am not sure that server side api will return error in localised language or not. If api will return localised language message then it is ok.
Other major problem with changing setPersonalDetails() code within src/libs/actions/PersonalDetails.js is that setPersonalDetails function may be called from multiple places, so once the code changes it will show Growl success or error message either it need to show or not.
For example I can see that setPersonalDetails is called from updateTimezone() function within src/libs/DateUtils.js file, and also from src/libs/Navigation/AppNavigator/AuthScreens.js file within Onyx.connect() at line 65, also called from setAvatar() method within src/libs/actions/PersonalDetails.js file itself.
I think it is not good ides to change api logic within lib file src/libs/actions/PersonalDetails.js because it may result to regression and affect the behaviour of other places from where setPersonalDetails() function called.
Let expensify engineer to decide which one is better way to go. Also thanks for the suggestion.
Hi @PrashantMangukiya, Thank you for looking into the solution and giving remarks! Both of the points are valid and I'll try to reply to them.
If api will not return response.message in localised language then in case of error it will show error message in english,
To show the translated version of the message, we can either use jsonCode or message of the response and based on that we can set correct message
An example where something similar is implemented:
https://github.com/Expensify/App/blob/6cd518e81fb60415ba8d4d4a659fdc5dfa95b6fd/src/libs/actions/BankAccounts.js#L794-L811
Other major problem with changing setPersonalDetails() code within src/libs/actions/PersonalDetails.js is that setPersonalDetails function may be called from multiple places, so once the code changes it will show Growl success or error message either it need to show or not.
I looked into this and found that this PR is already dealing with that (by setting a flag called shouldGrowl) so no regression might occur. (We can just tweak that a little if we want growls after API completion)
I hope all the questions are answered now.
Hi, @thesahindia I got it. Thanks for the message.
Triggered auto assignment to @stephanieelliott (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.
Sorry for the delay y'all, this looks like a nice external issue so I'm going to begin reviewing proposals 👍
Thanks for your proposals @thesahindia and @PrashantMangukiya !
I found this conversation in Slack which covers this situation. Since we have a unique error message that needs to be thrown only in this case, I will make a back-end change to throw this new jsonCode (I'll post here when I know what that code will be) so it can be handled on the front end.
@thesahindia I like your proposal best, so I'll assign this to you but I'm also going to put this issue on hold until the back-end work is done 👍
Thanks @Beamanator, I will wait for the back-end changes.
Internal PR in motion 👍
Quick update: Internal PR was merged, but the changes won't be visible in the production environment till probably tomorrow (Tuesday). Here's an overview of the changes:
- The
'First name shouldn\'t be longer than 50 characters'error will have ajsonCodeof400 - The
'Last name shouldn\'t be longer than 50 characters'error will have ajsonCodeof401
Just tested, the back end work is not live on production quite yet! Should be soon though.
Hi @thesahindia, I hate to delay this further but I've placed this issue on hold as per this update, as we are prioritising issues related to a feature release scheduled for 9/24. As an apology for the delay, we will add a $100 bonus as a thank you for waiting.
Change should be live on Production! @thesahindia feel free to work on a PR and submit when you have time, but as mentioned above we won't be merging this until the n6-hold is removed 👍
Still on hold for n6, hopefully will be taken off hold this or next week!
PR ready to merge, but won't merge till the n6 hold ends 👍 Nice work @thesahindia !
@stephanieelliott have you created a job for this? I didn't see it above, but I may have missed it :D
Thanks for the bump, @Beamanator! Just now created the job in Upwork, @thesahindia can you please post a quick proposal so we can get payment arranged once the PR is merged?
Here is the job: upwork.com/jobs/~01ab1db8fe7689f675
Simply put the maxLength ={50} prop in your text input. User will not able to put more than 50 characters. and don't need to put check like greater than or less than as it will effect on app performance.
@stephanieelliott, Submitted the proposal.