import { createReducer } from '@reduxjs/toolkit'; import { IChatsState, IChatsPayload,IChatPayload } from '../../../typescript/redux/chats/interfaces'; import { actionGetChatsSuccess, actionGetChatsReject, selectCompanionSuccess } from '../action'; const initialState: IChatsState = { chat:{ name: '', lastName: '', avatarUrl:'', color: '', _id: '', companionId: '', owner: { _id: '', }, createdAt: '', updatedAt: '', __v: 0, }, total: "0", limit: "0", page: "0", chats: [] } const reducerChats = createReducer(initialState, { [actionGetChatsSuccess.type]: (state,{ payload }:IChatsPayload) => { return {...state,...payload}; }, [actionGetChatsReject.type]: (state, _) => { return state; }, [selectCompanionSuccess.type]: (state, { payload }: IChatPayload) => { const newState = { ...state } newState.chat = payload return newState; }, }); export default reducerChats;