mirror of
https://github.com/logto-io/logto.git
synced 2025-01-06 20:40:08 -05:00
feat(console): store filters in url search params (#493)
This commit is contained in:
parent
4a904f2953
commit
766156fb6b
1 changed files with 13 additions and 5 deletions
|
@ -4,7 +4,7 @@ import classNames from 'classnames';
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import Modal from 'react-modal';
|
import Modal from 'react-modal';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate, useSearchParams } from 'react-router-dom';
|
||||||
import useSWR from 'swr';
|
import useSWR from 'swr';
|
||||||
|
|
||||||
import Button from '@/components/Button';
|
import Button from '@/components/Button';
|
||||||
|
@ -29,8 +29,9 @@ const pageSize = 20;
|
||||||
const Users = () => {
|
const Users = () => {
|
||||||
const [isCreateFormOpen, setIsCreateFormOpen] = useState(false);
|
const [isCreateFormOpen, setIsCreateFormOpen] = useState(false);
|
||||||
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
|
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
|
||||||
const [pageIndex, setPageIndex] = useState(1);
|
const [query, setQuery] = useSearchParams();
|
||||||
const [keyword, setKeyword] = useState<string>();
|
const pageIndex = Number(query.get('page') ?? '1');
|
||||||
|
const keyword = query.get('search') ?? '';
|
||||||
const { data, error, mutate } = useSWR<[User[], number], RequestError>(
|
const { data, error, mutate } = useSWR<[User[], number], RequestError>(
|
||||||
`/api/users?page=${pageIndex}&page_size=${pageSize}${conditionalString(
|
`/api/users?page=${pageIndex}&page_size=${pageSize}${conditionalString(
|
||||||
keyword && `&search=${keyword}`
|
keyword && `&search=${keyword}`
|
||||||
|
@ -68,7 +69,12 @@ const Users = () => {
|
||||||
</Modal>
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.filter}>
|
<div className={styles.filter}>
|
||||||
<Search defaultValue={keyword} onSearch={setKeyword} />
|
<Search
|
||||||
|
defaultValue={keyword}
|
||||||
|
onSearch={(value) => {
|
||||||
|
setQuery({ search: value });
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className={classNames(styles.table, tableStyles.scrollable)}>
|
<div className={classNames(styles.table, tableStyles.scrollable)}>
|
||||||
<table>
|
<table>
|
||||||
|
@ -133,7 +139,9 @@ const Users = () => {
|
||||||
<Pagination
|
<Pagination
|
||||||
pageCount={Math.ceil(totalCount / pageSize)}
|
pageCount={Math.ceil(totalCount / pageSize)}
|
||||||
pageIndex={pageIndex}
|
pageIndex={pageIndex}
|
||||||
onChange={setPageIndex}
|
onChange={(page) => {
|
||||||
|
setQuery({ page: String(page) });
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue