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

refactor: transformed class component to the functional #27424

Merged
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
106 changes: 51 additions & 55 deletions src/pages/ReimbursementAccount/RequestorOnfidoStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ import {withOnyx} from 'react-native-onyx';
import PropTypes from 'prop-types';
import lodashGet from 'lodash/get';
import styles from '../../styles/styles';
import withLocalize from '../../components/withLocalize';
import * as BankAccounts from '../../libs/actions/BankAccounts';
import Onfido from '../../components/Onfido';
import compose from '../../libs/compose';
import ONYXKEYS from '../../ONYXKEYS';
import Growl from '../../libs/Growl';
import CONST from '../../CONST';
import FullPageOfflineBlockingView from '../../components/BlockingViews/FullPageOfflineBlockingView';
import StepPropTypes from './StepPropTypes';
import HeaderWithBackButton from '../../components/HeaderWithBackButton';
import ScreenWrapper from '../../components/ScreenWrapper';
import useLocalize from '../../hooks/useLocalize';

const propTypes = {
...StepPropTypes,
Expand All @@ -27,65 +26,62 @@ const defaultProps = {
onfidoToken: null,
};

class RequestorOnfidoStep extends React.Component {
constructor(props) {
super(props);
this.submit = this.submit.bind(this);
}
const HEADER_STEP_COUNTER = {step: 3, total: 5};
const ONFIDO_ERROR_DISPLAY_DURATION = 10000;

submit(onfidoData) {
BankAccounts.verifyIdentityForBankAccount(lodashGet(this.props.reimbursementAccount, 'achData.bankAccountID') || 0, onfidoData);
function RequestorOnfidoStep({onBackButtonPress, reimbursementAccount, onfidoToken}) {
const {translate} = useLocalize();

const submitOnfidoData = (onfidoData) => {
BankAccounts.verifyIdentityForBankAccount(lodashGet(reimbursementAccount, 'achData.bankAccountID', 0), onfidoData);
BankAccounts.updateReimbursementAccountDraft({isOnfidoSetupComplete: true});
}
};

render() {
return (
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
shouldShowOfflineIndicator={false}
testID={RequestorOnfidoStep.displayName}
>
<HeaderWithBackButton
title={this.props.translate('requestorStep.headerTitle')}
stepCounter={{step: 3, total: 5}}
shouldShowGetAssistanceButton
guidesCallTaskID={CONST.GUIDES_CALL_TASK_IDS.WORKSPACE_BANK_ACCOUNT}
onBackButtonPress={this.props.onBackButtonPress}
/>
<FullPageOfflineBlockingView>
<ScrollView contentContainerStyle={styles.flex1}>
<Onfido
sdkToken={this.props.onfidoToken}
onUserExit={() => {
BankAccounts.clearOnfidoToken();
BankAccounts.goToWithdrawalAccountSetupStep(CONST.BANK_ACCOUNT.STEP.REQUESTOR);
}}
onError={() => {
// In case of any unexpected error we log it to the server, show a growl, and return the user back to the requestor step so they can try again.
Growl.error(this.props.translate('onfidoStep.genericError'), 10000);
BankAccounts.clearOnfidoToken();
BankAccounts.goToWithdrawalAccountSetupStep(CONST.BANK_ACCOUNT.STEP.REQUESTOR);
}}
onSuccess={(onfidoData) => {
this.submit(onfidoData);
}}
/>
</ScrollView>
</FullPageOfflineBlockingView>
</ScreenWrapper>
);
}
const handleOnfidoError = () => {
// In case of any unexpected error we log it to the server, show a growl, and return the user back to the requestor step so they can try again.
Growl.error(translate('onfidoStep.genericError'), ONFIDO_ERROR_DISPLAY_DURATION);
BankAccounts.clearOnfidoToken();
BankAccounts.goToWithdrawalAccountSetupStep(CONST.BANK_ACCOUNT.STEP.REQUESTOR);
};

const handleOnfidoUserExit = () => {
BankAccounts.clearOnfidoToken();
BankAccounts.goToWithdrawalAccountSetupStep(CONST.BANK_ACCOUNT.STEP.REQUESTOR);
};

return (
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
shouldShowOfflineIndicator={false}
testID={RequestorOnfidoStep.displayName}
>
<HeaderWithBackButton
title={translate('requestorStep.headerTitle')}
stepCounter={HEADER_STEP_COUNTER}
shouldShowGetAssistanceButton
guidesCallTaskID={CONST.GUIDES_CALL_TASK_IDS.WORKSPACE_BANK_ACCOUNT}
onBackButtonPress={onBackButtonPress}
/>
<FullPageOfflineBlockingView>
<ScrollView contentContainerStyle={styles.flex1}>
<Onfido
sdkToken={onfidoToken}
onUserExit={handleOnfidoUserExit}
onError={handleOnfidoError}
onSuccess={submitOnfidoData}
/>
</ScrollView>
</FullPageOfflineBlockingView>
</ScreenWrapper>
);
}

RequestorOnfidoStep.displayName = 'RequestorOnfidoStep';
RequestorOnfidoStep.propTypes = propTypes;
RequestorOnfidoStep.defaultProps = defaultProps;
barttom marked this conversation as resolved.
Show resolved Hide resolved

export default compose(
withLocalize,
withOnyx({
onfidoToken: {
key: ONYXKEYS.ONFIDO_TOKEN,
},
}),
)(RequestorOnfidoStep);
export default withOnyx({
onfidoToken: {
key: ONYXKEYS.ONFIDO_TOKEN,
},
})(RequestorOnfidoStep);
Loading