feat: implement inventory and pantry management views with CRUD functionality and user-friendly interfaces
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user