From c9198e591712f71241609f748e0303d70967819a Mon Sep 17 00:00:00 2001 From: cdOut <88325488+cdOut@users.noreply.github.com> Date: Wed, 2 Oct 2024 13:36:52 +0200 Subject: [PATCH 1/4] add completePaymentOnboarding into AddPaymentMethodMenu --- src/components/AddPaymentMethodMenu.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/components/AddPaymentMethodMenu.tsx b/src/components/AddPaymentMethodMenu.tsx index 5621c031f959..f21f3e119fb0 100644 --- a/src/components/AddPaymentMethodMenu.tsx +++ b/src/components/AddPaymentMethodMenu.tsx @@ -15,6 +15,7 @@ import * as Expensicons from './Icon/Expensicons'; import type {PaymentMethod} from './KYCWall/types'; import type BaseModalProps from './Modal/types'; import PopoverMenu from './PopoverMenu'; +import { completePaymentOnboarding } from '@libs/actions/IOU'; type AddPaymentMethodMenuOnyxProps = { /** Session info for the currently logged-in user. */ @@ -80,6 +81,7 @@ function AddPaymentMethodMenu({ return; } + completePaymentOnboarding(CONST.PAYMENT_SELECTED.PBA); onItemSelected(CONST.PAYMENT_METHODS.PERSONAL_BANK_ACCOUNT); }, [isPersonalOnlyOption, isVisible, onItemSelected]); @@ -108,7 +110,8 @@ function AddPaymentMethodMenu({ text: translate('common.personalBankAccount'), icon: Expensicons.Bank, onSelected: () => { - onItemSelected(CONST.PAYMENT_METHODS.PERSONAL_BANK_ACCOUNT); + completePaymentOnboarding(CONST.PAYMENT_SELECTED.PBA); + onItemSelected(CONST.PAYMENT_METHODS.PERSONAL_BANK_ACCOUNT); }, }, ] @@ -118,7 +121,10 @@ function AddPaymentMethodMenu({ { text: translate('common.businessBankAccount'), icon: Expensicons.Building, - onSelected: () => onItemSelected(CONST.PAYMENT_METHODS.BUSINESS_BANK_ACCOUNT), + onSelected: () => { + completePaymentOnboarding(CONST.PAYMENT_SELECTED.BBA); + onItemSelected(CONST.PAYMENT_METHODS.BUSINESS_BANK_ACCOUNT); + }, }, ] : []), From bd074ad4e05bd5d130f2febe4ed06b52b1d1a8d9 Mon Sep 17 00:00:00 2001 From: cdOut <88325488+cdOut@users.noreply.github.com> Date: Wed, 2 Oct 2024 13:51:10 +0200 Subject: [PATCH 2/4] fix prettier --- src/components/AddPaymentMethodMenu.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/AddPaymentMethodMenu.tsx b/src/components/AddPaymentMethodMenu.tsx index f21f3e119fb0..50c7d530a3c2 100644 --- a/src/components/AddPaymentMethodMenu.tsx +++ b/src/components/AddPaymentMethodMenu.tsx @@ -4,6 +4,7 @@ import type {View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; import {withOnyx} from 'react-native-onyx'; import useLocalize from '@hooks/useLocalize'; +import {completePaymentOnboarding} from '@libs/actions/IOU'; import * as ReportActionsUtils from '@libs/ReportActionsUtils'; import * as ReportUtils from '@libs/ReportUtils'; import CONST from '@src/CONST'; @@ -15,7 +16,6 @@ import * as Expensicons from './Icon/Expensicons'; import type {PaymentMethod} from './KYCWall/types'; import type BaseModalProps from './Modal/types'; import PopoverMenu from './PopoverMenu'; -import { completePaymentOnboarding } from '@libs/actions/IOU'; type AddPaymentMethodMenuOnyxProps = { /** Session info for the currently logged-in user. */ @@ -110,8 +110,8 @@ function AddPaymentMethodMenu({ text: translate('common.personalBankAccount'), icon: Expensicons.Bank, onSelected: () => { - completePaymentOnboarding(CONST.PAYMENT_SELECTED.PBA); - onItemSelected(CONST.PAYMENT_METHODS.PERSONAL_BANK_ACCOUNT); + completePaymentOnboarding(CONST.PAYMENT_SELECTED.PBA); + onItemSelected(CONST.PAYMENT_METHODS.PERSONAL_BANK_ACCOUNT); }, }, ] @@ -122,8 +122,8 @@ function AddPaymentMethodMenu({ text: translate('common.businessBankAccount'), icon: Expensicons.Building, onSelected: () => { - completePaymentOnboarding(CONST.PAYMENT_SELECTED.BBA); - onItemSelected(CONST.PAYMENT_METHODS.BUSINESS_BANK_ACCOUNT); + completePaymentOnboarding(CONST.PAYMENT_SELECTED.BBA); + onItemSelected(CONST.PAYMENT_METHODS.BUSINESS_BANK_ACCOUNT); }, }, ] From 8016c3c77654b948daa68a7bf8a4d52331faa278 Mon Sep 17 00:00:00 2001 From: cdOut <88325488+cdOut@users.noreply.github.com> Date: Wed, 2 Oct 2024 13:57:44 +0200 Subject: [PATCH 3/4] refactor AddPaymentMethodMenu into useOnyx --- src/components/AddPaymentMethodMenu.tsx | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/components/AddPaymentMethodMenu.tsx b/src/components/AddPaymentMethodMenu.tsx index 50c7d530a3c2..934083faab17 100644 --- a/src/components/AddPaymentMethodMenu.tsx +++ b/src/components/AddPaymentMethodMenu.tsx @@ -2,7 +2,7 @@ import type {RefObject} from 'react'; import React, {useEffect, useState} from 'react'; import type {View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; -import {withOnyx} from 'react-native-onyx'; +import {useOnyx} from 'react-native-onyx'; import useLocalize from '@hooks/useLocalize'; import {completePaymentOnboarding} from '@libs/actions/IOU'; import * as ReportActionsUtils from '@libs/ReportActionsUtils'; @@ -17,12 +17,7 @@ import type {PaymentMethod} from './KYCWall/types'; import type BaseModalProps from './Modal/types'; import PopoverMenu from './PopoverMenu'; -type AddPaymentMethodMenuOnyxProps = { - /** Session info for the currently logged-in user. */ - session: OnyxEntry; -}; - -type AddPaymentMethodMenuProps = AddPaymentMethodMenuOnyxProps & { +type AddPaymentMethodMenuProps = { /** Should the component be visible? */ isVisible: boolean; @@ -59,11 +54,11 @@ function AddPaymentMethodMenu({ anchorRef, iouReport, onItemSelected, - session, shouldShowPersonalBankAccountOption = false, }: AddPaymentMethodMenuProps) { const {translate} = useLocalize(); const [restoreFocusType, setRestoreFocusType] = useState(); + const [session] = useOnyx(ONYXKEYS.SESSION); // Users can choose to pay with business bank account in case of Expense reports or in case of P2P IOU report // which then starts a bottom up flow and creates a Collect workspace where the payer is an admin and payee is an employee. @@ -146,8 +141,4 @@ function AddPaymentMethodMenu({ AddPaymentMethodMenu.displayName = 'AddPaymentMethodMenu'; -export default withOnyx({ - session: { - key: ONYXKEYS.SESSION, - }, -})(AddPaymentMethodMenu); +export default AddPaymentMethodMenu; From d425f25b00dbb0ed0707bfa2937aed4762dcb23e Mon Sep 17 00:00:00 2001 From: cdOut <88325488+cdOut@users.noreply.github.com> Date: Wed, 2 Oct 2024 14:24:23 +0200 Subject: [PATCH 4/4] fix eslint errors --- src/components/AddPaymentMethodMenu.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/AddPaymentMethodMenu.tsx b/src/components/AddPaymentMethodMenu.tsx index 934083faab17..0057438e3913 100644 --- a/src/components/AddPaymentMethodMenu.tsx +++ b/src/components/AddPaymentMethodMenu.tsx @@ -10,7 +10,7 @@ import * as ReportUtils from '@libs/ReportUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {AnchorPosition} from '@src/styles'; -import type {Report, Session} from '@src/types/onyx'; +import type {Report} from '@src/types/onyx'; import type AnchorAlignment from '@src/types/utils/AnchorAlignment'; import * as Expensicons from './Icon/Expensicons'; import type {PaymentMethod} from './KYCWall/types';