2022-03-07 21:16:20 +00:00
|
|
|
import { IOmnichannelRoom, TApplicationActions } from '../../../definitions';
|
2020-08-28 19:41:08 +00:00
|
|
|
import { INQUIRY } from '../../../actions/actionsTypes';
|
2020-07-31 18:22:30 +00:00
|
|
|
|
2022-03-07 21:16:20 +00:00
|
|
|
export interface IInquiry {
|
|
|
|
enabled: boolean;
|
|
|
|
queued: IOmnichannelRoom[];
|
|
|
|
error: any;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const initialState: IInquiry = {
|
2020-07-31 18:22:30 +00:00
|
|
|
enabled: false,
|
|
|
|
queued: [],
|
|
|
|
error: {}
|
|
|
|
};
|
|
|
|
|
2022-03-07 21:16:20 +00:00
|
|
|
export default function inquiry(state = initialState, action: TApplicationActions): IInquiry {
|
2020-07-31 18:22:30 +00:00
|
|
|
switch (action.type) {
|
|
|
|
case INQUIRY.SUCCESS:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
queued: action.inquiries
|
|
|
|
};
|
|
|
|
case INQUIRY.FAILURE:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
error: action.error
|
|
|
|
};
|
|
|
|
case INQUIRY.SET_ENABLED:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
enabled: action.enabled
|
|
|
|
};
|
|
|
|
case INQUIRY.QUEUE_ADD:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
queued: [...state.queued, action.inquiry]
|
|
|
|
};
|
|
|
|
case INQUIRY.QUEUE_UPDATE:
|
|
|
|
return {
|
|
|
|
...state,
|
2021-09-13 20:41:05 +00:00
|
|
|
queued: state.queued.map(item => {
|
2020-07-31 18:22:30 +00:00
|
|
|
if (item._id === action.inquiry._id) {
|
|
|
|
return action.inquiry;
|
|
|
|
}
|
|
|
|
return item;
|
|
|
|
})
|
|
|
|
};
|
|
|
|
case INQUIRY.QUEUE_REMOVE:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
queued: state.queued.filter(({ _id }) => _id !== action.inquiryId)
|
|
|
|
};
|
|
|
|
case INQUIRY.RESET:
|
|
|
|
return initialState;
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|