From 453f0eb64521d95aa06445dde5ed3654310dd535 Mon Sep 17 00:00:00 2001 From: Cristi Paval Date: Wed, 31 May 2023 23:17:43 +0300 Subject: [PATCH 1/9] Hook refactor for ValidateLoginPage/index.js --- src/pages/ValidateLoginPage/index.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/pages/ValidateLoginPage/index.js b/src/pages/ValidateLoginPage/index.js index 97461b42ab92..942c6d744783 100644 --- a/src/pages/ValidateLoginPage/index.js +++ b/src/pages/ValidateLoginPage/index.js @@ -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'; @@ -39,26 +39,24 @@ const defaultProps = { preferredLocale: CONST.LOCALES.DEFAULT, }; -class ValidateLoginPage extends Component { - componentDidMount() { - const accountID = lodashGet(this.props.route.params, 'accountID', ''); - const validateCode = lodashGet(this.props.route.params, 'validateCode', ''); - if (Permissions.canUsePasswordlessLogins(this.props.betas)) { - if (lodashGet(this.props, 'session.authToken')) { +function ValidateLoginPage(props) { + useEffect(() => { + const accountID = lodashGet(props.route.params, 'accountID', ''); + const validateCode = lodashGet(props.route.params, 'validateCode', ''); + if (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); } } else { User.validateLogin(accountID, validateCode); } - } + }, []); - render() { - return ; - } + return ; } ValidateLoginPage.propTypes = propTypes; From 69538e83ee0c09796ceda9784c1d67aa47c246df Mon Sep 17 00:00:00 2001 From: Cristi Paval Date: Thu, 8 Jun 2023 23:55:39 +0300 Subject: [PATCH 2/9] disable the rule for lint. --- src/pages/ValidateLoginPage/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pages/ValidateLoginPage/index.js b/src/pages/ValidateLoginPage/index.js index 832b1eec3c8c..9b0b833bead4 100644 --- a/src/pages/ValidateLoginPage/index.js +++ b/src/pages/ValidateLoginPage/index.js @@ -65,6 +65,7 @@ function ValidateLoginPage(props) { } else { User.validateLogin(accountID, validateCode); } + // eslint-disable-next-line react-hooks/exhaustive-deps }, []); return ; From b47023eb336832b5d8076fa3c74933a20a2c6d08 Mon Sep 17 00:00:00 2001 From: Cristi Paval Date: Fri, 9 Jun 2023 21:02:44 +0300 Subject: [PATCH 3/9] usePermissions custom hook --- src/pages/ValidateLoginPage/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pages/ValidateLoginPage/index.js b/src/pages/ValidateLoginPage/index.js index 9b0b833bead4..aced500b2e01 100644 --- a/src/pages/ValidateLoginPage/index.js +++ b/src/pages/ValidateLoginPage/index.js @@ -7,7 +7,7 @@ import * as User from '../../libs/actions/User'; import FullScreenLoadingIndicator from '../../components/FullscreenLoadingIndicator'; import ONYXKEYS from '../../ONYXKEYS'; import * as Session from '../../libs/actions/Session'; -import Permissions from '../../libs/Permissions'; +import usePermissions from '../../hooks/usePermissions'; import Navigation from '../../libs/Navigation/Navigation'; import withLocalize from '../../components/withLocalize'; import CONST from '../../CONST'; @@ -47,6 +47,8 @@ const defaultProps = { }; function ValidateLoginPage(props) { + const {canUsePasswordlessLogins} = usePermissions(); + useEffect(() => { const login = lodashGet(props, 'credentials.login', null); const accountID = lodashGet(props.route.params, 'accountID', ''); @@ -54,7 +56,7 @@ function ValidateLoginPage(props) { // 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(props.betas)) { + if (!login || canUsePasswordlessLogins) { 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. From 9c177e52f6c458ee387ddf04d62374b81bee8e97 Mon Sep 17 00:00:00 2001 From: Cristi Paval Date: Fri, 9 Jun 2023 21:17:49 +0300 Subject: [PATCH 4/9] Remove withLocalize --- src/pages/ValidateLoginPage/index.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/pages/ValidateLoginPage/index.js b/src/pages/ValidateLoginPage/index.js index aced500b2e01..157c97d7056b 100644 --- a/src/pages/ValidateLoginPage/index.js +++ b/src/pages/ValidateLoginPage/index.js @@ -9,7 +9,6 @@ import ONYXKEYS from '../../ONYXKEYS'; import * as Session from '../../libs/actions/Session'; import usePermissions from '../../hooks/usePermissions'; import Navigation from '../../libs/Navigation/Navigation'; -import withLocalize from '../../components/withLocalize'; import CONST from '../../CONST'; import compose from '../../libs/compose'; @@ -76,11 +75,8 @@ function ValidateLoginPage(props) { ValidateLoginPage.propTypes = propTypes; ValidateLoginPage.defaultProps = defaultProps; -export default compose( - withLocalize, - withOnyx({ - betas: {key: ONYXKEYS.BETAS}, - credentials: {key: ONYXKEYS.CREDENTIALS}, - session: {key: ONYXKEYS.SESSION}, - }), -)(ValidateLoginPage); +export default withOnyx({ + betas: {key: ONYXKEYS.BETAS}, + credentials: {key: ONYXKEYS.CREDENTIALS}, + session: {key: ONYXKEYS.SESSION}, +})(ValidateLoginPage); From 707161f8a5b33872afae4aeb9f5789817bade7a5 Mon Sep 17 00:00:00 2001 From: Cristi Paval Date: Fri, 9 Jun 2023 22:08:33 +0300 Subject: [PATCH 5/9] Make Lint happy --- src/pages/ValidateLoginPage/index.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/pages/ValidateLoginPage/index.js b/src/pages/ValidateLoginPage/index.js index 157c97d7056b..5894a04b40f2 100644 --- a/src/pages/ValidateLoginPage/index.js +++ b/src/pages/ValidateLoginPage/index.js @@ -10,15 +10,11 @@ import * as Session from '../../libs/actions/Session'; import usePermissions from '../../hooks/usePermissions'; import Navigation from '../../libs/Navigation/Navigation'; import CONST from '../../CONST'; -import compose from '../../libs/compose'; const propTypes = { /** The accountID and validateCode are passed via the URL */ route: validateLinkPropTypes, - /** List of betas available to current user */ - betas: PropTypes.arrayOf(PropTypes.string), - /** Session of currently logged in user */ session: PropTypes.shape({ /** Currently logged in user authToken */ @@ -76,7 +72,6 @@ ValidateLoginPage.propTypes = propTypes; ValidateLoginPage.defaultProps = defaultProps; export default withOnyx({ - betas: {key: ONYXKEYS.BETAS}, credentials: {key: ONYXKEYS.CREDENTIALS}, session: {key: ONYXKEYS.SESSION}, })(ValidateLoginPage); From b3b7cf0033bdb125fc907410483cf445b52a68bf Mon Sep 17 00:00:00 2001 From: Cristi Paval Date: Fri, 9 Jun 2023 22:14:26 +0300 Subject: [PATCH 6/9] I hate you Lint --- src/pages/ValidateLoginPage/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/ValidateLoginPage/index.js b/src/pages/ValidateLoginPage/index.js index 5894a04b40f2..21d14c2bffac 100644 --- a/src/pages/ValidateLoginPage/index.js +++ b/src/pages/ValidateLoginPage/index.js @@ -33,7 +33,6 @@ const propTypes = { const defaultProps = { route: validateLinkDefaultProps, - betas: [], session: { authToken: null, }, From 1ab85df7fd3ab9bc138f51e54ae03323fa795921 Mon Sep 17 00:00:00 2001 From: Cristi Paval Date: Mon, 12 Jun 2023 22:47:39 +0300 Subject: [PATCH 7/9] useLocalize hook to get preferredLocale value --- src/pages/ValidateLoginPage/index.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/pages/ValidateLoginPage/index.js b/src/pages/ValidateLoginPage/index.js index 21d14c2bffac..09eecb696f64 100644 --- a/src/pages/ValidateLoginPage/index.js +++ b/src/pages/ValidateLoginPage/index.js @@ -8,6 +8,7 @@ import FullScreenLoadingIndicator from '../../components/FullscreenLoadingIndica import ONYXKEYS from '../../ONYXKEYS'; import * as Session from '../../libs/actions/Session'; import usePermissions from '../../hooks/usePermissions'; +import useLocalize from '../../hooks/useLocalize'; import Navigation from '../../libs/Navigation/Navigation'; import CONST from '../../CONST'; @@ -26,9 +27,6 @@ const propTypes = { /** The email the user logged in with */ login: PropTypes.string, }), - - /** Indicates which locale the user currently has selected */ - preferredLocale: PropTypes.string, }; const defaultProps = { @@ -37,11 +35,11 @@ const defaultProps = { authToken: null, }, credentials: {}, - preferredLocale: CONST.LOCALES.DEFAULT, }; function ValidateLoginPage(props) { const {canUsePasswordlessLogins} = usePermissions(); + const {preferredLocale} = useLocalize(); useEffect(() => { const login = lodashGet(props, 'credentials.login', null); @@ -56,7 +54,7 @@ function ValidateLoginPage(props) { // because we don't want to block the user with the interstitial page. Navigation.goBack(false); } else { - Session.signInWithValidateCodeAndNavigate(accountID, validateCode, props.preferredLocale); + Session.signInWithValidateCodeAndNavigate(accountID, validateCode, preferredLocale); } } else { User.validateLogin(accountID, validateCode); From 524f83876def31348034e211b36d595acbf36e04 Mon Sep 17 00:00:00 2001 From: Cristi Paval Date: Mon, 12 Jun 2023 23:03:59 +0300 Subject: [PATCH 8/9] Make Lint happy again --- src/pages/ValidateLoginPage/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/ValidateLoginPage/index.js b/src/pages/ValidateLoginPage/index.js index 09eecb696f64..2309a7af5852 100644 --- a/src/pages/ValidateLoginPage/index.js +++ b/src/pages/ValidateLoginPage/index.js @@ -10,7 +10,6 @@ import * as Session from '../../libs/actions/Session'; import usePermissions from '../../hooks/usePermissions'; import useLocalize from '../../hooks/useLocalize'; import Navigation from '../../libs/Navigation/Navigation'; -import CONST from '../../CONST'; const propTypes = { /** The accountID and validateCode are passed via the URL */ From 2f023643d630d77fa7da5c54c08b45240193e5b8 Mon Sep 17 00:00:00 2001 From: Cristi Paval Date: Wed, 5 Jul 2023 13:23:12 +0300 Subject: [PATCH 9/9] Add displayName --- src/pages/ValidateLoginPage/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pages/ValidateLoginPage/index.js b/src/pages/ValidateLoginPage/index.js index 2309a7af5852..57893a03b8bc 100644 --- a/src/pages/ValidateLoginPage/index.js +++ b/src/pages/ValidateLoginPage/index.js @@ -64,8 +64,9 @@ function ValidateLoginPage(props) { return ; } -ValidateLoginPage.propTypes = propTypes; ValidateLoginPage.defaultProps = defaultProps; +ValidateLoginPage.displayName = 'ValidateLoginPage'; +ValidateLoginPage.propTypes = propTypes; export default withOnyx({ credentials: {key: ONYXKEYS.CREDENTIALS},