2019-10-29 07:20:54 +00:00
|
|
|
export const isEmptyObject = obj =>
|
|
|
|
Object.keys(obj).length === 0 && obj.constructor === Object;
|
|
|
|
|
|
|
|
export const arrayToHashById = array =>
|
|
|
|
array.reduce((map, obj) => {
|
|
|
|
const newMap = map;
|
|
|
|
newMap[obj.id] = obj;
|
|
|
|
return newMap;
|
|
|
|
}, {});
|
2020-01-17 08:06:05 +00:00
|
|
|
|
|
|
|
export const IFrameHelper = {
|
|
|
|
isIFrame: () => window.self !== window.top,
|
|
|
|
sendMessage: msg => {
|
|
|
|
window.parent.postMessage(
|
|
|
|
`chatwoot-widget:${JSON.stringify({ ...msg })}`,
|
|
|
|
'*'
|
|
|
|
);
|
|
|
|
},
|
|
|
|
};
|
2020-02-05 05:57:22 +00:00
|
|
|
|
|
|
|
export const getAvailableAgentsText = (agents = []) => {
|
|
|
|
const count = agents.length;
|
|
|
|
if (count === 1) {
|
|
|
|
const [agent] = agents;
|
|
|
|
return `${agent.name} is available`;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count === 2) {
|
|
|
|
const [first, second] = agents;
|
2020-02-05 06:26:33 +00:00
|
|
|
return `${first.name} and ${second.name} are available`;
|
2020-02-05 05:57:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const [agent] = agents;
|
|
|
|
const rest = agents.length - 1;
|
|
|
|
return `${agent.name} and ${rest} others are available`;
|
|
|
|
};
|