From 497c6436efe19750851ab6e2764e77686aaa8ba4 Mon Sep 17 00:00:00 2001 From: themoonalsofall Date: Wed, 4 Dec 2024 21:38:55 +0700 Subject: [PATCH 1/3] update display name when update legal name --- src/libs/actions/PersonalDetails.ts | 37 ++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/src/libs/actions/PersonalDetails.ts b/src/libs/actions/PersonalDetails.ts index 94a9dc95e846..479a1eff2c39 100644 --- a/src/libs/actions/PersonalDetails.ts +++ b/src/libs/actions/PersonalDetails.ts @@ -121,20 +121,35 @@ 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, + }, + }, + ]; + 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(); } From e7e29c8ecc530c94def866a85c7541db5741b539 Mon Sep 17 00:00:00 2001 From: themoonalsofall Date: Thu, 5 Dec 2024 11:50:29 +0700 Subject: [PATCH 2/3] add comment --- src/libs/actions/PersonalDetails.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/actions/PersonalDetails.ts b/src/libs/actions/PersonalDetails.ts index 479a1eff2c39..38cfb42bf3f9 100644 --- a/src/libs/actions/PersonalDetails.ts +++ b/src/libs/actions/PersonalDetails.ts @@ -131,6 +131,7 @@ function updateLegalName(legalFirstName: string, legalLastName: string) { }, }, ]; + // 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, From 72da7982312e3b37262754bcb3d15d6bf0b0812c Mon Sep 17 00:00:00 2001 From: themoonalsofall Date: Tue, 24 Dec 2024 16:24:47 +0700 Subject: [PATCH 3/3] fix lint --- .../Search/SearchRouter/SearchRouterList.tsx | 2 +- src/libs/DebugUtils.ts | 2 +- src/libs/PolicyUtils.ts | 2 +- src/libs/ReportUtils.ts | 8 ++++---- src/libs/TransactionUtils/index.ts | 5 ++++- src/libs/actions/PersonalDetails.ts | 2 +- src/libs/actions/Policy/Policy.ts | 2 +- src/pages/Debug/Transaction/DebugTransactionPage.tsx | 2 +- src/pages/home/HeaderView.tsx | 10 ++++++---- src/pages/home/report/ReportActionsList.tsx | 4 ++-- src/pages/workspace/WorkspaceNamePage.tsx | 2 +- src/pages/workspace/WorkspacesListPage.tsx | 6 +++--- 12 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/components/Search/SearchRouter/SearchRouterList.tsx b/src/components/Search/SearchRouter/SearchRouterList.tsx index a53e49374d81..a70f4b13b94d 100644 --- a/src/components/Search/SearchRouter/SearchRouterList.tsx +++ b/src/components/Search/SearchRouter/SearchRouterList.tsx @@ -179,7 +179,7 @@ function SearchRouterList( if (currentUser) { autocompleteOptions.push({ name: currentUser.displayName ?? Str.removeSMSDomain(currentUser.login ?? ''), - accountID: currentUser.accountID?.toString() ?? '-1', + accountID: currentUser.accountID?.toString(), }); } diff --git a/src/libs/DebugUtils.ts b/src/libs/DebugUtils.ts index cfc56559ed35..af66cd77168a 100644 --- a/src/libs/DebugUtils.ts +++ b/src/libs/DebugUtils.ts @@ -1369,7 +1369,7 @@ function getReasonAndReportActionForRBRInLHNRow(report: Report, reportActions: O } function getTransactionID(report: OnyxEntry, reportActions: OnyxEntry) { - const transactionID = TransactionUtils.getTransactionID(report?.reportID ?? '-1'); + const transactionID = TransactionUtils.getTransactionID(report?.reportID); return Number(transactionID) > 0 ? transactionID diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 4982e8660dec..f44f5605b5d8 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -1093,7 +1093,7 @@ function getCurrentTaxID(policy: OnyxEntry, taxID: string): string | und return Object.keys(policy?.taxRates?.taxes ?? {}).find((taxIDKey) => policy?.taxRates?.taxes?.[taxIDKey].previousTaxCode === taxID || taxIDKey === taxID); } -function getWorkspaceAccountID(policyID: string) { +function getWorkspaceAccountID(policyID: string | undefined) { const policy = getPolicy(policyID); if (!policy) { diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index c20ec7386b0a..e6511154fd13 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1040,8 +1040,8 @@ function isSettled(reportOrID: OnyxInputOrEntry | SearchReport | string /** * Whether the current user is the submitter of the report */ -function isCurrentUserSubmitter(reportID: string): boolean { - if (!allReports) { +function isCurrentUserSubmitter(reportID: string | undefined): boolean { + if (!allReports || !reportID) { return false; } const report = allReports[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; @@ -7381,8 +7381,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 6643cd721d45..62365bf111a2 100644 --- a/src/libs/TransactionUtils/index.ts +++ b/src/libs/TransactionUtils/index.ts @@ -1210,7 +1210,10 @@ function compareDuplicateTransactionFields( return {keep, change}; } -function getTransactionID(threadReportID: string): string | undefined { +function getTransactionID(threadReportID: string | undefined): 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 38cfb42bf3f9..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; }, }); diff --git a/src/libs/actions/Policy/Policy.ts b/src/libs/actions/Policy/Policy.ts index f855ea477856..a9026aedd131 100644 --- a/src/libs/actions/Policy/Policy.ts +++ b/src/libs/actions/Policy/Policy.ts @@ -725,7 +725,7 @@ function clearWorkspaceReimbursementErrors(policyID: string) { Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {errorFields: {reimbursementChoice: null}}); } -function leaveWorkspace(policyID: string) { +function leaveWorkspace(policyID: string | undefined) { const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]; const workspaceChats = ReportUtils.getAllWorkspaceReports(policyID); diff --git a/src/pages/Debug/Transaction/DebugTransactionPage.tsx b/src/pages/Debug/Transaction/DebugTransactionPage.tsx index 86a8e3ded86a..7515d5bc74c0 100644 --- a/src/pages/Debug/Transaction/DebugTransactionPage.tsx +++ b/src/pages/Debug/Transaction/DebugTransactionPage.tsx @@ -85,7 +85,7 @@ function DebugTransactionPage({