import { useEffect } from 'react' import { Link, useLocation, useNavigate, useSearchParams, } from 'react-router-dom' import { Heading, Link as ChakraLink, Table, Tbody, Td, Th, Thead, Tr, Avatar, Badge, } from '@chakra-ui/react' import cx from 'classnames' import { Helmet } from 'react-helmet-async' import GroupAPI, { SortOrder } from '@/client/api/group' import { swrConfig } from '@/client/options' import { CreateGroupButton } from '@/components/top-bar/top-bar-buttons' import prettyDate from '@/helpers/pretty-date' import { decodeQuery } from '@/helpers/query' import { groupPaginationStorage } from '@/infra/pagination' import { SectionSpinner, PagePagination, usePagePagination } from '@/lib' const GroupListPage = () => { const navigate = useNavigate() const location = useLocation() const [searchParams] = useSearchParams() const query = decodeQuery(searchParams.get('q') as string) const { page, size, steps, setPage, setSize } = usePagePagination({ navigate, location, storage: groupPaginationStorage(), }) const { data: list, error, mutate, } = GroupAPI.useList( { query, page, size, sortOrder: SortOrder.Desc }, swrConfig(), ) useEffect(() => { mutate() }, [query, page, size, mutate]) return ( <> Groups
Groups {error && (
Failed to load groups.
)} {!list && !error && } {list && list.data.length === 0 && (
There are no groups.
)} {list && list.data.length > 0 && ( {list.data.map((g) => ( ))}
Name Organization Permission Date
{g.name}
{g.organization.name} {g.permission} {prettyDate(g.createTime)}
)} {list && ( )}
) } export default GroupListPage