Skip to content
Snippets Groups Projects
Commit 1e8f5403 authored by Alexandru Munteanu's avatar Alexandru Munteanu
Browse files

refactor(user-management): refactor to work with new endpoint

parent d9c428c1
No related branches found
No related tags found
1 merge request!5Refactor component invite
......@@ -18,8 +18,15 @@ import { getRoleOptions, setAdmin, parseUpdateUser } from './utils'
const onSubmit = (values, dispatch, { isEdit, history }) => {
if (!isEdit) {
const newValues = setAdmin(values)
return create('/users/invite', newValues)
.then(() => history.push('/admin/users'))
return create('/users', newValues)
.then(r => {
history.push('/admin/users')
create(`/emails`, {
email: r.email,
type: 'invite',
role: values.role,
})
})
.catch(error => {
const err = get(error, 'response')
if (err) {
......
import { pick, map } from 'lodash'
import { pick, map, omit } from 'lodash'
const generatePasswordHash = () =>
Array.from({ length: 4 }, () =>
Math.random()
.toString(36)
.slice(4),
).join('')
export const getRoleOptions = journal =>
map(journal.roles, (value, key) => ({ label: value, value: key }))
......@@ -11,7 +18,14 @@ export const setAdmin = values => {
newValues.admin = false
}
return newValues
return {
...omit(newValues, ['role']),
isConfirmed: false,
passwordResetToken: generatePasswordHash(),
password: 'defaultpass',
editorInChief: newValues.role === 'editorInChief',
handlingEditor: newValues.role === 'handlingEditor',
}
}
export const parseUpdateUser = values => {
......@@ -22,7 +36,6 @@ export const parseUpdateUser = values => {
'affiliation',
'title',
'roles',
'rev',
'editorInChief',
'handlingEditor',
]
......
......@@ -7,5 +7,6 @@
"pubsweet-components-faraday",
"@pubsweet/component-aws-s3",
"pubsweet-component-invite",
"pubsweet-component-user-manager"
"pubsweet-component-user-manager",
"pubsweet-component-email"
]
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