Skip to content

Commit 2260557

Browse files
authored
Merge pull request #53558 from Themoonalsofall/update-display-name
update display name when update legal name
2 parents 2f60b30 + 436c017 commit 2260557

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

src/libs/TransactionUtils/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1288,11 +1288,10 @@ function compareDuplicateTransactionFields(
12881288
return {keep, change};
12891289
}
12901290

1291-
function getTransactionID(threadReportID: string | undefined): string | undefined {
1291+
function getTransactionID(threadReportID?: string): string | undefined {
12921292
if (!threadReportID) {
12931293
return;
12941294
}
1295-
12961295
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${threadReportID}`];
12971296
const parentReportAction = isThread(report) ? getReportAction(report.parentReportID, report.parentReportActionID) : undefined;
12981297
const IOUTransactionID = isMoneyRequestAction(parentReportAction) ? getOriginalMessage(parentReportAction)?.IOUTransactionID : undefined;

src/libs/actions/PersonalDetails.ts

+28-12
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Onyx.connect({
3737
key: ONYXKEYS.SESSION,
3838
callback: (val) => {
3939
currentUserEmail = val?.email ?? '';
40-
currentUserAccountID = val?.accountID ?? -1;
40+
currentUserAccountID = val?.accountID ?? CONST.DEFAULT_NUMBER_ID;
4141
},
4242
});
4343

@@ -121,20 +121,36 @@ function updateDisplayName(firstName: string, lastName: string) {
121121

122122
function updateLegalName(legalFirstName: string, legalLastName: string) {
123123
const parameters: UpdateLegalNameParams = {legalFirstName, legalLastName};
124-
125-
API.write(WRITE_COMMANDS.UPDATE_LEGAL_NAME, parameters, {
126-
optimisticData: [
127-
{
128-
onyxMethod: Onyx.METHOD.MERGE,
129-
key: ONYXKEYS.PRIVATE_PERSONAL_DETAILS,
130-
value: {
131-
legalFirstName,
132-
legalLastName,
124+
const optimisticData: OnyxUpdate[] = [
125+
{
126+
onyxMethod: Onyx.METHOD.MERGE,
127+
key: ONYXKEYS.PRIVATE_PERSONAL_DETAILS,
128+
value: {
129+
legalFirstName,
130+
legalLastName,
131+
},
132+
},
133+
];
134+
// In case the user does not have a display name, we will update the display name based on the legal name
135+
if (!allPersonalDetails?.[currentUserAccountID]?.firstName && !allPersonalDetails?.[currentUserAccountID]?.lastName) {
136+
optimisticData.push({
137+
onyxMethod: Onyx.METHOD.MERGE,
138+
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
139+
value: {
140+
[currentUserAccountID]: {
141+
displayName: PersonalDetailsUtils.createDisplayName(currentUserEmail ?? '', {
142+
firstName: legalFirstName,
143+
lastName: legalLastName,
144+
}),
133145
},
146+
firstName: legalFirstName,
147+
lastName: legalLastName,
134148
},
135-
],
149+
});
150+
}
151+
API.write(WRITE_COMMANDS.UPDATE_LEGAL_NAME, parameters, {
152+
optimisticData,
136153
});
137-
138154
Navigation.goBack();
139155
}
140156

0 commit comments

Comments
 (0)