Updating the `unattended` tab to include conversations where the customer responded and is awaiting an agent's response. Previously it showed only the conversations where the first response was pending. Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
62 lines
1.9 KiB
JavaScript
62 lines
1.9 KiB
JavaScript
export const findPendingMessageIndex = (chat, message) => {
|
|
const { echo_id: tempMessageId } = message;
|
|
return chat.messages.findIndex(
|
|
m => m.id === message.id || m.id === tempMessageId
|
|
);
|
|
};
|
|
|
|
export const filterByStatus = (chatStatus, filterStatus) =>
|
|
filterStatus === 'all' ? true : chatStatus === filterStatus;
|
|
|
|
export const filterByInbox = (shouldFilter, inboxId, chatInboxId) => {
|
|
const isOnInbox = Number(inboxId) === chatInboxId;
|
|
return inboxId ? isOnInbox && shouldFilter : shouldFilter;
|
|
};
|
|
|
|
export const filterByTeam = (shouldFilter, teamId, chatTeamId) => {
|
|
const isOnTeam = Number(teamId) === chatTeamId;
|
|
return teamId ? isOnTeam && shouldFilter : shouldFilter;
|
|
};
|
|
|
|
export const filterByLabel = (shouldFilter, labels, chatLabels) => {
|
|
const isOnLabel = labels.every(label => chatLabels.includes(label));
|
|
return labels.length ? isOnLabel && shouldFilter : shouldFilter;
|
|
};
|
|
export const filterByUnattended = (
|
|
shouldFilter,
|
|
conversationType,
|
|
firstReplyOn,
|
|
waitingSince
|
|
) => {
|
|
return conversationType === 'unattended'
|
|
? (!firstReplyOn || !!waitingSince) && shouldFilter
|
|
: shouldFilter;
|
|
};
|
|
|
|
export const applyPageFilters = (conversation, filters) => {
|
|
const { inboxId, status, labels = [], teamId, conversationType } = filters;
|
|
const {
|
|
status: chatStatus,
|
|
inbox_id: chatInboxId,
|
|
labels: chatLabels = [],
|
|
meta = {},
|
|
first_reply_created_at: firstReplyOn,
|
|
waiting_since: waitingSince,
|
|
} = conversation;
|
|
const team = meta.team || {};
|
|
const { id: chatTeamId } = team;
|
|
|
|
let shouldFilter = filterByStatus(chatStatus, status);
|
|
shouldFilter = filterByInbox(shouldFilter, inboxId, chatInboxId);
|
|
shouldFilter = filterByTeam(shouldFilter, teamId, chatTeamId);
|
|
shouldFilter = filterByLabel(shouldFilter, labels, chatLabels);
|
|
shouldFilter = filterByUnattended(
|
|
shouldFilter,
|
|
conversationType,
|
|
firstReplyOn,
|
|
waitingSince
|
|
);
|
|
|
|
return shouldFilter;
|
|
};
|