Newer
Older
import React from 'react'
import { Field } from 'formik'
import { ErrorText, H1, Link, Button, Checkbox, TextField } from '@pubsweet/ui'
import { th } from '@pubsweet/ui-toolkit'
import styled from 'styled-components'
import { Page, Notification } from '../ui'
import SignInFooter from '../SignInFooter'
import UserCore from '../UserCore'
margin: ${th('gridUnit')} 0 0;
text-indent: calc(3 * ${th('gridUnit')});
`
const ShowPassword = styled(Checkbox)`
position: absolute;
right: 0;
top: 0;
font-size: ${th('fontSizeBaseSmall')};
`
const PasswordDetails = styled.div`
display: flex;
align-items: center;
width: 50%;
max-width: 100%;
@media screen and (max-width: 1000px) {
width: 600px;
@media screen and (max-width: 800px) {
display: block;
width: 408px;
}
`
width: 308px;
max-width: 100%;
margin-right: calc(${th('gridUnit')} * 1.5);
@media screen and (max-width: 1000px) {
width: 408px;
}
@media screen and (max-width: 800px) {
width: 100%;
}
const PasswordRules = styled.ul`
font-size: ${th('fontSizeBaseSmall')};
padding-left: calc(${th('gridUnit')} * 4);
@media screen and (max-width: 800px) {
display: flex;
justify-content: space-between;
margin: calc(-${th('gridUnit')} * 3) 0 calc(${th('gridUnit')} * 3);
padding: 0 ${th('gridUnit')};
li {
margin-left: calc(${th('gridUnit')} * 2);
}
}
class Signup extends React.Component {
state = {
accept: false,
}
setButtonRef = button => {
this.button = button
}
toggleAccept = () => {
const { accept, showPassword } = this.state
this.setState({
accept: !accept,
showPassword,
})
}
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
toggleShowPassword = () => {
const { showPassword } = this.state
this.setState({
showPassword: !showPassword,
})
}
validatePassword = e => {
if (!e.target.value) {
return
}
const isValidLength = e.target.value.length >= 8
this.setState({
isValidLength,
})
}
PasswordInput = props => (
<TextField
invalidTest={props.invalidTest}
label="Password"
{...props.field}
onBlur={e => this.validatePassword(e)}
onKeyUp={e => this.validatePassword(e)}
type="password"
/>
)
PlainPasswordInput = props => (
<TextField
invalidTest={props.invalidTest}
label="Password"
onBlur={e => this.validatePassword(e)}
onKeyUp={e => this.validatePassword(e)}
{...props.field}
/>
)
const { values, errors, handleSubmit, touched, location } = this.props
<H1>Create a Europe PMC plus account</H1>
{values.success && (
<Notification type="success"> {values.success} </Notification>
)}
{values.error && (
)}
<form onSubmit={handleSubmit}>
<PasswordDetails>
<PasswordField>
{!this.state.showPassword && (
<Field component={this.PasswordInput} name="password" />
)}
{this.state.showPassword && (
<Field component={this.PlainPasswordInput} name="password" />
)}
<ShowPassword
checked={this.state.showPassword}
label="Show password"
onChange={() => this.toggleShowPassword()}
/>
{errors.password && touched.password && (
<ErrorText>{errors.password}</ErrorText>
)}
</PasswordField>
<PasswordRules>
<li style={{ opacity: this.state.isValidLength ? 1 : 0.5 }}>
8 characters
</li>
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<div className="accept">
<Checkbox
checked={this.state.accept}
label="I have read and accept the privacy notice."
onChange={() => this.toggleAccept()}
/>
<Notice>
{`See `}
<Link
target="_blank"
to="//www.ebi.ac.uk/data-protection/privacy-notice/europe-pmc-plus"
>
Privacy notice
</Link>
{` for Europe PMC’s Advanced User Services.`}
</Notice>
</div>
<p>
<Button
disabled={!this.state.accept}
primary
ref={this.setButtonRef}
type="submit"
>
Create account
</Button>
</p>
</form>
<SignIn>
<Link to={`/login${location.search}`}>Sign in.</Link>