Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/many-moons-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Adds deprecation warning on legacy method: `livechat:removeUnit`
8 changes: 3 additions & 5 deletions apps/meteor/client/omnichannel/units/UnitEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { useQueryClient } from '@tanstack/react-query';
import { useId, useMemo } from 'react';
import { useForm, Controller } from 'react-hook-form';

import { useRemoveUnit } from './useRemoveUnit';
import AutoCompleteDepartmentMultiple from '../../components/AutoCompleteDepartmentMultiple';
import AutoCompleteMonitors from '../../components/AutoCompleteMonitors';
import {
Expand Down Expand Up @@ -36,16 +35,15 @@ type UnitEditProps = {
unitMonitors?: Serialized<ILivechatUnitMonitor>[];
unitDepartments?: Serialized<ILivechatDepartment>[];
onClose: () => void;
onDelete?: () => void;
};

const UnitEdit = ({ unitData, unitMonitors, unitDepartments, onClose }: UnitEditProps) => {
const UnitEdit = ({ unitData, unitMonitors, unitDepartments, onClose, onDelete }: UnitEditProps) => {
const t = useTranslation();
const saveUnit = useMethod('livechat:saveUnit');
const dispatchToastMessage = useToastMessageDispatch();
const queryClient = useQueryClient();

const handleDeleteUnit = useRemoveUnit();

const visibilityOpts: SelectOption[] = [
['public', t('Public')],
['private', t('Private')],
Expand Down Expand Up @@ -250,7 +248,7 @@ const UnitEdit = ({ unitData, unitMonitors, unitDepartments, onClose }: UnitEdit
{_id && (
<Box mbs={8}>
<ButtonGroup stretch>
<Button icon='trash' danger onClick={() => handleDeleteUnit(_id)}>
<Button icon='trash' danger onClick={() => onDelete?.()}>
{t('Delete')}
</Button>
</ButtonGroup>
Expand Down
10 changes: 9 additions & 1 deletion apps/meteor/client/omnichannel/units/UnitEditWithData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useQuery } from '@tanstack/react-query';
import { useTranslation } from 'react-i18next';

import UnitEdit from './UnitEdit';
import { useRemoveUnit } from './useRemoveUnit';
import { ContextualbarSkeletonBody } from '../../components/Contextualbar';

const UnitEditWithData = ({ unitId, onClose }: { unitId: IOmnichannelBusinessUnit['_id']; onClose: () => void }) => {
Expand All @@ -13,6 +14,7 @@ const UnitEditWithData = ({ unitId, onClose }: { unitId: IOmnichannelBusinessUni
const getUnitById = useEndpoint('GET', '/v1/livechat/units/:id', { id: unitId });
const getMonitorsByUnitId = useEndpoint('GET', '/v1/livechat/units/:unitId/monitors', { unitId });
const getDepartmentsByUnitId = useEndpoint('GET', '/v1/livechat/units/:unitId/departments', { unitId });
const removeUnit = useRemoveUnit(unitId);

const {
data: unitData,
Expand Down Expand Up @@ -55,7 +57,13 @@ const UnitEditWithData = ({ unitId, onClose }: { unitId: IOmnichannelBusinessUni
}

return (
<UnitEdit unitData={unitData} unitMonitors={unitMonitors?.monitors} unitDepartments={unitDepartments?.departments} onClose={onClose} />
<UnitEdit
unitData={unitData}
unitMonitors={unitMonitors?.monitors}
unitDepartments={unitDepartments?.departments}
onClose={onClose}
onDelete={removeUnit}
/>
);
};

Expand Down
36 changes: 36 additions & 0 deletions apps/meteor/client/omnichannel/units/UnitTableRow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { IconButton } from '@rocket.chat/fuselage';
import { useEffectEvent } from '@rocket.chat/fuselage-hooks';
import { useRouter } from '@rocket.chat/ui-contexts';
import { useTranslation } from 'react-i18next';

import { useRemoveUnit } from './useRemoveUnit';
import { GenericTableCell, GenericTableRow } from '../../components/GenericTable';

const UnitsTableRow = ({ _id, name, visibility }: { _id: string; name: string; visibility: string }) => {
const { t } = useTranslation();
const router = useRouter();

const onRowClick = useEffectEvent((id: string) => () => router.navigate(`/omnichannel/units/edit/${id}`));
const handleDelete = useRemoveUnit(_id);

return (
<GenericTableRow key={_id} tabIndex={0} role='link' data-qa-id={name} onClick={onRowClick(_id)} action qa-user-id={_id}>
<GenericTableCell withTruncatedText>{name}</GenericTableCell>
<GenericTableCell withTruncatedText>{visibility}</GenericTableCell>
<GenericTableCell>
<IconButton
icon='trash'
small
title={t('Remove')}
data-qa-id={`remove-unit-${name}`}
onClick={(e) => {
e.stopPropagation();
handleDelete();
}}
/>
</GenericTableCell>
</GenericTableRow>
);
};

export default UnitsTableRow;
25 changes: 3 additions & 22 deletions apps/meteor/client/omnichannel/units/UnitsTable.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import { Pagination, IconButton } from '@rocket.chat/fuselage';
import { Pagination } from '@rocket.chat/fuselage';
import { useDebouncedValue, useEffectEvent } from '@rocket.chat/fuselage-hooks';
import { useEndpoint, useRouter } from '@rocket.chat/ui-contexts';
import { useQuery, hashKey } from '@tanstack/react-query';
import { useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';

import { useRemoveUnit } from './useRemoveUnit';
import UnitTableRow from './UnitTableRow';
import FilterByText from '../../components/FilterByText';
import GenericNoResults from '../../components/GenericNoResults/GenericNoResults';
import {
GenericTable,
GenericTableHeader,
GenericTableHeaderCell,
GenericTableBody,
GenericTableCell,
GenericTableLoadingRow,
GenericTableRow,
} from '../../components/GenericTable';
import { usePagination } from '../../components/GenericTable/hooks/usePagination';
import { useSort } from '../../components/GenericTable/hooks/useSort';
Expand Down Expand Up @@ -51,8 +49,6 @@ const UnitsTable = () => {
const queryHasChanged = defaultQuery !== hashKey([query]);

const handleAddNew = useEffectEvent(() => router.navigate('/omnichannel/units/new'));
const onRowClick = useEffectEvent((id: string) => () => router.navigate(`/omnichannel/units/edit/${id}`));
const handleDelete = useRemoveUnit();

const headers = (
<>
Expand Down Expand Up @@ -103,22 +99,7 @@ const UnitsTable = () => {
<GenericTableHeader>{headers}</GenericTableHeader>
<GenericTableBody>
{data.units.map(({ _id, name, visibility }) => (
<GenericTableRow key={_id} tabIndex={0} role='link' data-qa-id={name} onClick={onRowClick(_id)} action qa-user-id={_id}>
<GenericTableCell withTruncatedText>{name}</GenericTableCell>
<GenericTableCell withTruncatedText>{visibility}</GenericTableCell>
<GenericTableCell>
<IconButton
icon='trash'
small
title={t('Remove')}
data-qa-id={`remove-unit-${name}`}
onClick={(e) => {
e.stopPropagation();
handleDelete(_id);
}}
/>
</GenericTableCell>
</GenericTableRow>
<UnitTableRow key={_id} _id={_id} name={name} visibility={visibility} />
))}
</GenericTableBody>
</GenericTable>
Expand Down
10 changes: 5 additions & 5 deletions apps/meteor/client/omnichannel/units/useRemoveUnit.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { useEffectEvent } from '@rocket.chat/fuselage-hooks';
import { GenericModal } from '@rocket.chat/ui-client';
import { useSetModal, useToastMessageDispatch, useMethod, useTranslation, useRouter } from '@rocket.chat/ui-contexts';
import { useSetModal, useToastMessageDispatch, useTranslation, useRouter, useEndpoint } from '@rocket.chat/ui-contexts';
import { useQueryClient } from '@tanstack/react-query';

export const useRemoveUnit = () => {
export const useRemoveUnit = (id: string) => {
const t = useTranslation();
const setModal = useSetModal();
const router = useRouter();
const dispatchToastMessage = useToastMessageDispatch();

const queryClient = useQueryClient();
const removeUnit = useMethod('livechat:removeUnit');
const removeUnit = useEndpoint('DELETE', '/v1/livechat/units/:id', { id });

const handleDelete = useEffectEvent((id: string) => {
const handleDelete = useEffectEvent(() => {
const onDeleteAgent = async () => {
try {
await removeUnit(id);
await removeUnit();
dispatchToastMessage({ type: 'success', message: t('Unit_removed') });
router.navigate('/omnichannel/units');
queryClient.invalidateQueries({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { check } from 'meteor/check';
import { Meteor } from 'meteor/meteor';

import { hasPermissionAsync } from '../../../../../app/authorization/server/functions/hasPermission';
import { methodDeprecationLogger } from '../../../../../app/lib/server/lib/deprecationWarningLogger';
import { LivechatEnterprise } from '../lib/LivechatEnterprise';

declare module '@rocket.chat/ddp-client' {
Expand All @@ -14,6 +15,7 @@ declare module '@rocket.chat/ddp-client' {

Meteor.methods<ServerMethods>({
async 'livechat:removeUnit'(id) {
methodDeprecationLogger.method('livechat:removeUnit', '8.0.0', 'DELETE /v1/livechat/units/:id');
const uid = Meteor.userId();
if (!uid || !(await hasPermissionAsync(uid, 'manage-livechat-units'))) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:removeUnit' });
Expand Down
Loading