diff --git a/client/omnichannel/currentChats/CurrentChatsPage.js b/client/omnichannel/currentChats/CurrentChatsPage.js index 4226c2223c60..5cd71940a735 100644 --- a/client/omnichannel/currentChats/CurrentChatsPage.js +++ b/client/omnichannel/currentChats/CurrentChatsPage.js @@ -2,7 +2,9 @@ import React, { useEffect, useMemo } from 'react'; import { TextInput, Box, Icon, MultiSelect, Select, InputBox, Menu } from '@rocket.chat/fuselage'; import { useMutableCallback } from '@rocket.chat/fuselage-hooks'; import moment from 'moment'; +import { useSubscription } from 'use-subscription'; +import { formsSubscription } from '../additionalForms'; import Page from '../../components/basic/Page'; import { useTranslation } from '../../contexts/TranslationContext'; import { useEndpointDataExperimental } from '../../hooks/useEndpointDataExperimental'; @@ -30,13 +32,13 @@ const RemoveAllClosed = ({ handleClearFilters, handleRemoveClosed, ...props }) = ...canRemove && { removeClosed: { label: - {t('Remove')} + {t('Delete_all_closed_chats')} , action: handleRemoveClosed, }, }, }; - return ; + return ; }; @@ -50,7 +52,11 @@ const FilterByText = ({ setFilter, reload, ...props }) => { const agentOptions = useMemo(() => (agents && agents.users ? agents.users.map(({ _id, username }) => [_id, username || _id]) : []), [agents]); const statusOptions = [['all', t('All')], ['closed', t('Closed')], ['opened', t('Open')]]; - const { values, handlers, reset } = useForm({ guest: '', servedBy: [], status: 'all', department: undefined, from: '', to: '' }); + useEffect(() => { + !depOptions.find((dep) => dep[0] === 'all') && depOptions.unshift(['all', t('All')]); + }, [depOptions, t]); + + const { values, handlers, reset } = useForm({ guest: '', servedBy: [], status: 'all', department: 'all', from: '', to: '', tags: [] }); const { handleGuest, handleServedBy, @@ -58,6 +64,7 @@ const FilterByText = ({ setFilter, reload, ...props }) => { handleDepartment, handleFrom, handleTo, + handleTags, } = handlers; const { guest, @@ -66,8 +73,18 @@ const FilterByText = ({ setFilter, reload, ...props }) => { department, from, to, + tags, } = values; + const forms = useSubscription(formsSubscription); + + const { + useCurrentChatTags = () => {}, + } = forms; + + const Tags = useCurrentChatTags(); + + const onSubmit = useMutableCallback((e) => e.preventDefault()); useEffect(() => { @@ -78,9 +95,9 @@ const FilterByText = ({ setFilter, reload, ...props }) => { department, from: from && moment(new Date(from)).utc().format('YYYY-MM-DDTHH:mm:ss'), to: to && moment(new Date(to)).utc().format('YYYY-MM-DDTHH:mm:ss'), + tags, }); - console.log(servedBy); - }, [setFilter, guest, servedBy, status, department, from, to]); + }, [setFilter, guest, servedBy, status, department, from, to, tags]); const handleClearFilters = useMutableCallback(() => { reset(); @@ -90,36 +107,44 @@ const FilterByText = ({ setFilter, reload, ...props }) => { const handleRemoveClosed = useMutableCallback(async () => { await removeClosedChats(); - console.log(props); reload(); }); - return - - - - - - - - - - - - - - - - - - - + return + + + + + + + + + + + + + + + + + + + + + + + - + {Tags && + + + + + } ; }; diff --git a/client/omnichannel/currentChats/CurrentChatsRoute.js b/client/omnichannel/currentChats/CurrentChatsRoute.js index 10c767ef17dc..18fb5ced1f00 100644 --- a/client/omnichannel/currentChats/CurrentChatsRoute.js +++ b/client/omnichannel/currentChats/CurrentChatsRoute.js @@ -38,7 +38,7 @@ export function RemoveCurrentChatButton({ _id, reload }) { const sortDir = (sortDir) => (sortDir === 'asc' ? 1 : -1); -const useQuery = ({ guest, servedBy, department, status, from, to, itemsPerPage, current }, [column, direction]) => useMemo(() => { +const useQuery = ({ guest, servedBy, department, status, from, to, tags, itemsPerPage, current }, [column, direction]) => useMemo(() => { const query = { roomName: guest, sort: JSON.stringify({ [column]: sortDir(direction), usernames: column === 'name' ? sortDir(direction) : undefined }), @@ -56,13 +56,16 @@ const useQuery = ({ guest, servedBy, department, status, from, to, itemsPerPage, query.agents = servedBy; } if (department && department.length > 0) { - console.log(department); - query.departmentId = department; + if (department !== 'all') { + query.departmentId = department; + } + } + if (tags && tags.length > 0) { + query.tags = tags; } - console.log(query); return query; -}, [guest, servedBy, department, from, to, status, column, direction, itemsPerPage, current]); +}, [guest, column, direction, itemsPerPage, current, from, to, status, servedBy, department, tags]); function CurrentChatsRoute() { const t = useTranslation(); @@ -95,8 +98,6 @@ function CurrentChatsRoute() { const { data, reload } = useEndpointDataExperimental('livechat/rooms', query) || {}; const { data: departments } = useEndpointDataExperimental('livechat/department', query) || {}; - console.log(data, departments); - const header = useMemo(() => [ {t('Name')}, {t('Department')}, diff --git a/ee/client/omnichannel/additionalForms/register.js b/ee/client/omnichannel/additionalForms/register.js index 662dbd009cc3..8865d8609052 100644 --- a/ee/client/omnichannel/additionalForms/register.js +++ b/ee/client/omnichannel/additionalForms/register.js @@ -14,4 +14,5 @@ hasLicense('livechat-enterprise').then((enabled) => { registerForm({ useCustomFieldsAdditionalForm: () => useMemo(() => lazy(() => import('./CustomFieldsAdditionalForm')), []) }); registerForm({ useBusinessHoursTimeZone: () => useMemo(() => lazy(() => import('./BusinessHoursTimeZone')), []) }); registerForm({ useBusinessHoursMultiple: () => useMemo(() => lazy(() => import('./BusinessHoursMultiple')), []) }); + registerForm({ useCurrentChatTags: () => useMemo(() => lazy(() => import('../tags/CurrentChatTags')), []) }); }); diff --git a/ee/client/omnichannel/tags/CurrentChatTags.js b/ee/client/omnichannel/tags/CurrentChatTags.js new file mode 100644 index 000000000000..b42cee47d472 --- /dev/null +++ b/ee/client/omnichannel/tags/CurrentChatTags.js @@ -0,0 +1,13 @@ +import { MultiSelect } from '@rocket.chat/fuselage'; +import React, { useMemo } from 'react'; + +import { useEndpointDataExperimental } from '../../../../client/hooks/useEndpointDataExperimental'; + +const CurrentChatTags = ({ value, handler, ...props }) => { + const { data } = useEndpointDataExperimental('livechat/tags.list'); + const options = useMemo(() => (data && data.tags ? data.tags.map(({ name }) => [name, name]) : []), [data]); + + return ; +}; + +export default CurrentChatTags;