Skip to content

Commit e5b96c5

Browse files
refactor: AutoCompleteTagsMultiple to use useInfiniteTagsList
1 parent c3b8a58 commit e5b96c5

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

apps/meteor/client/omnichannel/tags/AutoCompleteTagsMultiple.tsx

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@ import { useDebouncedValue } from '@rocket.chat/fuselage-hooks';
44
import { memo, useMemo, useState } from 'react';
55
import { useTranslation } from 'react-i18next';
66

7-
import { useRecordList } from '../../hooks/lists/useRecordList';
8-
import { AsyncStatePhase } from '../../hooks/useAsyncState';
9-
import { useTagsList } from '../../hooks/useTagsList';
7+
import { useInfiniteTagsList } from '../../components/Omnichannel/hooks/useInfiniteTagsList';
108

119
type AutoCompleteTagsMultipleProps = {
1210
id?: string;
1311
value?: PaginatedMultiSelectOption[];
14-
onlyMyTags?: boolean;
1512
onChange?: (value: PaginatedMultiSelectOption[]) => void;
1613
department?: string;
1714
viewAll?: boolean;
@@ -20,7 +17,6 @@ type AutoCompleteTagsMultipleProps = {
2017
const AutoCompleteTagsMultiple = ({
2118
id,
2219
value = [],
23-
onlyMyTags = false,
2420
onChange = () => undefined,
2521
department,
2622
viewAll = false,
@@ -30,14 +26,11 @@ const AutoCompleteTagsMultiple = ({
3026

3127
const debouncedTagsFilter = useDebouncedValue(tagsFilter, 500);
3228

33-
const { itemsList: tagsList, loadMoreItems: loadMoreTags } = useTagsList(
34-
useMemo(
35-
() => ({ filter: debouncedTagsFilter, onlyMyTags, department, viewAll }),
36-
[debouncedTagsFilter, onlyMyTags, department, viewAll],
37-
),
38-
);
39-
40-
const { phase: tagsPhase, items: tagsItems, itemCount: tagsTotal } = useRecordList(tagsList);
29+
const { data: tagsItems = [], fetchNextPage } = useInfiniteTagsList({
30+
filter: debouncedTagsFilter,
31+
department,
32+
viewAll,
33+
});
4134

4235
const tagsOptions = useMemo(() => {
4336
const pending = value.filter(({ value }) => !tagsItems.find((tag) => tag.value === value));
@@ -57,9 +50,7 @@ const AutoCompleteTagsMultiple = ({
5750
flexShrink={0}
5851
flexGrow={0}
5952
placeholder={t('Select_an_option')}
60-
endReached={
61-
tagsPhase === AsyncStatePhase.LOADING ? () => undefined : (start) => start && loadMoreTags(start, Math.min(50, tagsTotal))
62-
}
53+
endReached={() => fetchNextPage()}
6354
/>
6455
);
6556
};

apps/meteor/client/views/omnichannel/departments/EditDepartment.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ function EditDepartment({ data, id, title, allowedToForwardData }: EditDepartmen
379379
onChange={onChange}
380380
onLoadItems={(list) => {
381381
// NOTE: list.itemCount > 1 to account for the "None" option
382-
setUnitRequired(!canManageUnits && list.itemCount > 1);
382+
setUnitRequired(!canManageUnits && list.length > 1);
383383
}}
384384
/>
385385
)}

0 commit comments

Comments
 (0)