mirror of
https://github.com/BarkProductions/barkman.git
synced 2026-06-13 06:11:55 +00:00
Refactor inventory functionality and improve modularity.
Relocated inventory page to features directory and renamed it for clarity. Introduced a reusable `Button` component and replaced inline buttons across components. Added type definitions for inventory items and environment variable support for API URL configuration.
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
VITE_API_URL=https://barkdev.ts.drewr.io
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Routes, Route} from 'react-router';
|
import { Routes, Route} from 'react-router';
|
||||||
import Home from './pages/home.tsx';
|
import Home from './pages/home.tsx';
|
||||||
import Inventory from "./pages/inventory.tsx";
|
import InventoryList from "./features/inventory/InventoryList.tsx";
|
||||||
import { QueryClientProvider, QueryClient } from '@tanstack/react-query';
|
import { QueryClientProvider, QueryClient } from '@tanstack/react-query';
|
||||||
|
|
||||||
// Create a client
|
// Create a client
|
||||||
@@ -12,7 +12,7 @@ function App() {
|
|||||||
<>
|
<>
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route index element={<Home />} />
|
<Route index element={<Home />} />
|
||||||
<Route path="inventory" element={<Inventory />} />
|
<Route path="inventory" element={<InventoryList />} />
|
||||||
</Routes>
|
</Routes>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import {PropsWithChildren} from "react";
|
||||||
|
|
||||||
|
function Button({children}: PropsWithChildren) {
|
||||||
|
return (
|
||||||
|
<button className="bg-brand rounded text-white font-bold px-4 py-2">{children}</button>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Button
|
||||||
+12
-7
@@ -1,17 +1,23 @@
|
|||||||
import {useQuery} from "@tanstack/react-query";
|
import {useQuery} from "@tanstack/react-query";
|
||||||
import {Link} from "react-router";
|
import {Link} from "react-router";
|
||||||
|
import {InventoryItem} from "./types";
|
||||||
|
import Button from "../../common/components/Button.tsx";
|
||||||
|
|
||||||
function Inventory() {
|
|
||||||
|
function InventoryList() {
|
||||||
|
|
||||||
const { isPending, error, data, isFetching } = useQuery({
|
const { isPending, error, data, isFetching } = useQuery({
|
||||||
queryKey: ['inventory'],
|
queryKey: ['inventory'],
|
||||||
queryFn: async () => {
|
queryFn: async (): Promise<InventoryItem[]> => {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
'https://barkdev.ts.drewr.io/inventory',
|
import.meta.env.VITE_API_URL + '/inventory',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (!response.ok) throw new Error('Failed to fetch inventory ' + response.statusText)
|
||||||
|
|
||||||
return await response.json()
|
return await response.json()
|
||||||
},
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
if (isPending) return 'Loading...'
|
if (isPending) return 'Loading...'
|
||||||
|
|
||||||
@@ -27,7 +33,7 @@ function Inventory() {
|
|||||||
ARFF ARFF BARK BARK
|
ARFF ARFF BARK BARK
|
||||||
</p>
|
</p>
|
||||||
<Link to="/">
|
<Link to="/">
|
||||||
<button className="bg-brand rounded text-white font-bold px-4 py-2">Home</button>
|
<Button>Home</Button>
|
||||||
</Link>
|
</Link>
|
||||||
<div>{isFetching ? 'Updating...' : ''}</div>
|
<div>{isFetching ? 'Updating...' : ''}</div>
|
||||||
|
|
||||||
@@ -54,5 +60,4 @@ function Inventory() {
|
|||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
export default InventoryList;
|
||||||
export default Inventory
|
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
export interface InventoryItem {
|
||||||
|
id: number,
|
||||||
|
brand: string,
|
||||||
|
name: string,
|
||||||
|
status: string,
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import {Link} from "react-router";
|
import {Link} from "react-router";
|
||||||
|
import Button from "../common/components/Button.tsx";
|
||||||
|
|
||||||
|
|
||||||
function Home() {
|
function Home() {
|
||||||
@@ -13,7 +14,7 @@ function Home() {
|
|||||||
ARFF ARFF BARK BARK
|
ARFF ARFF BARK BARK
|
||||||
</p>
|
</p>
|
||||||
<Link to="/inventory">
|
<Link to="/inventory">
|
||||||
<button className="bg-brand rounded text-white font-bold px-4 py-2">Inventory</button>
|
<Button>Inventory</Button>
|
||||||
</Link>
|
</Link>
|
||||||
|
|
||||||
</>
|
</>
|
||||||
|
|||||||
Reference in New Issue
Block a user