diff --git a/packages/components-faraday/src/components/Admin/AddEditUser.js b/packages/components-faraday/src/components/Admin/AddEditUser.js index 08223f1067bbcd57b9f9e4be533c21bac1654b27..2b76bde79831c4296b5bfd4c555fa5c178c538e7 100644 --- a/packages/components-faraday/src/components/Admin/AddEditUser.js +++ b/packages/components-faraday/src/components/Admin/AddEditUser.js @@ -49,6 +49,7 @@ const AddEditUser = ({ user, history, error, + submitting, }) => ( <Root> <FormContainer onSubmit={handleSubmit}> @@ -68,7 +69,7 @@ const AddEditUser = ({ )} <Row> <Button onClick={history.goBack}>Back</Button> - <Button primary type="submit"> + <Button disabled={submitting} primary type="submit"> Save user </Button> </Row> diff --git a/packages/components-faraday/src/components/Admin/utils.js b/packages/components-faraday/src/components/Admin/utils.js index 9d1204cbbeaf5a4d05a82b63f5e8de425ac4f2b1..1029db45e7ae91d1919fa005dbb927398badd507 100644 --- a/packages/components-faraday/src/components/Admin/utils.js +++ b/packages/components-faraday/src/components/Admin/utils.js @@ -48,7 +48,8 @@ export const parseUpdateUser = values => { export const handleFormError = error => { const err = get(error, 'response') if (err) { - const errorMessage = get(JSON.parse(err), 'error') + const errorMessage = + get(JSON.parse(err), 'error') || get(JSON.parse(err), 'message') throw new SubmissionError({ _error: errorMessage || 'Something went wrong', }) diff --git a/packages/components-faraday/src/components/SignUp/SignUpInvitationPage.js b/packages/components-faraday/src/components/SignUp/SignUpInvitationPage.js index 89bed246e694a9bd159ea127a934fbc392b4a91e..dccbba1310d2fa5ce8f2172331503653a3900d91 100644 --- a/packages/components-faraday/src/components/SignUp/SignUpInvitationPage.js +++ b/packages/components-faraday/src/components/SignUp/SignUpInvitationPage.js @@ -1,46 +1,29 @@ -import { get } from 'lodash' +import { omit } from 'lodash' import { withJournal } from 'xpub-journal' -import { SubmissionError } from 'redux-form' import { create } from 'pubsweet-client/src/helpers/api' import { loginUser } from 'pubsweet-component-login/actions' import { compose, withState, withProps, withHandlers } from 'recompose' import SignUpInvitation from './SignUpInvitationForm' -import { parseSignupAuthor } from '../utils' +import { parseSignupAuthor, handleFormError } from '../utils' const login = (dispatch, values, history) => dispatch(loginUser(values)) .then(() => { history.push('/') }) - .catch(error => { - const err = get(error, 'response') - if (err) { - const errorMessage = get(JSON.parse(err), 'error') - throw new SubmissionError({ - confirmPassword: errorMessage || 'Something went wrong', - }) - } - }) + .catch(handleFormError) const confirmUser = (email, token, history) => (values, dispatch) => { const request = { ...values, email, token } if (values) { - return create('/users/reset-password', request) + return create('/users/reset-password', omit(request, ['confirmPassword'])) .then(r => { const { username } = r const { password } = values login(dispatch, { username, password }, history) }) - .catch(error => { - const err = get(error, 'response') - if (err) { - const errorMessage = get(JSON.parse(err), 'error') - throw new SubmissionError({ - _error: errorMessage || 'Something went wrong', - }) - } - }) + .catch(handleFormError) } } @@ -56,29 +39,12 @@ const signUpUser = history => (values, dispatch) => }) }) }) - .catch(error => { - const err = get(error, 'response') - if (err) { - const errorMessage = get(JSON.parse(err), 'message') - throw new SubmissionError({ - confirmPassword: errorMessage || 'Something went wrong', - }) - } - }) + .catch(handleFormError) export default compose( withJournal, withState('step', 'changeStep', 0), - withHandlers({ - nextStep: ({ changeStep }) => () => changeStep(step => step + 1), - prevStep: ({ changeStep }) => () => changeStep(step => step - 1), - submitConfirmation: ({ - initialValues: { email = '', token = '' }, - history, - }) => confirmUser(email, token, history), - signUp: ({ history }) => signUpUser(history), - }), - withProps(({ location, type, signUp, submitConfirmation }) => { + withProps(({ location }) => { const params = new URLSearchParams(location.search) const email = params.get('email') || '' const token = params.get('token') || '' @@ -96,7 +62,18 @@ export default compose( firstName, affiliation, }, - onSubmit: type === 'signup' ? signUp : submitConfirmation, } }), + withHandlers({ + nextStep: ({ changeStep }) => () => changeStep(step => step + 1), + prevStep: ({ changeStep }) => () => changeStep(step => step - 1), + submitConfirmation: ({ + initialValues: { email = '', token = '' }, + history, + }) => confirmUser(email, token, history), + signUp: ({ history }) => signUpUser(history), + }), + withProps(({ type, signUp, submitConfirmation }) => ({ + onSubmit: type === 'signup' ? signUp : submitConfirmation, + })), )(SignUpInvitation) diff --git a/packages/components-faraday/src/components/SignUp/SignUpStep0.js b/packages/components-faraday/src/components/SignUp/SignUpStep0.js index dbee6e7e06abd5556d9d15c7aa50c04ffeddc910..f9249333ee6cd689a869366bcaf43ae1644d3602 100644 --- a/packages/components-faraday/src/components/SignUp/SignUpStep0.js +++ b/packages/components-faraday/src/components/SignUp/SignUpStep0.js @@ -90,6 +90,7 @@ const Step0 = ({ journal, handleSubmit, initialValues, error }) => for further information. </PrivatePolicy> </Row> + <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 55a407e0a1a492832dd8511f050853f9ced68520..062cfadd92fe333b85c54f05b62eb463a090bad6 100644 --- a/packages/components-faraday/src/components/SignUp/SignUpStep1.js +++ b/packages/components-faraday/src/components/SignUp/SignUpStep1.js @@ -52,6 +52,7 @@ const Step1 = ({ handleSubmit, error, type, prevStep, submitting }) => ( </RowItem> </Row> )} + <Row /> <Row> <Button onClick={prevStep} type="button"> BACK diff --git a/packages/components-faraday/src/components/UIComponents/FormItems.js b/packages/components-faraday/src/components/UIComponents/FormItems.js index 3d8841a2525edf90c148cd71fe10c0b31bfe37ea..8f6ebf89faf00b45808573e56a929b1635470ee5 100644 --- a/packages/components-faraday/src/components/UIComponents/FormItems.js +++ b/packages/components-faraday/src/components/UIComponents/FormItems.js @@ -86,7 +86,7 @@ export const Err = styled.span` color: ${th('colorError')}; font-family: ${th('fontReading')}; font-size: ${th('fontSizeBase')}; - margin-top: calc(${th('gridUnit')} * -1); + margin-top: 0; text-align: center; ` diff --git a/packages/components-faraday/src/components/utils.js b/packages/components-faraday/src/components/utils.js index 0771a359c73ad1fab8e65e839decae6ff907711c..49b33a507b7b597b2eb5bf72078024eb5fcae83f 100644 --- a/packages/components-faraday/src/components/utils.js +++ b/packages/components-faraday/src/components/utils.js @@ -1,3 +1,4 @@ +import { SubmissionError } from 'redux-form' import { get, find, capitalize } from 'lodash' export const parseTitle = version => { @@ -55,6 +56,17 @@ export const handleError = fn => e => { fn(get(JSON.parse(e.response), 'error') || 'Oops! Something went wrong!') } +export const handleFormError = error => { + const err = get(error, 'response') + if (err) { + const errorMessage = + get(JSON.parse(err), 'error') || get(JSON.parse(err), 'message') + throw new SubmissionError({ + _error: errorMessage || 'Something went wrong', + }) + } +} + const emailRegex = new RegExp( /^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i, //eslint-disable-line )