MCPcopy Create free account
hub / github.com/Expensify/App / AddPaymentMethodMenu

Function AddPaymentMethodMenu

src/components/AddPaymentMethodMenu.tsx:49–147  ·  view source on GitHub ↗
({
    isVisible,
    onClose,
    anchorPosition,
    anchorAlignment = {
        horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT,
        vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM,
    },
    anchorRef,
    iouReport,
    onItemSelected,
    shouldShowPersonalBankAccountOption = false,
}: AddPaymentMethodMenuProps)

Source from the content-addressed store, hash-verified

47};
48
49function AddPaymentMethodMenu({
50 isVisible,
51 onClose,
52 anchorPosition,
53 anchorAlignment = {
54 horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT,
55 vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM,
56 },
57 anchorRef,
58 iouReport,
59 onItemSelected,
60 shouldShowPersonalBankAccountOption = false,
61}: AddPaymentMethodMenuProps) {
62 const icons = useMemoizedLazyExpensifyIcons(['Building', 'Bank']);
63 const {translate} = useLocalize();
64 const [restoreFocusType, setRestoreFocusType] = useState<BaseModalProps['restoreFocusType']>();
65 const [session] = useOnyx(ONYXKEYS.SESSION);
66 const [introSelected, introSelectedStatus] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
67 const [isSelfTourViewed = false] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector});
68 const [betas] = useOnyx(ONYXKEYS.BETAS);
69 const {accountID: currentUserAccountID} = useCurrentUserPersonalDetails();
70
71 // Users can choose to pay with business bank account in case of Expense reports or in case of P2P IOU report
72 // which then starts a bottom up flow and creates a Collect workspace where the payer is an admin and payee is an employee.
73 const isIOU = isIOUReport(iouReport);
74 const canUseBusinessBankAccount = isExpenseReport(iouReport) || (isIOU && !hasRequestFromCurrentAccount(iouReport, session?.accountID ?? CONST.DEFAULT_NUMBER_ID));
75
76 const canUsePersonalBankAccount = shouldShowPersonalBankAccountOption || isIOU;
77
78 const isPersonalOnlyOption = canUsePersonalBankAccount && !canUseBusinessBankAccount;
79
80 const isLoadingIntroSelected = isLoadingOnyxValue(introSelectedStatus);
81
82 // We temporarily disabled P2P debit cards so we will automatically select the personal bank account option if there is no other option to select.
83 useEffect(() => {
84 if (!isVisible || !isPersonalOnlyOption || isLoadingIntroSelected) {
85 return;
86 }
87
88 completePaymentOnboarding(CONST.PAYMENT_SELECTED.PBA, introSelected, isSelfTourViewed, betas, currentUserAccountID);
89 onItemSelected(CONST.PAYMENT_METHODS.PERSONAL_BANK_ACCOUNT);
90 }, [betas, currentUserAccountID, introSelected, isLoadingIntroSelected, isPersonalOnlyOption, isVisible, onItemSelected, isSelfTourViewed]);
91
92 if (isPersonalOnlyOption) {
93 return null;
94 }
95
96 return (
97 <PopoverMenu
98 isVisible={isVisible}
99 onClose={() => {
100 setRestoreFocusType(undefined);
101 onClose();
102 }}
103 anchorPosition={anchorPosition}
104 anchorAlignment={anchorAlignment}
105 anchorRef={anchorRef}
106 onItemSelected={() => {

Callers

nothing calls this directly

Calls 12

isIOUReportFunction · 0.90
isExpenseReportFunction · 0.90
useLocalizeFunction · 0.85
useOnyxFunction · 0.85
isLoadingOnyxValueFunction · 0.85
onItemSelectedFunction · 0.85
translateFunction · 0.70
onCloseFunction · 0.50

Tested by

no test coverage detected