import { Container, EmptyState, Flex, Heading, Table, VStack, } from "@chakra-ui/react" import { useQuery } from "@tanstack/react-query" import { createFileRoute, useNavigate } from "@tanstack/react-router" import { FiSearch } from "react-icons/fi" import { z } from "zod" import { ItemsService } from "@/client" import { ItemActionsMenu } from "@/components/Common/ItemActionsMenu" import AddItem from "@/components/Items/AddItem" import PendingItems from "@/components/Pending/PendingItems" import { PaginationItems, PaginationNextTrigger, PaginationPrevTrigger, PaginationRoot, } from "@/components/ui/pagination.tsx" const itemsSearchSchema = z.object({ page: z.number().catch(1), }) const PER_PAGE = 5 function getItemsQueryOptions({ page }: { page: number }) { return { queryFn: () => ItemsService.readItems({ skip: (page - 1) * PER_PAGE, limit: PER_PAGE }), queryKey: ["items", { page }], } } export const Route = createFileRoute("/_layout/items")({ component: Items, validateSearch: (search) => itemsSearchSchema.parse(search), }) function ItemsTable() { const navigate = useNavigate({ from: Route.fullPath }) const { page } = Route.useSearch() const { data, isLoading, isPlaceholderData } = useQuery({ ...getItemsQueryOptions({ page }), placeholderData: (prevData) => prevData, }) const setPage = (page: number) => { navigate({ to: "/items", search: (prev) => ({ ...prev, page }), }) } const items = data?.data.slice(0, PER_PAGE) ?? [] const count = data?.count ?? 0 if (isLoading) { return } if (items.length === 0) { return ( You don't have any items yet Add a new item to get started ) } return ( <> ID Title Description Actions {items?.map((item) => ( {item.id} {item.title} {item.description || "N/A"} ))} setPage(page)} > ) } function Items() { return ( Items Management ) }