maybe almost there

This commit is contained in:
2025-02-05 10:57:08 -06:00
parent 54adaa99ce
commit 246b7072b6
2 changed files with 20 additions and 19 deletions
@@ -1,27 +1,13 @@
import {useQuery} from "@tanstack/react-query";
import {InventoryItem} from "./types";
import {Flex, Table} from '@mantine/core'; import {Flex, Table} from '@mantine/core';
import BarkButton from "../../common/components/BarkButton.tsx"; import BarkButton from "../../common/components/BarkButton.tsx";
import {Link, NavLink} from "react-router"; import {Link, NavLink} from "react-router";
import useInventoryList from "./hooks/useInventoryList.tsx";
function InventoryList() { function InventoryList() {
const { isPending, error, data, isFetching } = useQuery({ const data = useInventoryList();
queryKey: ['inventory'],
queryFn: async (): Promise<InventoryItem[]> => {
const response = await fetch(
import.meta.env.VITE_API_URL + '/inventory',
)
if (!response.ok) throw new Error('Failed to fetch inventory ' + response.statusText)
return await response.json()
},
});
if (isPending) return 'Loading...'
if (error) return 'An error has occurred: ' + error.message
return ( return (
<> <>
@@ -40,8 +26,6 @@ function InventoryList() {
</Flex> </Flex>
<div>{isFetching ? 'Updating...' : ''}</div>
<Table striped> <Table striped>
<Table.Thead> <Table.Thead>
<Table.Tr> <Table.Tr>
@@ -53,7 +37,7 @@ function InventoryList() {
</Table.Tr> </Table.Tr>
</Table.Thead> </Table.Thead>
<Table.Tbody> <Table.Tbody>
{data.map((data) => ( {data?.map((data) => (
<Table.Tr key={data.id}> <Table.Tr key={data.id}>
<Table.Td>{data.barcode}</Table.Td> <Table.Td>{data.barcode}</Table.Td>
<Table.Td>{data.brand}</Table.Td> <Table.Td>{data.brand}</Table.Td>
@@ -0,0 +1,17 @@
import {useQuery} from "@tanstack/react-query";
import {InventoryItem} from "../types.js";
const useInventoryList = () => useQuery({
queryKey: ['inventory'],
queryFn: async (): Promise<InventoryItem[]> => {
const response = await fetch(
import.meta.env.VITE_API_URL + '/inventory',
)
if (!response.ok) throw new Error('Failed to fetch inventory ' + response.statusText)
return await response.json()
},
});
export default useInventoryList;