"use client"; import { useState } from "react"; import { LineItemsEditor } from "@/components/po/po-line-items-editor"; import { managerEditLineItems } from "./manager-line-edit-actions"; import type { LineItemInput } from "@/lib/validations/po"; interface Props { poId: string; initialItems: LineItemInput[]; } export function ManagerLineItemsEditor({ poId, initialItems }: Props) { const [editing, setEditing] = useState(false); const [items, setItems] = useState(initialItems); const [pending, setPending] = useState(false); const [error, setError] = useState(""); const [saved, setSaved] = useState(false); async function handleSave() { setPending(true); setError(""); const result = await managerEditLineItems({ poId, lineItems: items }); if ("error" in result) { setError(result.error); setPending(false); } else { setSaved(true); setEditing(false); setPending(false); } } function handleCancel() { setItems(initialItems); setEditing(false); setError(""); } if (!editing) { return (
{saved && (

Line items updated. The original values are shown with strikethrough on the detail view.

)}
); } return (

Manager — Editing Line Items

{error &&

{error}

}
); }