feat: integrate authFetch for API calls in InventoryView and PantryView, and add pantry route with authentication
This commit is contained in:
@@ -4,19 +4,21 @@ import { useState, useEffect, useCallback } from 'react';
|
||||
import type { InventoryItem, Product } from '../../../../features/inventory/types';
|
||||
import InventoryList from '../../../inventory/InventoryList';
|
||||
import InventoryForm from '../../../inventory/InventoryForm';
|
||||
import { useAuthFetch } from '../../../../lib/use-auth-fetch';
|
||||
|
||||
export default function InventoryView() {
|
||||
const [inventory, setInventory] = useState<InventoryItem[]>([]);
|
||||
const [products, setProducts] = useState<Product[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const authFetch = useAuthFetch();
|
||||
|
||||
const load = useCallback(async () => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const [invRes, prodRes] = await Promise.all([
|
||||
fetch('/api/inventory'),
|
||||
authFetch('/api/inventory'),
|
||||
fetch('/api/products'),
|
||||
]);
|
||||
if (!invRes.ok) throw new Error('Kunde inte hämta inventarie');
|
||||
@@ -29,7 +31,7 @@ export default function InventoryView() {
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, []);
|
||||
}, [authFetch]);
|
||||
|
||||
useEffect(() => { load(); }, [load]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user