Skip to content

Commit dd8c91b

Browse files
committed
chore: add correct items.tsx file
1 parent 9f9725c commit dd8c91b

File tree

1 file changed

+32
-57
lines changed

1 file changed

+32
-57
lines changed
Lines changed: 32 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import {
2-
Badge,
3-
Box,
42
Button,
53
Container,
64
Flex,
@@ -19,53 +17,52 @@ import { createFileRoute, useNavigate } from "@tanstack/react-router"
1917
import { useEffect } from "react"
2018
import { z } from "zod"
2119

22-
import { type UserPublic, UsersService } from "../../client"
23-
import AddUser from "../../components/Admin/AddUser"
20+
import { ItemsService } from "../../client"
2421
import ActionsMenu from "../../components/Common/ActionsMenu"
2522
import Navbar from "../../components/Common/Navbar"
23+
import AddItem from "../../components/Items/AddItem"
2624

27-
const usersSearchSchema = z.object({
25+
const itemsSearchSchema = z.object({
2826
page: z.number().catch(1),
2927
})
3028

31-
export const Route = createFileRoute("/_layout/admin")({
32-
component: Admin,
33-
validateSearch: (search) => usersSearchSchema.parse(search),
29+
export const Route = createFileRoute("/_layout/items")({
30+
component: Items,
31+
validateSearch: (search) => itemsSearchSchema.parse(search),
3432
})
3533

3634
const PER_PAGE = 5
3735

38-
function getUsersQueryOptions({ page }: { page: number }) {
36+
function getItemsQueryOptions({ page }: { page: number }) {
3937
return {
4038
queryFn: () =>
41-
UsersService.readUsers({ skip: (page - 1) * PER_PAGE, limit: PER_PAGE }),
42-
queryKey: ["users", { page }],
39+
ItemsService.readItems({ skip: (page - 1) * PER_PAGE, limit: PER_PAGE }),
40+
queryKey: ["items", { page }],
4341
}
4442
}
4543

46-
function UsersTable() {
44+
function ItemsTable() {
4745
const queryClient = useQueryClient()
48-
const currentUser = queryClient.getQueryData<UserPublic>(["currentUser"])
4946
const { page } = Route.useSearch()
5047
const navigate = useNavigate({ from: Route.fullPath })
5148
const setPage = (page: number) =>
5249
navigate({ search: (prev) => ({ ...prev, page }) })
5350

5451
const {
55-
data: users,
52+
data: items,
5653
isPending,
5754
isPlaceholderData,
5855
} = useQuery({
59-
...getUsersQueryOptions({ page }),
56+
...getItemsQueryOptions({ page }),
6057
placeholderData: (prevData) => prevData,
6158
})
6259

63-
const hasNextPage = !isPlaceholderData && users?.data.length === PER_PAGE
60+
const hasNextPage = !isPlaceholderData && items?.data.length === PER_PAGE
6461
const hasPreviousPage = page > 1
6562

6663
useEffect(() => {
6764
if (hasNextPage) {
68-
queryClient.prefetchQuery(getUsersQueryOptions({ page: page + 1 }))
65+
queryClient.prefetchQuery(getItemsQueryOptions({ page: page + 1 }))
6966
}
7067
}, [page, queryClient, hasNextPage])
7168

@@ -75,11 +72,10 @@ function UsersTable() {
7572
<Table size={{ base: "sm", md: "md" }}>
7673
<Thead>
7774
<Tr>
78-
<Th width="20%">Full name</Th>
79-
<Th width="50%">Email</Th>
80-
<Th width="10%">Role</Th>
81-
<Th width="10%">Status</Th>
82-
<Th width="10%">Actions</Th>
75+
<Th>ID</Th>
76+
<Th>Title</Th>
77+
<Th>Description</Th>
78+
<Th>Actions</Th>
8379
</Tr>
8480
</Thead>
8581
{isPending ? (
@@ -94,42 +90,21 @@ function UsersTable() {
9490
</Tbody>
9591
) : (
9692
<Tbody>
97-
{users?.data.map((user) => (
98-
<Tr key={user.id}>
93+
{items?.data.map((item) => (
94+
<Tr key={item.id} opacity={isPlaceholderData ? 0.5 : 1}>
95+
<Td>{item.id}</Td>
96+
<Td isTruncated maxWidth="150px">
97+
{item.title}
98+
</Td>
9999
<Td
100-
color={!user.full_name ? "ui.dim" : "inherit"}
100+
color={!item.description ? "ui.dim" : "inherit"}
101101
isTruncated
102102
maxWidth="150px"
103103
>
104-
{user.full_name || "N/A"}
105-
{currentUser?.id === user.id && (
106-
<Badge ml="1" colorScheme="teal">
107-
You
108-
</Badge>
109-
)}
110-
</Td>
111-
<Td isTruncated maxWidth="150px">
112-
{user.email}
104+
{item.description || "N/A"}
113105
</Td>
114-
<Td>{user.is_superuser ? "Superuser" : "User"}</Td>
115106
<Td>
116-
<Flex gap={2}>
117-
<Box
118-
w="2"
119-
h="2"
120-
borderRadius="50%"
121-
bg={user.is_active ? "ui.success" : "ui.danger"}
122-
alignSelf="center"
123-
/>
124-
{user.is_active ? "Active" : "Inactive"}
125-
</Flex>
126-
</Td>
127-
<Td>
128-
<ActionsMenu
129-
type="User"
130-
value={user}
131-
disabled={currentUser?.id === user.id ? true : false}
132-
/>
107+
<ActionsMenu type={"Item"} value={item} />
133108
</Td>
134109
</Tr>
135110
))}
@@ -156,15 +131,15 @@ function UsersTable() {
156131
)
157132
}
158133

159-
function Admin() {
134+
function Items() {
160135
return (
161136
<Container maxW="full">
162137
<Heading size="lg" textAlign={{ base: "center", md: "left" }} pt={12}>
163-
Users Management
138+
Items Management
164139
</Heading>
165140

166-
<Navbar type={"User"} addModalAs={AddUser} />
167-
<UsersTable />
141+
<Navbar type={"Item"} addModalAs={AddItem} />
142+
<ItemsTable />
168143
</Container>
169144
)
170-
}
145+
}

0 commit comments

Comments
 (0)