From 8e58e8c06a4734885d6c435660fcc14ea8f231db Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Thu, 11 Dec 2025 18:31:34 +0700 Subject: [PATCH 1/4] remove connect method --- src/components/KYCWall/BaseKYCWall.tsx | 11 +++++-- src/libs/actions/Policy/Policy.ts | 44 ++++++++++++-------------- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/components/KYCWall/BaseKYCWall.tsx b/src/components/KYCWall/BaseKYCWall.tsx index 9a9046555a68..feca3a4d0325 100644 --- a/src/components/KYCWall/BaseKYCWall.tsx +++ b/src/components/KYCWall/BaseKYCWall.tsx @@ -3,6 +3,7 @@ import React, {useCallback, useEffect, useImperativeHandle, useRef, useState} fr import {Dimensions} from 'react-native'; import type {EmitterSubscription, View} from 'react-native'; import AddPaymentMethodMenu from '@components/AddPaymentMethodMenu'; +import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import useLocalize from '@hooks/useLocalize'; import useOnyx from '@hooks/useOnyx'; import {openPersonalBankAccountSetupView} from '@libs/actions/BankAccounts'; @@ -58,7 +59,12 @@ function KYCWall({ const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: true}); const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED, {canBeMissing: true}); const {formatPhoneNumber} = useLocalize(); - + const currentUserDetails = useCurrentUserPersonalDetails(); + const currentUserEmail = currentUserDetails.email ?? ''; + const [parentReportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport?.parentReportID}`, {canBeMissing: true}); + const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {canBeMissing: false}); + const employeeEmail = personalDetails?.[iouReport?.ownerAccountID ?? CONST.DEFAULT_NUMBER_ID]?.login ?? ''; + const reportPreviewAction = iouReport?.parentReportActionID ? parentReportActions?.[iouReport?.parentReportActionID] : undefined; const anchorRef = useRef(null); const transferBalanceButtonRef = useRef(null); @@ -148,7 +154,8 @@ function KYCWall({ return; } - const {policyID, workspaceChatReportID, reportPreviewReportActionID, adminsChatReportID} = createWorkspaceFromIOUPayment(iouReport) ?? {}; + const {policyID, workspaceChatReportID, reportPreviewReportActionID, adminsChatReportID} = + createWorkspaceFromIOUPayment(iouReport, reportPreviewAction, currentUserEmail, employeeEmail) ?? {}; if (policyID && iouReport?.policyID) { savePreferredPaymentMethod(iouReport.policyID, policyID, CONST.LAST_PAYMENT_METHOD.IOU, lastPaymentMethod?.[iouReport?.policyID]); } diff --git a/src/libs/actions/Policy/Policy.ts b/src/libs/actions/Policy/Policy.ts index 010303e87e57..7f9b5b72d691 100644 --- a/src/libs/actions/Policy/Policy.ts +++ b/src/libs/actions/Policy/Policy.ts @@ -3484,7 +3484,12 @@ function buildOptimisticRecentlyUsedCurrencies(currency?: string) { * @returns policyID of the workspace we have created */ // eslint-disable-next-line rulesdir/no-call-actions-from-actions -function createWorkspaceFromIOUPayment(iouReport: OnyxEntry): WorkspaceFromIOUCreationData | undefined { +function createWorkspaceFromIOUPayment( + iouReport: OnyxEntry, + reportPreviewAction: ReportAction | undefined, + currentUserEmail: string, + employeeEmail: string, +): WorkspaceFromIOUCreationData | undefined { // This flow only works for IOU reports if (!iouReport || !ReportUtils.isIOUReportUsingReport(iouReport)) { return; @@ -3492,7 +3497,7 @@ function createWorkspaceFromIOUPayment(iouReport: OnyxEntry): WorkspaceF // Generate new variables for the policy const policyID = generatePolicyID(); - const workspaceName = generateDefaultWorkspaceName(deprecatedSessionEmail); + const workspaceName = generateDefaultWorkspaceName(currentUserEmail); const employeeAccountID = iouReport?.ownerAccountID; const {customUnits, customUnitID, customUnitRateID} = buildOptimisticDistanceRateCustomUnits(iouReport?.currency); const oldPersonalPolicyID = iouReport?.policyID; @@ -3514,8 +3519,6 @@ function createWorkspaceFromIOUPayment(iouReport: OnyxEntry): WorkspaceF return; } - const employeeEmail = deprecatedAllPersonalDetails?.[employeeAccountID]?.login ?? ''; - // Create the expense chat for the employee whose IOU is being paid const employeeWorkspaceChat = createPolicyExpenseChats(policyID, {[employeeEmail]: employeeAccountID}, true); const newWorkspace = { @@ -3525,7 +3528,7 @@ function createWorkspaceFromIOUPayment(iouReport: OnyxEntry): WorkspaceF type: CONST.POLICY.TYPE.TEAM, name: workspaceName, role: CONST.POLICY.ROLE.ADMIN, - owner: deprecatedSessionEmail, + owner: currentUserEmail, ownerAccountID: deprecatedSessionAccountID, isPolicyExpenseChatEnabled: true, @@ -3535,7 +3538,7 @@ function createWorkspaceFromIOUPayment(iouReport: OnyxEntry): WorkspaceF autoReporting: true, autoReportingFrequency: CONST.POLICY.AUTO_REPORTING_FREQUENCIES.IMMEDIATE, approvalMode: CONST.POLICY.APPROVAL_MODE.BASIC, - approver: deprecatedSessionEmail, + approver: currentUserEmail, harvesting: { enabled: false, }, @@ -3549,9 +3552,9 @@ function createWorkspaceFromIOUPayment(iouReport: OnyxEntry): WorkspaceF areConnectionsEnabled: false, areExpensifyCardsEnabled: false, employeeList: { - [deprecatedSessionEmail]: { - email: deprecatedSessionEmail, - submitsTo: deprecatedSessionEmail, + [currentUserEmail]: { + email: currentUserEmail, + submitsTo: currentUserEmail, role: CONST.POLICY.ROLE.ADMIN, errors: {}, }, @@ -3559,7 +3562,7 @@ function createWorkspaceFromIOUPayment(iouReport: OnyxEntry): WorkspaceF ? { [employeeEmail]: { email: employeeEmail, - submitsTo: deprecatedSessionEmail, + submitsTo: currentUserEmail, role: CONST.POLICY.ROLE.USER, errors: {}, }, @@ -3801,21 +3804,16 @@ function createWorkspaceFromIOUPayment(iouReport: OnyxEntry): WorkspaceF value: transactionFailureData, }); - // We need to move the report preview action from the DM to the expense chat. - const parentReport = deprecatedAllReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport?.parentReportID}`]; - const parentReportActionID = iouReport?.parentReportActionID; - const reportPreview = iouReport?.parentReportID && parentReportActionID ? parentReport?.[parentReportActionID] : undefined; - - if (reportPreview?.reportActionID) { + if (reportPreviewAction?.reportActionID) { optimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${oldChatReportID}`, - value: {[reportPreview.reportActionID]: null}, + value: {[reportPreviewAction.reportActionID]: null}, }); failureData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${oldChatReportID}`, - value: {[reportPreview.reportActionID]: reportPreview}, + value: {[reportPreviewAction.reportActionID]: reportPreviewAction}, }); } @@ -3835,14 +3833,14 @@ function createWorkspaceFromIOUPayment(iouReport: OnyxEntry): WorkspaceF }, }); - if (reportPreview?.reportActionID) { + if (reportPreviewAction?.reportActionID) { // Update the created timestamp of the report preview action to be after the expense chat created timestamp. optimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${memberData.workspaceChatReportID}`, value: { - [reportPreview.reportActionID]: { - ...reportPreview, + [reportPreviewAction.reportActionID]: { + ...reportPreviewAction, message: [ { type: CONST.REPORT.MESSAGE.TYPE.TEXT, @@ -3856,7 +3854,7 @@ function createWorkspaceFromIOUPayment(iouReport: OnyxEntry): WorkspaceF failureData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${memberData.workspaceChatReportID}`, - value: {[reportPreview.reportActionID]: null}, + value: {[reportPreviewAction.reportActionID]: null}, }); } @@ -3950,7 +3948,7 @@ function createWorkspaceFromIOUPayment(iouReport: OnyxEntry): WorkspaceF API.write(WRITE_COMMANDS.CREATE_WORKSPACE_FROM_IOU_PAYMENT, params, {optimisticData, successData, failureData}); - return {policyID, workspaceChatReportID: memberData.workspaceChatReportID, reportPreviewReportActionID: reportPreview?.reportActionID, adminsChatReportID}; + return {policyID, workspaceChatReportID: memberData.workspaceChatReportID, reportPreviewReportActionID: reportPreviewAction?.reportActionID, adminsChatReportID}; } function enablePolicyConnections(policyID: string, enabled: boolean) { From 927d6c2fecd3a0bdde14eb95af032a422f7d554a Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Mon, 15 Dec 2025 14:29:06 +0700 Subject: [PATCH 2/4] address comments --- src/components/KYCWall/BaseKYCWall.tsx | 6 ++++-- src/libs/actions/Policy/Policy.ts | 16 ++++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/components/KYCWall/BaseKYCWall.tsx b/src/components/KYCWall/BaseKYCWall.tsx index a5f00015d55c..2e0fc06b414f 100644 --- a/src/components/KYCWall/BaseKYCWall.tsx +++ b/src/components/KYCWall/BaseKYCWall.tsx @@ -3,9 +3,11 @@ import React, {useCallback, useEffect, useImperativeHandle, useRef, useState} fr import {Dimensions} from 'react-native'; import type {EmitterSubscription, View} from 'react-native'; import AddPaymentMethodMenu from '@components/AddPaymentMethodMenu'; +import {usePersonalDetails} from '@components/OnyxListItemProvider'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import useLocalize from '@hooks/useLocalize'; import useOnyx from '@hooks/useOnyx'; +import useParentReportAction from '@hooks/useParentReportAction'; import {openPersonalBankAccountSetupView} from '@libs/actions/BankAccounts'; import {completePaymentOnboarding, savePreferredPaymentMethod} from '@libs/actions/IOU'; import {navigateToBankAccountRoute} from '@libs/actions/ReimbursementAccount'; @@ -66,8 +68,8 @@ function KYCWall({ const {formatPhoneNumber} = useLocalize(); const currentUserDetails = useCurrentUserPersonalDetails(); const currentUserEmail = currentUserDetails.email ?? ''; - const [parentReportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport?.parentReportID}`, {canBeMissing: true}); - const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {canBeMissing: false}); + const parentReportActions = useParentReportAction(iouReport); + const personalDetails = usePersonalDetails(); const employeeEmail = personalDetails?.[iouReport?.ownerAccountID ?? CONST.DEFAULT_NUMBER_ID]?.login ?? ''; const reportPreviewAction = iouReport?.parentReportActionID ? parentReportActions?.[iouReport?.parentReportActionID] : undefined; const anchorRef = useRef(null); diff --git a/src/libs/actions/Policy/Policy.ts b/src/libs/actions/Policy/Policy.ts index 7a5180dbc907..def845513edd 100644 --- a/src/libs/actions/Policy/Policy.ts +++ b/src/libs/actions/Policy/Policy.ts @@ -3487,7 +3487,7 @@ function createWorkspaceFromIOUPayment( iouReport: OnyxEntry, reportPreviewAction: ReportAction | undefined, currentUserEmail: string, - employeeEmail: string, + iouReportOwnerEmail: string, ): WorkspaceFromIOUCreationData | undefined { // This flow only works for IOU reports if (!iouReport || !ReportUtils.isIOUReportUsingReport(iouReport)) { @@ -3519,7 +3519,7 @@ function createWorkspaceFromIOUPayment( } // Create the expense chat for the employee whose IOU is being paid - const employeeWorkspaceChat = createPolicyExpenseChats(policyID, {[employeeEmail]: employeeAccountID}, true); + const employeeWorkspaceChat = createPolicyExpenseChats(policyID, {[iouReportOwnerEmail]: employeeAccountID}, true); const newWorkspace = { id: policyID, @@ -3557,10 +3557,10 @@ function createWorkspaceFromIOUPayment( role: CONST.POLICY.ROLE.ADMIN, errors: {}, }, - ...(employeeEmail + ...(iouReportOwnerEmail ? { - [employeeEmail]: { - email: employeeEmail, + [iouReportOwnerEmail]: { + email: iouReportOwnerEmail, submitsTo: currentUserEmail, role: CONST.POLICY.ROLE.USER, errors: {}, @@ -3744,9 +3744,9 @@ function createWorkspaceFromIOUPayment( // optimistically create the expense chat for them. const memberData = { accountID: Number(employeeAccountID), - email: employeeEmail, - workspaceChatReportID: employeeWorkspaceChat.reportCreationData[employeeEmail].reportID, - workspaceChatCreatedReportActionID: employeeWorkspaceChat.reportCreationData[employeeEmail].reportActionID, + email: iouReportOwnerEmail, + workspaceChatReportID: employeeWorkspaceChat.reportCreationData[iouReportOwnerEmail].reportID, + workspaceChatCreatedReportActionID: employeeWorkspaceChat.reportCreationData[iouReportOwnerEmail].reportActionID, }; const oldChatReportID = iouReport?.chatReportID; From cf0434ffec64ea1f4d79a43e27a364ab446855ba Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Mon, 15 Dec 2025 15:05:18 +0700 Subject: [PATCH 3/4] fix typecheck --- src/components/KYCWall/BaseKYCWall.tsx | 6 ++++-- src/libs/actions/Policy/Policy.ts | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/KYCWall/BaseKYCWall.tsx b/src/components/KYCWall/BaseKYCWall.tsx index 2e0fc06b414f..a45b59e05d17 100644 --- a/src/components/KYCWall/BaseKYCWall.tsx +++ b/src/components/KYCWall/BaseKYCWall.tsx @@ -68,10 +68,9 @@ function KYCWall({ const {formatPhoneNumber} = useLocalize(); const currentUserDetails = useCurrentUserPersonalDetails(); const currentUserEmail = currentUserDetails.email ?? ''; - const parentReportActions = useParentReportAction(iouReport); + const reportPreviewAction = useParentReportAction(iouReport); const personalDetails = usePersonalDetails(); const employeeEmail = personalDetails?.[iouReport?.ownerAccountID ?? CONST.DEFAULT_NUMBER_ID]?.login ?? ''; - const reportPreviewAction = iouReport?.parentReportActionID ? parentReportActions?.[iouReport?.parentReportActionID] : undefined; const anchorRef = useRef(null); const transferBalanceButtonRef = useRef(null); @@ -209,6 +208,9 @@ function KYCWall({ introSelected, formatPhoneNumber, lastPaymentMethod, + reportPreviewAction, + currentUserEmail, + employeeEmail, ], ); diff --git a/src/libs/actions/Policy/Policy.ts b/src/libs/actions/Policy/Policy.ts index def845513edd..78ee95bb137b 100644 --- a/src/libs/actions/Policy/Policy.ts +++ b/src/libs/actions/Policy/Policy.ts @@ -120,6 +120,7 @@ import type { PolicyCategory, Report, ReportActions, + ReportAction, Request, TaxRatesWithDefault, Transaction, From b4070f85da054d8dba0388be909e0377e66fde2b Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Mon, 15 Dec 2025 15:12:40 +0700 Subject: [PATCH 4/4] prettier --- src/libs/actions/Policy/Policy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Policy/Policy.ts b/src/libs/actions/Policy/Policy.ts index 78ee95bb137b..b6df6e728fc3 100644 --- a/src/libs/actions/Policy/Policy.ts +++ b/src/libs/actions/Policy/Policy.ts @@ -119,8 +119,8 @@ import type { PolicyCategories, PolicyCategory, Report, - ReportActions, ReportAction, + ReportActions, Request, TaxRatesWithDefault, Transaction,