Skip to content

Commit a6f1348

Browse files
authored
Merge pull request Expensify#52539 from truph01/fix/50916
fix: Payment option not updated in IOU details when it changed on IOU preview
2 parents b2b6e2d + 10624c8 commit a6f1348

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/components/SettlementButton/index.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import KYCWall from '@components/KYCWall';
88
import useLocalize from '@hooks/useLocalize';
99
import useNetwork from '@hooks/useNetwork';
1010
import Navigation from '@libs/Navigation/Navigation';
11+
import getPolicyEmployeeAccountIDs from '@libs/PolicyEmployeeListUtils';
1112
import * as ReportUtils from '@libs/ReportUtils';
1213
import playSound, {SOUNDS} from '@libs/Sound';
1314
import * as SubscriptionUtils from '@libs/SubscriptionUtils';
@@ -66,7 +67,11 @@ function SettlementButton({
6667
// 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.
6768
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${chatReportID || -1}`);
6869
const [isUserValidated] = useOnyx(ONYXKEYS.USER, {selector: (user) => !!user?.validated});
69-
const [lastPaymentMethod = '-1', lastPaymentMethodResult] = useOnyx(ONYXKEYS.NVP_LAST_PAYMENT_METHOD, {selector: (paymentMethod) => paymentMethod?.[policyID]});
70+
const policyEmployeeAccountIDs = policyID ? getPolicyEmployeeAccountIDs(policyID) : [];
71+
const reportBelongsToWorkspace = policyID ? ReportUtils.doesReportBelongToWorkspace(chatReport, policyEmployeeAccountIDs, policyID) : false;
72+
const policyIDKey = reportBelongsToWorkspace ? policyID : CONST.POLICY.ID_FAKE;
73+
const [lastPaymentMethod = '-1', lastPaymentMethodResult] = useOnyx(ONYXKEYS.NVP_LAST_PAYMENT_METHOD, {selector: (paymentMethod) => paymentMethod?.[policyIDKey]});
74+
7075
const isLoadingLastPaymentMethod = isLoadingOnyxValue(lastPaymentMethodResult);
7176
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`);
7277
const isInvoiceReport = (!isEmptyObject(iouReport) && ReportUtils.isInvoiceReport(iouReport)) || false;
@@ -248,7 +253,7 @@ function SettlementButton({
248253
if (policyID === '-1') {
249254
return;
250255
}
251-
savePreferredPaymentMethod(policyID, option.value);
256+
savePreferredPaymentMethod(policyIDKey, option.value);
252257
}}
253258
style={style}
254259
wrapperStyle={wrapperStyle}

0 commit comments

Comments
 (0)