diff --git a/.changeset/many-moons-wonder.md b/.changeset/many-moons-wonder.md new file mode 100644 index 0000000000000..a3af34836b626 --- /dev/null +++ b/.changeset/many-moons-wonder.md @@ -0,0 +1,5 @@ +--- +"@rocket.chat/meteor": patch +--- + +Adds deprecation warning on legacy method: `livechat:removeUnit` diff --git a/apps/meteor/client/omnichannel/units/UnitEdit.tsx b/apps/meteor/client/omnichannel/units/UnitEdit.tsx index db892ee28fef9..75b8d796fecb3 100644 --- a/apps/meteor/client/omnichannel/units/UnitEdit.tsx +++ b/apps/meteor/client/omnichannel/units/UnitEdit.tsx @@ -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 { @@ -36,16 +35,15 @@ type UnitEditProps = { unitMonitors?: Serialized[]; unitDepartments?: Serialized[]; 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')], @@ -250,7 +248,7 @@ const UnitEdit = ({ unitData, unitMonitors, unitDepartments, onClose }: UnitEdit {_id && ( - diff --git a/apps/meteor/client/omnichannel/units/UnitEditWithData.tsx b/apps/meteor/client/omnichannel/units/UnitEditWithData.tsx index 10e329fcb9661..f8c3f55adb005 100644 --- a/apps/meteor/client/omnichannel/units/UnitEditWithData.tsx +++ b/apps/meteor/client/omnichannel/units/UnitEditWithData.tsx @@ -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 }) => { @@ -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, @@ -55,7 +57,13 @@ const UnitEditWithData = ({ unitId, onClose }: { unitId: IOmnichannelBusinessUni } return ( - + ); }; diff --git a/apps/meteor/client/omnichannel/units/UnitTableRow.tsx b/apps/meteor/client/omnichannel/units/UnitTableRow.tsx new file mode 100644 index 0000000000000..8e6d7873c640f --- /dev/null +++ b/apps/meteor/client/omnichannel/units/UnitTableRow.tsx @@ -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 ( + + {name} + {visibility} + + { + e.stopPropagation(); + handleDelete(); + }} + /> + + + ); +}; + +export default UnitsTableRow; diff --git a/apps/meteor/client/omnichannel/units/UnitsTable.tsx b/apps/meteor/client/omnichannel/units/UnitsTable.tsx index b8dfa26e744d3..590a90fa60bd1 100644 --- a/apps/meteor/client/omnichannel/units/UnitsTable.tsx +++ b/apps/meteor/client/omnichannel/units/UnitsTable.tsx @@ -1,11 +1,11 @@ -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 { @@ -13,9 +13,7 @@ import { GenericTableHeader, GenericTableHeaderCell, GenericTableBody, - GenericTableCell, GenericTableLoadingRow, - GenericTableRow, } from '../../components/GenericTable'; import { usePagination } from '../../components/GenericTable/hooks/usePagination'; import { useSort } from '../../components/GenericTable/hooks/useSort'; @@ -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 = ( <> @@ -103,22 +99,7 @@ const UnitsTable = () => { {headers} {data.units.map(({ _id, name, visibility }) => ( - - {name} - {visibility} - - { - e.stopPropagation(); - handleDelete(_id); - }} - /> - - + ))} diff --git a/apps/meteor/client/omnichannel/units/useRemoveUnit.tsx b/apps/meteor/client/omnichannel/units/useRemoveUnit.tsx index f28904428005c..ba5b9131f2c7f 100644 --- a/apps/meteor/client/omnichannel/units/useRemoveUnit.tsx +++ b/apps/meteor/client/omnichannel/units/useRemoveUnit.tsx @@ -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({ diff --git a/apps/meteor/ee/app/livechat-enterprise/server/methods/removeUnit.ts b/apps/meteor/ee/app/livechat-enterprise/server/methods/removeUnit.ts index 3465c682ad75d..4ebd58a7a5e5a 100644 --- a/apps/meteor/ee/app/livechat-enterprise/server/methods/removeUnit.ts +++ b/apps/meteor/ee/app/livechat-enterprise/server/methods/removeUnit.ts @@ -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' { @@ -14,6 +15,7 @@ declare module '@rocket.chat/ddp-client' { Meteor.methods({ 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' });