Skip to content

Commit 5d9bf9d

Browse files
committed
Show Pay via Expensify for Invoice only if beta enabled
1 parent 1f31675 commit 5d9bf9d

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

src/components/SettlementButton/index.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ function SettlementButton({
154154
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
155155
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true});
156156
const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT);
157+
const isPayInvoiceViaExpensifyBetaEnabled = isBetaEnabled(CONST.BETAS.PAY_INVOICE_VIA_EXPENSIFY);
157158
const hasViolations = hasViolationsReportUtils(iouReport?.reportID, transactionViolations, accountID, email ?? '');
158159

159160
const isInvoiceReport = (!isEmptyObject(iouReport) && isInvoiceReportUtil(iouReport)) || false;
@@ -337,7 +338,7 @@ function SettlementButton({
337338
}
338339

339340
if (isInvoiceReport) {
340-
const isCurrencySupported = isCurrencySupportedForGlobalReimbursement(currency as CurrencyType);
341+
const showPayViaExpensifyOptions = isPayInvoiceViaExpensifyBetaEnabled && isCurrencySupportedForGlobalReimbursement(currency as CurrencyType);
341342
const hasActivePolicyAsAdmin = !!activePolicy && isPolicyAdmin(activePolicy) && isPaidGroupPolicy(activePolicy);
342343

343344
const isActivePolicyCurrencySupported = isCurrencySupportedForDirectReimbursement(activePolicy?.outputCurrency ?? '');
@@ -379,8 +380,8 @@ function SettlementButton({
379380
value: CONST.IOU.PAYMENT_TYPE.ELSEWHERE,
380381
};
381382
return [
382-
...(isCurrencySupported ? getPaymentSubItems(payAsBusiness) : []),
383-
...(isCurrencySupported && isPolicyCurrencySupported ? [addBankAccountItem] : []),
383+
...(showPayViaExpensifyOptions ? getPaymentSubItems(payAsBusiness) : []),
384+
...(showPayViaExpensifyOptions && isPolicyCurrencySupported ? [addBankAccountItem] : []),
384385
{
385386
text: translate('iou.payElsewhere', {formattedAmount: ''}),
386387
icon: icons.Cash,
@@ -445,6 +446,7 @@ function SettlementButton({
445446
activeAdminPolicies,
446447
checkForNecessaryAction,
447448
icons,
449+
isPayInvoiceViaExpensifyBetaEnabled,
448450
]);
449451

450452
const selectPaymentType = (event: KYCFlowEvent, iouPaymentType: PaymentMethodType) => {

src/hooks/useBulkPayOptions.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails';
2222
import {useMemoizedLazyExpensifyIcons} from './useLazyAsset';
2323
import useLocalize from './useLocalize';
2424
import useOnyx from './useOnyx';
25+
import usePermissions from './usePermissions';
2526
import usePolicy from './usePolicy';
2627
import useThemeStyles from './useThemeStyles';
2728

@@ -67,6 +68,8 @@ function useBulkPayOptions({
6768
const policy = usePolicy(selectedPolicyID);
6869
const [iouReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${selectedReportID}`, {canBeMissing: true});
6970
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${iouReport?.chatReportID}`, {canBeMissing: true});
71+
const {isBetaEnabled} = usePermissions();
72+
const isPayInvoiceViaExpensifyBetaEnabled = isBetaEnabled(CONST.BETAS.PAY_INVOICE_VIA_EXPENSIFY);
7073
const isIOUReport = isIOUReportUtil(selectedReportID);
7174
const isExpenseReport = isExpenseReportUtil(selectedReportID);
7275
const isInvoiceReport = isInvoiceReportUtil(selectedReportID);
@@ -172,7 +175,7 @@ function useBulkPayOptions({
172175
}
173176

174177
if (isInvoiceReport) {
175-
const isCurrencySupported = isCurrencySupportedForGlobalReimbursement(currency as CurrencyType);
178+
const showPayViaExpensifyOptions = isPayInvoiceViaExpensifyBetaEnabled && isCurrencySupportedForGlobalReimbursement(currency as CurrencyType);
176179
const getInvoicesOptions = (payAsBusiness: boolean) => {
177180
const addBankAccountItem = {
178181
text: translate('bankAccount.addBankAccount'),
@@ -183,8 +186,8 @@ function useBulkPayOptions({
183186
},
184187
};
185188
return [
186-
...(isCurrencySupported ? getPaymentSubItems(payAsBusiness) : []),
187-
...(isCurrencySupported ? [addBankAccountItem] : []),
189+
...(showPayViaExpensifyOptions ? getPaymentSubItems(payAsBusiness) : []),
190+
...(showPayViaExpensifyOptions ? [addBankAccountItem] : []),
188191
{
189192
text: translate('iou.payElsewhere', {formattedAmount: ''}),
190193
icon: icons.Cash,

src/hooks/usePaymentOptions.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails';
2424
import {useMemoizedLazyExpensifyIcons} from './useLazyAsset';
2525
import useLocalize from './useLocalize';
2626
import useOnyx from './useOnyx';
27+
import usePermissions from './usePermissions';
2728
import usePolicy from './usePolicy';
2829
import useThemeStyles from './useThemeStyles';
2930

@@ -100,6 +101,8 @@ function usePaymentOptions({
100101
const isLoadingLastPaymentMethod = isLoadingOnyxValue(lastPaymentMethodResult);
101102
const [bankAccountList = getEmptyObject<BankAccountList>()] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {canBeMissing: true});
102103
const [fundList = getEmptyObject<FundList>()] = useOnyx(ONYXKEYS.FUND_LIST, {canBeMissing: true});
104+
const {isBetaEnabled} = usePermissions();
105+
const isPayInvoiceViaExpensifyBetaEnabled = isBetaEnabled(CONST.BETAS.PAY_INVOICE_VIA_EXPENSIFY);
103106
const lastPaymentMethodRef = useRef(lastPaymentMethod);
104107

105108
useEffect(() => {
@@ -163,7 +166,7 @@ function usePaymentOptions({
163166

164167
if (isInvoiceReport) {
165168
const formattedPaymentMethods = formatPaymentMethods(bankAccountList, fundList, styles, translate);
166-
const isCurrencySupported = isCurrencySupportedForGlobalReimbursement(currency as CurrencyType);
169+
const showPayViaExpensifyOptions = isPayInvoiceViaExpensifyBetaEnabled && isCurrencySupportedForGlobalReimbursement(currency as CurrencyType);
167170
const getPaymentSubItems = (payAsBusiness: boolean) => {
168171
const requiredAccountType = payAsBusiness ? CONST.BANK_ACCOUNT.TYPE.BUSINESS : CONST.BANK_ACCOUNT.TYPE.PERSONAL;
169172
return formattedPaymentMethods
@@ -199,14 +202,14 @@ function usePaymentOptions({
199202
value: CONST.IOU.PAYMENT_TYPE.ELSEWHERE,
200203
backButtonText: translate('iou.individual'),
201204
subMenuItems: [
202-
...(isCurrencySupported ? getPaymentSubItems(false) : []),
205+
...(showPayViaExpensifyOptions ? getPaymentSubItems(false) : []),
203206
{
204207
text: translate('iou.payElsewhere', {formattedAmount: ''}),
205208
icon: icons.Cash,
206209
value: CONST.IOU.PAYMENT_TYPE.ELSEWHERE,
207210
onSelected: () => onPress(CONST.IOU.PAYMENT_TYPE.ELSEWHERE),
208211
},
209-
...(isCurrencySupported ? [addBankAccountItem] : []),
212+
...(showPayViaExpensifyOptions ? [addBankAccountItem] : []),
210213
],
211214
});
212215
}
@@ -217,8 +220,8 @@ function usePaymentOptions({
217220
value: CONST.IOU.PAYMENT_TYPE.ELSEWHERE,
218221
backButtonText: translate('iou.business'),
219222
subMenuItems: [
220-
...(isCurrencySupported ? getPaymentSubItems(true) : []),
221-
...(isCurrencySupported ? [addBankAccountItem] : []),
223+
...(showPayViaExpensifyOptions ? getPaymentSubItems(true) : []),
224+
...(showPayViaExpensifyOptions ? [addBankAccountItem] : []),
222225
{
223226
text: translate('iou.payElsewhere', {formattedAmount: ''}),
224227
icon: icons.Cash,

0 commit comments

Comments
 (0)