mirror of
https://github.com/BarkProductions/barkman.git
synced 2026-06-13 06:11:55 +00:00
refactored unneeded code
This commit is contained in:
@@ -13,7 +13,7 @@ function AddItem() {
|
|||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const rawData = useInventoryList();
|
const inventoryQuery = useInventoryList();
|
||||||
|
|
||||||
const newItemForm = useForm<NewItem>({
|
const newItemForm = useForm<NewItem>({
|
||||||
mode: 'uncontrolled',
|
mode: 'uncontrolled',
|
||||||
@@ -69,15 +69,14 @@ function AddItem() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (rawData.data) {
|
if (inventoryQuery.data) {
|
||||||
const data = rawData.data;
|
const nextBarcode = inventoryQuery.data[inventoryQuery.data.length - 1].barcode + 1;
|
||||||
const nextBarcode = data[data.length - 1].barcode + 1;
|
|
||||||
newItemForm.setValues({barcode: nextBarcode});
|
newItemForm.setValues({barcode: nextBarcode});
|
||||||
}
|
}
|
||||||
},[rawData.data]);
|
},[inventoryQuery.data]);
|
||||||
|
|
||||||
if (rawData.isPending) return 'Loading...'
|
if (inventoryQuery.isPending) return 'Loading...'
|
||||||
if (rawData.error) return 'An error has occurred: ' + rawData.error.message
|
if (inventoryQuery.error) return 'An error has occurred: ' + inventoryQuery.error.message
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,13 +6,12 @@ import useInventoryList from "./hooks/useInventoryList.tsx";
|
|||||||
|
|
||||||
function InventoryList() {
|
function InventoryList() {
|
||||||
|
|
||||||
const rawData = useInventoryList();
|
const inventoryQuery = useInventoryList();
|
||||||
|
|
||||||
if (rawData.isPending) return 'Loading...'
|
if (inventoryQuery.isPending) return 'Loading...'
|
||||||
|
|
||||||
if (rawData.error) return 'An error has occurred: ' + rawData.error.message
|
if (inventoryQuery.error) return 'An error has occurred: ' + inventoryQuery.error.message
|
||||||
|
|
||||||
const data = rawData.data
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -41,7 +40,7 @@ function InventoryList() {
|
|||||||
</Table.Tr>
|
</Table.Tr>
|
||||||
</Table.Thead>
|
</Table.Thead>
|
||||||
<Table.Tbody>
|
<Table.Tbody>
|
||||||
{data?.map((data) => (
|
{inventoryQuery.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>
|
||||||
|
|||||||
Reference in New Issue
Block a user