mirror of
https://github.com/astuto/astuto.git
synced 2025-12-14 18:57:51 +01:00
49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
import {
|
|
CommentRequestSuccessAction,
|
|
COMMENT_REQUEST_SUCCESS,
|
|
} from '../actions/Comment/requestComment';
|
|
|
|
import {
|
|
CommentUpdateActionTypes,
|
|
COMMENT_UPDATE_SUCCESS,
|
|
} from '../actions/Comment/updateComment';
|
|
|
|
import IComment from '../interfaces/IComment';
|
|
|
|
const initialState: IComment = {
|
|
id: 0,
|
|
body: '',
|
|
parentId: null,
|
|
isPostUpdate: false,
|
|
userFullName: '<Unknown user>',
|
|
userEmail: 'example@example.com',
|
|
userRole: 0,
|
|
createdAt: undefined,
|
|
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,
|
|
parentId: action.comment.parent_id,
|
|
isPostUpdate: action.comment.is_post_update,
|
|
userFullName: action.comment.user_full_name,
|
|
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; |