Skip to content

Commit

Permalink
fix: Payment option not updated in IOU details when it changed on IOU…
Browse files Browse the repository at this point in the history
… preview
  • Loading branch information
truph01 committed Nov 14, 2024
1 parent 99da1ac commit 10624c8
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/components/SettlementButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -248,7 +253,7 @@ function SettlementButton({
if (policyID === '-1') {
return;
}
savePreferredPaymentMethod(policyID, option.value);
savePreferredPaymentMethod(policyIDKey, option.value);
}}
style={style}
wrapperStyle={wrapperStyle}
Expand Down

0 comments on commit 10624c8

Please sign in to comment.