Files
astuto/app/javascript/reducers/postStatusChangesReducer.ts
Riccardo Graziosi dad382d2b1 Post follow and updates notifications V1 (#111)
* It is now possible to follow a post in order to receive updates about it
* Notifications are now sent when updates are published
* Post status changes are now tracked
* Update sidebar now shows the post status history
* Mark a comment as a post update using the comment form
* ... more ...
2022-05-28 11:03:36 +02:00

71 lines
1.7 KiB
TypeScript

import {
PostStatusChangesRequestActionTypes,
POST_STATUS_CHANGES_REQUEST_START,
POST_STATUS_CHANGES_REQUEST_SUCCESS,
POST_STATUS_CHANGES_REQUEST_FAILURE,
} from "../actions/PostStatusChange/requestPostStatusChanges";
import {
PostStatusChangeSubmitted,
POST_STATUS_CHANGE_SUBMITTED
} from '../actions/PostStatusChange/submittedPostStatusChange';
import IPostStatusChange from "../interfaces/IPostStatusChange";
export interface PostStatusChangesState {
items: Array<IPostStatusChange>;
areLoading: boolean;
error: string;
}
const initialState: PostStatusChangesState = {
items: [],
areLoading: false,
error: '',
};
const postStatusChangesReducer = (
state = initialState,
action:
PostStatusChangesRequestActionTypes |
PostStatusChangeSubmitted
) => {
switch (action.type) {
case POST_STATUS_CHANGES_REQUEST_START:
return {
...state,
areLoading: true,
};
case POST_STATUS_CHANGES_REQUEST_SUCCESS:
return {
...state,
items: action.postStatusChanges.map(postStatusChange => ({
postStatusId: postStatusChange.post_status_id,
userFullName: postStatusChange.user_full_name,
userEmail: postStatusChange.user_email,
updatedAt: postStatusChange.updated_at,
})),
areLoading: false,
error: '',
};
case POST_STATUS_CHANGES_REQUEST_FAILURE:
return {
...state,
areLoading: false,
error: action.error,
};
case POST_STATUS_CHANGE_SUBMITTED:
return {
...state,
items: [action.postStatusChange, ...state.items],
};
default:
return state;
}
}
export default postStatusChangesReducer;