diff --git a/webapp/src/pages/loginPage.scss b/webapp/src/pages/loginPage.scss index ec5cb1d64..adfb76b6d 100644 --- a/webapp/src/pages/loginPage.scss +++ b/webapp/src/pages/loginPage.scss @@ -4,13 +4,20 @@ width: 450px; height: 400px; margin: 150px auto; - padding: 40px; display: flex; align-items: center; justify-content: flex-start; flex-direction: column; box-shadow: rgba(var(--body-color), 0.1) 0px 0px 0px 1px, rgba(var(--body-color), 0.3) 0px 4px 8px; + form { + display: flex; + flex-direction: column; + align-items: flex-start; + justify-content: center; + margin: 60px auto; + } + @media screen and (max-width: 430px) { position: fixed; top: 0; diff --git a/webapp/src/pages/loginPage.tsx b/webapp/src/pages/loginPage.tsx index 1c48cc2bf..a49c33fa6 100644 --- a/webapp/src/pages/loginPage.tsx +++ b/webapp/src/pages/loginPage.tsx @@ -1,51 +1,46 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import React from 'react' - -import { - withRouter, - RouteComponentProps, - Link, -} from 'react-router-dom' +import React, {useState} from 'react' +import {useHistory, Link} from 'react-router-dom' +import {FormattedMessage} from 'react-intl' import Button from '../widgets/buttons/button' import client from '../octoClient' import './loginPage.scss' -type Props = RouteComponentProps +const LoginPage = React.memo(() => { + const [username, setUsername] = useState('') + const [password, setPassword] = useState('') + const [errorMessage, setErrorMessage] = useState('') + const history = useHistory() -type State = { - username: string - password: string - errorMessage?: string -} - -class LoginPage extends React.PureComponent { - state: State = { - username: '', - password: '', - } - - private handleLogin = async (): Promise => { - const logged = await client.login(this.state.username, this.state.password) + const handleLogin = async (): Promise => { + const logged = await client.login(username, password) if (logged) { - this.props.history.push('/') + history.push('/') } else { - this.setState({errorMessage: 'Login failed'}) + setErrorMessage('Login failed') } } - render(): React.ReactNode { - return ( -
+ return ( +
+
{ + e.preventDefault() + handleLogin() + }} + >
{'Log in'}
this.setState({username: e.target.value, errorMessage: undefined})} - onKeyPress={this.onKeyPress} + value={username} + onChange={(e) => { + setUsername(e.target.value) + setErrorMessage('') + }} />
@@ -53,36 +48,36 @@ class LoginPage extends React.PureComponent { id='login-password' type='password' placeholder={'Enter password'} - value={this.state.password} - onChange={(e) => this.setState({password: e.target.value, errorMessage: undefined})} - onKeyPress={this.onKeyPress} + value={password} + onChange={(e) => { + setPassword(e.target.value) + setErrorMessage('') + }} />
- {'or create an account if you don\'t have one'} - {this.state.errorMessage && -
- {this.state.errorMessage} -
- } -
- ) - } + + + + + {errorMessage && +
+ {errorMessage} +
+ } +
+ ) +}) - private onKeyPress = (e: React.KeyboardEvent) => { - if (!(e.metaKey || e.ctrlKey) && !e.shiftKey && e.key === 'Enter') { - this.handleLogin() - e.preventDefault() - return false - } - - return true - } -} - -export default withRouter(LoginPage) +export default LoginPage diff --git a/webapp/src/widgets/buttons/button.tsx b/webapp/src/widgets/buttons/button.tsx index 38cadcf5f..ec87c155f 100644 --- a/webapp/src/widgets/buttons/button.tsx +++ b/webapp/src/widgets/buttons/button.tsx @@ -11,12 +11,13 @@ type Props = { icon?: React.ReactNode filled?: boolean active?: boolean + submit?: boolean } function Button(props: Props): JSX.Element { return (