-
Notifications
You must be signed in to change notification settings - Fork 0
/
collectionCommentActions.js
60 lines (51 loc) · 2.18 KB
/
collectionCommentActions.js
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
60
import * as APIUtil from '../util/collectionCommentAPIUtil';
import { setRedirect } from './uiActions';
import { processResponse } from '../util/APIRequestHelpers';
export const RECEIVE_COLLECTION_COMMENT = 'RECEIVE_COLLECTION_COMMENT';
export const RECEIVE_UPDATED_COLLECTION_COMMENT = 'RECEIVE_UPDATED_COLLECTION_COMMENT';
export const REMOVE_COLLECTION_COMMENT = 'REMOVE_COLLECTION_COMMENT';
export const RECEIVE_COLLECTION_COMMENT_ERRORS = 'RECEIVE_COLLECTION_COMMENT_ERRORS';
export const RESET_COLLECTION_COMMENT_ERRORS = 'RESET_COLLECTION_COMMENT_ERRORS';
export const receiveCollectionComment = collectionComment => ({
type: RECEIVE_COLLECTION_COMMENT,
collectionComment,
});
export const receiveUpdatedCollectionComment = collectionComment => ({
type: RECEIVE_UPDATED_COLLECTION_COMMENT,
collectionComment,
});
export const removeCollectionComment = collectionCommentId => ({
type: REMOVE_COLLECTION_COMMENT,
collectionCommentId,
});
export const receiveCollectionCommentErrors = errors => ({
type: RECEIVE_COLLECTION_COMMENT_ERRORS,
errors,
});
export const resetCollectionCommentErrors = () => ({
type: RESET_COLLECTION_COMMENT_ERRORS,
});
export const createCollectionComment = collectionComment => dispatch => (
APIUtil.createCollectionComment(collectionComment).then(response => processResponse(response))
.then(collectionComment => {
dispatch(receiveCollectionComment(collectionComment));
dispatch(setRedirect(`/collections/${collectionComment.collection_id}`));
}).catch(errors => (
dispatch(receiveCollectionCommentErrors(errors))
))
);
export const updateCollectionComment = collectionComment => dispatch => (
APIUtil.updateCollectionComment(collectionComment).then(response => processResponse(response))
.then(collectionComment => {
dispatch(receiveUpdatedCollectionComment(collectionComment));
dispatch(setRedirect(`/collections/${collectionComment.collection_id}`));
}).catch(errors => (
dispatch(receiveCollectionCommentErrors(errors))
))
);
export const deleteCollectionComment = id => dispatch => (
APIUtil.deleteCollectionComment(id)
.then(response => (
dispatch(removeCollectionComment(id))
))
);