mirror of
https://github.com/BarkProductions/barkman.git
synced 2026-06-12 22:11:54 +00:00
added query to return last used barcode and autopoulate field
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import {Button, Group, TextInput, NumberInput, Container, Title, Flex} from '@mantine/core';
|
||||
import {useForm} from '@mantine/form';
|
||||
import {useMutation} from "@tanstack/react-query";
|
||||
import {NewItem} from "./types.ts";
|
||||
import {useMutation, useQuery} from "@tanstack/react-query";
|
||||
import {InventoryItem, NewItem} from "./types.ts";
|
||||
import { useNavigate} from "react-router";
|
||||
import { IconX, IconCheck } from '@tabler/icons-react';
|
||||
import { notifications } from '@mantine/notifications';
|
||||
@@ -10,9 +10,29 @@ function AddItem() {
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
const { isPending, error, data} = 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()
|
||||
},
|
||||
});
|
||||
|
||||
if (isPending) return 'Loading...'
|
||||
|
||||
if (error) return 'An error has occurred: ' + error.message
|
||||
|
||||
const lastBarcode = data[data.length - 1].barcode;
|
||||
|
||||
const newItemForm = useForm<NewItem>({
|
||||
mode: 'uncontrolled',
|
||||
initialValues: {
|
||||
barcode: lastBarcode + 1,
|
||||
name: "",
|
||||
brand: "",
|
||||
serialNumber: "",
|
||||
|
||||
@@ -23,7 +23,6 @@ function InventoryList() {
|
||||
|
||||
if (error) return 'An error has occurred: ' + error.message
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
<Flex
|
||||
|
||||
@@ -12,6 +12,7 @@ export interface InventoryItem {
|
||||
}
|
||||
|
||||
export interface NewItem {
|
||||
barcode: number,
|
||||
brand: string,
|
||||
name: string,
|
||||
serialNumber: string,
|
||||
|
||||
Reference in New Issue
Block a user