Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(InviteAgents): new tooltip design #1383

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ $base-class: 'invite-agents';
}

&__tooltip {
box-shadow: 0 1px 10px 0 rgb(66 77 87 / 30%);
max-width: 260px;

> div {
Expand Down Expand Up @@ -95,4 +96,16 @@ $base-class: 'invite-agents';
font-weight: 500;
font-style: normal;
}

&__accepting-agents {
display: flex;
flex-direction: column;
gap: var(--spacing-2);
}

&__accepting-agents-row {
display: flex;
gap: var(--spacing-2);
align-items: center;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,21 @@ describe('InviteAgents Component', () => {
email: 'alice@example.com',
status: 'available',
avatar: 'https://via.placeholder.com/150',
isBot: false,
},
{
name: 'Bob',
email: 'bob@example.com',
status: 'unavailable',
avatar: 'https://via.placeholder.com/150',
isBot: false,
},
{
name: 'Charlie',
email: 'charlie@example.com',
status: 'unknown',
avatar: 'https://via.placeholder.com/150',
isBot: true,
},
];

Expand All @@ -69,7 +72,7 @@ describe('InviteAgents Component', () => {
userEvent.hover(avatars[0]);

await waitFor(() => {
expect(screen.getByText(/1 accepting chats/i)).toBeInTheDocument();
expect(screen.getByText(/1 agent/i)).toBeInTheDocument();
});
});

Expand All @@ -80,6 +83,7 @@ describe('InviteAgents Component', () => {
email: 'bob@example.com',
status: 'unavailable',
avatar: 'https://via.placeholder.com/150',
isBot: false,
},
];

Expand All @@ -102,6 +106,7 @@ describe('InviteAgents Component', () => {
email: 'alice@example.com',
status: 'available',
avatar: 'https://via.placeholder.com/150',
isBot: false,
},
];

Expand All @@ -127,17 +132,18 @@ describe('InviteAgents Component', () => {
expect(mockOnAddAgentsClick).toHaveBeenCalledTimes(1);
});

it('displays additional agents count correctly', () => {
it('displays total accepting agents count correctly', () => {
const agents: Agent[] = Array.from({ length: 5 }, (_, index) => ({
name: `Agent ${index + 1}`,
email: `agent${index + 1}@example.com`,
status: 'available',
avatar: 'https://via.placeholder.com/150',
isBot: false,
}));

renderComponent(agents);

expect(screen.getByText('+2')).toBeInTheDocument();
expect(screen.getByText('5')).toBeInTheDocument();
});

it('renders "Not accepting" when all agents are unavailable', async () => {
Expand All @@ -147,12 +153,14 @@ describe('InviteAgents Component', () => {
email: 'bob@example.com',
status: 'unavailable',
avatar: 'https://via.placeholder.com/150',
isBot: false,
},
{
name: 'Charlie',
email: 'charlie@example.com',
status: 'unavailable',
avatar: 'https://via.placeholder.com/150',
isBot: false,
},
];

Expand Down Expand Up @@ -180,4 +188,34 @@ describe('InviteAgents Component', () => {
userEvent.click(chatbotButton);
expect(mockOnSetUpChatbotClick).toHaveBeenCalledTimes(1);
});

it('displays only bots when all agents are bots', async () => {
const agents: Agent[] = [
{
name: 'Alice',
email: 'alice@example.com',
status: 'available',
avatar: 'https://via.placeholder.com/150',
isBot: true,
},
{
name: 'Bob',
email: 'bob@example.com',
status: 'available',
avatar: 'https://via.placeholder.com/150',
isBot: true,
},
];

renderComponent(agents);

const avatars = screen.getAllByRole('img');
expect(avatars).toHaveLength(2);

userEvent.hover(avatars[0]);

await waitFor(() => {
expect(screen.getByText('2 bots')).toBeInTheDocument();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,35 @@ const mockAgents = [
email: 'bob@example.com',
status: 'unknown' as const,
avatar: '',
isBot: false,
},
{
name: 'Alice Johnson',
email: 'alice@example.com',
status: 'available' as const,
avatar: undefined,
isBot: false,
},
{
name: 'Alice Johnson 2',
email: 'alic2@example.com',
status: 'available' as const,
avatar: 'https://via.placeholder.com/150',
isBot: false,
},
{
name: 'Bob Smith',
email: 'bob3@example.com',
status: 'unavailable' as const,
avatar: 'https://via.placeholder.com/150',
isBot: false,
},
...[...Array(10)].map((_, index) => ({
name: `Unknown Agent ${index}`,
email: `unknown${index}@example.com`,
status: 'available' as const,
avatar: 'https://via.placeholder.com/150',
isBot: index % 2 === 0,
})),
];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
import { FC, memo, useMemo, useState } from 'react';

import { Add, ChatBotColored, PersonAdd } from '@livechat/design-system-icons';
import {
Add,
Bot,
ChatBotColored,
People,
PersonAdd,
} from '@livechat/design-system-icons';
import cx from 'clsx';

import { ThemeClassName } from '../../providers';
import { plural } from '../../utils/plural';
import { ActionMenu, ActionMenuItem } from '../ActionMenu';
import { Avatar } from '../Avatar';
import { Icon } from '../Icon';
import { Interactive, Tooltip } from '../Tooltip';
import { Text } from '../Typography';

import { AnimatedButton } from './components/AnimatedButton/AnimatedButton';
import { getAvailableAgentsTooltipText, getSortedAgents } from './helpers';
import { getSortedAgents } from './helpers';
import { InviteAgentsProps } from './types';

import styles from './InviteAgents.module.scss';
Expand All @@ -36,8 +43,9 @@ const InviteAgentsComponent: FC<InviteAgentsProps> = ({
const {
availableAgentsNumber,
visibleAgents,
additionalAgentsNumber,
hasOnlyUnavailableAgents,
onlyAgentsNumber,
onlyBotsNumber,
} = useMemo(() => {
const availableAgents = agents.filter(
(agent) => agent.status === 'available'
Expand All @@ -47,15 +55,19 @@ const InviteAgentsComponent: FC<InviteAgentsProps> = ({

const visibleAgents =
sortedAgents.length > 4 ? sortedAgents.slice(0, 3) : sortedAgents;
const additionalAgentsNumber = availableAgentsNumber - visibleAgents.length;
const hasOnlyUnavailableAgents =
agents.length > 0 && availableAgentsNumber === 0;
const onlyAgentsNumber = availableAgents.filter(
(agent) => !agent.isBot
).length;
const onlyBotsNumber = availableAgentsNumber - onlyAgentsNumber;

return {
availableAgentsNumber,
visibleAgents,
additionalAgentsNumber,
hasOnlyUnavailableAgents,
onlyAgentsNumber,
onlyBotsNumber,
};
}, [agents]);

Expand Down Expand Up @@ -154,11 +166,11 @@ const InviteAgentsComponent: FC<InviteAgentsProps> = ({
/>
))}
</div>
{additionalAgentsNumber > 0 && (
{availableAgentsNumber > 0 && (
<Text
className={styles[`${baseClass}__available-agents-number`]}
>
+{additionalAgentsNumber}
{availableAgentsNumber}
</Text>
)}
</div>
Expand All @@ -175,8 +187,33 @@ const InviteAgentsComponent: FC<InviteAgentsProps> = ({
}}
/>
) : (
<Text noMargin size="md">
{getAvailableAgentsTooltipText(availableAgentsNumber)}
<Text
as="div"
noMargin
size="md"
className={styles[`${baseClass}__accepting-agents`]}
>
<Text bold noMargin>
Accepting chats:
</Text>
<Text
noMargin
className={styles[`${baseClass}__accepting-agents-row`]}
>
<Icon source={People} />
{plural(
onlyAgentsNumber,
'1 agent',
`${onlyAgentsNumber} agents`
)}
</Text>
<Text
noMargin
className={styles[`${baseClass}__accepting-agents-row`]}
>
<Icon source={Bot} />
{plural(onlyBotsNumber, '1 bot', `${onlyBotsNumber} bots`)}
</Text>
</Text>
)}
</Tooltip>
Expand Down
10 changes: 0 additions & 10 deletions packages/react-components/src/components/InviteAgents/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,3 @@ export const getSortedAgents = (agents: Agent[]) => {
return statusPriority[a.status] - statusPriority[b.status];
});
};

export const getAvailableAgentsTooltipText = (
availableAgentsNumber: number
) => {
if (availableAgentsNumber === 0) {
return 'No one assist your customers';
}

return `${availableAgentsNumber} accepting chats`;
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface Agent {
email: string;
status: 'available' | 'unavailable' | 'unknown';
avatar?: string;
isBot: boolean;
}

export interface InviteAgentsProps extends ComponentCoreProps {
Expand Down
Loading