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

update display name when update legal name #53558

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
38 changes: 27 additions & 11 deletions src/libs/actions/PersonalDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
key: ONYXKEYS.SESSION,
callback: (val) => {
currentUserEmail = val?.email ?? '';
currentUserAccountID = val?.accountID ?? -1;

Check failure on line 40 in src/libs/actions/PersonalDetails.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

},
});

Expand Down Expand Up @@ -121,20 +121,36 @@

function updateLegalName(legalFirstName: string, legalLastName: string) {
const parameters: UpdateLegalNameParams = {legalFirstName, legalLastName};

API.write(WRITE_COMMANDS.UPDATE_LEGAL_NAME, parameters, {
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PRIVATE_PERSONAL_DETAILS,
value: {
legalFirstName,
legalLastName,
const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PRIVATE_PERSONAL_DETAILS,
value: {
legalFirstName,
legalLastName,
},
},
];
// In case the user does not have a display name, we will update the display name based on the legal name
if (!allPersonalDetails?.[currentUserAccountID]?.firstName && !allPersonalDetails?.[currentUserAccountID]?.lastName) {
Themoonalsofall marked this conversation as resolved.
Show resolved Hide resolved
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: {
[currentUserAccountID]: {
displayName: PersonalDetailsUtils.createDisplayName(currentUserEmail ?? '', {
firstName: legalFirstName,
lastName: legalLastName,
}),
},
firstName: legalFirstName,
lastName: legalLastName,
},
],
});
}
API.write(WRITE_COMMANDS.UPDATE_LEGAL_NAME, parameters, {
optimisticData,
});

Navigation.goBack();
}

Expand Down
Loading