Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invoicing bank accounts section #47218

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
67e37b9
create raw WorkspaceInvoiceVBASection
rezkiy37 Aug 12, 2024
c2b9af4
add invoice types
rezkiy37 Aug 12, 2024
077a401
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fea…
rezkiy37 Aug 12, 2024
be90481
integrate bank accounts logic
rezkiy37 Aug 12, 2024
8e9d73e
add translations
rezkiy37 Aug 12, 2024
3661b67
integrate add bank account button
rezkiy37 Aug 12, 2024
e7a88a0
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fea…
rezkiy37 Aug 13, 2024
97d6073
omit card logic
rezkiy37 Aug 13, 2024
54591c2
reuse types
rezkiy37 Aug 13, 2024
2a8f11f
integrate usePaymentMethodState hook
rezkiy37 Aug 13, 2024
cb90633
rename shouldUseSuccessAddBankAccountButton
rezkiy37 Aug 13, 2024
05af88f
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fea…
rezkiy37 Aug 14, 2024
edd8507
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fea…
rezkiy37 Sep 2, 2024
2bec476
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fea…
rezkiy37 Sep 3, 2024
162d4da
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fea…
rezkiy37 Sep 9, 2024
c3258e2
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fea…
rezkiy37 Sep 12, 2024
68cb5a2
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fea…
rezkiy37 Sep 16, 2024
676a0da
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fea…
rezkiy37 Sep 24, 2024
8094a1a
implement setInvoicingTransferBankAccount
rezkiy37 Sep 25, 2024
6b2fff4
PaymentMethodList accepts invoiceTransferBankAccountID
rezkiy37 Sep 25, 2024
d273a5a
implement default back account in WorkspaceInvoiceVBASection
rezkiy37 Sep 25, 2024
46f5e1b
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fea…
rezkiy37 Sep 25, 2024
03b76f2
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fea…
rezkiy37 Sep 26, 2024
386dc9c
Refactor PaymentMethodList component to use useOnyx
rezkiy37 Sep 26, 2024
7b0f675
Merge branches 'feature/45177-invoice-back-accounts-section', 'featur…
rezkiy37 Sep 27, 2024
c8861f3
update disabled prop
rezkiy37 Sep 27, 2024
5ae1ca6
rename shouldShowAddBankAccountButton
rezkiy37 Sep 27, 2024
5635b84
tweak comment
rezkiy37 Sep 27, 2024
2ffc83e
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fea…
rezkiy37 Sep 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
integrate usePaymentMethodState hook
  • Loading branch information
rezkiy37 committed Aug 13, 2024
commit 2a8f11f83a0b5490896757a0f50ce44d4d6dfd0a
28 changes: 28 additions & 0 deletions src/hooks/usePaymentMethodState/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {useCallback, useState} from 'react';
import type {PaymentMethodState} from './types';

const initialState: PaymentMethodState = {
isSelectedPaymentMethodDefault: false,
selectedPaymentMethod: {},
formattedSelectedPaymentMethod: {
title: '',
},
methodID: '',
selectedPaymentMethodType: '',
};

function usePaymentMethodState() {
const [paymentMethod, setPaymentMethod] = useState<PaymentMethodState>(initialState);

const resetSelectedPaymentMethodData = useCallback(() => {
setPaymentMethod(initialState);
}, [setPaymentMethod]);

return {
paymentMethod,
setPaymentMethod,
resetSelectedPaymentMethodData,
};
}

export default usePaymentMethodState;
28 changes: 28 additions & 0 deletions src/hooks/usePaymentMethodState/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type {ViewStyle} from 'react-native';
import type {AccountData} from '@src/types/onyx';
import type IconAsset from '@src/types/utils/IconAsset';

type FormattedSelectedPaymentMethodIcon = {
icon: IconAsset;
iconHeight?: number;
iconWidth?: number;
iconStyles?: ViewStyle[];
iconSize?: number;
};

type FormattedSelectedPaymentMethod = {
title: string;
icon?: FormattedSelectedPaymentMethodIcon;
description?: string;
type?: string;
};

type PaymentMethodState = {
isSelectedPaymentMethodDefault: boolean;
selectedPaymentMethod: AccountData;
formattedSelectedPaymentMethod: FormattedSelectedPaymentMethod;
methodID: string | number;
selectedPaymentMethodType: string;
};

export type {FormattedSelectedPaymentMethodIcon, FormattedSelectedPaymentMethod, PaymentMethodState};
2 changes: 1 addition & 1 deletion src/pages/settings/Wallet/PaymentMethodList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import OfflineWithFeedback from '@components/OfflineWithFeedback';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import type {FormattedSelectedPaymentMethodIcon} from '@hooks/usePaymentMethodState/types';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import * as CardUtils from '@libs/CardUtils';
Expand All @@ -35,7 +36,6 @@ import type {Errors} from '@src/types/onyx/OnyxCommon';
import type PaymentMethod from '@src/types/onyx/PaymentMethod';
import type {FilterMethodPaymentType} from '@src/types/onyx/WalletTransfer';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import type {FormattedSelectedPaymentMethodIcon} from './WalletPage/types';

type PaymentMethodListOnyxProps = {
/** List of bank accounts */
Expand Down
28 changes: 4 additions & 24 deletions src/pages/settings/Wallet/WalletPage/WalletPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import Section from '@components/Section';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import usePaymentMethodState from '@hooks/usePaymentMethodState';
import type {FormattedSelectedPaymentMethod, FormattedSelectedPaymentMethodIcon} from '@hooks/usePaymentMethodState/types';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
Expand All @@ -39,7 +41,7 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {AccountData} from '@src/types/onyx';
import type {FormattedSelectedPaymentMethod, FormattedSelectedPaymentMethodIcon, PaymentMethodState, WalletPageOnyxProps, WalletPageProps} from './types';
import type {WalletPageOnyxProps, WalletPageProps} from './types';

function WalletPage({bankAccountList = {}, cardList = {}, fundList = {}, isLoadingPaymentMethods = true, shouldListenForResize = false, userWallet, walletTerms = {}}: WalletPageProps) {
const theme = useTheme();
Expand All @@ -48,19 +50,10 @@ function WalletPage({bankAccountList = {}, cardList = {}, fundList = {}, isLoadi
const network = useNetwork();
const {windowWidth} = useWindowDimensions();
const {shouldUseNarrowLayout} = useResponsiveLayout();
const {paymentMethod, setPaymentMethod, resetSelectedPaymentMethodData} = usePaymentMethodState();
const [shouldShowAddPaymentMenu, setShouldShowAddPaymentMenu] = useState(false);
const [shouldShowDefaultDeleteMenu, setShouldShowDefaultDeleteMenu] = useState(false);
const [shouldShowLoadingSpinner, setShouldShowLoadingSpinner] = useState(false);
const [paymentMethod, setPaymentMethod] = useState<PaymentMethodState>({
isSelectedPaymentMethodDefault: false,
selectedPaymentMethod: {},
formattedSelectedPaymentMethod: {
title: '',
},
methodID: '',
selectedPaymentMethodType: '',
});

const addPaymentMethodAnchorRef = useRef(null);
const paymentMethodButtonRef = useRef<HTMLDivElement | null>(null);
const [anchorPosition, setAnchorPosition] = useState({
Expand Down Expand Up @@ -118,19 +111,6 @@ function WalletPage({bankAccountList = {}, cardList = {}, fundList = {}, isLoadi
}
}, [paymentMethod.selectedPaymentMethod.bankAccountID, paymentMethod.selectedPaymentMethod.fundID, paymentMethod.selectedPaymentMethodType]);

const resetSelectedPaymentMethodData = useCallback(() => {
// Reset to same values as in the constructor
setPaymentMethod({
isSelectedPaymentMethodDefault: false,
selectedPaymentMethod: {},
formattedSelectedPaymentMethod: {
title: '',
},
methodID: '',
selectedPaymentMethodType: '',
});
}, [setPaymentMethod]);

/**
* Display the delete/default menu, or the add payment method menu
*/
Expand Down
29 changes: 2 additions & 27 deletions src/pages/settings/Wallet/WalletPage/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type {ViewStyle} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import type {AccountData, BankAccountList, CardList, FundList, UserWallet, WalletTerms, WalletTransfer} from '@src/types/onyx';
import type IconAsset from '@src/types/utils/IconAsset';
import type {BankAccountList, CardList, FundList, UserWallet, WalletTerms, WalletTransfer} from '@src/types/onyx';

type WalletPageOnyxProps = {
/** Wallet balance transfer props */
Expand Down Expand Up @@ -30,27 +28,4 @@ type WalletPageProps = WalletPageOnyxProps & {
shouldListenForResize?: boolean;
};

type FormattedSelectedPaymentMethodIcon = {
icon: IconAsset;
iconHeight?: number;
iconWidth?: number;
iconStyles?: ViewStyle[];
iconSize?: number;
};

type FormattedSelectedPaymentMethod = {
title: string;
icon?: FormattedSelectedPaymentMethodIcon;
description?: string;
type?: string;
};

type PaymentMethodState = {
isSelectedPaymentMethodDefault: boolean;
selectedPaymentMethod: AccountData;
formattedSelectedPaymentMethod: FormattedSelectedPaymentMethod;
methodID: string | number;
selectedPaymentMethodType: string;
};

export type {WalletPageOnyxProps, WalletPageProps, FormattedSelectedPaymentMethodIcon, FormattedSelectedPaymentMethod, PaymentMethodState};
export type {WalletPageOnyxProps, WalletPageProps};
26 changes: 3 additions & 23 deletions src/pages/workspace/invoices/WorkspaceInvoiceVBASection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import MenuItem from '@components/MenuItem';
import Popover from '@components/Popover';
import Section from '@components/Section';
import useLocalize from '@hooks/useLocalize';
import usePaymentMethodState from '@hooks/usePaymentMethodState';
import type {FormattedSelectedPaymentMethod, FormattedSelectedPaymentMethodIcon} from '@hooks/usePaymentMethodState/types';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import getClickedTargetLocation from '@libs/getClickedTargetLocation';
import * as PaymentUtils from '@libs/PaymentUtils';
import PaymentMethodList from '@pages/settings/Wallet/PaymentMethodList';
import type {FormattedSelectedPaymentMethod, FormattedSelectedPaymentMethodIcon, PaymentMethodState} from '@pages/settings/Wallet/WalletPage/types';
import variables from '@styles/variables';
import * as BankAccounts from '@userActions/BankAccounts';
import * as PaymentMethods from '@userActions/PaymentMethods';
Expand All @@ -37,20 +38,12 @@ function WorkspaceInvoiceVBASection({policyID}: WorkspaceInvoiceVBASectionProps)
const {translate} = useLocalize();
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`);
const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST);
const {paymentMethod, setPaymentMethod, resetSelectedPaymentMethodData} = usePaymentMethodState();
const addPaymentMethodAnchorRef = useRef(null);
const paymentMethodButtonRef = useRef<HTMLDivElement | null>(null);
const [shouldShowAddPaymentMenu, setShouldShowAddPaymentMenu] = useState(false);
const [showConfirmDeleteModal, setShowConfirmDeleteModal] = useState(false);
const [shouldShowDefaultDeleteMenu, setShouldShowDefaultDeleteMenu] = useState(false);
const [paymentMethod, setPaymentMethod] = useState<PaymentMethodState>({
isSelectedPaymentMethodDefault: false,
selectedPaymentMethod: {},
formattedSelectedPaymentMethod: {
title: '',
},
methodID: '',
selectedPaymentMethodType: '',
});
const [anchorPosition, setAnchorPosition] = useState({
anchorPositionHorizontal: 0,
anchorPositionVertical: 0,
Expand Down Expand Up @@ -167,19 +160,6 @@ function WorkspaceInvoiceVBASection({policyID}: WorkspaceInvoiceVBASectionProps)
}
}, [paymentMethod.methodID, paymentMethod.selectedPaymentMethod.bankAccountID, paymentMethod.selectedPaymentMethodType, bankAccountList, styles]);

const resetSelectedPaymentMethodData = useCallback(() => {
// Reset to same values as in the constructor
setPaymentMethod({
isSelectedPaymentMethodDefault: false,
selectedPaymentMethod: {},
formattedSelectedPaymentMethod: {
title: '',
},
methodID: '',
selectedPaymentMethodType: '',
});
}, [setPaymentMethod]);

/**
* Navigate to the appropriate payment type addition screen
*/
Expand Down