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

feat(signup): add TC and PP, confirm password

parent 6a931a90
No related branches found
No related tags found
2 merge requests!13Sprint #14,!12Signup functionality
...@@ -17,6 +17,7 @@ const SignUpInvitation = ({ ...@@ -17,6 +17,7 @@ const SignUpInvitation = ({
journal, journal,
onSubmit, onSubmit,
nextStep, nextStep,
prevStep,
initialValues, initialValues,
type = 'invitation', type = 'invitation',
subtitle = defaultSubtitle, subtitle = defaultSubtitle,
...@@ -41,6 +42,7 @@ const SignUpInvitation = ({ ...@@ -41,6 +42,7 @@ const SignUpInvitation = ({
initialValues={initialValues} initialValues={initialValues}
journal={journal} journal={journal}
onSubmit={onSubmit} onSubmit={onSubmit}
prevStep={prevStep}
type={type} type={type}
/> />
)} )}
......
...@@ -65,20 +65,19 @@ export default compose( ...@@ -65,20 +65,19 @@ export default compose(
nextStep: ({ changeStep }) => () => changeStep(step => step + 1), nextStep: ({ changeStep }) => () => changeStep(step => step + 1),
prevStep: ({ changeStep }) => () => changeStep(step => step - 1), prevStep: ({ changeStep }) => () => changeStep(step => step - 1),
submitConfirmation: ({ submitConfirmation: ({
initialValues: { email, token }, initialValues: { email = '', token = '' },
history, history,
...rest
}) => confirmUser(email, token, history), }) => confirmUser(email, token, history),
signUp: ({ history }) => signUpUser(history), signUp: ({ history }) => signUpUser(history),
}), }),
withProps(({ location, type, signUp, submitConfirmation }) => { withProps(({ location, type, signUp, submitConfirmation }) => {
const params = new URLSearchParams(location.search) const params = new URLSearchParams(location.search)
const email = params.get('email') const email = params.get('email') || ''
const token = params.get('token') const token = params.get('token') || ''
const title = params.get('title') const title = params.get('title') || ''
const lastName = params.get('lastName') const lastName = params.get('lastName') || ''
const firstName = params.get('firstName') const firstName = params.get('firstName') || ''
const affiliation = params.get('affiliation') const affiliation = params.get('affiliation') || ''
return { return {
initialValues: { initialValues: {
......
...@@ -2,11 +2,18 @@ import React from 'react' ...@@ -2,11 +2,18 @@ import React from 'react'
import { isUndefined } from 'lodash' import { isUndefined } from 'lodash'
import { reduxForm } from 'redux-form' import { reduxForm } from 'redux-form'
import { required } from 'xpub-validators' import { required } from 'xpub-validators'
import { Button, ValidatedField, TextField, Menu } from '@pubsweet/ui' import { Button, ValidatedField, TextField, Menu, Checkbox } from '@pubsweet/ui'
import { FormItems } from '../UIComponents' import { FormItems } from '../UIComponents'
const { FormContainer, Row, RowItem, Label } = FormItems const {
FormContainer,
Row,
RowItem,
Label,
PrivatePolicy,
DefaultText,
} = FormItems
const Step0 = ({ journal, handleSubmit, initialValues, error }) => const Step0 = ({ journal, handleSubmit, initialValues, error }) =>
!isUndefined(initialValues) ? ( !isUndefined(initialValues) ? (
...@@ -48,6 +55,29 @@ const Step0 = ({ journal, handleSubmit, initialValues, error }) => ...@@ -48,6 +55,29 @@ const Step0 = ({ journal, handleSubmit, initialValues, error }) =>
/> />
</RowItem> </RowItem>
</Row> </Row>
<Row justify="left">
<ValidatedField
component={input => (
<Checkbox checked={input.value} type="checkbox" {...input} />
)}
name="agreeTC"
validate={[required]}
/>
<DefaultText>
By creating this account, you agree to the{' '}
<a href="https://www.hindawi.com/terms/">Terms of Service</a>.
</DefaultText>
</Row>
<Row>
<PrivatePolicy>
This account information will be processed by us in accordance with
our Privacy Policy for the purpose of registering your Faraday account
and allowing you to use the services available via the Faraday
platform. Please read our{' '}
<a href="https://www.hindawi.com/privacy/">Privacy Policy</a> for
further information.
</PrivatePolicy>
</Row>
<Row> <Row>
<RowItem centered> <RowItem centered>
<Button primary type="submit"> <Button primary type="submit">
......
...@@ -4,13 +4,14 @@ import { required } from 'xpub-validators' ...@@ -4,13 +4,14 @@ import { required } from 'xpub-validators'
import { Button, ValidatedField, TextField } from '@pubsweet/ui' import { Button, ValidatedField, TextField } from '@pubsweet/ui'
import { FormItems } from '../UIComponents' import { FormItems } from '../UIComponents'
import { passwordValidator, emailValidator } from '../utils'
const { Row, Err, Label, RowItem, FormContainer } = FormItems const { Row, Err, Label, RowItem, FormContainer } = FormItems
const PasswordField = input => <TextField {...input} type="password" /> const PasswordField = input => <TextField {...input} type="password" />
const EmailField = input => <TextField {...input} type="email" /> const EmailField = input => <TextField {...input} type="email" />
const Step1 = ({ journal, handleSubmit, error, type }) => ( const Step1 = ({ handleSubmit, error, type, prevStep }) => (
<FormContainer onSubmit={handleSubmit}> <FormContainer onSubmit={handleSubmit}>
{type === 'signup' && ( {type === 'signup' && (
<Row> <Row>
...@@ -19,7 +20,7 @@ const Step1 = ({ journal, handleSubmit, error, type }) => ( ...@@ -19,7 +20,7 @@ const Step1 = ({ journal, handleSubmit, error, type }) => (
<ValidatedField <ValidatedField
component={EmailField} component={EmailField}
name="email" name="email"
validate={[required]} validate={[required, emailValidator]}
/> />
</RowItem> </RowItem>
</Row> </Row>
...@@ -52,6 +53,9 @@ const Step1 = ({ journal, handleSubmit, error, type }) => ( ...@@ -52,6 +53,9 @@ const Step1 = ({ journal, handleSubmit, error, type }) => (
</Row> </Row>
)} )}
<Row> <Row>
<Button onClick={prevStep} type="button">
BACK
</Button>
<Button primary type="submit"> <Button primary type="submit">
CONFIRM CONFIRM
</Button> </Button>
...@@ -63,4 +67,5 @@ export default reduxForm({ ...@@ -63,4 +67,5 @@ export default reduxForm({
form: 'signUpInvitation', form: 'signUpInvitation',
destroyOnUnmount: false, destroyOnUnmount: false,
forceUnregisterOnUnmount: true, forceUnregisterOnUnmount: true,
validate: passwordValidator,
})(Step1) })(Step1)
...@@ -7,6 +7,9 @@ const defaultText = css` ...@@ -7,6 +7,9 @@ const defaultText = css`
font-family: ${th('fontReading')}; font-family: ${th('fontReading')};
font-size: ${th('fontSizeBaseSmall')}; font-size: ${th('fontSizeBaseSmall')};
` `
export const DefaultText = styled.div`
${defaultText};
`
export const RootContainer = styled.div` export const RootContainer = styled.div`
background-color: ${th('backgroundColorReverse')}; background-color: ${th('backgroundColorReverse')};
...@@ -49,7 +52,7 @@ export const Row = styled.div` ...@@ -49,7 +52,7 @@ export const Row = styled.div`
align-items: flex-start; align-items: flex-start;
display: flex; display: flex;
flex-direction: row; flex-direction: row;
justify-content: space-evenly; justify-content: ${({ justify }) => justify || 'space-evenly'};
margin: ${({ noMargin }) => margin: ${({ noMargin }) =>
noMargin ? 0 : css`calc(${th('subGridUnit')} * 2) 0`}; noMargin ? 0 : css`calc(${th('subGridUnit')} * 2) 0`};
...@@ -126,4 +129,9 @@ export const CustomRadioGroup = styled.div` ...@@ -126,4 +129,9 @@ export const CustomRadioGroup = styled.div`
} }
` `
export const PrivatePolicy = styled.div`
${defaultText};
text-align: justify;
`
export const TextAreaField = input => <Textarea {...input} height={70} /> export const TextAreaField = input => <Textarea {...input} height={70} />
...@@ -74,6 +74,20 @@ const generatePasswordHash = () => ...@@ -74,6 +74,20 @@ const generatePasswordHash = () =>
.slice(4), .slice(4),
).join('') ).join('')
export const passwordValidator = values => {
const errors = {}
if (!values.password) {
errors.password = 'Required'
}
if (!values.confirmPassword) {
errors.confirmPassword = 'Required'
} else if (values.confirmPassword !== values.password) {
errors.confirmPassword = 'Password mismatched'
}
return errors
}
export const parseSignupAuthor = ({ token, confirmPassword, ...values }) => ({ export const parseSignupAuthor = ({ token, confirmPassword, ...values }) => ({
...values, ...values,
admin: false, admin: false,
......
...@@ -125,6 +125,7 @@ module.exports = { ...@@ -125,6 +125,7 @@ module.exports = {
handlingEditor: Joi.boolean(), handlingEditor: Joi.boolean(),
invitationToken: Joi.string().allow(''), invitationToken: Joi.string().allow(''),
confirmationToken: Joi.string().allow(''), confirmationToken: Joi.string().allow(''),
agreeTC: Joi.boolean(),
}, },
team: { team: {
group: Joi.string(), group: Joi.string(),
......
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