mirror of
https://github.com/BarkProductions/barkman.git
synced 2026-06-13 06:11:55 +00:00
@@ -6,6 +6,7 @@ import {createTheme, MantineProvider} from '@mantine/core';
|
|||||||
import '@mantine/core/styles.css';
|
import '@mantine/core/styles.css';
|
||||||
import ItemDetail from "./features/inventory/ItemDetail.tsx";
|
import ItemDetail from "./features/inventory/ItemDetail.tsx";
|
||||||
import EditItem from "./features/inventory/EditItem.tsx";
|
import EditItem from "./features/inventory/EditItem.tsx";
|
||||||
|
import {BarkHeader} from "./common/components/BarkHeader.tsx";
|
||||||
|
|
||||||
// Create a client
|
// Create a client
|
||||||
const queryClient = new QueryClient()
|
const queryClient = new QueryClient()
|
||||||
@@ -33,6 +34,7 @@ function App() {
|
|||||||
return <MantineProvider defaultColorScheme="auto" theme={barkTheme}>{ (
|
return <MantineProvider defaultColorScheme="auto" theme={barkTheme}>{ (
|
||||||
<QueryClientProvider client={queryClient}>
|
<QueryClientProvider client={queryClient}>
|
||||||
<>
|
<>
|
||||||
|
<BarkHeader></BarkHeader>
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route index element={<Home />} />
|
<Route index element={<Home />} />
|
||||||
<Route path="inventory" element={<InventoryList />} />
|
<Route path="inventory" element={<InventoryList />} />
|
||||||
@@ -40,7 +42,6 @@ function App() {
|
|||||||
<Route path="editItem/:itemId" element={<EditItem />} />
|
<Route path="editItem/:itemId" element={<EditItem />} />
|
||||||
</Routes>
|
</Routes>
|
||||||
|
|
||||||
|
|
||||||
</>
|
</>
|
||||||
</QueryClientProvider>
|
</QueryClientProvider>
|
||||||
) }</MantineProvider>;
|
) }</MantineProvider>;
|
||||||
|
|||||||
@@ -1,13 +1,30 @@
|
|||||||
import {NumberInput, Stack, Text, Textarea, TextInput} from "@mantine/core";
|
import {Button, Group, TextInput, Text, Textarea, NumberInput} from '@mantine/core';
|
||||||
import {BarkHeader} from "../../common/components/BarkHeader.tsx";
|
import { useForm } from '@mantine/form';
|
||||||
import {useParams} from "react-router";
|
import {useParams} from "react-router";
|
||||||
|
import {useMutation, useQuery, useQueryClient} from "@tanstack/react-query";
|
||||||
import {InventoryItem} from "./types.ts";
|
import {InventoryItem} from "./types.ts";
|
||||||
import {useQuery} from "@tanstack/react-query";
|
import {useEffect} from "react";
|
||||||
|
|
||||||
|
|
||||||
|
type EditableInventoryItem = Omit<InventoryItem, 'id'>;
|
||||||
|
|
||||||
function EditItem() {
|
function EditItem() {
|
||||||
let params = useParams();
|
const params = useParams();
|
||||||
|
|
||||||
|
const form = useForm<EditableInventoryItem>({
|
||||||
|
mode: 'uncontrolled',
|
||||||
|
initialValues: {
|
||||||
|
name: "",
|
||||||
|
brand: "",
|
||||||
|
status: "",
|
||||||
|
serialNumber: "",
|
||||||
|
rentalPrice: 0,
|
||||||
|
replacementCost: 0,
|
||||||
|
notes: "",
|
||||||
|
},
|
||||||
|
|
||||||
|
validate: {
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const { isPending, error, data, isFetching } = useQuery({
|
const { isPending, error, data, isFetching } = useQuery({
|
||||||
queryKey: ['inventory', params.itemId],
|
queryKey: ['inventory', params.itemId],
|
||||||
@@ -22,35 +39,67 @@ function EditItem() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
const updateItem = useMutation({
|
||||||
|
mutationFn: async (values: EditableInventoryItem) => {
|
||||||
|
|
||||||
|
// await <call the api, do the things>
|
||||||
|
const result = await fetch(import.meta.env.VITE_API_URL + '/inventory/' + params.itemId, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify(values),
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!result.ok) {
|
||||||
|
throw new Error('Failed to update inventory item');
|
||||||
|
}
|
||||||
|
|
||||||
|
// invalidate the queries so they pull updated information
|
||||||
|
// this is a prefix, so it covers both the query that pulls a list, and also `['inventory', itemId]` in this file
|
||||||
|
await queryClient.invalidateQueries({
|
||||||
|
queryKey: ['inventory']
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (data) {
|
||||||
|
// Even if query.data changes, form will be initialized only once
|
||||||
|
form.initialize(data);
|
||||||
|
}
|
||||||
|
}, [data]);
|
||||||
|
|
||||||
if (isPending) return 'Loading...'
|
if (isPending) return 'Loading...'
|
||||||
|
|
||||||
if (error) return 'An error has occurred: ' + error.message
|
if (error) return 'An error has occurred: ' + error.message
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<form onSubmit={form.onSubmit(async (values) => await
|
||||||
<BarkHeader></BarkHeader>
|
updateItem.mutateAsync(values))}>
|
||||||
<Stack
|
|
||||||
h={600}
|
|
||||||
bg="var(--mantine-color-body)"
|
|
||||||
align="center"
|
|
||||||
justify="center"
|
|
||||||
gap="md"
|
|
||||||
>
|
|
||||||
<Text c="red">Edit Item</Text>
|
|
||||||
<div>{isFetching ? 'Updating...' : ''}</div>
|
<div>{isFetching ? 'Updating...' : ''}</div>
|
||||||
<Text>ID: {data.id}</Text>
|
<Text>ID: {data.id}</Text>
|
||||||
<TextInput withAsterisk size="md" label="Brand" placeholder={data.brand}/>
|
<TextInput withAsterisk key={form.key('brand')} size="md" label="Brand"
|
||||||
<TextInput withAsterisk size="md" label="Name" placeholder={data.name}/>
|
placeholder="Brand" {...form.getInputProps('brand')}/>
|
||||||
<TextInput size="md" label="Status" placeholder={data.status}/>
|
<TextInput withAsterisk key={form.key('name')} size="md" label="Name"
|
||||||
<TextInput size="md" label="Serial Number" placeholder={data.serialNumber}/>
|
placeholder="Name" {...form.getInputProps('name')}/>
|
||||||
<NumberInput size="md" label="Rental Price" placeholder={data.rentalPrice.toString()}/>
|
<TextInput size="md" key={form.key('status')} label="Status"
|
||||||
<NumberInput size="md" label="Replacement Cost" placeholder={data.replacementCost.toString()}/>
|
placeholder="Status" {...form.getInputProps('status')}/>
|
||||||
<Text>Replacement Cost: ${data.replacementCost}</Text>
|
<TextInput size="md" key={form.key('serialNumber')} label="Serial Number"
|
||||||
<Textarea label="Notes" placeholder={data.notes}/>
|
placeholder="Serial Number"{...form.getInputProps('serialNumber')}/>
|
||||||
</Stack>
|
<NumberInput size="md" key={form.key('rentalPrice')} label="Rental Price"
|
||||||
|
placeholder="Rental Price" {...form.getInputProps('rentalPrice')}/>
|
||||||
|
<NumberInput size="md" key={form.key('replacementCost')} label="Replacement Cost"
|
||||||
|
placeholder="Replacement Cost" {...form.getInputProps('replacementCost')}/>
|
||||||
|
<Textarea label="Notes" key={form.key('notes')} placeholder="Notes" {...form.getInputProps('notes')}/>
|
||||||
|
|
||||||
</>
|
<Group justify="flex-end" mt="md">
|
||||||
)
|
<Button type="submit">Submit</Button>
|
||||||
|
</Group>
|
||||||
|
</form>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default EditItem
|
export default EditItem;
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
import {useQuery} from "@tanstack/react-query";
|
import {useQuery} from "@tanstack/react-query";
|
||||||
import {InventoryItem} from "./types";
|
import {InventoryItem} from "./types";
|
||||||
import {BarkHeader} from "../../common/components/BarkHeader.tsx";
|
|
||||||
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} from "react-router";
|
import {Link} from "react-router";
|
||||||
@@ -27,8 +26,6 @@ function InventoryList() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<BarkHeader></BarkHeader>
|
|
||||||
|
|
||||||
<Flex
|
<Flex
|
||||||
mih={50}
|
mih={50}
|
||||||
gap="xl"
|
gap="xl"
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
import {Text} from "@mantine/core";
|
import {Text} from "@mantine/core";
|
||||||
import {BarkHeader} from "../../common/components/BarkHeader.tsx";
|
|
||||||
import {Link, useParams} from "react-router";
|
import {Link, useParams} from "react-router";
|
||||||
import {InventoryItem} from "./types.ts";
|
import {InventoryItem} from "./types.ts";
|
||||||
import {useQuery} from "@tanstack/react-query";
|
import {useQuery} from "@tanstack/react-query";
|
||||||
import editItem from "./EditItem.tsx";
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -29,7 +27,6 @@ if (error) return 'An error has occurred: ' + error.message
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<BarkHeader></BarkHeader>
|
|
||||||
<Text c="red">Item Detail</Text>
|
<Text c="red">Item Detail</Text>
|
||||||
<div>{isFetching ? 'Updating...' : ''}</div>
|
<div>{isFetching ? 'Updating...' : ''}</div>
|
||||||
<Text>ID: {data.id}</Text>
|
<Text>ID: {data.id}</Text>
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import {BarkHeader} from "../common/components/BarkHeader.tsx";
|
|
||||||
import {Text} from "@mantine/core";
|
import {Text} from "@mantine/core";
|
||||||
|
|
||||||
|
|
||||||
@@ -7,11 +6,7 @@ function Home() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<BarkHeader></BarkHeader>
|
|
||||||
|
|
||||||
<Text c="red">Bark productions: at the intersection of professionalism and degeneracy</Text>
|
<Text c="red">Bark productions: at the intersection of professionalism and degeneracy</Text>
|
||||||
|
|
||||||
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user