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

Migrate OnfidoPrivacy.js to functional component #25458

Merged
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
90 changes: 43 additions & 47 deletions src/pages/EnablePayments/OnfidoPrivacy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, {useRef} from 'react';
import {View} from 'react-native';
import lodashGet from 'lodash/get';
import _ from 'underscore';
Expand Down Expand Up @@ -35,57 +35,53 @@ const defaultProps = {
},
};

class OnfidoPrivacy extends React.Component {
constructor(props) {
super(props);
function OnfidoPrivacy({walletOnfidoData, translate, form}) {
const {isLoading = false, hasAcceptedPrivacyPolicy} = walletOnfidoData;

this.openOnfidoFlow = this.openOnfidoFlow.bind(this);
}
const formRef = useRef(null);

openOnfidoFlow() {
const openOnfidoFlow = () => {
BankAccounts.openOnfidoFlow();
}
};

render() {
let onfidoError = ErrorUtils.getLatestErrorMessage(this.props.walletOnfidoData) || '';
const onfidoFixableErrors = lodashGet(this.props, 'walletOnfidoData.fixableErrors', []);
onfidoError += !_.isEmpty(onfidoFixableErrors) ? `\n${onfidoFixableErrors.join('\n')}` : '';
let onfidoError = ErrorUtils.getLatestErrorMessage(walletOnfidoData) || '';
const onfidoFixableErrors = lodashGet(walletOnfidoData, 'fixableErrors', []);
onfidoError += !_.isEmpty(onfidoFixableErrors) ? `\n${onfidoFixableErrors.join('\n')}` : '';

return (
<View style={[styles.flex1, styles.justifyContentBetween]}>
{!this.props.walletOnfidoData.hasAcceptedPrivacyPolicy ? (
<>
<FormScrollView ref={(el) => (this.form = el)}>
<View style={[styles.mh5, styles.justifyContentCenter]}>
<Text style={[styles.mb5]}>
{this.props.translate('onfidoStep.acceptTerms')}
<TextLink href="https://onfido.com/facial-scan-policy-and-release/">{this.props.translate('onfidoStep.facialScan')}</TextLink>
{', '}
<TextLink href="https://onfido.com/privacy/">{this.props.translate('common.privacy')}</TextLink>
{` ${this.props.translate('common.and')} `}
<TextLink href="https://onfido.com/terms-of-service/">{this.props.translate('common.termsOfService')}</TextLink>.
</Text>
</View>
</FormScrollView>
<FixedFooter>
<FormAlertWithSubmitButton
isAlertVisible={Boolean(onfidoError)}
onSubmit={this.openOnfidoFlow}
onFixTheErrorsLinkPressed={() => {
this.form.scrollTo({y: 0, animated: true});
}}
message={onfidoError}
isLoading={this.props.walletOnfidoData.isLoading}
buttonText={onfidoError ? this.props.translate('onfidoStep.tryAgain') : this.props.translate('common.continue')}
containerStyles={[styles.mh0, styles.mv0, styles.mb0]}
/>
</FixedFooter>
</>
) : null}
{this.props.walletOnfidoData.hasAcceptedPrivacyPolicy && this.props.walletOnfidoData.isLoading ? <FullscreenLoadingIndicator /> : null}
</View>
);
}
return (
<View style={[styles.flex1, styles.justifyContentBetween]}>
{!hasAcceptedPrivacyPolicy ? (
<>
<FormScrollView ref={formRef}>
<View style={[styles.mh5, styles.justifyContentCenter]}>
<Text style={[styles.mb5]}>
{translate('onfidoStep.acceptTerms')}
<TextLink href="https://onfido.com/facial-scan-policy-and-release/">{translate('onfidoStep.facialScan')}</TextLink>
{', '}
<TextLink href="https://onfido.com/privacy/">{translate('common.privacy')}</TextLink>
{` ${translate('common.and')} `}
<TextLink href="https://onfido.com/terms-of-service/">{translate('common.termsOfService')}</TextLink>.
</Text>
</View>
</FormScrollView>
<FixedFooter>
<FormAlertWithSubmitButton
isAlertVisible={Boolean(onfidoError)}
onSubmit={openOnfidoFlow}
onFixTheErrorsLinkPressed={() => {
form.scrollTo({y: 0, animated: true});
}}
message={onfidoError}
isLoading={isLoading}
buttonText={onfidoError ? translate('onfidoStep.tryAgain') : translate('common.continue')}
containerStyles={[styles.mh0, styles.mv0, styles.mb0]}
/>
</FixedFooter>
</>
) : null}
{hasAcceptedPrivacyPolicy && isLoading ? <FullscreenLoadingIndicator /> : null}
</View>
);
}

OnfidoPrivacy.propTypes = propTypes;
Expand Down
Loading