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

refactor(component): wip: handle errors

parent b16375e0
No related branches found
No related tags found
No related merge requests found
import React from 'react'
import { get, map } from 'lodash'
import { connect } from 'react-redux'
import { reduxForm } from 'redux-form'
import { reduxForm, SubmissionError } from 'redux-form'
import styled from 'styled-components'
import { actions } from 'pubsweet-client'
import { create } from 'pubsweet-client/src/helpers/api'
......@@ -17,12 +17,19 @@ import EditUserForm from './EditUserForm'
const getRoleOptions = journal =>
map(journal.roles, (value, key) => ({ label: value, value: key }))
const onSubmit = (values, dispatch, { isEdit }) => {
const onSubmit = (values, dispatch, { isEdit, history }) => {
if (!isEdit) {
create('/users/invite', values).then(
r => r,
// err => console.log(err),
)
return create('/users/invite', values)
.then(r => history.push('/admin/users'))
.catch(error => {
const err = get(error, 'response')
if (err) {
const errorMessage = get(JSON.parse(err), 'error')
throw new SubmissionError({
role: errorMessage || 'Something went wrong',
})
}
})
}
}
......
......@@ -33,7 +33,7 @@ const Admin = ({
<div>
<Header>
<span>Users</span>
<AddButton onClick={() => history.push('/')}>
<AddButton onClick={() => history.push('/admin/urers/add')}>
<Icon color="#667080">plus-circle</Icon>
Add User
</AddButton>
......
import { get } from 'lodash'
import { withJournal } from 'xpub-journal'
import { login } from 'pubsweet-component-xpub-authentication/src/redux/login'
import { SubmissionError } from 'redux-form'
import { create } from 'pubsweet-client/src/helpers/api'
import { compose, withState, withProps, withHandlers } from 'recompose'
import SignUpInvitation from './SignUpInvitationForm'
const loginUser = (dispatch, values, history) =>
dispatch(login(values))
.then(() => {
history.push('/')
})
.catch(error => {
const err = get(error, 'response')
if (err) {
const errorMessage = get(JSON.parse(err), 'error')
throw new SubmissionError({
password: errorMessage || 'Something went wrong',
})
}
})
const confirmUser = (email, token) => (values, dispatch, { history }) => {
const request = { ...values, email, token }
if (values) {
create('/users/invite/password/reset', request).then(
r => history.push('/'),
// err => console.log(err),
)
return create('/users/invite/password/reset', request)
.then(r => {
const { username } = r
const { password } = values
loginUser(dispatch, { username, password }, history)
})
.catch(error => {
const err = get(error, 'response')
if (err) {
const errorMessage = get(JSON.parse(err), 'error')
throw new SubmissionError({
password: errorMessage || 'Something went wrong',
})
}
})
}
}
......
......@@ -25,7 +25,7 @@ module.exports = {
'pubsweet-client': {
API_ENDPOINT: '/api',
'login-redirect': '/',
'redux-log': false,
'redux-log': true,
theme: process.env.PUBSWEET_THEME,
},
'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