import React, { Fragment, useEffect, useState } from 'react'; import http, { FractalPaginatedResponse, PaginatedResult, PaginationDataSet, QueryBuilderParams, toPaginatedSet, withQueryBuilderParams, } from '@/api/http'; import { UUID } from '@/api/definitions'; import { Transformers, User } from '@definitions/admin'; import { Transition } from '@/components/elements/transitions'; import { LockOpenIcon, PlusIcon, SupportIcon, TrashIcon } from '@heroicons/react/solid'; import { Button } from '@/components/elements/button/index'; import { Checkbox, InputField } from '@/components/elements/inputs'; import UserTableRow from '@/components/admin/users/UserTableRow'; import useSWR, { SWRConfiguration, SWRResponse } from 'swr'; import { AxiosError } from 'axios'; const useGetUsers = ( params?: QueryBuilderParams<'id' | 'email' | 'uuid'>, config?: SWRConfiguration, ): SWRResponse, AxiosError> => { return useSWR>([ '/api/application/users', params ], async () => { const { data } = await http.get( '/api/application/users', { params: withQueryBuilderParams(params) }, ); return toPaginatedSet(data, Transformers.toUser); }, config || { revalidateOnMount: true, revalidateOnFocus: false }); }; const PaginationFooter = ({ pagination, span }: { span: number; pagination: PaginationDataSet }) => { const start = (pagination.currentPage - 1) * pagination.perPage; const end = ((pagination.currentPage - 1) * pagination.perPage) + pagination.count; return (

Showing {Math.max(start, 1)} to  {end} of  {pagination.total} results.

); }; const UsersContainer = () => { const { data: users } = useGetUsers(); const [ selected, setSelected ] = useState([]); useEffect(() => { document.title = 'Admin | Users'; }, []); const onRowChange = (user: User, checked: boolean) => { setSelected((state) => { return checked ? [ ...state, user.uuid ] : selected.filter((uuid) => uuid !== user.uuid); }); }; const selectAllChecked = users && users.items.length > 0 && selected.length > 0; const onSelectAll = () => setSelected((state) => state.length > 0 ? [] : users?.items.map(({ uuid }) => uuid) || []); return (
0} duration={'duration-75'}>
{users?.items.map(user => ( ))} {users && }
Email
); }; export default UsersContainer;