Files
astuto/app/javascript/reducers/commentReducer.ts
2019-09-30 23:28:52 +02:00

37 lines
836 B
TypeScript

import {
CommentRequestSuccessAction,
COMMENT_REQUEST_SUCCESS,
} from '../actions/requestComment';
import IComment from '../interfaces/IComment';
const initialState: IComment = {
id: 0,
body: '',
parentId: null,
userFullName: '<Unknown user>',
userEmail: 'example@example.com',
updatedAt: undefined,
};
const commentReducer = (
state = initialState,
action: CommentRequestSuccessAction,
): IComment => {
switch (action.type) {
case COMMENT_REQUEST_SUCCESS:
return {
id: action.comment.id,
body: action.comment.body,
parentId: action.comment.parent_id,
userFullName: action.comment.user_full_name,
userEmail: action.comment.user_email,
updatedAt: action.comment.updated_at,
};
default:
return state;
}
}
export default commentReducer;