2019-09-17 11:33:18 +02:00
|
|
|
import {
|
2019-09-26 16:03:41 +02:00
|
|
|
CommentRequestSuccessAction,
|
2019-09-17 11:33:18 +02:00
|
|
|
COMMENT_REQUEST_SUCCESS,
|
2022-05-07 11:27:07 +02:00
|
|
|
} from '../actions/Comment/requestComment';
|
2019-09-17 11:33:18 +02:00
|
|
|
|
2022-06-22 10:17:42 +02:00
|
|
|
import {
|
|
|
|
|
CommentUpdateActionTypes,
|
|
|
|
|
COMMENT_UPDATE_SUCCESS,
|
|
|
|
|
} from '../actions/Comment/updateComment';
|
|
|
|
|
|
2019-09-17 11:33:18 +02:00
|
|
|
import IComment from '../interfaces/IComment';
|
|
|
|
|
|
|
|
|
|
const initialState: IComment = {
|
|
|
|
|
id: 0,
|
|
|
|
|
body: '',
|
2019-09-17 17:04:19 +02:00
|
|
|
parentId: null,
|
2019-10-01 19:15:03 +02:00
|
|
|
isPostUpdate: false,
|
2019-09-17 17:04:19 +02:00
|
|
|
userFullName: '<Unknown user>',
|
2019-09-30 23:28:52 +02:00
|
|
|
userEmail: 'example@example.com',
|
2024-02-14 19:40:39 +01:00
|
|
|
userRole: 0,
|
2022-06-22 10:17:42 +02:00
|
|
|
createdAt: undefined,
|
2019-09-17 17:04:19 +02:00
|
|
|
updatedAt: undefined,
|
2019-09-17 11:33:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const commentReducer = (
|
|
|
|
|
state = initialState,
|
2022-06-22 10:17:42 +02:00
|
|
|
action: CommentRequestSuccessAction | CommentUpdateActionTypes,
|
2019-09-17 11:33:18 +02:00
|
|
|
): IComment => {
|
|
|
|
|
switch (action.type) {
|
|
|
|
|
case COMMENT_REQUEST_SUCCESS:
|
2022-06-22 10:17:42 +02:00
|
|
|
case COMMENT_UPDATE_SUCCESS:
|
2019-09-17 11:33:18 +02:00
|
|
|
return {
|
|
|
|
|
id: action.comment.id,
|
|
|
|
|
body: action.comment.body,
|
2019-09-17 17:04:19 +02:00
|
|
|
parentId: action.comment.parent_id,
|
2019-10-01 19:15:03 +02:00
|
|
|
isPostUpdate: action.comment.is_post_update,
|
2019-09-17 11:33:18 +02:00
|
|
|
userFullName: action.comment.user_full_name,
|
2019-09-30 23:28:52 +02:00
|
|
|
userEmail: action.comment.user_email,
|
2024-02-14 19:40:39 +01:00
|
|
|
userRole: action.comment.user_role,
|
2022-06-22 10:17:42 +02:00
|
|
|
createdAt: action.comment.created_at,
|
2019-09-17 11:33:18 +02:00
|
|
|
updatedAt: action.comment.updated_at,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default commentReducer;
|