♻️ Add PaginationFooter component (#1381)
This commit is contained in:
36
frontend/src/components/Common/PaginationFooter.tsx
Normal file
36
frontend/src/components/Common/PaginationFooter.tsx
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import { Button, Flex } from "@chakra-ui/react"
|
||||||
|
|
||||||
|
type PaginationFooterProps = {
|
||||||
|
hasNextPage?: boolean
|
||||||
|
hasPreviousPage?: boolean
|
||||||
|
onChangePage: (newPage: number) => void
|
||||||
|
page: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export function PaginationFooter({
|
||||||
|
hasNextPage,
|
||||||
|
hasPreviousPage,
|
||||||
|
onChangePage,
|
||||||
|
page,
|
||||||
|
}: PaginationFooterProps) {
|
||||||
|
return (
|
||||||
|
<Flex
|
||||||
|
gap={4}
|
||||||
|
alignItems="center"
|
||||||
|
mt={4}
|
||||||
|
direction="row"
|
||||||
|
justifyContent="flex-end"
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
onClick={() => onChangePage(page - 1)}
|
||||||
|
isDisabled={!hasPreviousPage || page <= 1}
|
||||||
|
>
|
||||||
|
Previous
|
||||||
|
</Button>
|
||||||
|
<span>Page {page}</span>
|
||||||
|
<Button isDisabled={!hasNextPage} onClick={() => onChangePage(page + 1)}>
|
||||||
|
Next
|
||||||
|
</Button>
|
||||||
|
</Flex>
|
||||||
|
)
|
||||||
|
}
|
@@ -1,7 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
Badge,
|
Badge,
|
||||||
Box,
|
Box,
|
||||||
Button,
|
|
||||||
Container,
|
Container,
|
||||||
Flex,
|
Flex,
|
||||||
Heading,
|
Heading,
|
||||||
@@ -23,6 +22,7 @@ import { type UserPublic, UsersService } from "../../client"
|
|||||||
import AddUser from "../../components/Admin/AddUser"
|
import AddUser from "../../components/Admin/AddUser"
|
||||||
import ActionsMenu from "../../components/Common/ActionsMenu"
|
import ActionsMenu from "../../components/Common/ActionsMenu"
|
||||||
import Navbar from "../../components/Common/Navbar"
|
import Navbar from "../../components/Common/Navbar"
|
||||||
|
import { PaginationFooter } from "../../components/Common/PaginationFooter.tsx"
|
||||||
|
|
||||||
const usersSearchSchema = z.object({
|
const usersSearchSchema = z.object({
|
||||||
page: z.number().catch(1),
|
page: z.number().catch(1),
|
||||||
@@ -128,7 +128,7 @@ function UsersTable() {
|
|||||||
<ActionsMenu
|
<ActionsMenu
|
||||||
type="User"
|
type="User"
|
||||||
value={user}
|
value={user}
|
||||||
disabled={currentUser?.id === user.id ? true : false}
|
disabled={currentUser?.id === user.id}
|
||||||
/>
|
/>
|
||||||
</Td>
|
</Td>
|
||||||
</Tr>
|
</Tr>
|
||||||
@@ -137,21 +137,12 @@ function UsersTable() {
|
|||||||
)}
|
)}
|
||||||
</Table>
|
</Table>
|
||||||
</TableContainer>
|
</TableContainer>
|
||||||
<Flex
|
<PaginationFooter
|
||||||
gap={4}
|
onChangePage={setPage}
|
||||||
alignItems="center"
|
page={page}
|
||||||
mt={4}
|
hasNextPage={hasNextPage}
|
||||||
direction="row"
|
hasPreviousPage={hasPreviousPage}
|
||||||
justifyContent="flex-end"
|
/>
|
||||||
>
|
|
||||||
<Button onClick={() => setPage(page - 1)} isDisabled={!hasPreviousPage}>
|
|
||||||
Previous
|
|
||||||
</Button>
|
|
||||||
<span>Page {page}</span>
|
|
||||||
<Button isDisabled={!hasNextPage} onClick={() => setPage(page + 1)}>
|
|
||||||
Next
|
|
||||||
</Button>
|
|
||||||
</Flex>
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
Button,
|
|
||||||
Container,
|
Container,
|
||||||
Flex,
|
|
||||||
Heading,
|
Heading,
|
||||||
SkeletonText,
|
SkeletonText,
|
||||||
Table,
|
Table,
|
||||||
@@ -21,6 +19,7 @@ import { ItemsService } from "../../client"
|
|||||||
import ActionsMenu from "../../components/Common/ActionsMenu"
|
import ActionsMenu from "../../components/Common/ActionsMenu"
|
||||||
import Navbar from "../../components/Common/Navbar"
|
import Navbar from "../../components/Common/Navbar"
|
||||||
import AddItem from "../../components/Items/AddItem"
|
import AddItem from "../../components/Items/AddItem"
|
||||||
|
import { PaginationFooter } from "../../components/Common/PaginationFooter.tsx"
|
||||||
|
|
||||||
const itemsSearchSchema = z.object({
|
const itemsSearchSchema = z.object({
|
||||||
page: z.number().catch(1),
|
page: z.number().catch(1),
|
||||||
@@ -112,21 +111,12 @@ function ItemsTable() {
|
|||||||
)}
|
)}
|
||||||
</Table>
|
</Table>
|
||||||
</TableContainer>
|
</TableContainer>
|
||||||
<Flex
|
<PaginationFooter
|
||||||
gap={4}
|
page={page}
|
||||||
alignItems="center"
|
onChangePage={setPage}
|
||||||
mt={4}
|
hasNextPage={hasNextPage}
|
||||||
direction="row"
|
hasPreviousPage={hasPreviousPage}
|
||||||
justifyContent="flex-end"
|
/>
|
||||||
>
|
|
||||||
<Button onClick={() => setPage(page - 1)} isDisabled={!hasPreviousPage}>
|
|
||||||
Previous
|
|
||||||
</Button>
|
|
||||||
<span>Page {page}</span>
|
|
||||||
<Button isDisabled={!hasNextPage} onClick={() => setPage(page + 1)}>
|
|
||||||
Next
|
|
||||||
</Button>
|
|
||||||
</Flex>
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user