Skip to content

Commit 8d52d01

Browse files
authored
♻️ Add PaginationFooter component (#1381)
1 parent 88e1a60 commit 8d52d01

File tree

3 files changed

+51
-34
lines changed

3 files changed

+51
-34
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { Button, Flex } from "@chakra-ui/react"
2+
3+
type PaginationFooterProps = {
4+
hasNextPage?: boolean
5+
hasPreviousPage?: boolean
6+
onChangePage: (newPage: number) => void
7+
page: number
8+
}
9+
10+
export function PaginationFooter({
11+
hasNextPage,
12+
hasPreviousPage,
13+
onChangePage,
14+
page,
15+
}: PaginationFooterProps) {
16+
return (
17+
<Flex
18+
gap={4}
19+
alignItems="center"
20+
mt={4}
21+
direction="row"
22+
justifyContent="flex-end"
23+
>
24+
<Button
25+
onClick={() => onChangePage(page - 1)}
26+
isDisabled={!hasPreviousPage || page <= 1}
27+
>
28+
Previous
29+
</Button>
30+
<span>Page {page}</span>
31+
<Button isDisabled={!hasNextPage} onClick={() => onChangePage(page + 1)}>
32+
Next
33+
</Button>
34+
</Flex>
35+
)
36+
}

frontend/src/routes/_layout/admin.tsx

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {
22
Badge,
33
Box,
4-
Button,
54
Container,
65
Flex,
76
Heading,
@@ -23,6 +22,7 @@ import { type UserPublic, UsersService } from "../../client"
2322
import AddUser from "../../components/Admin/AddUser"
2423
import ActionsMenu from "../../components/Common/ActionsMenu"
2524
import Navbar from "../../components/Common/Navbar"
25+
import { PaginationFooter } from "../../components/Common/PaginationFooter.tsx"
2626

2727
const usersSearchSchema = z.object({
2828
page: z.number().catch(1),
@@ -128,7 +128,7 @@ function UsersTable() {
128128
<ActionsMenu
129129
type="User"
130130
value={user}
131-
disabled={currentUser?.id === user.id ? true : false}
131+
disabled={currentUser?.id === user.id}
132132
/>
133133
</Td>
134134
</Tr>
@@ -137,21 +137,12 @@ function UsersTable() {
137137
)}
138138
</Table>
139139
</TableContainer>
140-
<Flex
141-
gap={4}
142-
alignItems="center"
143-
mt={4}
144-
direction="row"
145-
justifyContent="flex-end"
146-
>
147-
<Button onClick={() => setPage(page - 1)} isDisabled={!hasPreviousPage}>
148-
Previous
149-
</Button>
150-
<span>Page {page}</span>
151-
<Button isDisabled={!hasNextPage} onClick={() => setPage(page + 1)}>
152-
Next
153-
</Button>
154-
</Flex>
140+
<PaginationFooter
141+
onChangePage={setPage}
142+
page={page}
143+
hasNextPage={hasNextPage}
144+
hasPreviousPage={hasPreviousPage}
145+
/>
155146
</>
156147
)
157148
}

frontend/src/routes/_layout/items.tsx

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import {
2-
Button,
32
Container,
4-
Flex,
53
Heading,
64
SkeletonText,
75
Table,
@@ -21,6 +19,7 @@ import { ItemsService } from "../../client"
2119
import ActionsMenu from "../../components/Common/ActionsMenu"
2220
import Navbar from "../../components/Common/Navbar"
2321
import AddItem from "../../components/Items/AddItem"
22+
import { PaginationFooter } from "../../components/Common/PaginationFooter.tsx"
2423

2524
const itemsSearchSchema = z.object({
2625
page: z.number().catch(1),
@@ -112,21 +111,12 @@ function ItemsTable() {
112111
)}
113112
</Table>
114113
</TableContainer>
115-
<Flex
116-
gap={4}
117-
alignItems="center"
118-
mt={4}
119-
direction="row"
120-
justifyContent="flex-end"
121-
>
122-
<Button onClick={() => setPage(page - 1)} isDisabled={!hasPreviousPage}>
123-
Previous
124-
</Button>
125-
<span>Page {page}</span>
126-
<Button isDisabled={!hasNextPage} onClick={() => setPage(page + 1)}>
127-
Next
128-
</Button>
129-
</Flex>
114+
<PaginationFooter
115+
page={page}
116+
onChangePage={setPage}
117+
hasNextPage={hasNextPage}
118+
hasPreviousPage={hasPreviousPage}
119+
/>
130120
</>
131121
)
132122
}

0 commit comments

Comments
 (0)