feat: implement inventory and pantry management views with CRUD functionality and user-friendly interfaces

This commit is contained in:
Nils-Johan Gynther
2026-04-21 14:43:18 +02:00
parent 82c3dc3fee
commit 81b63b3fdb
14 changed files with 352 additions and 59 deletions
+6 -2
View File
@@ -16,15 +16,19 @@ type InventoryItem = {
type Props = {
items: PantryItem[];
inventoryByProductId: Record<number, InventoryItem[]>;
onDeleted?: () => void;
};
export default function PantryList({ items, inventoryByProductId }: Props) {
export default function PantryList({ items, inventoryByProductId, onDeleted }: Props) {
const router = useRouter();
async function handleRemove(id: number, name: string) {
if (!confirm(`Ta bort "${name}" från baslagret?`)) return;
const res = await fetch(`/api/admin/pantry-item/${id}`, { method: 'DELETE' });
if (res.ok) router.refresh();
if (res.ok) {
if (onDeleted) onDeleted();
else router.refresh();
}
}
if (items.length === 0) {