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

Disable add bank account button for non-validated user #46697

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
72 changes: 38 additions & 34 deletions src/pages/AddPersonalBankAccountPage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, {useCallback, useEffect, useState} from 'react';
import {withOnyx} from 'react-native-onyx';
import {useOnyx, withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import AddPlaidBankAccount from '@components/AddPlaidBankAccount';
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
import ConfirmationPage from '@components/ConfirmationPage';
import FormProvider from '@components/Form/FormProvider';
import InputWrapper from '@components/Form/InputWrapper';
Expand Down Expand Up @@ -29,6 +30,7 @@ function AddPersonalBankAccountPage({personalBankAccount, plaidData}: AddPersona
const styles = useThemeStyles();
const {translate} = useLocalize();
const [selectedPlaidAccountId, setSelectedPlaidAccountId] = useState('');
const [isUserValidated] = useOnyx(ONYXKEYS.USER, {selector: (user) => !!user?.validated});
const shouldShowSuccess = personalBankAccount?.shouldShowSuccess ?? false;

const submitBankAccountForm = useCallback(() => {
Expand Down Expand Up @@ -65,41 +67,43 @@ function AddPersonalBankAccountPage({personalBankAccount, plaidData}: AddPersona
shouldShowOfflineIndicator={false}
testID={AddPersonalBankAccountPage.displayName}
>
<HeaderWithBackButton
title={translate('bankAccount.addBankAccount')}
onBackButtonPress={exitFlow}
/>
{shouldShowSuccess ? (
<ConfirmationPage
heading={translate('addPersonalBankAccountPage.successTitle')}
description={translate('addPersonalBankAccountPage.successMessage')}
shouldShowButton
buttonText={translate('common.continue')}
onButtonPress={() => exitFlow(true)}
<FullPageNotFoundView shouldShow={!isUserValidated}>
<HeaderWithBackButton
title={translate('bankAccount.addBankAccount')}
onBackButtonPress={exitFlow}
/>
) : (
<FormProvider
formID={ONYXKEYS.FORMS.PERSONAL_BANK_ACCOUNT_FORM}
isSubmitButtonVisible={(plaidData?.bankAccounts ?? []).length > 0}
submitButtonText={translate('common.saveAndContinue')}
scrollContextEnabled
onSubmit={submitBankAccountForm}
validate={BankAccounts.validatePlaidSelection}
style={[styles.mh5, styles.flex1]}
>
<InputWrapper
inputID={INPUT_IDS.BANK_INFO_STEP.SELECTED_PLAID_ACCOUNT_ID}
InputComponent={AddPlaidBankAccount}
onSelect={setSelectedPlaidAccountId}
text={translate('walletPage.chooseAccountBody')}
plaidData={plaidData}
isDisplayedInWalletFlow
onExitPlaid={() => Navigation.goBack()}
receivedRedirectURI={getPlaidOAuthReceivedRedirectURI()}
selectedPlaidAccountID={selectedPlaidAccountId}
{shouldShowSuccess ? (
<ConfirmationPage
heading={translate('addPersonalBankAccountPage.successTitle')}
description={translate('addPersonalBankAccountPage.successMessage')}
shouldShowButton
buttonText={translate('common.continue')}
onButtonPress={() => exitFlow(true)}
/>
</FormProvider>
)}
) : (
<FormProvider
formID={ONYXKEYS.FORMS.PERSONAL_BANK_ACCOUNT_FORM}
isSubmitButtonVisible={(plaidData?.bankAccounts ?? []).length > 0}
submitButtonText={translate('common.saveAndContinue')}
scrollContextEnabled
onSubmit={submitBankAccountForm}
validate={BankAccounts.validatePlaidSelection}
style={[styles.mh5, styles.flex1]}
>
<InputWrapper
inputID={INPUT_IDS.BANK_INFO_STEP.SELECTED_PLAID_ACCOUNT_ID}
InputComponent={AddPlaidBankAccount}
onSelect={setSelectedPlaidAccountId}
text={translate('walletPage.chooseAccountBody')}
plaidData={plaidData}
isDisplayedInWalletFlow
onExitPlaid={() => Navigation.goBack()}
receivedRedirectURI={getPlaidOAuthReceivedRedirectURI()}
selectedPlaidAccountID={selectedPlaidAccountId}
/>
</FormProvider>
)}
</FullPageNotFoundView>
</ScreenWrapper>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/EnablePayments/AddBankAccount/SetupMethod.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function SetupMethod({isPlaidDisabled, user}: SetupMethodProps) {
icon={Expensicons.Bank}
text={translate('bankAccount.addBankAccount')}
onPress={() => BankAccounts.openPersonalBankAccountSetupWithPlaid()}
isDisabled={isPlaidDisabled ?? !user?.validated}
isDisabled={!!isPlaidDisabled || !user?.validated}
style={[styles.mt4, styles.mb2]}
iconStyles={styles.buttonCTAIcon}
shouldShowRightIcon
Expand Down
6 changes: 4 additions & 2 deletions src/pages/settings/Wallet/PaymentMethodList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, {useCallback, useMemo} from 'react';
import type {GestureResponderEvent, StyleProp, ViewStyle} from 'react-native';
import {FlatList, View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import {useOnyx, withOnyx} from 'react-native-onyx';
import type {SvgProps} from 'react-native-svg/lib/typescript/ReactNativeSVG';
import type {ValueOf} from 'type-fest';
import type {RenderSuggestionMenuItemProps} from '@components/AutoCompleteSuggestions/types';
Expand Down Expand Up @@ -197,6 +197,7 @@ function PaymentMethodList({
const StyleUtils = useStyleUtils();
const {translate} = useLocalize();
const {isOffline} = useNetwork();
const [isUserValidated] = useOnyx(ONYXKEYS.USER, {selector: (user) => !!user?.validated});

const filteredPaymentMethods = useMemo(() => {
if (shouldShowAssignedCards) {
Expand Down Expand Up @@ -320,10 +321,11 @@ function PaymentMethodList({
wrapperStyle={[styles.paymentMethod, listItemStyle]}
hoverAndPressStyle={styles.hoveredComponentBG}
ref={buttonRef}
disabled={!isUserValidated}
/>
),

[onPress, translate, styles.paymentMethod, styles.hoveredComponentBG, listItemStyle, buttonRef],
[onPress, translate, styles.paymentMethod, styles.hoveredComponentBG, listItemStyle, buttonRef, isUserValidated],
);

/**
Expand Down
Loading