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: Extension List panel UI not aligned with designs #24645

Merged
merged 1 commit into from
Feb 28, 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
27 changes: 27 additions & 0 deletions client/views/admin/settings/groups/voip/AssignAgentButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Table, Icon, Button } from '@rocket.chat/fuselage';
import { useMutableCallback } from '@rocket.chat/fuselage-hooks';
import React, { FC } from 'react';

import { useSetModal } from '../../../../../contexts/ModalContext';
import { useTranslation } from '../../../../../contexts/TranslationContext';
import AssignAgentModal from './AssignAgentModal';

const AssignAgentButton: FC<{ extension: string; reload: () => void }> = ({ extension, reload }) => {
const t = useTranslation();
const setModal = useSetModal();

const handleAssociation = useMutableCallback((e) => {
e.stopPropagation();
setModal(<AssignAgentModal existingExtension={extension} closeModal={(): void => setModal()} reload={reload} />);
});

return (
<Table.Cell fontScale='p2' color='hint' withTruncatedText>
<Button small ghost title={t('Associate_Agent')} onClick={handleAssociation}>
<Icon name='user-plus' size='x20' mie='x4' />
</Button>
</Table.Cell>
);
};

export default AssignAgentButton;
5 changes: 3 additions & 2 deletions client/views/admin/settings/groups/voip/AssignAgentModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import { useEndpointData } from '../../../../../hooks/useEndpointData';
type AssignAgentModalParams = {
closeModal: () => void;
reload: () => void;
existingExtension?: string;
};

const AssignAgentModal: FC<AssignAgentModalParams> = ({ closeModal, reload }) => {
const AssignAgentModal: FC<AssignAgentModalParams> = ({ existingExtension, closeModal, reload }) => {
const t = useTranslation();
const [agent, setAgent] = useState('');
const [extension, setExtension] = useState('');
const [extension, setExtension] = useState(existingExtension || '');
const query = useMemo(() => ({ type: 'available' as const, userId: agent }), [agent]);

const assignAgent = useEndpoint('POST', 'omnichannel/agent/extension');
Expand Down
6 changes: 3 additions & 3 deletions client/views/admin/settings/groups/voip/RemoveAgentButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const RemoveAgentButton: FC<{ username: string; reload: () => void }> = ({ usern
const handleRemoveClick = useMutableCallback(async () => {
try {
await removeAgent({ username });
} catch (error) {
} catch (error: any) {
dispatchToastMessage({ type: 'error', message: error });
}
reload();
Expand All @@ -29,7 +29,7 @@ const RemoveAgentButton: FC<{ username: string; reload: () => void }> = ({ usern
try {
await handleRemoveClick();
dispatchToastMessage({ type: 'success', message: t('Agent_removed') });
} catch (error) {
} catch (error: any) {
dispatchToastMessage({ type: 'error', message: error });
}
setModal();
Expand All @@ -48,7 +48,7 @@ const RemoveAgentButton: FC<{ username: string; reload: () => void }> = ({ usern

return (
<Table.Cell fontScale='p2' color='hint' withTruncatedText>
<Button small ghost title={t('Remove')} onClick={handleDelete}>
<Button small ghost title={t('Remove_Association')} onClick={handleDelete}>
<Icon name='trash' size='x16' />
</Button>
</Table.Cell>
Expand Down
23 changes: 20 additions & 3 deletions client/views/admin/settings/groups/voip/VoipExtensionsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import React, { FC, useMemo, useCallback, useState } from 'react';

import GenericTable from '../../../../../components/GenericTable';
import Page from '../../../../../components/Page';
import UserAvatar from '../../../../../components/avatar/UserAvatar';
import { useSetModal } from '../../../../../contexts/ModalContext';
import { useTranslation } from '../../../../../contexts/TranslationContext';
import { useEndpointData } from '../../../../../hooks/useEndpointData';
import AssignAgentButton from './AssignAgentButton';
import AssignAgentModal from './AssignAgentModal';
import RemoveAgentButton from './RemoveAgentButton';

Expand Down Expand Up @@ -51,10 +53,25 @@ const VoipExtensionsPage: FC = () => {
);

const renderRow = useCallback(
({ _id, extension, username, state, queues }) => (
({ _id, extension, username, name, state, queues }) => (
<Table.Row key={_id} tabIndex={0}>
<Table.Cell withTruncatedText>{extension}</Table.Cell>
<Table.Cell withTruncatedText>{username || t('Unassigned')}</Table.Cell>
<Table.Cell withTruncatedText>
{username ? (
<Box display='flex' alignItems='center'>
<UserAvatar size={'x28'} username={username} />
<Box display='flex' mi='x8'>
<Box display='flex' flexDirection='column' alignSelf='center'>
<Box fontScale='p2m' color='default'>
{name || username}
</Box>
</Box>
</Box>
</Box>
) : (
t('Free')
)}
</Table.Cell>
<Table.Cell withTruncatedText>{state}</Table.Cell>
<Table.Cell withTruncatedText maxHeight='x36'>
<Box display='flex' flexDirection='row' alignItems='center' title={queues?.join(', ')}>
Expand All @@ -69,7 +86,7 @@ const VoipExtensionsPage: FC = () => {
{queues?.length > 2 && `+${(queues.length - 2).toString()}`}
</Box>
</Table.Cell>
{username ? <RemoveAgentButton username={username} reload={reload} /> : null}
{username ? <RemoveAgentButton username={username} reload={reload} /> : <AssignAgentButton extension={extension} reload={reload} />}
</Table.Row>
),
[reload, t],
Expand Down
1 change: 1 addition & 0 deletions definition/IVoipExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface IVoipExtensionWithAgentInfo extends IVoipExtensionBase {
queues?: string[];
userId?: IUser['_id'];
username?: IUser['username'];
name?: IUser['name'];
}

export const isIVoipExtensionBase = (obj: any): obj is IVoipExtensionBase =>
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -3552,6 +3552,7 @@
"Reload_Pages": "Reload Pages",
"Remove": "Remove",
"Remove_Admin": "Remove Admin",
"Remove_Association": "Remove Association",
"Remove_as_leader": "Remove as leader",
"Remove_as_moderator": "Remove as moderator",
"Remove_as_owner": "Remove as owner",
Expand Down
2 changes: 2 additions & 0 deletions server/services/omnichannel-voip/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,13 +361,15 @@ export class OmnichannelVoipService extends ServiceClassInternal implements IOmn
extension: 1,
_id: 1,
username: 1,
name: 1,
});

return (extensions as unknown as IVoipExtensionBase[]).map((ext) => {
const user = allocatedExtensions.find((ex) => ex.extension === ext.extension);
return {
userId: user?._id,
username: user?.username,
name: user?.name,
queues: this.getQueuesForExt(ext.extension, summary),
...ext,
};
Expand Down