Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { actions } from 'pubsweet-client'
/* constants */
export const CREATE_DRAFT_REQUEST = 'CREATE_DRAFT_REQUEST'
export const CREATE_DRAFT_SUCCESS = 'CREATE_DRAFT_SUCCESS'
/* action creators */
export const createDraftRequest = () => ({
type: CREATE_DRAFT_REQUEST,
})
export const createDraftSuccess = draft => ({
type: CREATE_DRAFT_SUCCESS,
draft,
})
/* actions */
export const createDraftSubmission = history => dispatch =>
dispatch(actions.createCollection()).then(({ collection }) => {
if (!collection.id) {
throw new Error('Failed to create a project')
}
// TODO: rethrow errors so they can be caught here
return dispatch(
actions.createFragment(collection, {
created: new Date(), // TODO: set on server
files: {
supplementary: [],
},
fragmentType: 'version',
metadata: {},
version: 1,
}),
).then(({ fragment }) => {
const route = `/projects/${collection.id}/versions/${fragment.id}/submit`
// redirect after a short delay
window.setTimeout(() => {
history.push(route)
}, 1000)
})
})
/* reducer */
const initialState = {
complete: undefined,
converting: false,
error: undefined,
}
export default (state = initialState, action) => {
switch (action.type) {
default:
return state
}
}