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}

)}