Files
astuto/app/javascript/reducers/commentReducer.ts

49 lines
1.2 KiB
TypeScript
Raw Normal View History

import {
2019-09-26 16:03:41 +02:00
CommentRequestSuccessAction,
COMMENT_REQUEST_SUCCESS,
2022-05-07 11:27:07 +02:00
} from '../actions/Comment/requestComment';
import {
CommentUpdateActionTypes,
COMMENT_UPDATE_SUCCESS,
} from '../actions/Comment/updateComment';
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',
userRole: 0,
createdAt: undefined,
2019-09-17 17:04:19 +02:00
updatedAt: undefined,
};
const commentReducer = (
state = initialState,
action: CommentRequestSuccessAction | CommentUpdateActionTypes,
): IComment => {
switch (action.type) {
case COMMENT_REQUEST_SUCCESS:
case COMMENT_UPDATE_SUCCESS:
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,
userFullName: action.comment.user_full_name,
2019-09-30 23:28:52 +02:00
userEmail: action.comment.user_email,
userRole: action.comment.user_role,
createdAt: action.comment.created_at,
updatedAt: action.comment.updated_at,
};
default:
return state;
}
}
export default commentReducer;