Skip to content
Snippets Groups Projects
Commit cc847884 authored by Bogdan Cochior's avatar Bogdan Cochior
Browse files

refactor(component): handle error on user signup

parent 2e6ebc35
No related branches found
No related tags found
No related merge requests found
...@@ -12,6 +12,7 @@ const SignUpInvitation = ({ ...@@ -12,6 +12,7 @@ const SignUpInvitation = ({
nextStep, nextStep,
submitConfirmation, submitConfirmation,
initialValues, initialValues,
error,
}) => ( }) => (
<Root> <Root>
<Title>Add New Account Details</Title> <Title>Add New Account Details</Title>
...@@ -20,6 +21,7 @@ const SignUpInvitation = ({ ...@@ -20,6 +21,7 @@ const SignUpInvitation = ({
your password. your password.
</Subtitle> </Subtitle>
<Email>{email}</Email> <Email>{email}</Email>
{error && <Err>Token expired or Something went wrong.</Err>}
{step === 0 && ( {step === 0 && (
<Step0 <Step0
initialValues={initialValues} initialValues={initialValues}
...@@ -68,3 +70,7 @@ const Email = styled.div` ...@@ -68,3 +70,7 @@ const Email = styled.div`
text-align: center; text-align: center;
margin: 10px auto; margin: 10px auto;
` `
const Err = styled.div`
color: red;
text-align: center;
`
...@@ -68,9 +68,13 @@ export default compose( ...@@ -68,9 +68,13 @@ export default compose(
componentDidMount() { componentDidMount() {
const { email, token } = this.props const { email, token } = this.props
const encodedUri = `?email=${encodeURIComponent(email)}&token=${token}` const encodedUri = `?email=${encodeURIComponent(email)}&token=${token}`
request(`/users/invite${encodedUri}`).then(res => { request(`/users/invite${encodedUri}`)
this.setState({ initialValues: res }) .then(res => {
}) this.setState({ initialValues: res })
})
.catch(err => {
this.setState({ error: err.response })
})
}, },
}), }),
)(SignUpInvitation) )(SignUpInvitation)
import React from 'react' import React from 'react'
import styled from 'styled-components' import styled from 'styled-components'
import { reduxForm } from 'redux-form' import { reduxForm } from 'redux-form'
import { isUndefined } from 'lodash'
import { required } from 'xpub-validators' import { required } from 'xpub-validators'
import { Button, ValidatedField, TextField, Menu } from '@pubsweet/ui' import { Button, ValidatedField, TextField, Menu } from '@pubsweet/ui'
const Step0 = ({ journal, handleSubmit, initialValues }) => ( const Step0 = ({ journal, handleSubmit, initialValues }) =>
<FormContainer onSubmit={handleSubmit}> !isUndefined(initialValues) ? (
<Row> <FormContainer onSubmit={handleSubmit}>
<RowItem> <Row>
<Label> First name* </Label> <RowItem>
<ValidatedField <Label> First name* </Label>
component={TextField} <ValidatedField
name="firstName" component={TextField}
validate={[required]} name="firstName"
/> validate={[required]}
</RowItem> />
<RowItem> </RowItem>
<Label> Affiliation* </Label> <RowItem>
<ValidatedField <Label> Affiliation* </Label>
component={TextField} <ValidatedField
name="affiliation" component={TextField}
validate={[required]} name="affiliation"
/> validate={[required]}
</RowItem> />
</Row> </RowItem>
<Row> </Row>
<RowItem> <Row>
<Label> Last name* </Label> <RowItem>
<ValidatedField <Label> Last name* </Label>
component={TextField} <ValidatedField
name="lastName" component={TextField}
validate={[required]} name="lastName"
/> validate={[required]}
</RowItem> />
<RowItem> </RowItem>
<Label> Title* </Label> <RowItem>
<ValidatedField <Label> Title* </Label>
component={input => <Menu {...input} options={journal.title} />} <ValidatedField
name="title" component={input => <Menu {...input} options={journal.title} />}
validate={[required]} name="title"
/> validate={[required]}
</RowItem> />
</Row> </RowItem>
<Row> </Row>
<Button primary type="submit"> <Row>
CONFIRM & PROCEED TO SET PASSWORD <Button primary type="submit">
</Button> CONFIRM & PROCEED TO SET PASSWORD
</Row> </Button>
</FormContainer> </Row>
) </FormContainer>
) : (
<div>Loading...</div>
)
export default reduxForm({ export default reduxForm({
form: 'signUpInvitation', form: 'signUpInvitation',
......
...@@ -25,7 +25,7 @@ module.exports = { ...@@ -25,7 +25,7 @@ module.exports = {
'pubsweet-client': { 'pubsweet-client': {
API_ENDPOINT: '/api', API_ENDPOINT: '/api',
'login-redirect': '/', 'login-redirect': '/',
'redux-log': true, 'redux-log': false,
theme: process.env.PUBSWEET_THEME, theme: process.env.PUBSWEET_THEME,
}, },
'mail-transport': { 'mail-transport': {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment