diff --git a/packages/components-faraday/src/components/Admin/EditUserForm.js b/packages/components-faraday/src/components/Admin/EditUserForm.js index 20971b7faf88ed16396bc5efd7c6e9d98f905c67..716b8f55a97e2c8135c173a1812b9453843315c3 100644 --- a/packages/components-faraday/src/components/Admin/EditUserForm.js +++ b/packages/components-faraday/src/components/Admin/EditUserForm.js @@ -113,6 +113,9 @@ const Row = styled.div` const RowItem = styled.div` flex: 1; margin-right: calc(${th('subGridUnit')}*3); + label + div[role='alert'] { + margin-top: 0; + } ` const Title = styled.h4` diff --git a/packages/components-faraday/src/components/SignUp/SignUpInvitationForm.js b/packages/components-faraday/src/components/SignUp/SignUpInvitationForm.js index 4a3f999575a9203892e840c831767f76f9086793..798ee6587ed00cdf39e6db9ea3286ebe73a28d57 100644 --- a/packages/components-faraday/src/components/SignUp/SignUpInvitationForm.js +++ b/packages/components-faraday/src/components/SignUp/SignUpInvitationForm.js @@ -11,12 +11,11 @@ your password.` const SignUpInvitation = ({ step, - email, - token, error, journal, onSubmit, nextStep, + prevStep, initialValues, type = 'invitation', subtitle = defaultSubtitle, @@ -41,6 +40,7 @@ const SignUpInvitation = ({ initialValues={initialValues} journal={journal} onSubmit={onSubmit} + prevStep={prevStep} type={type} /> )} diff --git a/packages/components-faraday/src/components/SignUp/SignUpInvitationPage.js b/packages/components-faraday/src/components/SignUp/SignUpInvitationPage.js index 9c8b24d62c3c81767db501d5712f8f4ee3cfc84e..89bed246e694a9bd159ea127a934fbc392b4a91e 100644 --- a/packages/components-faraday/src/components/SignUp/SignUpInvitationPage.js +++ b/packages/components-faraday/src/components/SignUp/SignUpInvitationPage.js @@ -6,7 +6,7 @@ import { loginUser } from 'pubsweet-component-login/actions' import { compose, withState, withProps, withHandlers } from 'recompose' import SignUpInvitation from './SignUpInvitationForm' -import { handleError, parseSignupAuthor } from '../utils' +import { parseSignupAuthor } from '../utils' const login = (dispatch, values, history) => dispatch(loginUser(values)) @@ -18,7 +18,7 @@ const login = (dispatch, values, history) => if (err) { const errorMessage = get(JSON.parse(err), 'error') throw new SubmissionError({ - password: errorMessage || 'Something went wrong', + confirmPassword: errorMessage || 'Something went wrong', }) } }) @@ -56,7 +56,15 @@ const signUpUser = history => (values, dispatch) => }) }) }) - .catch(handleError) + .catch(error => { + const err = get(error, 'response') + if (err) { + const errorMessage = get(JSON.parse(err), 'message') + throw new SubmissionError({ + confirmPassword: errorMessage || 'Something went wrong', + }) + } + }) export default compose( withJournal, @@ -65,20 +73,19 @@ export default compose( nextStep: ({ changeStep }) => () => changeStep(step => step + 1), prevStep: ({ changeStep }) => () => changeStep(step => step - 1), submitConfirmation: ({ - initialValues: { email, token }, + initialValues: { email = '', token = '' }, history, - ...rest }) => confirmUser(email, token, history), signUp: ({ history }) => signUpUser(history), }), withProps(({ location, type, signUp, submitConfirmation }) => { const params = new URLSearchParams(location.search) - const email = params.get('email') - const token = params.get('token') - const title = params.get('title') - const lastName = params.get('lastName') - const firstName = params.get('firstName') - const affiliation = params.get('affiliation') + const email = params.get('email') || '' + const token = params.get('token') || '' + const title = params.get('title') || '' + const lastName = params.get('lastName') || '' + const firstName = params.get('firstName') || '' + const affiliation = params.get('affiliation') || '' return { initialValues: { diff --git a/packages/components-faraday/src/components/SignUp/SignUpStep0.js b/packages/components-faraday/src/components/SignUp/SignUpStep0.js index 237bba74d5e87c3fd28aaa53c3928709334d4e79..dbee6e7e06abd5556d9d15c7aa50c04ffeddc910 100644 --- a/packages/components-faraday/src/components/SignUp/SignUpStep0.js +++ b/packages/components-faraday/src/components/SignUp/SignUpStep0.js @@ -2,11 +2,18 @@ import React from 'react' import { isUndefined } from 'lodash' import { reduxForm } from 'redux-form' 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' -const { FormContainer, Row, RowItem, Label } = FormItems +const { + FormContainer, + Row, + RowItem, + Label, + PrivatePolicy, + DefaultText, +} = FormItems const Step0 = ({ journal, handleSubmit, initialValues, error }) => !isUndefined(initialValues) ? ( @@ -48,6 +55,41 @@ const Step0 = ({ journal, handleSubmit, initialValues, error }) => /> </RowItem> </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/" + rel="noopener noreferrer" + target="_blank" + > + 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/" + rel="noopener noreferrer" + target="_blank" + > + Privacy Policy + </a>{' '} + for further information. + </PrivatePolicy> + </Row> <Row> <RowItem centered> <Button primary type="submit"> diff --git a/packages/components-faraday/src/components/SignUp/SignUpStep1.js b/packages/components-faraday/src/components/SignUp/SignUpStep1.js index ae97bc2a168eaa13c9c69b3d0ef5bd07bc0ed57c..55a407e0a1a492832dd8511f050853f9ced68520 100644 --- a/packages/components-faraday/src/components/SignUp/SignUpStep1.js +++ b/packages/components-faraday/src/components/SignUp/SignUpStep1.js @@ -4,13 +4,14 @@ import { required } from 'xpub-validators' import { Button, ValidatedField, TextField } from '@pubsweet/ui' import { FormItems } from '../UIComponents' +import { passwordValidator, emailValidator } from '../utils' const { Row, Err, Label, RowItem, FormContainer } = FormItems const PasswordField = input => <TextField {...input} type="password" /> const EmailField = input => <TextField {...input} type="email" /> -const Step1 = ({ journal, handleSubmit, error, type }) => ( +const Step1 = ({ handleSubmit, error, type, prevStep, submitting }) => ( <FormContainer onSubmit={handleSubmit}> {type === 'signup' && ( <Row> @@ -19,7 +20,7 @@ const Step1 = ({ journal, handleSubmit, error, type }) => ( <ValidatedField component={EmailField} name="email" - validate={[required]} + validate={[required, emailValidator]} /> </RowItem> </Row> @@ -52,7 +53,10 @@ const Step1 = ({ journal, handleSubmit, error, type }) => ( </Row> )} <Row> - <Button primary type="submit"> + <Button onClick={prevStep} type="button"> + BACK + </Button> + <Button disabled={submitting} primary type="submit"> CONFIRM </Button> </Row> @@ -63,4 +67,5 @@ export default reduxForm({ form: 'signUpInvitation', destroyOnUnmount: false, forceUnregisterOnUnmount: true, + validate: passwordValidator, })(Step1) diff --git a/packages/components-faraday/src/components/UIComponents/FormItems.js b/packages/components-faraday/src/components/UIComponents/FormItems.js index 275aea4bece3e3f10968df8a6c55f58858ab3c69..3d8841a2525edf90c148cd71fe10c0b31bfe37ea 100644 --- a/packages/components-faraday/src/components/UIComponents/FormItems.js +++ b/packages/components-faraday/src/components/UIComponents/FormItems.js @@ -7,6 +7,9 @@ const defaultText = css` font-family: ${th('fontReading')}; font-size: ${th('fontSizeBaseSmall')}; ` +export const DefaultText = styled.div` + ${defaultText}; +` export const RootContainer = styled.div` background-color: ${th('backgroundColorReverse')}; @@ -49,11 +52,11 @@ export const Row = styled.div` align-items: flex-start; display: flex; flex-direction: row; - justify-content: space-evenly; + justify-content: ${({ justify }) => justify || 'space-evenly'}; margin: ${({ noMargin }) => noMargin ? 0 : css`calc(${th('subGridUnit')} * 2) 0`}; - div[role='alert'] { + label + div[role='alert'] { margin-top: 0; } ` @@ -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} /> diff --git a/packages/components-faraday/src/components/utils.js b/packages/components-faraday/src/components/utils.js index 3050fa966fc9ec5eb5e64c27dee085456277d5a8..0771a359c73ad1fab8e65e839decae6ff907711c 100644 --- a/packages/components-faraday/src/components/utils.js +++ b/packages/components-faraday/src/components/utils.js @@ -74,6 +74,20 @@ const generatePasswordHash = () => .slice(4), ).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 }) => ({ ...values, admin: false, diff --git a/packages/xpub-faraday/config/validations.js b/packages/xpub-faraday/config/validations.js index 591ba26b0cf2ecb99fc3fd51d14fdb69a2562782..ec4ff13a360763abf602ba41b92742870cbf3a4a 100644 --- a/packages/xpub-faraday/config/validations.js +++ b/packages/xpub-faraday/config/validations.js @@ -125,6 +125,7 @@ module.exports = { handlingEditor: Joi.boolean(), invitationToken: Joi.string().allow(''), confirmationToken: Joi.string().allow(''), + agreeTC: Joi.boolean(), }, team: { group: Joi.string(),