mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-09 00:18:00 +01:00
fix: user search pagination (#997)
This commit is contained in:
parent
2e367b3a04
commit
1caf9a924c
@ -54,8 +54,20 @@ const UsersList = ({ search }: IUsersListProps) => {
|
||||
const ref = useLoading(loading);
|
||||
const { filtered, setFilter } = useUsersFilter(users);
|
||||
const { sorted, sort, setSort } = useUsersSort(filtered);
|
||||
|
||||
const filterUsersByQueryPage = (user: IUser) => {
|
||||
const fieldsToSearch = [
|
||||
user.name ?? '',
|
||||
user.username ?? user.email ?? '',
|
||||
];
|
||||
|
||||
return fieldsToSearch.some(field => {
|
||||
return field.toLowerCase().includes(search.toLowerCase());
|
||||
});
|
||||
};
|
||||
// Filter users and reset pagination page when search is triggered
|
||||
const { page, pages, nextPage, prevPage, setPageIndex, pageIndex } =
|
||||
usePagination(sorted, 50);
|
||||
usePagination(sorted, 50, filterUsersByQueryPage);
|
||||
|
||||
useEffect(() => {
|
||||
setFilter(filter => ({ ...filter, query: search }));
|
||||
|
@ -20,6 +20,7 @@ const usePagination = <T>(
|
||||
}
|
||||
|
||||
const result = paginate(dataToPaginate, limit);
|
||||
setPageIndex(0);
|
||||
setPaginatedData(result);
|
||||
/* eslint-disable-next-line */
|
||||
}, [JSON.stringify(data), limit]);
|
||||
|
Loading…
Reference in New Issue
Block a user