Simplifying register page

This commit is contained in:
Jesús Espino 2021-04-09 17:13:25 +02:00
parent 5cf59d6ff5
commit 23964c22ae
5 changed files with 75 additions and 67 deletions

View file

@ -12,6 +12,7 @@
"CardDetail.add-icon": "Add icon", "CardDetail.add-icon": "Add icon",
"CardDetail.add-property": "+ Add a property", "CardDetail.add-property": "+ Add a property",
"CardDetail.addCardText": "add card text", "CardDetail.addCardText": "add card text",
"CardDetail.moveContent": "move card content",
"CardDetail.new-comment-placeholder": "Add a comment...", "CardDetail.new-comment-placeholder": "Add a comment...",
"CardDialog.editing-template": "You're editing a template", "CardDialog.editing-template": "You're editing a template",
"CardDialog.nocard": "This card doesn't exist or is inaccessible", "CardDialog.nocard": "This card doesn't exist or is inaccessible",
@ -159,5 +160,10 @@
"ViewTitle.show-description": "show description", "ViewTitle.show-description": "show description",
"ViewTitle.untitled-board": "Untitled board", "ViewTitle.untitled-board": "Untitled board",
"Workspace.editing-board-template": "You're editing a board template", "Workspace.editing-board-template": "You're editing a board template",
"default-properties.title": "Title" "default-properties.title": "Title",
"login.log-in-button": "Log in",
"login.log-in-title": "Log in",
"login.register-button": "or create an account if you don't have one",
"register.login-button": "or login if you already have an account",
"register.signup-title": "Sign up for your account"
} }

View file

@ -15,7 +15,7 @@
flex-direction: column; flex-direction: column;
align-items: flex-start; align-items: flex-start;
justify-content: center; justify-content: center;
margin: 60px auto; margin: 50px auto;
} }
@media screen and (max-width: 430px) { @media screen and (max-width: 430px) {
@ -53,7 +53,7 @@
} }
} }
> .Button { form > .Button {
margin-top: 10px; margin-top: 10px;
margin-bottom: 20px; margin-bottom: 20px;
min-height: 38px; min-height: 38px;

View file

@ -31,7 +31,12 @@ const LoginPage = React.memo(() => {
handleLogin() handleLogin()
}} }}
> >
<div className='title'>{'Log in'}</div> <div className='title'>{'Log in'}
<FormattedMessage
id='login.log-in-title'
defaultMessage='Log in'
/>
</div>
<div className='username'> <div className='username'>
<input <input
id='login-username' id='login-username'

View file

@ -11,6 +11,13 @@
flex-direction: column; flex-direction: column;
box-shadow: rgba(var(--body-color), 0.1) 0px 0px 0px 1px, rgba(var(--body-color), 0.3) 0px 4px 8px; 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;
}
@media screen and (max-width: 430px) { @media screen and (max-width: 430px) {
position: fixed; position: fixed;
top: 0; top: 0;
@ -46,7 +53,7 @@
} }
} }
> .Button { form > .Button {
margin-top: 10px; margin-top: 10px;
margin-bottom: 20px; margin-bottom: 20px;
min-height: 38px; min-height: 38px;

View file

@ -1,73 +1,68 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information. // See LICENSE.txt for license information.
import React from 'react' import React, {useState} from 'react'
import {useHistory, Link} from 'react-router-dom'
import { import {FormattedMessage} from 'react-intl'
withRouter,
RouteComponentProps,
Link,
} from 'react-router-dom'
import Button from '../widgets/buttons/button' import Button from '../widgets/buttons/button'
import client from '../octoClient' import client from '../octoClient'
import './registerPage.scss' import './registerPage.scss'
type Props = RouteComponentProps const RegisterPage = React.memo(() => {
const [username, setUsername] = useState('')
const [password, setPassword] = useState('')
const [email, setEmail] = useState('')
const [errorMessage, setErrorMessage] = useState('')
const history = useHistory()
type State = { const handleRegister = async (): Promise<void> => {
email: string
username: string
password: string
errorMessage?: string
}
class RegisterPage extends React.PureComponent<Props, State> {
state: State = {
email: '',
username: '',
password: '',
}
private handleRegister = async (): Promise<void> => {
const queryString = new URLSearchParams(window.location.search) const queryString = new URLSearchParams(window.location.search)
const signupToken = queryString.get('t') || '' const signupToken = queryString.get('t') || ''
const response = await client.register(this.state.email, this.state.username, this.state.password, signupToken) const response = await client.register(email, username, password, signupToken)
if (response.code === 200) { if (response.code === 200) {
const logged = await client.login(this.state.username, this.state.password) const logged = await client.login(username, password)
if (logged) { if (logged) {
this.props.history.push('/') history.push('/')
// HACKHACK: react-router-dom seems to require a refresh to navigate correctly // HACKHACK: react-router-dom seems to require a refresh to navigate correctly
// this.setState({email: '', username: '', password: ''}) // this.setState({email: '', username: '', password: ''})
} }
} else if (response.code === 401) { } else if (response.code === 401) {
this.setState({errorMessage: 'Invalid registration link, please contact your administrator'}) setErrorMessage('Invalid registration link, please contact your administrator')
} else { } else {
this.setState({errorMessage: response.json?.error}) setErrorMessage(response.json?.error)
} }
} }
render(): React.ReactNode { return (
return ( <div className='RegisterPage'>
<div className='RegisterPage'> <form
<div className='title'>{'Sign up for your account'}</div> onSubmit={(e: React.FormEvent) => {
e.preventDefault()
handleRegister()
}}
>
<div className='title'>
<FormattedMessage
id='register.signup-title'
defaultMessage='Sign up for your account'
/>
</div>
<div className='email'> <div className='email'>
<input <input
id='login-email' id='login-email'
placeholder={'Enter email'} placeholder={'Enter email'}
value={this.state.email} value={email}
onChange={(e) => this.setState({email: e.target.value})} onChange={(e) => setEmail(e.target.value)}
onKeyPress={this.onKeyPress}
/> />
</div> </div>
<div className='username'> <div className='username'>
<input <input
id='login-username' id='login-username'
placeholder={'Enter username'} placeholder={'Enter username'}
value={this.state.username} value={username}
onChange={(e) => this.setState({username: e.target.value})} onChange={(e) => setUsername(e.target.value)}
onKeyPress={this.onKeyPress}
/> />
</div> </div>
<div className='password'> <div className='password'>
@ -75,35 +70,30 @@ class RegisterPage extends React.PureComponent<Props, State> {
id='login-password' id='login-password'
type='password' type='password'
placeholder={'Enter password'} placeholder={'Enter password'}
value={this.state.password} value={password}
onChange={(e) => this.setState({password: e.target.value})} onChange={(e) => setPassword(e.target.value)}
onKeyPress={this.onKeyPress}
/> />
</div> </div>
<Button <Button
filled={true} filled={true}
onClick={this.handleRegister} submit={true}
> >
{'Register'} {'Register'}
</Button> </Button>
<Link to='/login'>{'or login if you already have an account'}</Link> </form>
{this.state.errorMessage && <Link to='/login'>
<div className='error'> <FormattedMessage
{this.state.errorMessage} id='register.login-button'
</div> defaultMessage={'or login if you already have an account'}
} />
</div> </Link>
) {errorMessage &&
} <div className='error'>
{errorMessage}
</div>
}
</div>
)
})
private onKeyPress = (e: React.KeyboardEvent) => { export default RegisterPage
if (!(e.metaKey || e.ctrlKey) && !e.shiftKey && e.key === 'Enter') {
this.handleRegister()
e.preventDefault()
return false
}
return true
}
}
export default withRouter(RegisterPage)