Skip to content

Commit

Permalink
fix: don't save the filter value on offlineMessageChannelName (#30576)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinSchoeler authored and debdutdeb committed Oct 26, 2023
1 parent 55d94ba commit 78f9c5b
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import {
Button,
PaginatedSelectFiltered,
} from '@rocket.chat/fuselage';
import { useMutableCallback, useUniqueId } from '@rocket.chat/fuselage-hooks';
import { useDebouncedValue, useMutableCallback, useUniqueId } from '@rocket.chat/fuselage-hooks';
import { useToastMessageDispatch, useRoute, useMethod, useEndpoint, useTranslation } from '@rocket.chat/ui-contexts';
import { useQueryClient } from '@tanstack/react-query';
import React, { useMemo } from 'react';
import React, { useMemo, useState } from 'react';
import { Controller, useForm } from 'react-hook-form';

import { validateEmail } from '../../../../lib/emailValidator';
Expand Down Expand Up @@ -130,10 +130,13 @@ function EditDepartment({ data, id, title, allowedToForwardData }: EditDepartmen
} = useForm<FormValues>({ mode: 'onChange', defaultValues: initialValues });

const requestTagBeforeClosingChat = watch('requestTagBeforeClosingChat');
const offlineMessageChannelName = watch('offlineMessageChannelName');

const [fallbackFilter, setFallbackFilter] = useState<string>('');

const debouncedFallbackFilter = useDebouncedValue(fallbackFilter, 500);

const { itemsList: RoomsList, loadMoreItems: loadMoreRooms } = useRoomsList(
useMemo(() => ({ text: offlineMessageChannelName }), [offlineMessageChannelName]),
useMemo(() => ({ text: debouncedFallbackFilter }), [debouncedFallbackFilter]),
);

const { phase: roomsPhase, items: roomsItems, itemCount: roomsTotal } = useRecordList(RoomsList);
Expand Down Expand Up @@ -324,13 +327,14 @@ function EditDepartment({ data, id, title, allowedToForwardData }: EditDepartmen
value={value}
onChange={onChange}
flexShrink={0}
filter={value}
setFilter={onChange}
filter={fallbackFilter}
setFilter={setFallbackFilter as (value?: string | number) => void}
options={roomsItems}
placeholder={t('Channel_name')}
endReached={
roomsPhase === AsyncStatePhase.LOADING ? () => undefined : (start) => loadMoreRooms(start, Math.min(50, roomsTotal))
}
aria-busy={fallbackFilter !== debouncedFallbackFilter}
/>
)}
/>
Expand Down

0 comments on commit 78f9c5b

Please sign in to comment.