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

Regression: Calling info on VoipFooter when performing an outbound call #26138

Merged
merged 3 commits into from
Jul 7, 2022
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
58 changes: 45 additions & 13 deletions apps/meteor/client/sidebar/footer/voip/VoipFooter.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Box } from '@rocket.chat/fuselage';
import { VoIpCallerInfo } from '@rocket.chat/core-typings';
import { Box, Icon } from '@rocket.chat/fuselage';
import { ComponentStory } from '@storybook/react';
import React, { useState } from 'react';

Expand All @@ -22,6 +23,12 @@ const tooltips = {
endCall: 'End Call',
};

const callerDefault = {
tiagoevanp marked this conversation as resolved.
Show resolved Hide resolved
callerName: '',
callerId: '+5551999999999',
host: '',
};

export default {
title: 'Sidebar/Footer/VoipFooter',
component: VoipFooter,
Expand All @@ -48,33 +55,31 @@ export default {
dispatchEvent: { control: false },
openedRoomInfo: { control: false },
anonymousText: { control: false },
options: { control: false },
},
};

const VoipFooterTemplate: ComponentStory<typeof VoipFooter> = (args) => {
const [muted, toggleMic] = useState(false);
const [paused, togglePause] = useState(false);

const getSubtitle = () => {
if (args.callerState === 'OFFER_RECEIVED') {
return 'Calling';
}
const getSubtitle = (state: VoIpCallerInfo['state']): string => {
const subtitles: Record<string, string> = {
IN_CALL: 'In Progress',
OFFER_RECEIVED: 'Ringing',
OFFER_SENT: 'Calling',
ON_HOLD: 'On Hold',
};

return paused ? 'On Hold' : 'In Progress';
return subtitles[state] || '';
};

return (
<Box maxWidth='x300' bg='neutral-800' borderRadius='x4'>
<VoipFooter
{...args}
caller={{
callerName: 'Tiago',
callerId: 'guest-1',
host: '',
}}
callActions={callActions}
title='Sales Department'
subtitle={getSubtitle()}
subtitle={getSubtitle(args.callerState)}
muted={muted}
paused={paused}
toggleMic={toggleMic}
Expand All @@ -86,23 +91,50 @@ const VoipFooterTemplate: ComponentStory<typeof VoipFooter> = (args) => {
dispatchEvent={() => null}
openedRoomInfo={{ v: { token: '' }, rid: '' }}
anonymousText={'Anonymous'}
options={{
deviceSettings: {
label: (
<Box alignItems='center' display='flex'>
<Icon mie='x4' name='customize' size='x16' />
Device Settings
</Box>
),
},
}}
/>
</Box>
);
};

export const IncomingCall = VoipFooterTemplate.bind({});
IncomingCall.args = {
title: 'Sales Department',
callerState: 'OFFER_RECEIVED',
caller: callerDefault,
};

export const OutboundCall = VoipFooterTemplate.bind({});
OutboundCall.args = {
title: 'Phone Call',
callerState: 'OFFER_SENT',
caller: {
callerName: '',
callerId: '+5551999999999',
host: '',
},
};

export const InCall = VoipFooterTemplate.bind({});
InCall.args = {
title: 'Sales Department',
callerState: 'IN_CALL',
caller: callerDefault,
};

export const NoEnterpriseLicence = VoipFooterTemplate.bind({});
NoEnterpriseLicence.args = {
title: 'Sales Department',
callerState: 'IN_CALL',
isEnterprise: false,
caller: callerDefault,
};
6 changes: 3 additions & 3 deletions apps/meteor/client/sidebar/footer/voip/VoipFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { css } from '@rocket.chat/css-in-js';
import { Box, Button, ButtonGroup, Icon, SidebarFooter, Menu, IconButton } from '@rocket.chat/fuselage';
import React, { ReactElement, MouseEvent, ReactNode } from 'react';

import { useVoipFooterMenu } from '../../../../ee/client/hooks/useVoipFooterMenu';
import type { VoipFooterMenuOptions } from '../../../../ee/client/hooks/useVoipFooterMenu';
import { CallActionsType } from '../../../contexts/CallContext';

type VoipFooterPropsType = {
Expand Down Expand Up @@ -33,6 +33,7 @@ type VoipFooterPropsType = {
anonymousText: string;
isEnterprise: boolean;
children?: ReactNode;
options: VoipFooterMenuOptions;
};

export const VoipFooter = ({
Expand All @@ -54,6 +55,7 @@ export const VoipFooter = ({
anonymousText,
isEnterprise = false,
children,
options,
}: VoipFooterPropsType): ReactElement => {
const cssClickable =
callerState === 'IN_CALL' || callerState === 'ON_HOLD'
Expand All @@ -62,8 +64,6 @@ export const VoipFooter = ({
`
: '';

const options = useVoipFooterMenu();

const handleHold = (e: MouseEvent<HTMLButtonElement>): void => {
e.stopPropagation();
const eventName = paused ? 'VOIP-CALL-UNHOLD' : 'VOIP-CALL-ON-HOLD';
Expand Down
24 changes: 13 additions & 11 deletions apps/meteor/client/sidebar/footer/voip/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { VoIpCallerInfo } from '@rocket.chat/core-typings';
import { useEndpoint, useTranslation } from '@rocket.chat/ui-contexts';
import React, { ReactElement, useCallback, useMemo, useState } from 'react';

import { useHasLicenseModule } from '../../../../ee/client/hooks/useHasLicenseModule';
import { useVoipFooterMenu } from '../../../../ee/client/hooks/useVoipFooterMenu';
import {
useCallActions,
useCallCreateRoom,
Expand All @@ -26,6 +28,7 @@ export const VoipFooter = (): ReactElement | null => {
const queueCounter = useQueueCounter();
const queueName = useQueueName();
const openedRoomInfo = useOpenedRoomInfo();
const options = useVoipFooterMenu();

const [muted, setMuted] = useState(false);
const [paused, setPaused] = useState(false);
Expand All @@ -48,17 +51,15 @@ export const VoipFooter = (): ReactElement | null => {
[callActions],
);

const getSubtitle = (): string => {
switch (callerInfo.state) {
case 'IN_CALL':
return t('In_progress');
case 'OFFER_RECEIVED':
return t('Ringing');
case 'ON_HOLD':
return t('On_Hold');
}
const getSubtitle = (state: VoIpCallerInfo['state']): string => {
const subtitles: Record<string, string> = {
IN_CALL: t('In_progress'),
OFFER_RECEIVED: t('Ringing'),
OFFER_SENT: t('Calling'),
ON_HOLD: t('On_Hold'),
};

return '';
return subtitles[state] || '';
};

const tooltips = {
Expand Down Expand Up @@ -91,7 +92,7 @@ export const VoipFooter = (): ReactElement | null => {
callerState={callerInfo.state}
callActions={callActions}
title={queueName || t('Phone_call')}
subtitle={getSubtitle()}
subtitle={getSubtitle(callerInfo.state)}
muted={muted}
paused={paused}
toggleMic={toggleMic}
Expand All @@ -105,6 +106,7 @@ export const VoipFooter = (): ReactElement | null => {
anonymousText={t('Anonymous')}
isEnterprise={isEE === true}
children={<SidebarFooterWatermark />}
options={options}
/>
);
};
2 changes: 1 addition & 1 deletion apps/meteor/ee/client/hooks/useVoipFooterMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ReactNode, useMemo } from 'react';

import { useDevicesMenuOption } from './useDevicesMenuOption';

type VoipFooterMenuOptions = Record<
export type VoipFooterMenuOptions = Record<
string,
{
type?: 'option' | 'heading' | 'divider';
Expand Down
4 changes: 2 additions & 2 deletions packages/core-typings/src/voip/VoIpCallerInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ export interface IState {

export type VoIpCallerInfo =
| {
state: Exclude<CallStates, 'IN_CALL' | 'OFFER_RECEIVED' | 'ON_HOLD'>;
state: Exclude<CallStates, 'IN_CALL' | 'OFFER_RECEIVED' | 'ON_HOLD' | 'OFFER_SENT'>;
userState: UserState;
}
| {
state: 'IN_CALL' | 'ON_HOLD' | 'OFFER_RECEIVED';
state: 'IN_CALL' | 'ON_HOLD' | 'OFFER_RECEIVED' | 'OFFER_SENT';
userState: UserState;
caller: ICallerInfo;
}; // TODO: Check for additional properties and States (E.g. call on hold, muted, etc)