@@ -8,6 +8,7 @@ import KYCWall from '@components/KYCWall';
8
8
import useLocalize from '@hooks/useLocalize' ;
9
9
import useNetwork from '@hooks/useNetwork' ;
10
10
import Navigation from '@libs/Navigation/Navigation' ;
11
+ import getPolicyEmployeeAccountIDs from '@libs/PolicyEmployeeListUtils' ;
11
12
import * as ReportUtils from '@libs/ReportUtils' ;
12
13
import playSound , { SOUNDS } from '@libs/Sound' ;
13
14
import * as SubscriptionUtils from '@libs/SubscriptionUtils' ;
@@ -66,7 +67,11 @@ function SettlementButton({
66
67
// 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.
67
68
const [ chatReport ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT } ${ chatReportID || - 1 } ` ) ;
68
69
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
+
70
75
const isLoadingLastPaymentMethod = isLoadingOnyxValue ( lastPaymentMethodResult ) ;
71
76
const [ policy ] = useOnyx ( `${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` ) ;
72
77
const isInvoiceReport = ( ! isEmptyObject ( iouReport ) && ReportUtils . isInvoiceReport ( iouReport ) ) || false ;
@@ -248,7 +253,7 @@ function SettlementButton({
248
253
if ( policyID === '-1' ) {
249
254
return ;
250
255
}
251
- savePreferredPaymentMethod ( policyID , option . value ) ;
256
+ savePreferredPaymentMethod ( policyIDKey , option . value ) ;
252
257
} }
253
258
style = { style }
254
259
wrapperStyle = { wrapperStyle }
0 commit comments