From 5b47d5e85fe7fca05466797205e4990edb0ca58b Mon Sep 17 00:00:00 2001 From: Douglas Fabris Date: Tue, 7 Nov 2023 10:45:16 -0300 Subject: [PATCH] chore: Remove unnecessary `useForm` in `CannedResponsesTable` (#30854) --- .../cannedResponses/CannedResponseFilter.tsx | 46 ++++++++----------- .../cannedResponses/CannedResponsesTable.tsx | 36 ++++----------- 2 files changed, 30 insertions(+), 52 deletions(-) diff --git a/apps/meteor/ee/client/omnichannel/cannedResponses/CannedResponseFilter.tsx b/apps/meteor/ee/client/omnichannel/cannedResponses/CannedResponseFilter.tsx index 066a34302a61..fb379886318f 100644 --- a/apps/meteor/ee/client/omnichannel/cannedResponses/CannedResponseFilter.tsx +++ b/apps/meteor/ee/client/omnichannel/cannedResponses/CannedResponseFilter.tsx @@ -1,30 +1,25 @@ import type { SelectOption } from '@rocket.chat/fuselage'; import { Box, Icon, TextInput, Select } from '@rocket.chat/fuselage'; import { useTranslation } from '@rocket.chat/ui-contexts'; -import type { FC, FormEvent } from 'react'; -import React, { memo, useCallback } from 'react'; +import type { ChangeEvent } from 'react'; +import React, { memo } from 'react'; import AutoCompleteAgent from '../../../../client/components/AutoCompleteAgent'; +type SharingValues = '' | 'user' | 'global' | 'department'; + type CannedResponsesFilterProps = { - sharingValue: string; - createdByValue: string; - shortcutValue: string; - setSharing: (eventOrValue: unknown) => void; - setCreatedBy: (eventOrValue: unknown) => void; - setShortcut: (eventOrValue: unknown) => void; + createdBy: string; + setCreatedBy: (value: string) => void; + sharing: SharingValues; + setSharing: (value: SharingValues) => void; + text: string; + setText: (text: string) => void; }; -const CannedResponsesFilter: FC = ({ - sharingValue = '', - createdByValue = '', - shortcutValue = '', - setSharing, - setCreatedBy, - setShortcut, - ...props -}) => { +const CannedResponsesFilter = ({ createdBy, setCreatedBy, sharing, setSharing, text, setText }: CannedResponsesFilterProps) => { const t = useTranslation(); + const sharingList: SelectOption[] = [ ['', t('All')], ['user', t('Private')], @@ -32,24 +27,23 @@ const CannedResponsesFilter: FC = ({ ['department', t('Department')], ]; - const handleFormSubmit = useCallback((event: FormEvent) => { - event.preventDefault(); - }, []); - return ( - + {t('Search')} - } onChange={setShortcut} value={shortcutValue} /> + ) => setText(e.target.value)} + addon={} + /> - {t('Sharing')} - setSharing(value as SharingValues)} options={sharingList} /> {t('Created_by')} - + ); diff --git a/apps/meteor/ee/client/omnichannel/cannedResponses/CannedResponsesTable.tsx b/apps/meteor/ee/client/omnichannel/cannedResponses/CannedResponsesTable.tsx index aba399285de6..e2db45bf832e 100644 --- a/apps/meteor/ee/client/omnichannel/cannedResponses/CannedResponsesTable.tsx +++ b/apps/meteor/ee/client/omnichannel/cannedResponses/CannedResponsesTable.tsx @@ -17,19 +17,10 @@ import { import { usePagination } from '../../../../client/components/GenericTable/hooks/usePagination'; import { useSort } from '../../../../client/components/GenericTable/hooks/useSort'; import UserAvatar from '../../../../client/components/avatar/UserAvatar'; -import { useForm } from '../../../../client/hooks/useForm'; import { useFormatDateAndTime } from '../../../../client/hooks/useFormatDateAndTime'; import CannedResponseFilter from './CannedResponseFilter'; import RemoveCannedResponseButton from './RemoveCannedResponseButton'; -type CannedResponseFilterValues = { - sharing: string; - createdBy: string; - tags: Array<{ value: string; label: string }>; - text: string; - firstMessage: string; -}; - type Scope = 'global' | 'department' | 'user'; const CannedResponsesTable = () => { @@ -41,21 +32,14 @@ const CannedResponsesTable = () => { const isMonitor = usePermission('save-department-canned-responses'); const isManager = usePermission('save-all-canned-responses'); - const { values, handlers } = useForm({ - sharing: '', - createdBy: '', - tags: [], - text: '', - }); - - const { sharing, createdBy, text } = values as CannedResponseFilterValues; - const { handleSharing, handleCreatedBy, handleText } = handlers; + const [createdBy, setCreatedBy] = useState('all'); + const [sharing, setSharing] = useState<'' | 'user' | 'global' | 'department'>(''); + const [text, setText] = useState(''); + const debouncedText = useDebouncedValue(text, 500); const { current, itemsPerPage, setItemsPerPage: onSetItemsPerPage, setCurrent: onSetCurrent, ...paginationProps } = usePagination(); const { sortBy, setSort, sortDirection } = useSort<'shortcut' | 'scope' | 'tags' | '_createdAt' | 'createdBy'>('shortcut'); - const debouncedText = useDebouncedValue(text, 500); - const query = useMemo( () => ({ text: debouncedText, @@ -131,12 +115,12 @@ const CannedResponsesTable = () => { <> {((isSuccess && data?.cannedResponses.length > 0) || queryHasChanged) && ( )} {isLoading && (