fix(notifications): rationalise who gets which email
PO_SUBMITTED: managers only, submitter no longer copied PAYMENT_SENT: submitter only (it is a receipt prompt, not a manager action) PARTIAL_RECEIPT_CONFIRMED: managers now notified via new event type RECEIPT_CONFIRMED: unchanged (managers + accounts) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
d82d18bac2
commit
7169d52885
6 changed files with 20 additions and 14 deletions
|
|
@ -177,8 +177,7 @@ export async function markPaid({
|
|||
});
|
||||
}
|
||||
|
||||
const managers = await db.user.findMany({ where: { role: "MANAGER", isActive: true } });
|
||||
await notify({ event: "PAYMENT_SENT", po, recipients: [po.submitter, ...managers] });
|
||||
await notify({ event: "PAYMENT_SENT", po, recipients: [po.submitter] });
|
||||
|
||||
revalidatePath("/payments");
|
||||
revalidatePath(`/po/${poId}`);
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ export async function submitDraftPo(
|
|||
});
|
||||
|
||||
const managers = await db.user.findMany({ where: { role: "MANAGER", isActive: true } });
|
||||
await notify({ event: "PO_SUBMITTED", po, recipients: [po.submitter, ...managers] });
|
||||
await notify({ event: "PO_SUBMITTED", po, recipients: managers });
|
||||
|
||||
revalidatePath(`/po/${poId}`);
|
||||
revalidatePath("/dashboard");
|
||||
|
|
|
|||
|
|
@ -187,7 +187,7 @@ export async function updatePo(
|
|||
db.user.findMany({ where: { role: "MANAGER", isActive: true } }),
|
||||
]);
|
||||
if (fullPo) {
|
||||
await notify({ event: "PO_SUBMITTED", po: fullPo, recipients: [fullPo.submitter, ...managers] });
|
||||
await notify({ event: "PO_SUBMITTED", po: fullPo, recipients: managers });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -132,13 +132,12 @@ export async function confirmReceipt({
|
|||
revalidatePath(`/admin/sites/${siteId}`);
|
||||
}
|
||||
|
||||
// Notify on full close only
|
||||
const managers = await db.user.findMany({ where: { role: "MANAGER", isActive: true } });
|
||||
if (allDelivered) {
|
||||
const [managers, accounts] = await Promise.all([
|
||||
db.user.findMany({ where: { role: "MANAGER", isActive: true } }),
|
||||
db.user.findMany({ where: { role: "ACCOUNTS", isActive: true } }),
|
||||
]);
|
||||
const accounts = await db.user.findMany({ where: { role: "ACCOUNTS", isActive: true } });
|
||||
await notify({ event: "RECEIPT_CONFIRMED", po, recipients: [...managers, ...accounts] });
|
||||
} else {
|
||||
await notify({ event: "PARTIAL_RECEIPT_CONFIRMED", po, recipients: managers });
|
||||
}
|
||||
|
||||
revalidatePath(`/po/${poId}`);
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ export async function createPo(
|
|||
db.user.findMany({ where: { role: "MANAGER", isActive: true } }),
|
||||
]);
|
||||
if (fullPo) {
|
||||
await notify({ event: "PO_SUBMITTED", po: fullPo, recipients: [fullPo.submitter, ...managers] });
|
||||
await notify({ event: "PO_SUBMITTED", po: fullPo, recipients: managers });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,8 @@ export type NotificationEvent =
|
|||
| "VENDOR_ID_PROVIDED"
|
||||
| "PAYMENT_PROCESSING"
|
||||
| "PAYMENT_SENT"
|
||||
| "RECEIPT_CONFIRMED";
|
||||
| "RECEIPT_CONFIRMED"
|
||||
| "PARTIAL_RECEIPT_CONFIRMED";
|
||||
|
||||
interface NotifyParams {
|
||||
event: NotificationEvent;
|
||||
|
|
@ -136,6 +137,9 @@ function buildInAppBody(
|
|||
case "RECEIPT_CONFIRMED":
|
||||
return `Receipt confirmed — ${pn} closed`;
|
||||
|
||||
case "PARTIAL_RECEIPT_CONFIRMED":
|
||||
return `Partial receipt confirmed on ${pn} — items still outstanding`;
|
||||
|
||||
default:
|
||||
return `Update on ${pn}`;
|
||||
}
|
||||
|
|
@ -195,6 +199,7 @@ function buildActionLabel(event: NotificationEvent, recipient: User, po: Purchas
|
|||
case "PAYMENT_SENT":
|
||||
return isSubmitter ? "Confirm Receipt" : "View Purchase Order";
|
||||
case "RECEIPT_CONFIRMED":
|
||||
case "PARTIAL_RECEIPT_CONFIRMED":
|
||||
return "View Purchase Order";
|
||||
default:
|
||||
return "View Purchase Order";
|
||||
|
|
@ -216,6 +221,7 @@ function buildSubject(event: NotificationEvent, poNumber: string): string | null
|
|||
PAYMENT_PROCESSING: `Payment initiated for ${base}`,
|
||||
PAYMENT_SENT: `Payment confirmed for ${base}`,
|
||||
RECEIPT_CONFIRMED: `Receipt confirmed — ${base} closed`,
|
||||
PARTIAL_RECEIPT_CONFIRMED: `Partial receipt confirmed for ${base}`,
|
||||
};
|
||||
return map[event] ?? null;
|
||||
}
|
||||
|
|
@ -251,6 +257,8 @@ function buildEmailBody(
|
|||
return `Payment has been confirmed for <strong>${po.poNumber}</strong>. Please confirm delivery/receipt when the goods arrive.`;
|
||||
case "RECEIPT_CONFIRMED":
|
||||
return `Receipt has been confirmed for <strong>${po.poNumber}</strong>. The order is now closed.`;
|
||||
case "PARTIAL_RECEIPT_CONFIRMED":
|
||||
return `A partial delivery has been confirmed for <strong>${po.poNumber}</strong>. Some items are still outstanding.`;
|
||||
default:
|
||||
return `There has been an update on purchase order ${po.poNumber}.`;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue