From 3e5d11c4ae5dbba6a80d15b4da242a1bc59a6097 Mon Sep 17 00:00:00 2001 From: Hardik Date: Wed, 27 May 2026 04:41:53 +0530 Subject: [PATCH] feat(po): show note author name on manager note banners Derives the author from the most recent EDITS_REQUESTED / REJECTED / APPROVED action that carries a note. PO detail banner now shows 'Note from [name]', edit-page banner shows 'Edits requested by [name]', and the closed-orders list prefixes the truncated note with the author's name. No schema changes required - uses the already-fetched actions with actor. Co-Authored-By: Claude Sonnet 4.6 --- App/app/(portal)/my-orders/page.tsx | 12 +++++++++++- App/app/(portal)/po/[id]/edit/edit-po-form.tsx | 7 +++++-- App/app/(portal)/po/[id]/edit/page.tsx | 11 +++++++++-- App/components/po/po-detail.tsx | 12 +++++++++++- 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/App/app/(portal)/my-orders/page.tsx b/App/app/(portal)/my-orders/page.tsx index 1e95f25..2bd44a8 100644 --- a/App/app/(portal)/my-orders/page.tsx +++ b/App/app/(portal)/my-orders/page.tsx @@ -24,6 +24,15 @@ export default async function MyOrdersPage() { include: { vessel: { select: { name: true } }, account: { select: { name: true, code: true } }, + actions: { + where: { + actionType: { in: ["EDITS_REQUESTED", "REJECTED", "APPROVED", "APPROVED_WITH_NOTE"] }, + note: { not: null }, + }, + orderBy: { createdAt: "desc" }, + take: 1, + select: { actor: { select: { name: true } } }, + }, }, }); @@ -62,6 +71,7 @@ type PoRow = { account: { name: string; code: string }; updatedAt: Date; managerNote: string | null; + actions: { actor: { name: string } }[]; }; function PoTable({ title, rows, className = "" }: { title: string; rows: PoRow[]; className?: string }) { @@ -95,7 +105,7 @@ function PoTable({ title, rows, className = "" }: { title: string; rows: PoRow[] {po.managerNote && (

- Note: {po.managerNote} + {po.actions[0]?.actor.name ? `${po.actions[0].actor.name}: ` : "Note: "}{po.managerNote}

)} diff --git a/App/app/(portal)/po/[id]/edit/edit-po-form.tsx b/App/app/(portal)/po/[id]/edit/edit-po-form.tsx index e147848..5ab5394 100644 --- a/App/app/(portal)/po/[id]/edit/edit-po-form.tsx +++ b/App/app/(portal)/po/[id]/edit/edit-po-form.tsx @@ -37,9 +37,10 @@ interface Props { vessels: Vessel[]; accounts: Account[]; vendors: Vendor[]; + managerNoteAuthor?: string | null; } -export function EditPoForm({ po, vessels, accounts, vendors }: Props) { +export function EditPoForm({ po, vessels, accounts, vendors, managerNoteAuthor }: Props) { const router = useRouter(); const [lineItems, setLineItems] = useState( po.lineItems.map((li) => ({ @@ -104,7 +105,9 @@ export function EditPoForm({ po, vessels, accounts, vendors }: Props) {
e.preventDefault()}> {canResubmit && (
-

Edits requested

+

+ {managerNoteAuthor ? `Edits requested by ${managerNoteAuthor}` : "Edits requested"} +

{po.managerNote && (

"{po.managerNote}"

)} diff --git a/App/app/(portal)/po/[id]/edit/page.tsx b/App/app/(portal)/po/[id]/edit/page.tsx index ae99d5a..e51bb78 100644 --- a/App/app/(portal)/po/[id]/edit/page.tsx +++ b/App/app/(portal)/po/[id]/edit/page.tsx @@ -29,10 +29,17 @@ export default async function EditPoPage({ params }: Props) { po.submitterId === session.user.id || session.user.role === "SUPERUSER"; if (!canEdit) redirect(`/po/${id}`); - const [vessels, accounts, vendors] = await Promise.all([ + const [vessels, accounts, vendors, noteAction] = await Promise.all([ db.vessel.findMany({ where: { isActive: true }, orderBy: { name: "asc" } }), db.account.findMany({ where: { isActive: true }, orderBy: { name: "asc" } }), db.vendor.findMany({ where: { isActive: true }, orderBy: { name: "asc" } }), + po.status === "EDITS_REQUESTED" + ? db.pOAction.findFirst({ + where: { poId: po.id, actionType: "EDITS_REQUESTED", note: { not: null } }, + orderBy: { createdAt: "desc" }, + include: { actor: { select: { name: true } } }, + }) + : Promise.resolve(null), ]); const serializedPo = { @@ -53,7 +60,7 @@ export default async function EditPoPage({ params }: Props) {

Edit Purchase Order

{po.poNumber}

- + ); } diff --git a/App/components/po/po-detail.tsx b/App/components/po/po-detail.tsx index 2e2ab49..5fda1e3 100644 --- a/App/components/po/po-detail.tsx +++ b/App/components/po/po-detail.tsx @@ -106,6 +106,14 @@ export async function PoDetail({ po, currentUserId, currentRole, readOnly = fals .reverse() .find((a) => a.actionType === "MANAGER_LINE_EDIT"); + const noteAction = [...po.actions] + .reverse() + .find((a) => + ["EDITS_REQUESTED", "REJECTED", "APPROVED", "APPROVED_WITH_NOTE"].includes(a.actionType) && + a.note + ); + const managerNoteAuthor = noteAction?.actor.name ?? null; + // Resubmit snapshot: stored in the most recent SUBMITTED action's metadata // when the submitter resubmits after EDITS_REQUESTED. type ResubmitSnapshot = { @@ -208,7 +216,9 @@ export async function PoDetail({ po, currentUserId, currentRole, readOnly = fals {/* Manager note banner */} {po.managerNote && (
-

Manager note

+

+ {managerNoteAuthor ? `Note from ${managerNoteAuthor}` : "Manager note"} +

{po.managerNote}

)}