Files
supabase/apps/studio/components/interfaces/Auth/Users/UsersPagination.tsx
Alaister YoungandJoshen Lim e9c1966ab5 chore: improve auth screens loading (#19940)
* chore: improve auth screens loading

* Update apps/studio/components/interfaces/Auth/Users/UsersList.tsx

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>

* handle error

* better pagination for users list

* disgusting boolean logic

* return user to previous page after deleting last user

* only show reloading indicator when it's refetching

* fix date formatting

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2024-01-02 05:13:33 +00:00

59 lines
1.8 KiB
TypeScript

import { memo } from 'react'
import { USERS_PAGE_LIMIT } from 'data/auth/users-query'
import { Button } from 'ui'
interface UsersPaginationProps {
total: number
page: number
setPage: (page: number) => void
isFetchingNextPage: boolean
}
const UsersPagination = ({ total, page, setPage, isFetchingNextPage }: UsersPaginationProps) => {
const startRowFromPage = USERS_PAGE_LIMIT * (page - 1) + 1
const fromRow = startRowFromPage > total ? total : startRowFromPage
const endRowFromPage = USERS_PAGE_LIMIT * page
const toRow = endRowFromPage > total ? total : endRowFromPage
const hasPrevious = page > 1
const hasNext = toRow < total
return (
<nav className="flex items-center justify-between overflow-hidden" aria-label="Pagination">
<div className="hidden sm:block">
<p className="text-xs text-foreground-lighter">
Showing
<span className="px-1 font-medium text-foreground-light">{fromRow}</span>
to
<span className="px-1 font-medium text-foreground-light">{toRow}</span>
of
<span className="px-1 font-medium text-foreground-light">{total}</span>
results
</p>
</div>
<div className="flex flex-1 justify-between sm:justify-end">
{hasPrevious && !(isFetchingNextPage && page === 2) && (
<Button type="default" onClick={() => setPage(page - 1)} disabled={isFetchingNextPage}>
Previous
</Button>
)}
{(hasNext || isFetchingNextPage) && (
<Button
type="default"
className="ml-3"
onClick={() => setPage(page + 1)}
disabled={isFetchingNextPage}
loading={isFetchingNextPage}
>
Next
</Button>
)}
</div>
</nav>
)
}
export default UsersPagination