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