diff --git a/src/app/api/pantry/[id]/route.ts b/src/app/api/pantry/[id]/route.ts index c56ab36..7aa433b 100644 --- a/src/app/api/pantry/[id]/route.ts +++ b/src/app/api/pantry/[id]/route.ts @@ -2,7 +2,7 @@ import { NextResponse } from "next/server"; import { z } from "zod"; import { ItemSource } from "@prisma/client"; import { db } from "@/lib/db"; -import { requireAuth, isAdmin } from "@/lib/auth"; +import { requireAuth } from "@/lib/auth"; const PANTRY_SELECT = { id: true, name: true, description: true, quantity: true, unit: true, @@ -96,7 +96,6 @@ export async function PATCH(req: Request, { params }: { params: { id: string } } export async function DELETE(_req: Request, { params }: { params: { id: string } }) { try { const session = await requireAuth(); - if (!isAdmin(session.user.role)) return NextResponse.json({ error: "Forbidden" }, { status: 403 }); await db.item.update({ where: { id: params.id }, data: { active: false } }); await db.auditEvent.create({ data: { action: "pantry.delete", entityId: params.id, actorId: session.user.id }, diff --git a/src/components/pantry/pantry-client.tsx b/src/components/pantry/pantry-client.tsx index a6944ab..63fe833 100644 --- a/src/components/pantry/pantry-client.tsx +++ b/src/components/pantry/pantry-client.tsx @@ -1,7 +1,7 @@ "use client"; import { useState } from "react"; -import { AlertTriangle, ChevronDown, ChevronRight, UtensilsCrossed } from "lucide-react"; +import { AlertTriangle, ChevronDown, ChevronRight, Trash2, UtensilsCrossed } from "lucide-react"; import { PantryItemDialog } from "./pantry-item-dialog"; import { PullDialog } from "./pull-dialog"; import { UseItemDialog } from "./use-item-dialog"; @@ -51,6 +51,20 @@ function ExpiryBadge({ date }: { date: Date }) { function ItemRow({ item, locations, plants, onRefresh }: { item: PantryItem; locations: LocationOption[]; plants: PlantOption[]; onRefresh: () => void; }) { + const [confirming, setConfirming] = useState(false); + const [deleting, setDeleting] = useState(false); + + async function handleDelete() { + setDeleting(true); + try { + const res = await fetch(`/api/pantry/${item.id}`, { method: "DELETE" }); + if (res.ok) onRefresh(); + } finally { + setDeleting(false); + setConfirming(false); + } + } + const priceStr = item.pricePaid != null ? `$${item.pricePaid.toFixed(2)}${item.priceUnit && item.priceUnit !== "package" ? `/${item.priceUnit}` : ""}` : null; @@ -83,8 +97,37 @@ function ItemRow({ item, locations, plants, onRefresh }: { {item.notes &&
{item.notes}
}