From 0fa3d34d5da93af4e87225818c21dd2c2e498923 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Mon, 5 Aug 2024 17:00:32 +0200 Subject: [PATCH 01/26] create Balance component --- src/components/Balance.tsx | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/components/Balance.tsx diff --git a/src/components/Balance.tsx b/src/components/Balance.tsx new file mode 100644 index 0000000000000..b9ca3ac6b28ff --- /dev/null +++ b/src/components/Balance.tsx @@ -0,0 +1,20 @@ +import React from 'react'; +import type {TextStyle} from 'react-native'; +import useThemeStyles from '@hooks/useThemeStyles'; +import * as CurrencyUtils from '@libs/CurrencyUtils'; +import Text from './Text'; + +type BalanceProps = { + style?: TextStyle; + balance: number; +}; + +function Balance({style, balance}: BalanceProps) { + const styles = useThemeStyles(); + const formattedBalance = CurrencyUtils.convertToDisplayString(balance); + return {formattedBalance}; +} + +Balance.displayName = 'Balance'; + +export default Balance; From 0107f87633367dd697f36ff15520385174de5303 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Mon, 5 Aug 2024 17:06:17 +0200 Subject: [PATCH 02/26] add translations --- src/languages/en.ts | 2 ++ src/languages/es.ts | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/languages/en.ts b/src/languages/en.ts index 8cc1f0887e75d..2822ac080201d 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -3285,6 +3285,8 @@ export default { payingAsIndividual: 'Paying as an individual', payingAsBusiness: 'Paying as a business', }, + invoiceBalance: 'Invoice balance', + invoiceBalanceSubtitle: 'Here’s your current balance from collecting payments on invoices.', }, travel: { unlockConciergeBookingTravel: 'Unlock Concierge travel booking', diff --git a/src/languages/es.ts b/src/languages/es.ts index b659123c06328..bd7ac8efaff0e 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -3336,6 +3336,8 @@ export default { payingAsIndividual: 'Pago individual', payingAsBusiness: 'Pagar como una empresa', }, + invoiceBalance: 'Saldo de la factura', + invoiceBalanceSubtitle: 'Aquí está su saldo actual de la recaudación de pagos en las facturas.', }, travel: { unlockConciergeBookingTravel: 'Desbloquea la reserva de viajes con Concierge', From bfefb1c194c3a2dc47cc714b40eef5053d90e661 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Mon, 5 Aug 2024 17:06:26 +0200 Subject: [PATCH 03/26] integrate raw WorkspaceInvoiceBalanceSection --- .../WorkspaceInvoiceBalanceSection.tsx | 55 +++++++++++++++++++ .../invoices/WorkspaceInvoicesPage.tsx | 2 + src/styles/index.ts | 8 +++ 3 files changed, 65 insertions(+) create mode 100644 src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.tsx diff --git a/src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.tsx b/src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.tsx new file mode 100644 index 0000000000000..98352daf39f39 --- /dev/null +++ b/src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.tsx @@ -0,0 +1,55 @@ +import React from 'react'; +import {useOnyx} from 'react-native-onyx'; +import Balance from '@components/Balance'; +import * as Expensicons from '@components/Icon/Expensicons'; +import Section from '@components/Section'; +import useLocalize from '@hooks/useLocalize'; +import useThemeStyles from '@hooks/useThemeStyles'; +import ONYXKEYS from '@src/ONYXKEYS'; + +type WorkspaceInvoiceBalanceSectionProps = { + /** The policy ID currently being configured */ + policyID: string; +}; + +function WorkspaceInvoiceBalanceSection({policyID}: WorkspaceInvoiceBalanceSectionProps) { + const styles = useThemeStyles(); + const {translate} = useLocalize(); + const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`); + + return ( +
console.debug('Transfer balance'), + icon: Expensicons.Transfer, + shouldShowRightIcon: true, + iconRight: Expensicons.ArrowRight, + wrapperStyle: [styles.workspaceTransferBalance], + }, + ] + : [] + } + > + +
+ ); +} + +export default WorkspaceInvoiceBalanceSection; diff --git a/src/pages/workspace/invoices/WorkspaceInvoicesPage.tsx b/src/pages/workspace/invoices/WorkspaceInvoicesPage.tsx index 40a8239b9ab10..6f86a450fc9a5 100644 --- a/src/pages/workspace/invoices/WorkspaceInvoicesPage.tsx +++ b/src/pages/workspace/invoices/WorkspaceInvoicesPage.tsx @@ -8,6 +8,7 @@ import type {FullScreenNavigatorParamList} from '@navigation/types'; import WorkspacePageWithSections from '@pages/workspace/WorkspacePageWithSections'; import CONST from '@src/CONST'; import type SCREENS from '@src/SCREENS'; +import WorkspaceInvoiceBalanceSection from './WorkspaceInvoiceBalanceSection'; import WorkspaceInvoicesNoVBAView from './WorkspaceInvoicesNoVBAView'; import WorkspaceInvoicesVBAView from './WorkspaceInvoicesVBAView'; @@ -28,6 +29,7 @@ function WorkspaceInvoicesPage({route}: WorkspaceInvoicesPageProps) { > {(hasVBA?: boolean, policyID?: string) => ( + {policyID && } {!hasVBA && policyID && } {hasVBA && policyID && } diff --git a/src/styles/index.ts b/src/styles/index.ts index 3d5a2e98f3b91..a0f3fd7b52229 100644 --- a/src/styles/index.ts +++ b/src/styles/index.ts @@ -5151,6 +5151,14 @@ const styles = (theme: ThemeColors) => width: 184, height: 112, }, + + workspaceTransferBalance: { + height: variables.optionRowHeight, + marginTop: 20, + paddingLeft: 8, + paddingRight: 0, + borderRadius: 100, + }, } satisfies Styles); type ThemeStyles = ReturnType; From 69fc85c535e40c7ceab2a382dba711e687562e50 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Mon, 5 Aug 2024 17:09:50 +0200 Subject: [PATCH 04/26] integrate Balance in CurrentWalletBalance --- src/components/Balance.tsx | 8 ++++---- src/components/CurrentWalletBalance.tsx | 11 +++++++---- .../invoices/WorkspaceInvoiceBalanceSection.tsx | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/components/Balance.tsx b/src/components/Balance.tsx index b9ca3ac6b28ff..b0db99993b65f 100644 --- a/src/components/Balance.tsx +++ b/src/components/Balance.tsx @@ -1,18 +1,18 @@ import React from 'react'; -import type {TextStyle} from 'react-native'; +import type {StyleProp, TextStyle} from 'react-native'; import useThemeStyles from '@hooks/useThemeStyles'; import * as CurrencyUtils from '@libs/CurrencyUtils'; import Text from './Text'; type BalanceProps = { - style?: TextStyle; + textStyles?: StyleProp; balance: number; }; -function Balance({style, balance}: BalanceProps) { +function Balance({textStyles, balance}: BalanceProps) { const styles = useThemeStyles(); const formattedBalance = CurrencyUtils.convertToDisplayString(balance); - return {formattedBalance}; + return {formattedBalance}; } Balance.displayName = 'Balance'; diff --git a/src/components/CurrentWalletBalance.tsx b/src/components/CurrentWalletBalance.tsx index 8761b50465f38..4391593d40949 100644 --- a/src/components/CurrentWalletBalance.tsx +++ b/src/components/CurrentWalletBalance.tsx @@ -3,10 +3,9 @@ import type {StyleProp, TextStyle} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; import {withOnyx} from 'react-native-onyx'; import useThemeStyles from '@hooks/useThemeStyles'; -import * as CurrencyUtils from '@libs/CurrencyUtils'; import ONYXKEYS from '@src/ONYXKEYS'; import type UserWallet from '@src/types/onyx/UserWallet'; -import Text from './Text'; +import Balance from './Balance'; type CurrentWalletBalanceOnyxProps = { /** The user's wallet account */ @@ -19,8 +18,12 @@ type CurrentWalletBalanceProps = CurrentWalletBalanceOnyxProps & { function CurrentWalletBalance({userWallet, balanceStyles}: CurrentWalletBalanceProps) { const styles = useThemeStyles(); - const formattedBalance = CurrencyUtils.convertToDisplayString(userWallet?.currentBalance ?? 0); - return {formattedBalance}; + return ( + + ); } CurrentWalletBalance.displayName = 'CurrentWalletBalance'; diff --git a/src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.tsx b/src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.tsx index 98352daf39f39..7d3c17cfba9ee 100644 --- a/src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.tsx +++ b/src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.tsx @@ -43,7 +43,7 @@ function WorkspaceInvoiceBalanceSection({policyID}: WorkspaceInvoiceBalanceSecti } > Date: Tue, 6 Aug 2024 14:02:04 +0200 Subject: [PATCH 05/26] add invoice types --- .../invoices/WorkspaceInvoiceBalanceSection.tsx | 4 ---- src/types/onyx/Policy.ts | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.tsx b/src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.tsx index 7d3c17cfba9ee..56fc3fca7c72d 100644 --- a/src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.tsx +++ b/src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.tsx @@ -26,8 +26,6 @@ function WorkspaceInvoiceBalanceSection({policyID}: WorkspaceInvoiceBalanceSecti childrenStyles={styles.pt5} subtitleMuted menuItems={ - // @ts-expect-error TODO: Add invoice to types/onyx/Policy.ts - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access policy?.invoice?.bankAccount ? [ { @@ -44,8 +42,6 @@ function WorkspaceInvoiceBalanceSection({policyID}: WorkspaceInvoiceBalanceSecti > diff --git a/src/types/onyx/Policy.ts b/src/types/onyx/Policy.ts index 5b781ed7c0344..726154b2757ba 100644 --- a/src/types/onyx/Policy.ts +++ b/src/types/onyx/Policy.ts @@ -1292,6 +1292,18 @@ type PolicyReportField = { defaultExternalID?: string | null; }; +/** Policy invoicing details */ +type PolicyInvoicingDetails = OnyxCommon.OnyxValueWithOfflineFeedback<{ + /** Back account */ + bankAccount?: { + /** Account balance */ + stripeConnectAccountBalance?: number; + + /** bankAccountID of selected BBA for payouts */ + transferBankAccountID?: number; + }; +}>; + /** Names of policy features */ type PolicyFeatureName = ValueOf; @@ -1447,6 +1459,9 @@ type Policy = OnyxCommon.OnyxValueWithOfflineFeedback< */ isTaxTrackingEnabled?: boolean; + /** Policy invoicing details */ + invoice?: PolicyInvoicingDetails; + /** Tax data */ tax?: { /** Whether or not the policy has tax tracking enabled */ From cac61f88224e7b03718d0c81439aabd6acd740ee Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Tue, 6 Aug 2024 15:03:15 +0200 Subject: [PATCH 06/26] integrate raw WorkspaceTransferInvoiceBalance --- src/ROUTES.ts | 4 ++++ src/SCREENS.ts | 1 + .../AppNavigator/ModalStackNavigators/index.tsx | 1 + .../linkingConfig/FULL_SCREEN_TO_RHP_MAPPING.ts | 1 + src/libs/Navigation/linkingConfig/config.ts | 3 +++ src/libs/Navigation/types.ts | 3 +++ .../workspace/invoices/WorkspaceInvoiceBalanceSection.tsx | 6 ++++-- .../invoices/WorkspaceTransferInvoiceBalance.tsx | 8 ++++++++ 8 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 1589d67c985a8..474fdb33fa579 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -679,6 +679,10 @@ const ROUTES = { route: 'settings/workspaces/:policyID/invoices', getRoute: (policyID: string) => `settings/workspaces/${policyID}/invoices` as const, }, + WORKSPACE_INVOICES_TRANSFER_BALANCE: { + route: 'settings/workspaces/:policyID/invoices/transfer-balance', + getRoute: (policyID: string) => `settings/workspaces/${policyID}/invoices/transfer-balance` as const, + }, WORKSPACE_TRAVEL: { route: 'settings/workspaces/:policyID/travel', getRoute: (policyID: string) => `settings/workspaces/${policyID}/travel` as const, diff --git a/src/SCREENS.ts b/src/SCREENS.ts index 831a058ebbbb8..a762e9d28b5ed 100644 --- a/src/SCREENS.ts +++ b/src/SCREENS.ts @@ -370,6 +370,7 @@ const SCREENS = { EXPENSIFY_CARD_SETTINGS_FREQUENCY: 'Workspace_ExpensifyCard_Settings_Frequency', BILLS: 'Workspace_Bills', INVOICES: 'Workspace_Invoices', + INVOICES_TRANSFER_BALANCE: 'Workspace_Invoices_Transfer_Balance', TRAVEL: 'Workspace_Travel', MEMBERS: 'Workspace_Members', INVITE: 'Workspace_Invite', diff --git a/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx b/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx index 5b84fba03a398..05497d7328acc 100644 --- a/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx +++ b/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx @@ -418,6 +418,7 @@ const SettingsModalStackNavigator = createModalStackNavigator require('../../../../pages/workspace/taxes/ValuePage').default, [SCREENS.WORKSPACE.TAX_CREATE]: () => require('../../../../pages/workspace/taxes/WorkspaceCreateTaxPage').default, [SCREENS.WORKSPACE.TAX_CODE]: () => require('../../../../pages/workspace/taxes/WorkspaceTaxCodePage').default, + [SCREENS.WORKSPACE.INVOICES_TRANSFER_BALANCE]: () => require('../../../../pages/workspace/invoices/WorkspaceTransferInvoiceBalance').default, [SCREENS.WORKSPACE.EXPENSIFY_CARD_ISSUE_NEW]: () => require('../../../../pages/workspace/expensifyCard/issueNew/IssueNewCardPage').default, [SCREENS.WORKSPACE.EXPENSIFY_CARD_SETTINGS]: () => require('../../../../pages/workspace/expensifyCard/WorkspaceCardSettingsPage').default, [SCREENS.WORKSPACE.EXPENSIFY_CARD_SETTINGS_ACCOUNT]: () => require('../../../../pages/workspace/expensifyCard/WorkspaceSettlementAccountPage').default, diff --git a/src/libs/Navigation/linkingConfig/FULL_SCREEN_TO_RHP_MAPPING.ts b/src/libs/Navigation/linkingConfig/FULL_SCREEN_TO_RHP_MAPPING.ts index c27ccaab51769..9e9acabd63ffd 100755 --- a/src/libs/Navigation/linkingConfig/FULL_SCREEN_TO_RHP_MAPPING.ts +++ b/src/libs/Navigation/linkingConfig/FULL_SCREEN_TO_RHP_MAPPING.ts @@ -159,6 +159,7 @@ const FULL_SCREEN_TO_RHP_MAPPING: Partial> = { SCREENS.WORKSPACE.REPORT_FIELDS_EDIT_VALUE, SCREENS.WORKSPACE.REPORT_FIELDS_EDIT_INITIAL_VALUE, ], + [SCREENS.WORKSPACE.INVOICES]: [SCREENS.WORKSPACE.INVOICES_TRANSFER_BALANCE], [SCREENS.WORKSPACE.EXPENSIFY_CARD]: [ SCREENS.WORKSPACE.EXPENSIFY_CARD_ISSUE_NEW, SCREENS.WORKSPACE.EXPENSIFY_CARD_BANK_ACCOUNT, diff --git a/src/libs/Navigation/linkingConfig/config.ts b/src/libs/Navigation/linkingConfig/config.ts index 87802e1130cd2..94448ef2854ff 100644 --- a/src/libs/Navigation/linkingConfig/config.ts +++ b/src/libs/Navigation/linkingConfig/config.ts @@ -475,6 +475,9 @@ const config: LinkingOptions['config'] = { [SCREENS.WORKSPACE.SHARE]: { path: ROUTES.WORKSPACE_PROFILE_SHARE.route, }, + [SCREENS.WORKSPACE.INVOICES_TRANSFER_BALANCE]: { + path: ROUTES.WORKSPACE_INVOICES_TRANSFER_BALANCE.route, + }, [SCREENS.WORKSPACE.EXPENSIFY_CARD_LIMIT]: { path: ROUTES.WORKSPACE_EXPENSIFY_CARD_LIMIT.route, }, diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index c527a02c16af9..461b36bcef2f4 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -1138,6 +1138,9 @@ type FullScreenNavigatorParamList = { [SCREENS.WORKSPACE.INVOICES]: { policyID: string; }; + [SCREENS.WORKSPACE.INVOICES_TRANSFER_BALANCE]: { + policyID: string; + }; [SCREENS.WORKSPACE.TRAVEL]: { policyID: string; }; diff --git a/src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.tsx b/src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.tsx index 56fc3fca7c72d..d49f4f1718c5e 100644 --- a/src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.tsx +++ b/src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.tsx @@ -5,7 +5,9 @@ import * as Expensicons from '@components/Icon/Expensicons'; import Section from '@components/Section'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; +import Navigation from '@libs/Navigation/Navigation'; import ONYXKEYS from '@src/ONYXKEYS'; +import ROUTES from '@src/ROUTES'; type WorkspaceInvoiceBalanceSectionProps = { /** The policy ID currently being configured */ @@ -26,11 +28,11 @@ function WorkspaceInvoiceBalanceSection({policyID}: WorkspaceInvoiceBalanceSecti childrenStyles={styles.pt5} subtitleMuted menuItems={ - policy?.invoice?.bankAccount + !policy?.invoice?.bankAccount ? [ { title: translate('common.transferBalance'), - onPress: () => console.debug('Transfer balance'), + onPress: () => Navigation.navigate(ROUTES.WORKSPACE_INVOICES_TRANSFER_BALANCE.getRoute(policyID)), icon: Expensicons.Transfer, shouldShowRightIcon: true, iconRight: Expensicons.ArrowRight, diff --git a/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx b/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx new file mode 100644 index 0000000000000..894d6f34b0fff --- /dev/null +++ b/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx @@ -0,0 +1,8 @@ +import React from 'react'; +import Text from '@components/Text'; + +function WorkspaceTransferInvoiceBalance() { + return WorkspaceTransferInvoiceBalance; +} + +export default WorkspaceTransferInvoiceBalance; From efa7d46016c747f710cd6a25661e49399ecb49e8 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Tue, 6 Aug 2024 16:08:50 +0200 Subject: [PATCH 07/26] fix nav types --- src/libs/Navigation/types.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index 461b36bcef2f4..b77a3fe3ba513 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -665,6 +665,9 @@ type SettingsNavigatorParamList = { policyID: string; taxID: string; }; + [SCREENS.WORKSPACE.INVOICES_TRANSFER_BALANCE]: { + policyID: string; + }; [SCREENS.WORKSPACE.EXPENSIFY_CARD_ISSUE_NEW]: { policyID: string; }; @@ -1138,9 +1141,6 @@ type FullScreenNavigatorParamList = { [SCREENS.WORKSPACE.INVOICES]: { policyID: string; }; - [SCREENS.WORKSPACE.INVOICES_TRANSFER_BALANCE]: { - policyID: string; - }; [SCREENS.WORKSPACE.TRAVEL]: { policyID: string; }; From 3cf870bdf32a8df45748a082ba8c30629b5d6019 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Tue, 6 Aug 2024 16:09:22 +0200 Subject: [PATCH 08/26] integrate raw WorkspaceTransferInvoiceBalance --- src/ONYXKEYS.ts | 4 + .../WorkspaceTransferInvoiceBalance.tsx | 133 +++++++++++++++++- src/types/onyx/InvoiceBalanceTransfer.ts | 15 ++ src/types/onyx/index.ts | 2 + 4 files changed, 152 insertions(+), 2 deletions(-) create mode 100644 src/types/onyx/InvoiceBalanceTransfer.ts diff --git a/src/ONYXKEYS.ts b/src/ONYXKEYS.ts index 979bafcdab6dc..6f2333d91c814 100755 --- a/src/ONYXKEYS.ts +++ b/src/ONYXKEYS.ts @@ -397,6 +397,9 @@ const ONYXKEYS = { /** Stores the information about currently edited advanced approval workflow */ APPROVAL_WORKFLOW: 'approvalWorkflow', + /** Stores the information about the invoice balance transfer */ + INVOICE_BALANCE_TRANSFER: 'invoiceBalanceTransfer', + /** Collection Keys */ COLLECTION: { DOWNLOAD: 'download_', @@ -872,6 +875,7 @@ type OnyxValuesMapping = { [ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END]: number; [ONYXKEYS.NVP_PRIVATE_CANCELLATION_DETAILS]: OnyxTypes.CancellationDetails[]; [ONYXKEYS.APPROVAL_WORKFLOW]: OnyxTypes.ApprovalWorkflow; + [ONYXKEYS.INVOICE_BALANCE_TRANSFER]: OnyxTypes.InvoiceBalanceTransfer; }; type OnyxValues = OnyxValuesMapping & OnyxCollectionValuesMapping & OnyxFormValuesMapping & OnyxFormDraftValuesMapping; diff --git a/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx b/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx index 894d6f34b0fff..1cd6d66572a43 100644 --- a/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx +++ b/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx @@ -1,8 +1,137 @@ +import type {StackScreenProps} from '@react-navigation/stack'; import React from 'react'; +import {View} from 'react-native'; +import {useOnyx} from 'react-native-onyx'; +import Balance from '@components/Balance'; +import FormAlertWithSubmitButton from '@components/FormAlertWithSubmitButton'; +import HeaderWithBackButton from '@components/HeaderWithBackButton'; +import * as Expensicons from '@components/Icon/Expensicons'; +import MenuItem from '@components/MenuItem'; +import ScreenWrapper from '@components/ScreenWrapper'; +import ScrollView from '@components/ScrollView'; import Text from '@components/Text'; +import useLocalize from '@hooks/useLocalize'; +import useNetwork from '@hooks/useNetwork'; +import useStyledSafeAreaInsets from '@hooks/useStyledSafeAreaInsets'; +import useThemeStyles from '@hooks/useThemeStyles'; +import * as CurrencyUtils from '@libs/CurrencyUtils'; +import * as ErrorUtils from '@libs/ErrorUtils'; +import type {SettingsNavigatorParamList} from '@libs/Navigation/types'; +import * as PaymentUtils from '@libs/PaymentUtils'; +import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; +import variables from '@styles/variables'; +import * as PaymentMethods from '@userActions/PaymentMethods'; +import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; +import type SCREENS from '@src/SCREENS'; +import type PaymentMethod from '@src/types/onyx/PaymentMethod'; +import {isEmptyObject} from '@src/types/utils/EmptyObject'; -function WorkspaceTransferInvoiceBalance() { - return WorkspaceTransferInvoiceBalance; +type WorkspaceTransferInvoiceBalanceProps = StackScreenProps; + +function WorkspaceTransferInvoiceBalance({ + route: { + params: {policyID}, + }, +}: WorkspaceTransferInvoiceBalanceProps) { + const styles = useThemeStyles(); + const {isOffline} = useNetwork(); + const {paddingBottom} = useStyledSafeAreaInsets(); + const {translate} = useLocalize(); + const [invoiceBalanceTransfer] = useOnyx(ONYXKEYS.INVOICE_BALANCE_TRANSFER); + const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`); + const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST); + const [fundList] = useOnyx(ONYXKEYS.FUND_LIST); + + const selectedAccount: PaymentMethod | null = + PaymentUtils.formatPaymentMethods(bankAccountList ?? {}, fundList ?? {}, styles).find( + (paymentMethod) => paymentMethod.methodID === policy?.invoice?.bankAccount?.transferBankAccountID, + ) ?? null; + const balance = policy?.invoice?.bankAccount?.stripeConnectAccountBalance ?? 0; + const calculatedFee = PaymentUtils.calculateWalletTransferBalanceFee(balance, CONST.WALLET.TRANSFER_METHOD_TYPE.ACH); + const transferAmount = balance - calculatedFee; + const isTransferable = transferAmount > 0; + const isButtonDisabled = !isTransferable || !selectedAccount; + const errorMessage = ErrorUtils.getLatestErrorMessage(invoiceBalanceTransfer); + + return ( + + + + + + + + + + console.debug('ACH')} + /> + + {translate('transferAmountPage.whichAccount')} + + + {translate('transferAmountPage.fee')} + {CurrencyUtils.convertToDisplayString(calculatedFee)} + + + + selectedAccount && PaymentMethods.transferWalletBalance(selectedAccount)} + isDisabled={isButtonDisabled || isOffline} + message={errorMessage} + isAlertVisible={!isEmptyObject(errorMessage)} + containerStyles={[styles.ph5, !paddingBottom ? styles.pb5 : null]} + /> + + + + ); } +WorkspaceTransferInvoiceBalance.displayName = 'WorkspaceTransferInvoiceBalance'; + export default WorkspaceTransferInvoiceBalance; diff --git a/src/types/onyx/InvoiceBalanceTransfer.ts b/src/types/onyx/InvoiceBalanceTransfer.ts new file mode 100644 index 0000000000000..b850e6c3919cd --- /dev/null +++ b/src/types/onyx/InvoiceBalanceTransfer.ts @@ -0,0 +1,15 @@ +import type * as OnyxCommon from './OnyxCommon'; + +/** Model of invoice balance transfer */ +type InvoiceBalanceTransfer = { + /** Whether the data is being fetched from server */ + loading: boolean; + + /** Whether invoice balance has been transferred successfully */ + success: boolean; + + /** Error messages to show in UI */ + errors: OnyxCommon.Errors; +}; + +export default InvoiceBalanceTransfer; diff --git a/src/types/onyx/index.ts b/src/types/onyx/index.ts index a2a66e89003fb..84f0504493c5e 100644 --- a/src/types/onyx/index.ts +++ b/src/types/onyx/index.ts @@ -23,6 +23,7 @@ import type {FundList} from './Fund'; import type Fund from './Fund'; import type IntroSelected from './IntroSelected'; import type InvitedEmailsToAccountIDs from './InvitedEmailsToAccountIDs'; +import type InvoiceBalanceTransfer from './InvoiceBalanceTransfer'; import type IOU from './IOU'; import type LastExportMethod from './LastExportMethod'; import type LastPaymentMethod from './LastPaymentMethod'; @@ -218,4 +219,5 @@ export type { CancellationDetails, ApprovalWorkflow, MobileSelectionMode, + InvoiceBalanceTransfer, }; From d6d4cdd14fbcb503ef5aacee380103ed5ad6f5de Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Wed, 7 Aug 2024 16:35:41 +0200 Subject: [PATCH 09/26] fix styles --- .../workspace/invoices/WorkspaceInvoiceBalanceSection.tsx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.tsx b/src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.tsx index d49f4f1718c5e..96f70b005a167 100644 --- a/src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.tsx +++ b/src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.tsx @@ -42,10 +42,7 @@ function WorkspaceInvoiceBalanceSection({policyID}: WorkspaceInvoiceBalanceSecti : [] } > - + ); } From c4024d98d237844a8d40d5b19807f849506ad8dd Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Wed, 7 Aug 2024 17:24:36 +0200 Subject: [PATCH 10/26] improve TransferInvoiceBalance --- .../WorkspaceInvoiceBalanceSection.tsx | 1 + .../WorkspaceTransferInvoiceBalance.tsx | 36 ++++++++++--------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.tsx b/src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.tsx index 96f70b005a167..565a86b6c575b 100644 --- a/src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.tsx +++ b/src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.tsx @@ -28,6 +28,7 @@ function WorkspaceInvoiceBalanceSection({policyID}: WorkspaceInvoiceBalanceSecti childrenStyles={styles.pt5} subtitleMuted menuItems={ + // TODO: This is a temporary solution to show the Transfer Balance button !policy?.invoice?.bankAccount ? [ { diff --git a/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx b/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx index 1cd6d66572a43..0c9efb954f475 100644 --- a/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx +++ b/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx @@ -20,7 +20,6 @@ import type {SettingsNavigatorParamList} from '@libs/Navigation/types'; import * as PaymentUtils from '@libs/PaymentUtils'; import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; import variables from '@styles/variables'; -import * as PaymentMethods from '@userActions/PaymentMethods'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type SCREENS from '@src/SCREENS'; @@ -43,10 +42,12 @@ function WorkspaceTransferInvoiceBalance({ const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST); const [fundList] = useOnyx(ONYXKEYS.FUND_LIST); + const paymentMethods = PaymentUtils.formatPaymentMethods(bankAccountList ?? {}, fundList ?? {}, styles); const selectedAccount: PaymentMethod | null = - PaymentUtils.formatPaymentMethods(bankAccountList ?? {}, fundList ?? {}, styles).find( - (paymentMethod) => paymentMethod.methodID === policy?.invoice?.bankAccount?.transferBankAccountID, - ) ?? null; + paymentMethods.find((paymentMethod) => paymentMethod.methodID === policy?.invoice?.bankAccount?.transferBankAccountID) ?? + paymentMethods.find((paymentMethod) => paymentMethod.isDefault) ?? + paymentMethods[0] ?? + null; const balance = policy?.invoice?.bankAccount?.stripeConnectAccountBalance ?? 0; const calculatedFee = PaymentUtils.calculateWalletTransferBalanceFee(balance, CONST.WALLET.TRANSFER_METHOD_TYPE.ACH); const transferAmount = balance - calculatedFee; @@ -58,6 +59,7 @@ function WorkspaceTransferInvoiceBalance({ @@ -98,17 +100,19 @@ function WorkspaceTransferInvoiceBalance({ /> {translate('transferAmountPage.whichAccount')} - + {!!selectedAccount && ( + + )} {translate('transferAmountPage.fee')} {CurrencyUtils.convertToDisplayString(calculatedFee)} @@ -120,7 +124,7 @@ function WorkspaceTransferInvoiceBalance({ amount: isTransferable ? CurrencyUtils.convertToDisplayString(transferAmount) : '', })} isLoading={invoiceBalanceTransfer?.loading} - onSubmit={() => selectedAccount && PaymentMethods.transferWalletBalance(selectedAccount)} + onSubmit={() => selectedAccount && console.debug('Transfer', selectedAccount)} isDisabled={isButtonDisabled || isOffline} message={errorMessage} isAlertVisible={!isEmptyObject(errorMessage)} From 118f9f7f56a4f8b7d4e5558f5966b9d7163740e3 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Wed, 7 Aug 2024 18:15:48 +0200 Subject: [PATCH 11/26] integrate payment methods --- .../TransferInvoiceBalanceParams.ts | 7 ++ src/libs/API/parameters/index.ts | 1 + src/libs/API/types.ts | 2 + src/libs/actions/PaymentMethods.ts | 73 +++++++++++++++++++ .../WorkspaceTransferInvoiceBalance.tsx | 9 ++- 5 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 src/libs/API/parameters/TransferInvoiceBalanceParams.ts diff --git a/src/libs/API/parameters/TransferInvoiceBalanceParams.ts b/src/libs/API/parameters/TransferInvoiceBalanceParams.ts new file mode 100644 index 0000000000000..b7fa7ccf09c99 --- /dev/null +++ b/src/libs/API/parameters/TransferInvoiceBalanceParams.ts @@ -0,0 +1,7 @@ +type TransferInvoiceBalanceParams = { + policyID: string; + bankAccountID: number; + authToken: string; +}; + +export default TransferInvoiceBalanceParams; diff --git a/src/libs/API/parameters/index.ts b/src/libs/API/parameters/index.ts index 6b95190cd1ed5..5cab53bc1bfc5 100644 --- a/src/libs/API/parameters/index.ts +++ b/src/libs/API/parameters/index.ts @@ -269,3 +269,4 @@ export type {default as ExportSearchItemsToCSVParams} from './ExportSearchItemsT export type {default as UpdateExpensifyCardLimitParams} from './UpdateExpensifyCardLimitParams'; export type {CreateWorkspaceApprovalParams, UpdateWorkspaceApprovalParams, RemoveWorkspaceApprovalParams} from './WorkspaceApprovalParams'; export type {default as StartIssueNewCardFlowParams} from './StartIssueNewCardFlowParams'; +export type {default as TransferInvoiceBalanceParams} from './TransferInvoiceBalanceParams'; diff --git a/src/libs/API/types.ts b/src/libs/API/types.ts index 3f19c719fdd77..2b2632dc4378f 100644 --- a/src/libs/API/types.ts +++ b/src/libs/API/types.ts @@ -324,6 +324,7 @@ const WRITE_COMMANDS = { CREATE_WORKSPACE_APPROVAL: 'CreateWorkspaceApproval', UPDATE_WORKSPACE_APPROVAL: 'UpdateWorkspaceApproval', REMOVE_WORKSPACE_APPROVAL: 'RemoveWorkspaceApproval', + TRANSFER_POLICY_ACCOUNT_BALANCE: 'TransferPolicyAccountBalance', } as const; type WriteCommand = ValueOf; @@ -654,6 +655,7 @@ type WriteCommandParameters = { [WRITE_COMMANDS.CREATE_WORKSPACE_APPROVAL]: Parameters.CreateWorkspaceApprovalParams; [WRITE_COMMANDS.UPDATE_WORKSPACE_APPROVAL]: Parameters.UpdateWorkspaceApprovalParams; [WRITE_COMMANDS.REMOVE_WORKSPACE_APPROVAL]: Parameters.RemoveWorkspaceApprovalParams; + [WRITE_COMMANDS.TRANSFER_POLICY_ACCOUNT_BALANCE]: Parameters.TransferInvoiceBalanceParams; }; const READ_COMMANDS = { diff --git a/src/libs/actions/PaymentMethods.ts b/src/libs/actions/PaymentMethods.ts index bac3739af810d..de6a9310bb516 100644 --- a/src/libs/actions/PaymentMethods.ts +++ b/src/libs/actions/PaymentMethods.ts @@ -10,12 +10,14 @@ import type { DeletePaymentCardParams, MakeDefaultPaymentMethodParams, PaymentCardParams, + TransferInvoiceBalanceParams, TransferWalletBalanceParams, UpdateBillingCurrencyParams, } from '@libs/API/parameters'; import {READ_COMMANDS, SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from '@libs/API/types'; import * as CardUtils from '@libs/CardUtils'; import Navigation from '@libs/Navigation/Navigation'; +import * as NetworkStore from '@libs/Network/NetworkStore'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Route} from '@src/ROUTES'; @@ -531,6 +533,75 @@ function setPaymentCardForm(values: AccountData) { }); } +/** + * Transfers invoice balance to a bank account + */ +function transferInvoiceBalance(policyID: string, bankAccountID: number) { + const authToken = NetworkStore.getAuthToken(); + + if (!authToken) { + return; + } + + const optimisticData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.INVOICE_BALANCE_TRANSFER, + value: { + loading: true, + }, + }, + ]; + const successData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.INVOICE_BALANCE_TRANSFER, + value: { + loading: false, + success: true, + }, + }, + ]; + const failureData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.INVOICE_BALANCE_TRANSFER, + value: { + loading: false, + success: false, + }, + }, + ]; + + const parameters: TransferInvoiceBalanceParams = { + policyID, + bankAccountID, + authToken, + }; + + console.debug('Transfering invoice balance to bank account', parameters, { + optimisticData, + successData, + failureData, + }); + + API.write(WRITE_COMMANDS.TRANSFER_POLICY_ACCOUNT_BALANCE, parameters, { + optimisticData, + successData, + failureData, + }); +} + +/** + * Resets the invoice balance transfer data + */ +function resetInvoiceTransferData() { + Onyx.merge(ONYXKEYS.INVOICE_BALANCE_TRANSFER, { + loading: false, + success: false, + }); +} + export { deletePaymentCard, addPaymentCard, @@ -555,4 +626,6 @@ export { clearWalletTermsError, setPaymentCardForm, verifySetupIntent, + transferInvoiceBalance, + resetInvoiceTransferData, }; diff --git a/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx b/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx index 0c9efb954f475..0d0ae3e2dc4f7 100644 --- a/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx +++ b/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx @@ -1,5 +1,5 @@ import type {StackScreenProps} from '@react-navigation/stack'; -import React from 'react'; +import React, {useEffect} from 'react'; import {View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import Balance from '@components/Balance'; @@ -20,6 +20,7 @@ import type {SettingsNavigatorParamList} from '@libs/Navigation/types'; import * as PaymentUtils from '@libs/PaymentUtils'; import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; import variables from '@styles/variables'; +import * as PaymentMethods from '@userActions/PaymentMethods'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type SCREENS from '@src/SCREENS'; @@ -55,6 +56,10 @@ function WorkspaceTransferInvoiceBalance({ const isButtonDisabled = !isTransferable || !selectedAccount; const errorMessage = ErrorUtils.getLatestErrorMessage(invoiceBalanceTransfer); + useEffect(() => { + PaymentMethods.resetInvoiceTransferData(); + }, []); + return ( selectedAccount && console.debug('Transfer', selectedAccount)} + onSubmit={() => selectedAccount.methodID && PaymentMethods.transferInvoiceBalance(policyID, selectedAccount.methodID)} isDisabled={isButtonDisabled || isOffline} message={errorMessage} isAlertVisible={!isEmptyObject(errorMessage)} From 98a0b8a497db0b0e5fc857f2b9a7fc77aa8d3d01 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Thu, 8 Aug 2024 14:49:10 +0200 Subject: [PATCH 12/26] fix optional chain --- .../workspace/invoices/WorkspaceTransferInvoiceBalance.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx b/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx index 0d0ae3e2dc4f7..d8204e8b5073f 100644 --- a/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx +++ b/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx @@ -129,7 +129,7 @@ function WorkspaceTransferInvoiceBalance({ amount: isTransferable ? CurrencyUtils.convertToDisplayString(transferAmount) : '', })} isLoading={invoiceBalanceTransfer?.loading} - onSubmit={() => selectedAccount.methodID && PaymentMethods.transferInvoiceBalance(policyID, selectedAccount.methodID)} + onSubmit={() => selectedAccount?.methodID && PaymentMethods.transferInvoiceBalance(policyID, selectedAccount.methodID)} isDisabled={isButtonDisabled || isOffline} message={errorMessage} isAlertVisible={!isEmptyObject(errorMessage)} From e21a9a231d676355eb6ee1b1096839682723118a Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Thu, 8 Aug 2024 16:23:27 +0200 Subject: [PATCH 13/26] integrate success view --- src/libs/actions/PaymentMethods.ts | 18 +++++++++--- .../WorkspaceTransferInvoiceBalance.tsx | 29 +++++++++++++++---- src/types/onyx/InvoiceBalanceTransfer.ts | 6 ++-- 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/libs/actions/PaymentMethods.ts b/src/libs/actions/PaymentMethods.ts index de6a9310bb516..8696005952157 100644 --- a/src/libs/actions/PaymentMethods.ts +++ b/src/libs/actions/PaymentMethods.ts @@ -558,7 +558,7 @@ function transferInvoiceBalance(policyID: string, bankAccountID: number) { key: ONYXKEYS.INVOICE_BALANCE_TRANSFER, value: { loading: false, - success: true, + shouldShowSuccess: true, }, }, ]; @@ -568,7 +568,7 @@ function transferInvoiceBalance(policyID: string, bankAccountID: number) { key: ONYXKEYS.INVOICE_BALANCE_TRANSFER, value: { loading: false, - success: false, + shouldShowSuccess: false, }, }, ]; @@ -596,12 +596,21 @@ function transferInvoiceBalance(policyID: string, bankAccountID: number) { * Resets the invoice balance transfer data */ function resetInvoiceTransferData() { - Onyx.merge(ONYXKEYS.INVOICE_BALANCE_TRANSFER, { + Onyx.set(ONYXKEYS.INVOICE_BALANCE_TRANSFER, { loading: false, - success: false, + shouldShowSuccess: false, + errors: null, }); } +/** + * Dismisses the successful invoice transfer balance page + */ +function dismissSuccessfulInvoiceTransferBalancePage() { + Onyx.merge(ONYXKEYS.INVOICE_BALANCE_TRANSFER, {shouldShowSuccess: false}); + Navigation.goBack(); +} + export { deletePaymentCard, addPaymentCard, @@ -628,4 +637,5 @@ export { verifySetupIntent, transferInvoiceBalance, resetInvoiceTransferData, + dismissSuccessfulInvoiceTransferBalancePage, }; diff --git a/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx b/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx index d8204e8b5073f..563c02c6ecf55 100644 --- a/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx +++ b/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx @@ -3,6 +3,7 @@ import React, {useEffect} from 'react'; import {View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import Balance from '@components/Balance'; +import ConfirmationPage from '@components/ConfirmationPage'; import FormAlertWithSubmitButton from '@components/FormAlertWithSubmitButton'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import * as Expensicons from '@components/Icon/Expensicons'; @@ -43,6 +44,28 @@ function WorkspaceTransferInvoiceBalance({ const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST); const [fundList] = useOnyx(ONYXKEYS.FUND_LIST); + useEffect(() => { + PaymentMethods.resetInvoiceTransferData(); + }, []); + + if (invoiceBalanceTransfer?.shouldShowSuccess && !invoiceBalanceTransfer?.loading) { + return ( + + + + + ); + } + const paymentMethods = PaymentUtils.formatPaymentMethods(bankAccountList ?? {}, fundList ?? {}, styles); const selectedAccount: PaymentMethod | null = paymentMethods.find((paymentMethod) => paymentMethod.methodID === policy?.invoice?.bankAccount?.transferBankAccountID) ?? @@ -56,10 +79,6 @@ function WorkspaceTransferInvoiceBalance({ const isButtonDisabled = !isTransferable || !selectedAccount; const errorMessage = ErrorUtils.getLatestErrorMessage(invoiceBalanceTransfer); - useEffect(() => { - PaymentMethods.resetInvoiceTransferData(); - }, []); - return ( Date: Thu, 8 Aug 2024 16:41:57 +0200 Subject: [PATCH 14/26] remove debug log --- src/libs/actions/PaymentMethods.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/libs/actions/PaymentMethods.ts b/src/libs/actions/PaymentMethods.ts index 8696005952157..ba3ee0d745ad6 100644 --- a/src/libs/actions/PaymentMethods.ts +++ b/src/libs/actions/PaymentMethods.ts @@ -579,12 +579,6 @@ function transferInvoiceBalance(policyID: string, bankAccountID: number) { authToken, }; - console.debug('Transfering invoice balance to bank account', parameters, { - optimisticData, - successData, - failureData, - }); - API.write(WRITE_COMMANDS.TRANSFER_POLICY_ACCOUNT_BALANCE, parameters, { optimisticData, successData, From 5340ac6d91fc71e5a679d13d854b62d76a7bb564 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Thu, 8 Aug 2024 16:43:09 +0200 Subject: [PATCH 15/26] remove debug condition --- .../workspace/invoices/WorkspaceInvoiceBalanceSection.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.tsx b/src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.tsx index 565a86b6c575b..23e2582e08372 100644 --- a/src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.tsx +++ b/src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.tsx @@ -28,8 +28,7 @@ function WorkspaceInvoiceBalanceSection({policyID}: WorkspaceInvoiceBalanceSecti childrenStyles={styles.pt5} subtitleMuted menuItems={ - // TODO: This is a temporary solution to show the Transfer Balance button - !policy?.invoice?.bankAccount + policy?.invoice?.bankAccount ? [ { title: translate('common.transferBalance'), From 8034af8c9ba4d99cd80397bc1152fe495bccf8ad Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Fri, 9 Aug 2024 13:10:28 +0200 Subject: [PATCH 16/26] do not use bankAccountID for request --- src/libs/API/parameters/TransferInvoiceBalanceParams.ts | 1 - src/libs/actions/PaymentMethods.ts | 3 +-- .../workspace/invoices/WorkspaceTransferInvoiceBalance.tsx | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/libs/API/parameters/TransferInvoiceBalanceParams.ts b/src/libs/API/parameters/TransferInvoiceBalanceParams.ts index b7fa7ccf09c99..1e0532ff4b83f 100644 --- a/src/libs/API/parameters/TransferInvoiceBalanceParams.ts +++ b/src/libs/API/parameters/TransferInvoiceBalanceParams.ts @@ -1,6 +1,5 @@ type TransferInvoiceBalanceParams = { policyID: string; - bankAccountID: number; authToken: string; }; diff --git a/src/libs/actions/PaymentMethods.ts b/src/libs/actions/PaymentMethods.ts index ba3ee0d745ad6..3943fbd3f2c42 100644 --- a/src/libs/actions/PaymentMethods.ts +++ b/src/libs/actions/PaymentMethods.ts @@ -536,7 +536,7 @@ function setPaymentCardForm(values: AccountData) { /** * Transfers invoice balance to a bank account */ -function transferInvoiceBalance(policyID: string, bankAccountID: number) { +function transferInvoiceBalance(policyID: string) { const authToken = NetworkStore.getAuthToken(); if (!authToken) { @@ -575,7 +575,6 @@ function transferInvoiceBalance(policyID: string, bankAccountID: number) { const parameters: TransferInvoiceBalanceParams = { policyID, - bankAccountID, authToken, }; diff --git a/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx b/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx index 563c02c6ecf55..340389938c98a 100644 --- a/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx +++ b/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx @@ -148,7 +148,7 @@ function WorkspaceTransferInvoiceBalance({ amount: isTransferable ? CurrencyUtils.convertToDisplayString(transferAmount) : '', })} isLoading={invoiceBalanceTransfer?.loading} - onSubmit={() => selectedAccount?.methodID && PaymentMethods.transferInvoiceBalance(policyID, selectedAccount.methodID)} + onSubmit={() => PaymentMethods.transferInvoiceBalance(policyID)} isDisabled={isButtonDisabled || isOffline} message={errorMessage} isAlertVisible={!isEmptyObject(errorMessage)} From 451e13965ca3a958b30155731d2cb492a7952605 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Fri, 9 Aug 2024 13:11:53 +0200 Subject: [PATCH 17/26] simplify the logic for selecting the payment account --- .../workspace/invoices/WorkspaceTransferInvoiceBalance.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx b/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx index 340389938c98a..b1f1cf1b7e6de 100644 --- a/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx +++ b/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx @@ -67,11 +67,7 @@ function WorkspaceTransferInvoiceBalance({ } const paymentMethods = PaymentUtils.formatPaymentMethods(bankAccountList ?? {}, fundList ?? {}, styles); - const selectedAccount: PaymentMethod | null = - paymentMethods.find((paymentMethod) => paymentMethod.methodID === policy?.invoice?.bankAccount?.transferBankAccountID) ?? - paymentMethods.find((paymentMethod) => paymentMethod.isDefault) ?? - paymentMethods[0] ?? - null; + const selectedAccount: PaymentMethod | null = paymentMethods.find((paymentMethod) => paymentMethod.methodID === policy?.invoice?.bankAccount?.transferBankAccountID) ?? null; const balance = policy?.invoice?.bankAccount?.stripeConnectAccountBalance ?? 0; const calculatedFee = PaymentUtils.calculateWalletTransferBalanceFee(balance, CONST.WALLET.TRANSFER_METHOD_TYPE.ACH); const transferAmount = balance - calculatedFee; From ddd6ca3a436aa7f6ea2303c9ffb880814be999c5 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Fri, 9 Aug 2024 15:48:42 +0200 Subject: [PATCH 18/26] update transfer button title --- src/languages/en.ts | 1 + src/languages/es.ts | 1 + .../workspace/invoices/WorkspaceTransferInvoiceBalance.tsx | 4 +--- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index 6ce370738e4e3..4a7f8e4bfa689 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -284,6 +284,7 @@ export default { join: 'Join', leave: 'Leave', decline: 'Decline', + transfer: 'Transfer', transferBalance: 'Transfer balance', cantFindAddress: "Can't find your address? ", enterManually: 'Enter it manually', diff --git a/src/languages/es.ts b/src/languages/es.ts index ad07a59b60999..5a91646641631 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -274,6 +274,7 @@ export default { join: 'Unirse', leave: 'Salir', decline: 'Rechazar', + transfer: 'Transferencia', transferBalance: 'Transferencia de saldo', cantFindAddress: '¿No encuentras tu dirección? ', enterManually: 'Introducir manualmente', diff --git a/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx b/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx index b1f1cf1b7e6de..7efc0957cd872 100644 --- a/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx +++ b/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx @@ -140,9 +140,7 @@ function WorkspaceTransferInvoiceBalance({ PaymentMethods.transferInvoiceBalance(policyID)} isDisabled={isButtonDisabled || isOffline} From e274b8f8a312068911486a608fbf3ed989f59f55 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Fri, 9 Aug 2024 16:00:29 +0200 Subject: [PATCH 19/26] clear redundant press --- src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx b/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx index 7efc0957cd872..6fa1b52266b7a 100644 --- a/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx +++ b/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx @@ -116,7 +116,6 @@ function WorkspaceTransferInvoiceBalance({ ...styles.transferBalanceSelectedPayment, }} interactive={false} - onPress={() => console.debug('ACH')} /> {translate('transferAmountPage.whichAccount')} From 52cc88b6a0ad262f56f052b83e684fe37dbacf43 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Fri, 9 Aug 2024 16:01:36 +0200 Subject: [PATCH 20/26] update comment --- .../workspace/invoices/WorkspaceTransferInvoiceBalance.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx b/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx index 6fa1b52266b7a..783dbe9b82d22 100644 --- a/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx +++ b/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx @@ -80,7 +80,7 @@ function WorkspaceTransferInvoiceBalance({ accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN, CONST.POLICY.ACCESS_VARIANTS.PAID]} policyID={policyID} shouldBeBlocked={!selectedAccount} - // TODO: uncomment when CONST.POLICY.MORE_FEATURES.ARE_INVOICES_ENABLED is supported + // TODO: Uncomment the following line when the invoices screen is ready - https://github.com/Expensify/App/issues/45175. // featureName={CONST.POLICY.MORE_FEATURES.ARE_INVOICES_ENABLED} > Date: Fri, 9 Aug 2024 16:52:52 +0200 Subject: [PATCH 21/26] add empty lines --- src/components/Balance.tsx | 1 + src/components/CurrentWalletBalance.tsx | 1 + 2 files changed, 2 insertions(+) diff --git a/src/components/Balance.tsx b/src/components/Balance.tsx index b0db99993b65f..b9cd93f0ed7bc 100644 --- a/src/components/Balance.tsx +++ b/src/components/Balance.tsx @@ -12,6 +12,7 @@ type BalanceProps = { function Balance({textStyles, balance}: BalanceProps) { const styles = useThemeStyles(); const formattedBalance = CurrencyUtils.convertToDisplayString(balance); + return {formattedBalance}; } diff --git a/src/components/CurrentWalletBalance.tsx b/src/components/CurrentWalletBalance.tsx index 4391593d40949..5f0fa08ed3f5d 100644 --- a/src/components/CurrentWalletBalance.tsx +++ b/src/components/CurrentWalletBalance.tsx @@ -18,6 +18,7 @@ type CurrentWalletBalanceProps = CurrentWalletBalanceOnyxProps & { function CurrentWalletBalance({userWallet, balanceStyles}: CurrentWalletBalanceProps) { const styles = useThemeStyles(); + return ( Date: Tue, 3 Sep 2024 10:49:07 +0200 Subject: [PATCH 22/26] uncomment enabling feature line --- .../workspace/invoices/WorkspaceTransferInvoiceBalance.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx b/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx index 783dbe9b82d22..9708e7ed0ea20 100644 --- a/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx +++ b/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx @@ -80,8 +80,7 @@ function WorkspaceTransferInvoiceBalance({ accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN, CONST.POLICY.ACCESS_VARIANTS.PAID]} policyID={policyID} shouldBeBlocked={!selectedAccount} - // TODO: Uncomment the following line when the invoices screen is ready - https://github.com/Expensify/App/issues/45175. - // featureName={CONST.POLICY.MORE_FEATURES.ARE_INVOICES_ENABLED} + featureName={CONST.POLICY.MORE_FEATURES.ARE_INVOICES_ENABLED} > Date: Wed, 25 Sep 2024 12:31:04 +0200 Subject: [PATCH 23/26] revert transfer balance --- src/ONYXKEYS.ts | 5 - src/ROUTES.ts | 4 - src/SCREENS.ts | 1 - src/languages/en.ts | 1 - src/languages/es.ts | 1 - .../TransferInvoiceBalanceParams.ts | 6 - src/libs/API/parameters/index.ts | 1 - src/libs/API/types.ts | 2 - .../ModalStackNavigators/index.tsx | 1 - .../FULL_SCREEN_TO_RHP_MAPPING.ts | 2 +- src/libs/Navigation/linkingConfig/config.ts | 3 - src/libs/Navigation/types.ts | 3 - src/libs/actions/PaymentMethods.ts | 76 --------- .../WorkspaceInvoiceBalanceSection.tsx | 17 -- .../WorkspaceTransferInvoiceBalance.tsx | 157 ------------------ src/styles/index.ts | 8 - src/types/onyx/InvoiceBalanceTransfer.ts | 15 -- src/types/onyx/index.ts | 2 - 18 files changed, 1 insertion(+), 304 deletions(-) delete mode 100644 src/libs/API/parameters/TransferInvoiceBalanceParams.ts delete mode 100644 src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx delete mode 100644 src/types/onyx/InvoiceBalanceTransfer.ts diff --git a/src/ONYXKEYS.ts b/src/ONYXKEYS.ts index 9d7f03b45cfb8..7fcb675dc191e 100755 --- a/src/ONYXKEYS.ts +++ b/src/ONYXKEYS.ts @@ -411,12 +411,8 @@ const ONYXKEYS = { /** Stores the information about currently edited advanced approval workflow */ APPROVAL_WORKFLOW: 'approvalWorkflow', - /** Stores the information about the invoice balance transfer */ - INVOICE_BALANCE_TRANSFER: 'invoiceBalanceTransfer', - /** Stores the user search value for persistance across the screens */ ROOM_MEMBERS_USER_SEARCH_PHRASE: 'roomMembersUserSearchPhrase', - /** Stores information about recently uploaded spreadsheet file */ IMPORTED_SPREADSHEET: 'importedSpreadsheet', @@ -983,7 +979,6 @@ type OnyxValuesMapping = { [ONYXKEYS.NVP_WORKSPACE_TOOLTIP]: OnyxTypes.WorkspaceTooltip; [ONYXKEYS.NVP_SHOULD_HIDE_GBR_TOOLTIP]: boolean; [ONYXKEYS.NVP_PRIVATE_CANCELLATION_DETAILS]: OnyxTypes.CancellationDetails[]; - [ONYXKEYS.INVOICE_BALANCE_TRANSFER]: OnyxTypes.InvoiceBalanceTransfer; [ONYXKEYS.ROOM_MEMBERS_USER_SEARCH_PHRASE]: string; [ONYXKEYS.APPROVAL_WORKFLOW]: OnyxTypes.ApprovalWorkflowOnyx; [ONYXKEYS.IMPORTED_SPREADSHEET]: OnyxTypes.ImportedSpreadsheet; diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 12a8780ed9bd3..c0ec944b71e1c 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -688,10 +688,6 @@ const ROUTES = { route: 'settings/workspaces/:policyID/invoices', getRoute: (policyID: string) => `settings/workspaces/${policyID}/invoices` as const, }, - WORKSPACE_INVOICES_TRANSFER_BALANCE: { - route: 'settings/workspaces/:policyID/invoices/transfer-balance', - getRoute: (policyID: string) => `settings/workspaces/${policyID}/invoices/transfer-balance` as const, - }, WORKSPACE_INVOICES_COMPANY_NAME: { route: 'settings/workspaces/:policyID/invoices/company-name', getRoute: (policyID: string) => `settings/workspaces/${policyID}/invoices/company-name` as const, diff --git a/src/SCREENS.ts b/src/SCREENS.ts index 8ae7249c42e76..920bd48dd42e5 100644 --- a/src/SCREENS.ts +++ b/src/SCREENS.ts @@ -398,7 +398,6 @@ const SCREENS = { EXPENSIFY_CARD_SETTINGS_ACCOUNT: 'Workspace_ExpensifyCard_Settings_Account', EXPENSIFY_CARD_SETTINGS_FREQUENCY: 'Workspace_ExpensifyCard_Settings_Frequency', INVOICES: 'Workspace_Invoices', - INVOICES_TRANSFER_BALANCE: 'Workspace_Invoices_Transfer_Balance', INVOICES_COMPANY_NAME: 'Workspace_Invoices_Company_Name', INVOICES_COMPANY_WEBSITE: 'Workspace_Invoices_Company_Website', MEMBERS: 'Workspace_Members', diff --git a/src/languages/en.ts b/src/languages/en.ts index 9ac72dd58c5b2..d9d5ac89a9af3 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -296,7 +296,6 @@ export default { join: 'Join', leave: 'Leave', decline: 'Decline', - transfer: 'Transfer', transferBalance: 'Transfer balance', cantFindAddress: "Can't find your address? ", enterManually: 'Enter it manually', diff --git a/src/languages/es.ts b/src/languages/es.ts index e90d1b3214fc2..e39026fb1e855 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -287,7 +287,6 @@ export default { join: 'Unirse', leave: 'Salir', decline: 'Rechazar', - transfer: 'Transferencia', transferBalance: 'Transferencia de saldo', cantFindAddress: '¿No encuentras tu dirección? ', enterManually: 'Introducir manualmente', diff --git a/src/libs/API/parameters/TransferInvoiceBalanceParams.ts b/src/libs/API/parameters/TransferInvoiceBalanceParams.ts deleted file mode 100644 index 1e0532ff4b83f..0000000000000 --- a/src/libs/API/parameters/TransferInvoiceBalanceParams.ts +++ /dev/null @@ -1,6 +0,0 @@ -type TransferInvoiceBalanceParams = { - policyID: string; - authToken: string; -}; - -export default TransferInvoiceBalanceParams; diff --git a/src/libs/API/parameters/index.ts b/src/libs/API/parameters/index.ts index 62367959618b8..e5cde1b77be72 100644 --- a/src/libs/API/parameters/index.ts +++ b/src/libs/API/parameters/index.ts @@ -272,7 +272,6 @@ export type {default as ExportSearchItemsToCSVParams} from './ExportSearchItemsT export type {default as UpdateExpensifyCardLimitParams} from './UpdateExpensifyCardLimitParams'; export type {CreateWorkspaceApprovalParams, UpdateWorkspaceApprovalParams, RemoveWorkspaceApprovalParams} from './WorkspaceApprovalParams'; export type {default as StartIssueNewCardFlowParams} from './StartIssueNewCardFlowParams'; -export type {default as TransferInvoiceBalanceParams} from './TransferInvoiceBalanceParams'; export type {default as ConnectAsDelegateParams} from './ConnectAsDelegateParams'; export type {default as SetPolicyRulesEnabledParams} from './SetPolicyRulesEnabledParams'; export type {default as SetPolicyDefaultReportTitleParams} from './SetPolicyDefaultReportTitle'; diff --git a/src/libs/API/types.ts b/src/libs/API/types.ts index f4ce6fe7ba481..88372382d3c84 100644 --- a/src/libs/API/types.ts +++ b/src/libs/API/types.ts @@ -374,7 +374,6 @@ const WRITE_COMMANDS = { CREATE_WORKSPACE_APPROVAL: 'CreateWorkspaceApproval', UPDATE_WORKSPACE_APPROVAL: 'UpdateWorkspaceApproval', REMOVE_WORKSPACE_APPROVAL: 'RemoveWorkspaceApproval', - TRANSFER_POLICY_ACCOUNT_BALANCE: 'TransferPolicyAccountBalance', CONFIGURE_EXPENSIFY_CARDS_FOR_POLICY: 'ConfigureExpensifyCardsForPolicy', CREATE_EXPENSIFY_CARD: 'CreateExpensifyCard', CREATE_ADMIN_ISSUED_VIRTUAL_CARD: 'CreateAdminIssuedVirtualCard', @@ -795,7 +794,6 @@ type WriteCommandParameters = { [WRITE_COMMANDS.CREATE_WORKSPACE_APPROVAL]: Parameters.CreateWorkspaceApprovalParams; [WRITE_COMMANDS.UPDATE_WORKSPACE_APPROVAL]: Parameters.UpdateWorkspaceApprovalParams; [WRITE_COMMANDS.REMOVE_WORKSPACE_APPROVAL]: Parameters.RemoveWorkspaceApprovalParams; - [WRITE_COMMANDS.TRANSFER_POLICY_ACCOUNT_BALANCE]: Parameters.TransferInvoiceBalanceParams; [WRITE_COMMANDS.CONFIGURE_EXPENSIFY_CARDS_FOR_POLICY]: Parameters.ConfigureExpensifyCardsForPolicyParams; [WRITE_COMMANDS.CREATE_EXPENSIFY_CARD]: Omit; [WRITE_COMMANDS.CREATE_ADMIN_ISSUED_VIRTUAL_CARD]: Omit; diff --git a/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx b/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx index 728d298094118..4108addac0f35 100644 --- a/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx +++ b/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx @@ -434,7 +434,6 @@ const SettingsModalStackNavigator = createModalStackNavigator require('../../../../pages/workspace/taxes/ValuePage').default, [SCREENS.WORKSPACE.TAX_CREATE]: () => require('../../../../pages/workspace/taxes/WorkspaceCreateTaxPage').default, [SCREENS.WORKSPACE.TAX_CODE]: () => require('../../../../pages/workspace/taxes/WorkspaceTaxCodePage').default, - [SCREENS.WORKSPACE.INVOICES_TRANSFER_BALANCE]: () => require('../../../../pages/workspace/invoices/WorkspaceTransferInvoiceBalance').default, [SCREENS.WORKSPACE.INVOICES_COMPANY_NAME]: () => require('../../../../pages/workspace/invoices/WorkspaceInvoicingDetailsName').default, [SCREENS.WORKSPACE.INVOICES_COMPANY_WEBSITE]: () => require('../../../../pages/workspace/invoices/WorkspaceInvoicingDetailsWebsite').default, [SCREENS.WORKSPACE.COMPANY_CARDS_ASSIGN_CARD]: () => require('../../../../pages/workspace/companyCards/assignCard/AssignCardFeedPage').default, diff --git a/src/libs/Navigation/linkingConfig/FULL_SCREEN_TO_RHP_MAPPING.ts b/src/libs/Navigation/linkingConfig/FULL_SCREEN_TO_RHP_MAPPING.ts index 6d38baf607fca..6d8871e5a38a4 100755 --- a/src/libs/Navigation/linkingConfig/FULL_SCREEN_TO_RHP_MAPPING.ts +++ b/src/libs/Navigation/linkingConfig/FULL_SCREEN_TO_RHP_MAPPING.ts @@ -173,7 +173,7 @@ const FULL_SCREEN_TO_RHP_MAPPING: Partial> = { SCREENS.WORKSPACE.REPORT_FIELDS_EDIT_VALUE, SCREENS.WORKSPACE.REPORT_FIELDS_EDIT_INITIAL_VALUE, ], - [SCREENS.WORKSPACE.INVOICES]: [SCREENS.WORKSPACE.INVOICES_COMPANY_NAME, SCREENS.WORKSPACE.INVOICES_COMPANY_WEBSITE, SCREENS.WORKSPACE.INVOICES_TRANSFER_BALANCE], + [SCREENS.WORKSPACE.INVOICES]: [SCREENS.WORKSPACE.INVOICES_COMPANY_NAME, SCREENS.WORKSPACE.INVOICES_COMPANY_WEBSITE], [SCREENS.WORKSPACE.COMPANY_CARDS]: [ SCREENS.WORKSPACE.COMPANY_CARDS_SELECT_FEED, SCREENS.WORKSPACE.COMPANY_CARDS_ADD_NEW, diff --git a/src/libs/Navigation/linkingConfig/config.ts b/src/libs/Navigation/linkingConfig/config.ts index da5d5eb3cbc61..f90ddbe2f818e 100644 --- a/src/libs/Navigation/linkingConfig/config.ts +++ b/src/libs/Navigation/linkingConfig/config.ts @@ -500,9 +500,6 @@ const config: LinkingOptions['config'] = { [SCREENS.WORKSPACE.SHARE]: { path: ROUTES.WORKSPACE_PROFILE_SHARE.route, }, - [SCREENS.WORKSPACE.INVOICES_TRANSFER_BALANCE]: { - path: ROUTES.WORKSPACE_INVOICES_TRANSFER_BALANCE.route, - }, [SCREENS.WORKSPACE.INVOICES_COMPANY_NAME]: { path: ROUTES.WORKSPACE_INVOICES_COMPANY_NAME.route, }, diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index fc9604014772c..1326a0c86709f 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -716,9 +716,6 @@ type SettingsNavigatorParamList = { policyID: string; taxID: string; }; - [SCREENS.WORKSPACE.INVOICES_TRANSFER_BALANCE]: { - policyID: string; - }; [SCREENS.WORKSPACE.INVOICES_COMPANY_NAME]: { policyID: string; }; diff --git a/src/libs/actions/PaymentMethods.ts b/src/libs/actions/PaymentMethods.ts index 3943fbd3f2c42..bac3739af810d 100644 --- a/src/libs/actions/PaymentMethods.ts +++ b/src/libs/actions/PaymentMethods.ts @@ -10,14 +10,12 @@ import type { DeletePaymentCardParams, MakeDefaultPaymentMethodParams, PaymentCardParams, - TransferInvoiceBalanceParams, TransferWalletBalanceParams, UpdateBillingCurrencyParams, } from '@libs/API/parameters'; import {READ_COMMANDS, SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from '@libs/API/types'; import * as CardUtils from '@libs/CardUtils'; import Navigation from '@libs/Navigation/Navigation'; -import * as NetworkStore from '@libs/Network/NetworkStore'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Route} from '@src/ROUTES'; @@ -533,77 +531,6 @@ function setPaymentCardForm(values: AccountData) { }); } -/** - * Transfers invoice balance to a bank account - */ -function transferInvoiceBalance(policyID: string) { - const authToken = NetworkStore.getAuthToken(); - - if (!authToken) { - return; - } - - const optimisticData: OnyxUpdate[] = [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.INVOICE_BALANCE_TRANSFER, - value: { - loading: true, - }, - }, - ]; - const successData: OnyxUpdate[] = [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.INVOICE_BALANCE_TRANSFER, - value: { - loading: false, - shouldShowSuccess: true, - }, - }, - ]; - const failureData: OnyxUpdate[] = [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.INVOICE_BALANCE_TRANSFER, - value: { - loading: false, - shouldShowSuccess: false, - }, - }, - ]; - - const parameters: TransferInvoiceBalanceParams = { - policyID, - authToken, - }; - - API.write(WRITE_COMMANDS.TRANSFER_POLICY_ACCOUNT_BALANCE, parameters, { - optimisticData, - successData, - failureData, - }); -} - -/** - * Resets the invoice balance transfer data - */ -function resetInvoiceTransferData() { - Onyx.set(ONYXKEYS.INVOICE_BALANCE_TRANSFER, { - loading: false, - shouldShowSuccess: false, - errors: null, - }); -} - -/** - * Dismisses the successful invoice transfer balance page - */ -function dismissSuccessfulInvoiceTransferBalancePage() { - Onyx.merge(ONYXKEYS.INVOICE_BALANCE_TRANSFER, {shouldShowSuccess: false}); - Navigation.goBack(); -} - export { deletePaymentCard, addPaymentCard, @@ -628,7 +555,4 @@ export { clearWalletTermsError, setPaymentCardForm, verifySetupIntent, - transferInvoiceBalance, - resetInvoiceTransferData, - dismissSuccessfulInvoiceTransferBalancePage, }; diff --git a/src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.tsx b/src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.tsx index 23e2582e08372..5131dea983685 100644 --- a/src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.tsx +++ b/src/pages/workspace/invoices/WorkspaceInvoiceBalanceSection.tsx @@ -1,13 +1,10 @@ import React from 'react'; import {useOnyx} from 'react-native-onyx'; import Balance from '@components/Balance'; -import * as Expensicons from '@components/Icon/Expensicons'; import Section from '@components/Section'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; -import Navigation from '@libs/Navigation/Navigation'; import ONYXKEYS from '@src/ONYXKEYS'; -import ROUTES from '@src/ROUTES'; type WorkspaceInvoiceBalanceSectionProps = { /** The policy ID currently being configured */ @@ -27,20 +24,6 @@ function WorkspaceInvoiceBalanceSection({policyID}: WorkspaceInvoiceBalanceSecti titleStyles={styles.textStrong} childrenStyles={styles.pt5} subtitleMuted - menuItems={ - policy?.invoice?.bankAccount - ? [ - { - title: translate('common.transferBalance'), - onPress: () => Navigation.navigate(ROUTES.WORKSPACE_INVOICES_TRANSFER_BALANCE.getRoute(policyID)), - icon: Expensicons.Transfer, - shouldShowRightIcon: true, - iconRight: Expensicons.ArrowRight, - wrapperStyle: [styles.workspaceTransferBalance], - }, - ] - : [] - } > diff --git a/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx b/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx deleted file mode 100644 index 9708e7ed0ea20..0000000000000 --- a/src/pages/workspace/invoices/WorkspaceTransferInvoiceBalance.tsx +++ /dev/null @@ -1,157 +0,0 @@ -import type {StackScreenProps} from '@react-navigation/stack'; -import React, {useEffect} from 'react'; -import {View} from 'react-native'; -import {useOnyx} from 'react-native-onyx'; -import Balance from '@components/Balance'; -import ConfirmationPage from '@components/ConfirmationPage'; -import FormAlertWithSubmitButton from '@components/FormAlertWithSubmitButton'; -import HeaderWithBackButton from '@components/HeaderWithBackButton'; -import * as Expensicons from '@components/Icon/Expensicons'; -import MenuItem from '@components/MenuItem'; -import ScreenWrapper from '@components/ScreenWrapper'; -import ScrollView from '@components/ScrollView'; -import Text from '@components/Text'; -import useLocalize from '@hooks/useLocalize'; -import useNetwork from '@hooks/useNetwork'; -import useStyledSafeAreaInsets from '@hooks/useStyledSafeAreaInsets'; -import useThemeStyles from '@hooks/useThemeStyles'; -import * as CurrencyUtils from '@libs/CurrencyUtils'; -import * as ErrorUtils from '@libs/ErrorUtils'; -import type {SettingsNavigatorParamList} from '@libs/Navigation/types'; -import * as PaymentUtils from '@libs/PaymentUtils'; -import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; -import variables from '@styles/variables'; -import * as PaymentMethods from '@userActions/PaymentMethods'; -import CONST from '@src/CONST'; -import ONYXKEYS from '@src/ONYXKEYS'; -import type SCREENS from '@src/SCREENS'; -import type PaymentMethod from '@src/types/onyx/PaymentMethod'; -import {isEmptyObject} from '@src/types/utils/EmptyObject'; - -type WorkspaceTransferInvoiceBalanceProps = StackScreenProps; - -function WorkspaceTransferInvoiceBalance({ - route: { - params: {policyID}, - }, -}: WorkspaceTransferInvoiceBalanceProps) { - const styles = useThemeStyles(); - const {isOffline} = useNetwork(); - const {paddingBottom} = useStyledSafeAreaInsets(); - const {translate} = useLocalize(); - const [invoiceBalanceTransfer] = useOnyx(ONYXKEYS.INVOICE_BALANCE_TRANSFER); - const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`); - const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST); - const [fundList] = useOnyx(ONYXKEYS.FUND_LIST); - - useEffect(() => { - PaymentMethods.resetInvoiceTransferData(); - }, []); - - if (invoiceBalanceTransfer?.shouldShowSuccess && !invoiceBalanceTransfer?.loading) { - return ( - - - - - ); - } - - const paymentMethods = PaymentUtils.formatPaymentMethods(bankAccountList ?? {}, fundList ?? {}, styles); - const selectedAccount: PaymentMethod | null = paymentMethods.find((paymentMethod) => paymentMethod.methodID === policy?.invoice?.bankAccount?.transferBankAccountID) ?? null; - const balance = policy?.invoice?.bankAccount?.stripeConnectAccountBalance ?? 0; - const calculatedFee = PaymentUtils.calculateWalletTransferBalanceFee(balance, CONST.WALLET.TRANSFER_METHOD_TYPE.ACH); - const transferAmount = balance - calculatedFee; - const isTransferable = transferAmount > 0; - const isButtonDisabled = !isTransferable || !selectedAccount; - const errorMessage = ErrorUtils.getLatestErrorMessage(invoiceBalanceTransfer); - - return ( - - - - - - - - - - - - {translate('transferAmountPage.whichAccount')} - {!!selectedAccount && ( - - )} - - {translate('transferAmountPage.fee')} - {CurrencyUtils.convertToDisplayString(calculatedFee)} - - - - PaymentMethods.transferInvoiceBalance(policyID)} - isDisabled={isButtonDisabled || isOffline} - message={errorMessage} - isAlertVisible={!isEmptyObject(errorMessage)} - containerStyles={[styles.ph5, !paddingBottom ? styles.pb5 : null]} - /> - - - - ); -} - -WorkspaceTransferInvoiceBalance.displayName = 'WorkspaceTransferInvoiceBalance'; - -export default WorkspaceTransferInvoiceBalance; diff --git a/src/styles/index.ts b/src/styles/index.ts index 408fbee7540e4..f94a047fd4592 100644 --- a/src/styles/index.ts +++ b/src/styles/index.ts @@ -5186,14 +5186,6 @@ const styles = (theme: ThemeColors) => ...display.dFlex, }, - workspaceTransferBalance: { - height: variables.optionRowHeight, - marginTop: 20, - paddingLeft: 8, - paddingRight: 0, - borderRadius: 100, - }, - workflowApprovalVerticalLine: { height: 16, width: 1, diff --git a/src/types/onyx/InvoiceBalanceTransfer.ts b/src/types/onyx/InvoiceBalanceTransfer.ts deleted file mode 100644 index c98410a744c5a..0000000000000 --- a/src/types/onyx/InvoiceBalanceTransfer.ts +++ /dev/null @@ -1,15 +0,0 @@ -import type * as OnyxCommon from './OnyxCommon'; - -/** Model of invoice balance transfer */ -type InvoiceBalanceTransfer = { - /** Whether the data is being fetched from server */ - loading: boolean; - - /** Whether the success screen is shown to user. */ - shouldShowSuccess: boolean; - - /** Error messages to show in UI */ - errors?: OnyxCommon.Errors; -}; - -export default InvoiceBalanceTransfer; diff --git a/src/types/onyx/index.ts b/src/types/onyx/index.ts index 6906dad4678c4..420ccf884f91f 100644 --- a/src/types/onyx/index.ts +++ b/src/types/onyx/index.ts @@ -27,7 +27,6 @@ import type Fund from './Fund'; import type ImportedSpreadsheet from './ImportedSpreadsheet'; import type IntroSelected from './IntroSelected'; import type InvitedEmailsToAccountIDs from './InvitedEmailsToAccountIDs'; -import type InvoiceBalanceTransfer from './InvoiceBalanceTransfer'; import type IOU from './IOU'; import type LastExportMethod from './LastExportMethod'; import type LastPaymentMethod from './LastPaymentMethod'; @@ -228,7 +227,6 @@ export type { CancellationDetails, ApprovalWorkflowOnyx, MobileSelectionMode, - InvoiceBalanceTransfer, WorkspaceTooltip, CardFeeds, SaveSearch, From cda95f15635bdeec92d6c0bb45a00de8cd19830f Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Wed, 25 Sep 2024 12:42:24 +0200 Subject: [PATCH 24/26] use hooks and remove withOnyx --- src/components/CurrentWalletBalance.tsx | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/components/CurrentWalletBalance.tsx b/src/components/CurrentWalletBalance.tsx index 5f0fa08ed3f5d..743d284caf6c3 100644 --- a/src/components/CurrentWalletBalance.tsx +++ b/src/components/CurrentWalletBalance.tsx @@ -1,23 +1,17 @@ import React from 'react'; import type {StyleProp, TextStyle} from 'react-native'; -import type {OnyxEntry} from 'react-native-onyx'; -import {withOnyx} from 'react-native-onyx'; +import {useOnyx} from 'react-native-onyx'; import useThemeStyles from '@hooks/useThemeStyles'; import ONYXKEYS from '@src/ONYXKEYS'; -import type UserWallet from '@src/types/onyx/UserWallet'; import Balance from './Balance'; -type CurrentWalletBalanceOnyxProps = { - /** The user's wallet account */ - userWallet: OnyxEntry; -}; - -type CurrentWalletBalanceProps = CurrentWalletBalanceOnyxProps & { +type CurrentWalletBalanceProps = { balanceStyles?: StyleProp; }; -function CurrentWalletBalance({userWallet, balanceStyles}: CurrentWalletBalanceProps) { +function CurrentWalletBalance({balanceStyles}: CurrentWalletBalanceProps) { const styles = useThemeStyles(); + const [userWallet] = useOnyx(ONYXKEYS.USER_WALLET); return ( ({ - userWallet: { - key: ONYXKEYS.USER_WALLET, - }, -})(CurrentWalletBalance); +export default CurrentWalletBalance; From 14d26c4bed19a0daa0ee769162b17d5da26e7d17 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Wed, 25 Sep 2024 19:00:54 +0200 Subject: [PATCH 25/26] Refactor willBlurTextInputOnTapOutside to use getIsNarrowLayout --- src/libs/willBlurTextInputOnTapOutside/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/willBlurTextInputOnTapOutside/index.ts b/src/libs/willBlurTextInputOnTapOutside/index.ts index 987d8a1dfeea7..31a40932189e1 100644 --- a/src/libs/willBlurTextInputOnTapOutside/index.ts +++ b/src/libs/willBlurTextInputOnTapOutside/index.ts @@ -1,5 +1,6 @@ +import getIsNarrowLayout from '@libs/getIsNarrowLayout'; import type WillBlurTextInputOnTapOutside from './types'; -const willBlurTextInputOnTapOutside: WillBlurTextInputOnTapOutside = () => true; +const willBlurTextInputOnTapOutside: WillBlurTextInputOnTapOutside = () => !getIsNarrowLayout(); export default willBlurTextInputOnTapOutside; From d7535c318f3cfc56bfa329cf9b829bd82c9bcaf5 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Wed, 25 Sep 2024 19:02:55 +0200 Subject: [PATCH 26/26] Revert "Refactor willBlurTextInputOnTapOutside to use getIsNarrowLayout" This reverts commit 14d26c4bed19a0daa0ee769162b17d5da26e7d17. --- src/libs/willBlurTextInputOnTapOutside/index.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/willBlurTextInputOnTapOutside/index.ts b/src/libs/willBlurTextInputOnTapOutside/index.ts index 31a40932189e1..987d8a1dfeea7 100644 --- a/src/libs/willBlurTextInputOnTapOutside/index.ts +++ b/src/libs/willBlurTextInputOnTapOutside/index.ts @@ -1,6 +1,5 @@ -import getIsNarrowLayout from '@libs/getIsNarrowLayout'; import type WillBlurTextInputOnTapOutside from './types'; -const willBlurTextInputOnTapOutside: WillBlurTextInputOnTapOutside = () => !getIsNarrowLayout(); +const willBlurTextInputOnTapOutside: WillBlurTextInputOnTapOutside = () => true; export default willBlurTextInputOnTapOutside;