Skip to content

Commit

Permalink
feat: verify identity
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMuzyk committed Nov 24, 2023
1 parent 6beb491 commit 88e7b0a
Show file tree
Hide file tree
Showing 12 changed files with 203 additions and 35 deletions.
15 changes: 15 additions & 0 deletions src/libs/actions/BankAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,18 @@ function getVBBADataForOnyx(currentStep?: BankAccountStep): OnyxData {
};
}

function addBusinessWebstieForDraft(website: string) {
Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT_DRAFT, {website});
}

function addBusinessAddressForDraft(businessAddress: {addressStreet?: string; addressCity?: string; addressState?: string; addressZipCode?: string}) {
Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT_DRAFT, businessAddress);
}

function addPersonalAddressForDraft(personalAddress: {requestorAddressStreet?: string; requestorAddressCity?: string; requestorAddressState?: string; requestorAddressZipCode?: string}) {
Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT_DRAFT, personalAddress);
}

/**
* Submit Bank Account step with Plaid data so php can perform some checks.
*/
Expand Down Expand Up @@ -433,6 +445,9 @@ function setReimbursementAccountLoading(isLoading: boolean) {
}

export {
addBusinessWebstieForDraft,
addBusinessAddressForDraft,
addPersonalAddressForDraft,
addPersonalBankAccount,
clearOnfidoToken,
clearPersonalBankAccount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function BusinessInfo({reimbursementAccount, reimbursementAccountDraft, policyID
<InteractiveStepSubHeader
onStepSelected={() => {}}
// TODO Will be replaced with proper values
startStep={2}
startStep={1}
stepNames={STEP_NAMES}
/>
</View>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import {withOnyx} from 'react-native-onyx';
import Form from '@components/Form';
import FormProvider from '@components/Form/FormProvider';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import * as ValidationUtils from '@libs/ValidationUtils';
Expand All @@ -9,6 +9,7 @@ import {reimbursementAccountDefaultProps, reimbursementAccountPropTypes} from '@
import subStepPropTypes from '@pages/ReimbursementAccount/subStepPropTypes';
import getDefaultValueForReimbursementAccountField from '@pages/ReimbursementAccount/utils/getDefaultValueForReimbursementAccountField';
import styles from '@styles/styles';
import * as BankAccounts from '@userActions/BankAccounts';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';

Expand Down Expand Up @@ -58,12 +59,17 @@ function AddressBusiness({reimbursementAccount, onNext, isEditing}) {
zipCode: getDefaultValueForReimbursementAccountField(reimbursementAccount, companyBusinessInfoKey.ZIP_CODE, ''),
};

const handleSubmit = (values) => {
BankAccounts.addBusinessAddressForDraft(values);
onNext();
};

return (
<Form
<FormProvider
formID={ONYXKEYS.REIMBURSEMENT_ACCOUNT}
submitButtonText={isEditing ? translate('common.confirm') : translate('common.next')}
validate={validate}
onSubmit={onNext}
onSubmit={handleSubmit}
submitButtonStyles={[styles.mb0, styles.pb5]}
style={[styles.mh5, styles.flexGrow1]}
>
Expand All @@ -76,7 +82,7 @@ function AddressBusiness({reimbursementAccount, onNext, isEditing}) {
defaultValues={defaultValues}
streetTranslationKey="common.companyAddress"
/>
</Form>
</FormProvider>
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Str from 'expensify-common/lib/str';
import lodashGet from 'lodash/get';
import PropTypes from 'prop-types';
import React, {useMemo} from 'react';
import React, {useEffect, useMemo} from 'react';
import {withOnyx} from 'react-native-onyx';
import Form from '@components/Form';
import Text from '@components/Text';
Expand All @@ -12,6 +12,7 @@ import {reimbursementAccountDefaultProps, reimbursementAccountPropTypes} from '@
import subStepPropTypes from '@pages/ReimbursementAccount/subStepPropTypes';
import getDefaultValueForReimbursementAccountField from '@pages/ReimbursementAccount/utils/getDefaultValueForReimbursementAccountField';
import styles from '@styles/styles';
import * as BankAccounts from '@userActions/BankAccounts';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';

Expand Down Expand Up @@ -61,6 +62,10 @@ function WebsiteBusiness({reimbursementAccount, user, session, onNext, isEditing

const defaultCompanyWebsite = getDefaultValueForReimbursementAccountField(reimbursementAccount, companyWebsiteKey, defaultWebsiteExample);

useEffect(() => {
BankAccounts.addBusinessWebstieForDraft(defaultCompanyWebsite);
}, [defaultCompanyWebsite]);

return (
<Form
formID={ONYXKEYS.REIMBURSEMENT_ACCOUNT}
Expand Down
9 changes: 6 additions & 3 deletions src/pages/ReimbursementAccount/PersonalInfo/PersonalInfo.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import PropTypes from 'prop-types';
import React, {useCallback, useMemo} from 'react';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
Expand Down Expand Up @@ -30,6 +31,8 @@ const propTypes = {

/** The draft values of the bank account being setup */
reimbursementAccountDraft: reimbursementAccountDraftPropTypes,

onBackButtonPress: PropTypes.func.isRequired,
};

const defaultProps = {
Expand All @@ -44,7 +47,7 @@ const STEP_NAMES = ['1', '2', '3', '4', '5'];
const bodyContent = [FullName, DateOfBirth, SocialSecurityNumber, Address, Confirmation];
const personalInfoStepKeys = CONST.BANK_ACCOUNT.PERSONAL_INFO_STEP.INPUT_KEY;

function PersonalInfo({reimbursementAccount, reimbursementAccountDraft}) {
function PersonalInfo({reimbursementAccount, reimbursementAccountDraft, onBackButtonPress}) {
const {translate} = useLocalize();

const values = useMemo(() => getSubstepValues(personalInfoStepKeys, reimbursementAccountDraft, reimbursementAccount), [reimbursementAccount, reimbursementAccountDraft]);
Expand All @@ -63,7 +66,7 @@ function PersonalInfo({reimbursementAccount, reimbursementAccountDraft}) {

const handleBackButtonPress = () => {
if (screenIndex === 0) {
Navigation.goBack(ROUTES.HOME);
onBackButtonPress();
} else {
prevScreen();
}
Expand All @@ -84,7 +87,7 @@ function PersonalInfo({reimbursementAccount, reimbursementAccountDraft}) {
<InteractiveStepSubHeader
onStepSelected={() => {}}
// TODO Will be replaced with proper values
startStep={1}
startStep={2}
stepNames={STEP_NAMES}
/>
</View>
Expand Down
14 changes: 10 additions & 4 deletions src/pages/ReimbursementAccount/PersonalInfo/substeps/Address.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import Form from '@components/Form';
import FormProvider from '@components/Form/FormProvider';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import * as ValidationUtils from '@libs/ValidationUtils';
Expand All @@ -12,6 +12,7 @@ import * as ReimbursementAccountProps from '@pages/ReimbursementAccount/reimburs
import subStepPropTypes from '@pages/ReimbursementAccount/subStepPropTypes';
import getDefaultValueForReimbursementAccountField from '@pages/ReimbursementAccount/utils/getDefaultValueForReimbursementAccountField';
import styles from '@styles/styles';
import * as BankAccounts from '@userActions/BankAccounts';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';

Expand Down Expand Up @@ -61,12 +62,17 @@ function Address({reimbursementAccount, onNext, isEditing}) {
zipCode: getDefaultValueForReimbursementAccountField(reimbursementAccount, personalInfoStepKey.ZIP_CODE, ''),
};

const handleSubmit = (values) => {
BankAccounts.addPersonalAddressForDraft(values);
onNext();
};

return (
<Form
<FormProvider
formID={ONYXKEYS.REIMBURSEMENT_ACCOUNT}
submitButtonText={isEditing ? translate('common.confirm') : translate('common.next')}
validate={validate}
onSubmit={onNext}
onSubmit={handleSubmit}
submitButtonStyles={[styles.mb0, styles.pb5]}
style={[styles.mh5, styles.flexGrow1]}
>
Expand All @@ -85,7 +91,7 @@ function Address({reimbursementAccount, onNext, isEditing}) {
containerStyles={[styles.mt5]}
/>
</View>
</Form>
</FormProvider>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ function FullName({reimbursementAccount, onNext, isEditing}) {
<TextInput
inputID={personalInfoStepKey.FIRST_NAME}
label={translate('personalInfoStep.legalFirstName')}
accessibilityLabel={translate('personalInfoStep.legalFirstName')}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.TEXT}
aria-label={translate('personalInfoStep.legalFirstName')}
role={CONST.ACCESSIBILITY_ROLE.TEXT}
defaultValue={defaultValues.firstName}
shouldSaveDraft
/>
Expand All @@ -65,8 +65,8 @@ function FullName({reimbursementAccount, onNext, isEditing}) {
<TextInput
inputID={personalInfoStepKey.LAST_NAME}
label={translate('personalInfoStep.legalLastName')}
accessibilityLabel={translate('personalInfoStep.legalLastName')}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.TEXT}
aria-label={translate('personalInfoStep.legalLastName')}
role={CONST.ACCESSIBILITY_ROLE.TEXT}
defaultValue={defaultValues.lastName}
shouldSaveDraft
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ function SocialSecurityNumber({reimbursementAccount, onNext, isEditing}) {
<TextInput
inputID={personalInfoStepKey.SSN_LAST_4}
label={translate('personalInfoStep.last4SSN')}
accessibilityLabel={translate('personalInfoStep.last4SSN')}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.TEXT}
aria-label={translate('personalInfoStep.last4SSN')}
role={CONST.ACCESSIBILITY_ROLE.TEXT}
containerStyles={[styles.mt4]}
keyboardType={CONST.KEYBOARD_TYPE.NUMBER_PAD}
defaultValue={defaultSsnLast4}
Expand Down
3 changes: 0 additions & 3 deletions src/pages/ReimbursementAccount/ReimbursementAccountPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,11 +494,8 @@ class ReimbursementAccountPage extends React.Component {
const shouldShowOnfido = this.props.onfidoToken && !achData.isOnfidoSetupComplete;
return (
<RequestorStep
ref={this.requestorStepRef}
reimbursementAccount={this.props.reimbursementAccount}
onBackButtonPress={this.goBack}
shouldShowOnfido={Boolean(shouldShowOnfido)}
getDefaultStateForField={this.getDefaultStateForField}
/>
);
}
Expand Down
17 changes: 4 additions & 13 deletions src/pages/ReimbursementAccount/RequestorStep.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
import PropTypes from 'prop-types';
import React from 'react';
import VerifyIdentity from '@pages/ReimbursementAccount/VerifyIdentity/VerifyIdentity';

Check warning on line 3 in src/pages/ReimbursementAccount/RequestorStep.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected subpath import via alias '@pages/ReimbursementAccount/VerifyIdentity/VerifyIdentity'. Use './VerifyIdentity/VerifyIdentity' instead
import PersonalInfo from './PersonalInfo/PersonalInfo';
import {reimbursementAccountPropTypes} from './reimbursementAccountPropTypes';
import RequestorOnfidoStep from './RequestorOnfidoStep';

const propTypes = {
onBackButtonPress: PropTypes.func.isRequired,
reimbursementAccount: reimbursementAccountPropTypes.isRequired,

/** If we should show Onfido flow */
shouldShowOnfido: PropTypes.bool.isRequired,
};

const RequestorStep = React.forwardRef(({reimbursementAccount, shouldShowOnfido, onBackButtonPress}, ref) => {
const RequestorStep = React.forwardRef(({shouldShowOnfido, onBackButtonPress}) => {
if (shouldShowOnfido) {
return (
<RequestorOnfidoStep
ref={ref}
reimbursementAccount={reimbursementAccount}
onBackButtonPress={onBackButtonPress}
/>
);
return <VerifyIdentity onBackButtonPress={onBackButtonPress} />;
}

return <PersonalInfo />;
return <PersonalInfo onBackButtonPress={onBackButtonPress} />;
});

RequestorStep.propTypes = propTypes;
Expand Down
79 changes: 79 additions & 0 deletions src/pages/ReimbursementAccount/VerifyIdentity/VerifyIdentity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import PropTypes from 'prop-types';
import React, {useCallback} from 'react';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import InteractiveStepSubHeader from '@components/InteractiveStepSubHeader';
import ScreenWrapper from '@components/ScreenWrapper';
import useLocalize from '@hooks/useLocalize';
import useSubStep from '@hooks/useSubStep';
import {reimbursementAccountPropTypes} from '@pages/ReimbursementAccount/reimbursementAccountPropTypes';
import * as ReimbursementAccountProps from '@pages/ReimbursementAccount/reimbursementAccountPropTypes';
import getDefaultValueForReimbursementAccountField from '@pages/ReimbursementAccount/utils/getDefaultValueForReimbursementAccountField';
import OnfidoInitialize from '@pages/ReimbursementAccount/VerifyIdentity/substeps/OnfidoInitialize';

Check warning on line 13 in src/pages/ReimbursementAccount/VerifyIdentity/VerifyIdentity.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected subpath import via alias '@pages/ReimbursementAccount/VerifyIdentity/substeps/OnfidoInitialize'. Use './substeps/OnfidoInitialize' instead
import useThemeStyles from '@styles/useThemeStyles';
import * as BankAccounts from '@userActions/BankAccounts';
import ONYXKEYS from '@src/ONYXKEYS';

const propTypes = {
/** Reimbursement account from ONYX */
reimbursementAccount: reimbursementAccountPropTypes,

onBackButtonPress: PropTypes.func.isRequired,
};

const defaultProps = {
reimbursementAccount: ReimbursementAccountProps.reimbursementAccountDefaultProps,
};

// TODO Will most likely come from different place
const STEPS_HEADER_HEIGHT = 40;
const STEP_NAMES = ['1', '2', '3', '4', '5'];

const bodyContent = [OnfidoInitialize];

function VerifyIdentity({reimbursementAccount, onBackButtonPress}) {
const styles = useThemeStyles();
const {translate} = useLocalize();

const submit = useCallback(
(onfidoData) => {
BankAccounts.verifyIdentityForBankAccount(getDefaultValueForReimbursementAccountField(reimbursementAccount, 'bankAccountID', 0), onfidoData);
BankAccounts.updateReimbursementAccountDraft({isOnfidoSetupComplete: true});
},
[reimbursementAccount],
);

const {componentToRender: SubStep, isEditing, nextScreen, moveTo} = useSubStep({bodyContent, startFrom: 0, onFinished: submit});

return (
<ScreenWrapper testID={VerifyIdentity.displayName}>
<HeaderWithBackButton
onBackButtonPress={onBackButtonPress}
title={translate('onfidoStep.verifyIdentity')}
/>
<View style={[styles.ph5, styles.mv3, {height: STEPS_HEADER_HEIGHT}]}>
<InteractiveStepSubHeader
onStepSelected={() => {}}
startStep={3}
stepNames={STEP_NAMES}
/>
</View>
<SubStep
isEditing={isEditing}
onNext={nextScreen}
onMove={moveTo}
/>
</ScreenWrapper>
);
}

VerifyIdentity.propTypes = propTypes;
VerifyIdentity.defaultProps = defaultProps;
VerifyIdentity.displayName = 'VerifyIdentity';

export default withOnyx({
reimbursementAccount: {
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
},
})(VerifyIdentity);
Loading

0 comments on commit 88e7b0a

Please sign in to comment.