From 10624c8f0075e072893c0ed268588d4248d2f7d5 Mon Sep 17 00:00:00 2001 From: truph01 Date: Thu, 14 Nov 2024 16:53:11 +0700 Subject: [PATCH] fix: Payment option not updated in IOU details when it changed on IOU preview --- src/components/SettlementButton/index.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/SettlementButton/index.tsx b/src/components/SettlementButton/index.tsx index 53b09bfcbf31..c2b2d462aa41 100644 --- a/src/components/SettlementButton/index.tsx +++ b/src/components/SettlementButton/index.tsx @@ -8,6 +8,7 @@ import KYCWall from '@components/KYCWall'; import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; import Navigation from '@libs/Navigation/Navigation'; +import getPolicyEmployeeAccountIDs from '@libs/PolicyEmployeeListUtils'; import * as ReportUtils from '@libs/ReportUtils'; import playSound, {SOUNDS} from '@libs/Sound'; import * as SubscriptionUtils from '@libs/SubscriptionUtils'; @@ -66,7 +67,11 @@ function SettlementButton({ // The app would crash due to subscribing to the entire report collection if chatReportID is an empty string. So we should have a fallback ID here. const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${chatReportID || -1}`); const [isUserValidated] = useOnyx(ONYXKEYS.USER, {selector: (user) => !!user?.validated}); - const [lastPaymentMethod = '-1', lastPaymentMethodResult] = useOnyx(ONYXKEYS.NVP_LAST_PAYMENT_METHOD, {selector: (paymentMethod) => paymentMethod?.[policyID]}); + const policyEmployeeAccountIDs = policyID ? getPolicyEmployeeAccountIDs(policyID) : []; + const reportBelongsToWorkspace = policyID ? ReportUtils.doesReportBelongToWorkspace(chatReport, policyEmployeeAccountIDs, policyID) : false; + const policyIDKey = reportBelongsToWorkspace ? policyID : CONST.POLICY.ID_FAKE; + const [lastPaymentMethod = '-1', lastPaymentMethodResult] = useOnyx(ONYXKEYS.NVP_LAST_PAYMENT_METHOD, {selector: (paymentMethod) => paymentMethod?.[policyIDKey]}); + const isLoadingLastPaymentMethod = isLoadingOnyxValue(lastPaymentMethodResult); const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`); const isInvoiceReport = (!isEmptyObject(iouReport) && ReportUtils.isInvoiceReport(iouReport)) || false; @@ -248,7 +253,7 @@ function SettlementButton({ if (policyID === '-1') { return; } - savePreferredPaymentMethod(policyID, option.value); + savePreferredPaymentMethod(policyIDKey, option.value); }} style={style} wrapperStyle={wrapperStyle}