2024-03-08 14:58:36 +01:00
|
|
|
import {
|
|
|
|
Container,
|
|
|
|
Flex,
|
|
|
|
Heading,
|
|
|
|
Spinner,
|
|
|
|
Table,
|
|
|
|
TableContainer,
|
|
|
|
Tbody,
|
|
|
|
Td,
|
|
|
|
Th,
|
|
|
|
Thead,
|
|
|
|
Tr,
|
2024-03-17 17:28:45 +01:00
|
|
|
} from "@chakra-ui/react"
|
|
|
|
import { createFileRoute } from "@tanstack/react-router"
|
|
|
|
import { useQuery } from "react-query"
|
2024-02-12 16:46:51 -05:00
|
|
|
|
2024-03-17 17:28:45 +01:00
|
|
|
import { type ApiError, ItemsService } from "../../client"
|
|
|
|
import ActionsMenu from "../../components/Common/ActionsMenu"
|
|
|
|
import Navbar from "../../components/Common/Navbar"
|
|
|
|
import useCustomToast from "../../hooks/useCustomToast"
|
2024-02-12 16:46:51 -05:00
|
|
|
|
2024-03-17 17:28:45 +01:00
|
|
|
export const Route = createFileRoute("/_layout/items")({
|
2024-03-08 14:58:36 +01:00
|
|
|
component: Items,
|
2024-03-07 19:16:23 +01:00
|
|
|
})
|
2024-02-12 16:46:51 -05:00
|
|
|
|
2024-03-07 19:16:23 +01:00
|
|
|
function Items() {
|
2024-03-08 14:58:36 +01:00
|
|
|
const showToast = useCustomToast()
|
|
|
|
const {
|
|
|
|
data: items,
|
|
|
|
isLoading,
|
|
|
|
isError,
|
|
|
|
error,
|
2024-03-17 17:28:45 +01:00
|
|
|
} = useQuery("items", () => ItemsService.readItems({}))
|
2024-02-12 16:46:51 -05:00
|
|
|
|
2024-03-08 14:58:36 +01:00
|
|
|
if (isError) {
|
|
|
|
const errDetail = (error as ApiError).body?.detail
|
2024-03-17 17:28:45 +01:00
|
|
|
showToast("Something went wrong.", `${errDetail}`, "error")
|
2024-03-08 14:58:36 +01:00
|
|
|
}
|
2024-02-12 16:46:51 -05:00
|
|
|
|
2024-03-08 14:58:36 +01:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{isLoading ? (
|
|
|
|
// TODO: Add skeleton
|
|
|
|
<Flex justify="center" align="center" height="100vh" width="full">
|
|
|
|
<Spinner size="xl" color="ui.main" />
|
|
|
|
</Flex>
|
|
|
|
) : (
|
|
|
|
items && (
|
|
|
|
<Container maxW="full">
|
|
|
|
<Heading
|
|
|
|
size="lg"
|
2024-03-17 17:28:45 +01:00
|
|
|
textAlign={{ base: "center", md: "left" }}
|
2024-03-08 14:58:36 +01:00
|
|
|
pt={12}
|
|
|
|
>
|
|
|
|
Items Management
|
|
|
|
</Heading>
|
2024-03-17 17:28:45 +01:00
|
|
|
<Navbar type={"Item"} />
|
2024-03-08 14:58:36 +01:00
|
|
|
<TableContainer>
|
2024-03-17 17:28:45 +01:00
|
|
|
<Table size={{ base: "sm", md: "md" }}>
|
2024-03-08 14:58:36 +01:00
|
|
|
<Thead>
|
|
|
|
<Tr>
|
|
|
|
<Th>ID</Th>
|
|
|
|
<Th>Title</Th>
|
|
|
|
<Th>Description</Th>
|
|
|
|
<Th>Actions</Th>
|
|
|
|
</Tr>
|
|
|
|
</Thead>
|
|
|
|
<Tbody>
|
|
|
|
{items.data.map((item) => (
|
|
|
|
<Tr key={item.id}>
|
|
|
|
<Td>{item.id}</Td>
|
|
|
|
<Td>{item.title}</Td>
|
2024-04-01 22:53:33 -05:00
|
|
|
<Td color={!item.description ? "ui.dim" : "inherit"}>
|
2024-03-17 17:28:45 +01:00
|
|
|
{item.description || "N/A"}
|
2024-03-08 14:58:36 +01:00
|
|
|
</Td>
|
|
|
|
<Td>
|
2024-03-17 17:28:45 +01:00
|
|
|
<ActionsMenu type={"Item"} value={item} />
|
2024-03-08 14:58:36 +01:00
|
|
|
</Td>
|
|
|
|
</Tr>
|
|
|
|
))}
|
|
|
|
</Tbody>
|
|
|
|
</Table>
|
|
|
|
</TableContainer>
|
|
|
|
</Container>
|
|
|
|
)
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)
|
2024-02-12 16:46:51 -05:00
|
|
|
}
|