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

Hook refactor for ValidateLoginPage/index.js #19906

Merged
merged 11 commits into from
Jul 5, 2023
25 changes: 12 additions & 13 deletions src/pages/ValidateLoginPage/index.js
cristipaval marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {Component} from 'react';
import React, {useEffect} from 'react';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import lodashGet from 'lodash/get';
Expand Down Expand Up @@ -46,30 +46,29 @@ const defaultProps = {
preferredLocale: CONST.LOCALES.DEFAULT,
};

class ValidateLoginPage extends Component {
componentDidMount() {
const login = lodashGet(this.props, 'credentials.login', null);
const accountID = lodashGet(this.props.route.params, 'accountID', '');
const validateCode = lodashGet(this.props.route.params, 'validateCode', '');
function ValidateLoginPage(props) {
useEffect(() => {
const login = lodashGet(props, 'credentials.login', null);
const accountID = lodashGet(props.route.params, 'accountID', '');
const validateCode = lodashGet(props.route.params, 'validateCode', '');

// A fresh session will not have credentials.login and user permission betas available.
// In that case, we directly allow users to go through password less flow
if (!login || Permissions.canUsePasswordlessLogins(this.props.betas)) {
if (lodashGet(this.props, 'session.authToken')) {
if (!login || Permissions.canUsePasswordlessLogins(props.betas)) {
if (lodashGet(props, 'session.authToken')) {
// If already signed in, do not show the validate code if not on web,
// because we don't want to block the user with the interstitial page.
Navigation.goBack(false);
} else {
Session.signInWithValidateCodeAndNavigate(accountID, validateCode, this.props.preferredLocale);
Session.signInWithValidateCodeAndNavigate(accountID, validateCode, props.preferredLocale);
cristipaval marked this conversation as resolved.
Show resolved Hide resolved
}
} else {
User.validateLogin(accountID, validateCode);
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

render() {
return <FullScreenLoadingIndicator />;
}
return <FullScreenLoadingIndicator />;
}

ValidateLoginPage.propTypes = propTypes;
Expand Down