Old body
", + bodyText: "Old body", + }, + additionalAttachments: ["drawing.pdf"], + step: "po_sent" as const, + }; + vi.spyOn(global, "fetch").mockImplementation(async (input) => { + const url = String(input); + const groups = url.includes("tab=po_sent") ? [poSentGroup] : []; + return new Response(JSON.stringify({ groups }), { status: 200 }); + }); + + render(Old body
", + bodyText: "Old body", + }, + additional_attachments: ["drawing.pdf"], expand: { supplier: { id: "sup-1", @@ -409,6 +418,15 @@ describe("listBuyerTasks", () => { expect(groups).toHaveLength(1); expect(groups[0].poNumber).toBe("PO-26072901"); expect(groups[0].supplierEmail).toBe("orders@steelco.example"); + expect(groups[0].emailPayload).toEqual({ + to: "previous@example.com", + cc: "copy@example.com", + bcc: "blind@example.com", + subject: "Old subject", + body: "Old body
", + bodyText: "Old body", + }); + expect(groups[0].additionalAttachments).toEqual(["drawing.pdf"]); }); it("populates emailError from the related PO when the PO has an email_error", async () => { diff --git a/src/lib/server/buyer-tasks-service.ts b/src/lib/server/buyer-tasks-service.ts index 87bfdac..1281823 100644 --- a/src/lib/server/buyer-tasks-service.ts +++ b/src/lib/server/buyer-tasks-service.ts @@ -4,6 +4,7 @@ import { generatePurchaseOrderPdf, PurchaseOrderPdfValidationError, } from "@/lib/server/purchase-orders-service"; +import type { PurchaseOrderEmailPayload } from "@/lib/types"; export type BuyerTaskTab = "needs_po" | "po_draft" | "po_sent"; @@ -50,6 +51,10 @@ export type BuyerTaskGroup = { * layout. The full reason remains visible in the order page's send-modal * banner. */ emailError: string | null; + /** Last composed outbound email, used to prefill the resend modal. */ + emailPayload: PurchaseOrderEmailPayload | null; + /** File tokens for additional supplier attachments. */ + additionalAttachments: string[]; step: BuyerTaskTab; source: BuyerTaskGroupSource; }; @@ -111,7 +116,7 @@ export async function listBuyerTasks(tab: BuyerTaskTab): Promise