diff --git a/src/pages/signin/LoginForm/LoginFormNarrow.js b/src/pages/signin/LoginForm.js similarity index 78% rename from src/pages/signin/LoginForm/LoginFormNarrow.js rename to src/pages/signin/LoginForm.js index be41578056fd..d37e22431193 100644 --- a/src/pages/signin/LoginForm/LoginFormNarrow.js +++ b/src/pages/signin/LoginForm.js @@ -7,11 +7,14 @@ import { import {withOnyx} from 'react-native-onyx'; import PropTypes from 'prop-types'; import _ from 'underscore'; -import styles from '../../../styles/styles'; -import themeColors from '../../../styles/themes/default'; -import ButtonWithLoader from '../../../components/ButtonWithLoader'; -import {fetchAccountDetails} from '../../../libs/actions/Session'; -import ONYXKEYS from '../../../ONYXKEYS'; +import styles from '../../styles/styles'; +import themeColors from '../../styles/themes/default'; +import ButtonWithLoader from '../../components/ButtonWithLoader'; +import {fetchAccountDetails} from '../../libs/actions/Session'; +import ONYXKEYS from '../../ONYXKEYS'; +import withWindowDimensions, {windowDimensionsPropTypes} from '../../components/withWindowDimensions'; +import compose from '../../libs/compose'; +import canFocusInputOnScreenFocus from '../../libs/canFocusInputOnScreenFocus'; const propTypes = { /* Onyx Props */ @@ -27,13 +30,15 @@ const propTypes = { // Whether or not a sign on form is loading (being submitted) loading: PropTypes.bool, }), + + ...windowDimensionsPropTypes, }; const defaultProps = { account: {}, }; -class LoginFormNarrow extends React.Component { +class LoginForm extends React.Component { constructor(props) { super(props); @@ -77,6 +82,7 @@ class LoginFormNarrow extends React.Component { autoCapitalize="none" placeholder="Phone or Email" placeholderTextColor={themeColors.placeholderText} + autoFocus={canFocusInputOnScreenFocus()} /> @@ -108,9 +114,12 @@ class LoginFormNarrow extends React.Component { } } -LoginFormNarrow.propTypes = propTypes; -LoginFormNarrow.defaultProps = defaultProps; +LoginForm.propTypes = propTypes; +LoginForm.defaultProps = defaultProps; -export default withOnyx({ - account: {key: ONYXKEYS.ACCOUNT}, -})(LoginFormNarrow); +export default compose( + withOnyx({ + account: {key: ONYXKEYS.ACCOUNT}, + }), + withWindowDimensions, +)(LoginForm); diff --git a/src/pages/signin/LoginForm/LoginFormWide.js b/src/pages/signin/LoginForm/LoginFormWide.js deleted file mode 100644 index 1f5a969ff2db..000000000000 --- a/src/pages/signin/LoginForm/LoginFormWide.js +++ /dev/null @@ -1,111 +0,0 @@ -import React from 'react'; -import {Text, TextInput, View} from 'react-native'; -import {withOnyx} from 'react-native-onyx'; -import PropTypes from 'prop-types'; -import _ from 'underscore'; -import {fetchAccountDetails} from '../../../libs/actions/Session'; -import styles from '../../../styles/styles'; -import ButtonWithLoader from '../../../components/ButtonWithLoader'; -import ONYXKEYS from '../../../ONYXKEYS'; - -const propTypes = { - /* Onyx Props */ - - // The details about the account that the user is signing in with - account: PropTypes.shape({ - // An error message to display to the user - error: PropTypes.string, - - // Success message to display when necessary - success: PropTypes.string, - - // Whether or not a sign on form is loading (being submitted) - loading: PropTypes.bool, - }), -}; - -const defaultProps = { - account: {}, -}; - -class LoginFormWide extends React.Component { - constructor(props) { - super(props); - - this.validateAndSubmitForm = this.validateAndSubmitForm.bind(this); - - this.state = { - formError: false, - login: '', - }; - } - - /** - * Check that all the form fields are valid, then trigger the submit callback - */ - validateAndSubmitForm() { - if (!this.state.login.trim()) { - this.setState({formError: 'Please enter an email or phone number'}); - return; - } - - this.setState({ - formError: null, - }); - - // Check if this login has an account associated with it or not - fetchAccountDetails(this.state.login); - } - - render() { - return ( - <> - - Enter your phone or email: - this.setState({login: text})} - onSubmitEditing={this.validateAndSubmitForm} - autoCapitalize="none" - placeholder="Phone or Email" - autoFocus - /> - - - - - - {this.state.formError && ( - - {this.state.formError} - - )} - - {!_.isEmpty(this.props.account.error) && ( - - {this.props.account.error} - - )} - {!_.isEmpty(this.props.account.success) && ( - - {this.props.account.success} - - )} - - ); - } -} - -LoginFormWide.propTypes = propTypes; -LoginFormWide.defaultProps = defaultProps; - -export default withOnyx({ - account: {key: ONYXKEYS.ACCOUNT}, -})(LoginFormWide); diff --git a/src/pages/signin/LoginForm/index.js b/src/pages/signin/LoginForm/index.js deleted file mode 100644 index fc94e27e486e..000000000000 --- a/src/pages/signin/LoginForm/index.js +++ /dev/null @@ -1,19 +0,0 @@ -import React from 'react'; -import LoginFormNarrow from './LoginFormNarrow'; -import LoginFormWide from './LoginFormWide'; -import withWindowDimensions, {windowDimensionsPropTypes} from '../../../components/withWindowDimensions'; - -const propTypes = { - ...windowDimensionsPropTypes, -}; - -const LoginForm = ({isSmallScreenWidth}) => ( - !isSmallScreenWidth - ? - : -); - -LoginForm.propTypes = propTypes; -LoginForm.displayName = 'LoginForm'; - -export default withWindowDimensions(LoginForm); diff --git a/src/pages/signin/LoginForm/index.native.js b/src/pages/signin/LoginForm/index.native.js deleted file mode 100644 index e0f7e358f4fd..000000000000 --- a/src/pages/signin/LoginForm/index.native.js +++ /dev/null @@ -1,3 +0,0 @@ -import LoginFormNarrow from './LoginFormNarrow'; - -export default LoginFormNarrow; diff --git a/src/pages/signin/SignInPageLayout/index.js b/src/pages/signin/SignInPageLayout/index.js index 41313d9484cf..056052705729 100644 --- a/src/pages/signin/SignInPageLayout/index.js +++ b/src/pages/signin/SignInPageLayout/index.js @@ -10,9 +10,9 @@ const propTypes = { const SignInPageLayout = props => ( !props.isSmallScreenWidth // eslint-disable-next-line react/jsx-props-no-spreading - ? + ? {props.children} // eslint-disable-next-line react/jsx-props-no-spreading - : + : {props.children} ); SignInPageLayout.propTypes = propTypes;