PromucFlow_constructor/app/client/src/reducers/uiReducers/commentsReducer/handleCreateNewCommentThreadSuccess.ts
2021-05-20 17:33:08 +05:30

36 lines
998 B
TypeScript

import { ReduxAction } from "constants/ReduxActionConstants";
import { get } from "lodash";
import { CommentsReduxState } from "./interfaces";
/**
* Append threadId to { refId: commentThreadId[] }
* Update commentThreads map with newly created thread
*/
const handleCreateNewCommentThreadSuccess = (
state: CommentsReduxState,
action: ReduxAction<any>,
) => {
const { applicationId, id, refId } = action.payload;
state.commentThreadsMap[id] = action.payload;
if (!state.applicationCommentThreadsByRef[applicationId]) {
state.applicationCommentThreadsByRef[applicationId] = {};
}
const commentThreadsIdsForRefId = get(
state.applicationCommentThreadsByRef[applicationId],
refId,
[],
);
state.applicationCommentThreadsByRef[applicationId] = {
...state.applicationCommentThreadsByRef[applicationId],
[refId]: Array.from(new Set([id, ...commentThreadsIdsForRefId])),
};
return { ...state };
};
export default handleCreateNewCommentThreadSuccess;