Skip to content

Commit

Permalink
fix: Count queue time up to closedAt on closed rooms (#29842)
Browse files Browse the repository at this point in the history
Co-authored-by: Aleksander Nicacio da Silva <6494543+aleksandernsilva@users.noreply.github.com>
  • Loading branch information
KevLehman and aleksandernsilva committed Aug 28, 2023
1 parent 5832be2 commit 470c29d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 12 deletions.
9 changes: 9 additions & 0 deletions .changeset/bright-snakes-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@rocket.chat/meteor": patch
---

Fixed an issue causing `queue time` to be calculated from current time when a room was closed without being served.
Now:
- For served rooms: queue time = servedBy time - queuedAt
- For not served, but open rooms = now - queuedAt
- For not served and closed rooms = closedAt - queuedAt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useMutableCallback } from '@rocket.chat/fuselage-hooks';
import { useToastMessageDispatch, useRoute, useUserSubscription, useTranslation, usePermission } from '@rocket.chat/ui-contexts';
import { Meteor } from 'meteor/meteor';
import moment from 'moment';
import React, { useEffect, useState } from 'react';
import React, { useEffect, useMemo, useState } from 'react';

import { ContextualbarScrollableContent, ContextualbarFooter } from '../../../../../components/Contextualbar';
import { useEndpointData } from '../../../../../hooks/useEndpointData';
Expand All @@ -16,6 +16,7 @@ import Label from '../../../components/Label';
import { AgentField, SlaField, ContactField, SourceField } from '../../components';
import PriorityField from '../../components/PriorityField';
import { useOmnichannelRoomInfo } from '../../hooks/useOmnichannelRoomInfo';
import { formatQueuedAt } from '../../utils/formatQueuedAt';
import DepartmentField from './DepartmentField';
import VisitorClientInfo from './VisitorClientInfo';

Expand Down Expand Up @@ -57,6 +58,8 @@ function ChatInfo({ id, route }) {
const visitorId = v?._id;
const queueStartedAt = queuedAt || ts;

const queueTime = useMemo(() => formatQueuedAt(room), [room]);

useEffect(() => {
if (allCustomFields) {
const { customFields: customFieldsAPI } = allCustomFields;
Expand Down Expand Up @@ -124,11 +127,7 @@ function ChatInfo({ id, route }) {
{queueStartedAt && (
<Field>
<Label>{t('Queue_Time')}</Label>
{servedBy ? (
<Info>{moment(servedBy.ts).from(moment(queueStartedAt), true)}</Info>
) : (
<Info>{moment(queueStartedAt).fromNow(true)}</Info>
)}
<Info>{queueTime}</Info>
</Field>
)}
{closedAt && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useMutableCallback } from '@rocket.chat/fuselage-hooks';
import { useToastMessageDispatch, useRoute, useUserSubscription, useTranslation } from '@rocket.chat/ui-contexts';
import { Meteor } from 'meteor/meteor';
import moment from 'moment';
import React, { useEffect, useState } from 'react';
import React, { useEffect, useMemo, useState } from 'react';

import { hasPermission } from '../../../../../../app/authorization/client';
import { ContextualbarScrollableContent, ContextualbarFooter } from '../../../../../components/Contextualbar';
Expand All @@ -16,6 +16,7 @@ import Info from '../../../components/Info';
import Label from '../../../components/Label';
import { AgentField, ContactField, SlaField } from '../../components';
import PriorityField from '../../components/PriorityField';
import { formatQueuedAt } from '../../utils/formatQueuedAt';
import DepartmentField from './DepartmentField';
import VisitorClientInfo from './VisitorClientInfo';

Expand Down Expand Up @@ -52,6 +53,8 @@ function ChatInfoDirectory({ id, route = undefined, room }) {
const visitorId = v?._id;
const queueStartedAt = queuedAt || ts;

const queueTime = useMemo(() => formatQueuedAt(room), [room]);

const dispatchToastMessage = useToastMessageDispatch();
useEffect(() => {
if (allCustomFields) {
Expand Down Expand Up @@ -120,11 +123,7 @@ function ChatInfoDirectory({ id, route = undefined, room }) {
{queueStartedAt && (
<Field>
<Label>{t('Queue_Time')}</Label>
{servedBy ? (
<Info>{moment(servedBy.ts).from(moment(queueStartedAt), true)}</Info>
) : (
<Info>{moment(queueStartedAt).fromNow(true)}</Info>
)}
{queueTime}
</Field>
)}
{closedAt && (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { IOmnichannelRoom } from '@rocket.chat/core-typings';
import moment from 'moment';

export const formatQueuedAt = (room: IOmnichannelRoom) => {
const { servedBy, closedAt, open, queuedAt, ts } = room || {};
const queueStartedAt = queuedAt || ts;

// Room served
if (servedBy) {
return moment(servedBy.ts).from(moment(queueStartedAt), true);
}

// Room open and not served
if (open) {
return moment(queueStartedAt).fromNow(true);
}

// Room closed and not served
if (closedAt && queueStartedAt) {
return moment(closedAt).from(moment(queueStartedAt), true);
}

return '';
};

0 comments on commit 470c29d

Please sign in to comment.