diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 82aebd044a8f..d6a76162be0f 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -7406,8 +7406,8 @@ function getWorkspaceChats(policyID: string, accountIDs: number[], reports: Onyx * * @param policyID - the workspace ID to get all associated reports */ -function getAllWorkspaceReports(policyID: string): Array> { - return Object.values(allReports ?? {}).filter((report) => (report?.policyID ?? '-1') === policyID); +function getAllWorkspaceReports(policyID: string | undefined): Array> { + return Object.values(allReports ?? {}).filter((report) => report?.policyID === policyID); } /** diff --git a/src/libs/TransactionUtils/index.ts b/src/libs/TransactionUtils/index.ts index 1aa5f5fe101e..2708b32246be 100644 --- a/src/libs/TransactionUtils/index.ts +++ b/src/libs/TransactionUtils/index.ts @@ -1244,11 +1244,10 @@ function compareDuplicateTransactionFields( return {keep, change}; } -function getTransactionID(threadReportID: string | undefined): string | undefined { +function getTransactionID(threadReportID?: string): string | undefined { if (!threadReportID) { return; } - const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${threadReportID}`]; const parentReportAction = ReportUtils.isThread(report) ? ReportActionsUtils.getReportAction(report.parentReportID, report.parentReportActionID) : undefined; const IOUTransactionID = ReportActionsUtils.isMoneyRequestAction(parentReportAction) ? ReportActionsUtils.getOriginalMessage(parentReportAction)?.IOUTransactionID : undefined; diff --git a/src/libs/actions/PersonalDetails.ts b/src/libs/actions/PersonalDetails.ts index 94a9dc95e846..e0e739b56e86 100644 --- a/src/libs/actions/PersonalDetails.ts +++ b/src/libs/actions/PersonalDetails.ts @@ -37,7 +37,7 @@ Onyx.connect({ key: ONYXKEYS.SESSION, callback: (val) => { currentUserEmail = val?.email ?? ''; - currentUserAccountID = val?.accountID ?? -1; + currentUserAccountID = val?.accountID ?? CONST.DEFAULT_NUMBER_ID; }, }); @@ -121,20 +121,36 @@ function updateDisplayName(firstName: string, lastName: string) { 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) { + 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(); }