2021-09-13 20:41:05 +00:00
|
|
|
import { put, select, takeLatest } from 'redux-saga/effects';
|
2020-07-31 18:22:30 +00:00
|
|
|
|
2020-08-28 19:41:08 +00:00
|
|
|
import * as types from '../../../actions/actionsTypes';
|
2022-04-28 20:37:25 +00:00
|
|
|
import { Services } from '../../../lib/services';
|
2022-06-06 14:17:51 +00:00
|
|
|
import EventEmitter from '../../../lib/methods/helpers/events';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { inquiryFailure, inquirySetEnabled, inquirySuccess } from '../actions/inquiry';
|
|
|
|
import { getInquiriesQueued, isOmnichannelStatusAvailable } from '../lib';
|
2020-07-31 18:22:30 +00:00
|
|
|
|
|
|
|
const handleRequest = function* handleRequest() {
|
|
|
|
try {
|
2022-04-28 20:37:25 +00:00
|
|
|
const routingConfig = yield Services.getRoutingConfig();
|
2020-08-28 19:41:08 +00:00
|
|
|
const user = yield select(state => state.login.user);
|
2020-07-31 18:22:30 +00:00
|
|
|
// if routingConfig showQueue is enabled and omnichannel is enabled
|
2020-08-28 19:41:08 +00:00
|
|
|
const showQueue = routingConfig.showQueue && isOmnichannelStatusAvailable(user);
|
2020-07-31 18:22:30 +00:00
|
|
|
|
|
|
|
if (showQueue) {
|
|
|
|
// get all the current chats on the queue
|
2020-08-28 19:41:08 +00:00
|
|
|
const result = yield getInquiriesQueued();
|
2020-07-31 18:22:30 +00:00
|
|
|
if (result.success) {
|
|
|
|
const { inquiries } = result;
|
|
|
|
|
|
|
|
// subscribe to inquiry queue changes
|
2020-08-28 19:41:08 +00:00
|
|
|
EventEmitter.emit('INQUIRY_SUBSCRIBE');
|
2020-07-31 18:22:30 +00:00
|
|
|
|
|
|
|
// put request result on redux state
|
|
|
|
yield put(inquirySuccess(inquiries));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// set enabled to know if we should show the queue button
|
|
|
|
yield put(inquirySetEnabled(showQueue));
|
|
|
|
} catch (e) {
|
|
|
|
yield put(inquiryFailure(e));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const root = function* root() {
|
|
|
|
yield takeLatest(types.INQUIRY.REQUEST, handleRequest);
|
|
|
|
};
|
|
|
|
export default root;
|