Commit e3d38556 authored by Renato Becker's avatar Renato Becker Committed by Tasso Evangelista

[FIX] Get next agent (#163)

* Changed the logic to display the department field on registration form.

* After testing the new Livechat client in production environment, a few issues were detected and fixed.

* Fixes related to iframe api methods.

* Update src/lib/hooks.js
Co-Authored-By: 's avatarrenatobecker <renato.augusto.becker@gmail.com>
parent 45b02572
No preview for this file type
......@@ -72,8 +72,8 @@ const api = {
},
clearDepartment() {
const { iframe } = store.state;
store.setState({ iframe: { ...iframe, department: null } });
const { iframe: { guest, ...iframe } } = store.state;
store.setState({ iframe: { ...iframe, guest: { ...guest, department: null } } });
},
setExpanded(expanded) {
......
......@@ -17,11 +17,10 @@ const getAgent = (triggerAction) => {
if (params.sender === 'queue') {
const { state } = store;
const { triggerAgent } = state;
const { triggerAgent, iframe: { guest: { department } } } = state;
if (triggerAgent) {
const cacheAgent = triggerAgent;
// cache valid for 1h
if (cacheAgent.ts && Date.now() - cacheAgent.ts < agentCacheExpiry) {
return resolve(cacheAgent.agent);
......@@ -30,7 +29,7 @@ const getAgent = (triggerAction) => {
let agent;
try {
(agent = await Livechat.nextAgent());
(agent = await Livechat.nextAgent(department));
} catch (error) {
return reject(error);
}
......@@ -95,7 +94,7 @@ class Triggers {
async fire(trigger) {
const { token, user, firedTriggers = [] } = store.state;
if (!this._enabled || user) { // need to think about testing user obj here..
if (!this._enabled || user) {
return;
}
const { actions } = trigger;
......@@ -116,7 +115,6 @@ class Triggers {
await store.setState({ triggered: true, messages: insert(store.state.messages, message).filter(({ msg }) => ({ msg })) });
await processUnread();
// TODO: Need to think about the implementation below.. Is it possible that when the room is created, the available agent is not the same one that was previously selected?
if (agent && agent._id) {
await store.setState({ agent });
}
......
......@@ -26,7 +26,6 @@ const initialState = {
guest: {},
theme: {},
},
department: null,
gdpr: {
accepted: false,
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment