Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

Include top-level external notes in document emails (#1167)

Carbon Agent70334fd4efa6
diff --git a/packages/documents/src/email/PurchaseOrderEmail.tsx b/packages/documents/src/email/PurchaseOrderEmail.tsx
index e69d3c6cd3..6a2f506a95 100644
--- a/packages/documents/src/email/PurchaseOrderEmail.tsx
+++ b/packages/documents/src/email/PurchaseOrderEmail.tsx
@@ -18,6 +18,7 @@ import {
getTotal
} from "../utils/purchase-order";
import { getCurrencyFormatter } from "../utils/shared";
+import ExternalNotes from "./components/ExternalNotes";
import {
EmailThemeProvider,
getEmailInlineStyles,
@@ -126,6 +127,7 @@ const PurchaseOrderEmail = ({
any questions.
</Text>
</Section>
+ <ExternalNotes content={purchaseOrder.externalNotes} />
<Section className="bg-gray-50 rounded-lg text-xs">
<Row>
<Column className="p-5" colSpan={2}>
diff --git a/packages/documents/src/email/QuoteEmail.tsx b/packages/documents/src/email/QuoteEmail.tsx
index c4129259ed..212f641096 100644
--- a/packages/documents/src/email/QuoteEmail.tsx
+++ b/packages/documents/src/email/QuoteEmail.tsx
@@ -12,6 +12,7 @@ import {
Text
} from "@react-email/components";
import type { CompanySettings, Email } from "../types";
+import ExternalNotes from "./components/ExternalNotes";
import {
Button,
EmailThemeProvider,
@@ -85,31 +86,24 @@ const QuoteEmail = ({
</Row>
</Section>
<Section>
- {digitalQuoteUrl ? (
- <>
- <Text
- className={`text-left text-sm font-medium ${themeClasses.text} my-9`}
- style={{ color: lightStyles.text.color }}
- >
- {recipient.firstName ? `Hi ${recipient.firstName}, ` : "Hi, "}
- we are pleased to provide you with your digital quote, which
- is available for review here:
- </Text>
- <Button href={digitalQuoteUrl} className="mb-4">
- View Digital Quote
- </Button>
- </>
- ) : (
- <Text
- className={`text-left text-sm font-medium ${themeClasses.text} my-9`}
- style={{ color: lightStyles.text.color }}
- >
- {recipient.firstName ? `Hi ${recipient.firstName}, ` : "Hi, "}
- please see the attached quote and let me know if you have any
- questions.
- </Text>
- )}
+ <Text
+ className={`text-left text-sm font-medium ${themeClasses.text} my-9`}
+ style={{ color: lightStyles.text.color }}
+ >
+ {recipient.firstName ? `Hi ${recipient.firstName}, ` : "Hi, "}
+ {digitalQuoteUrl
+ ? "we are pleased to provide you with your digital quote, which is available for review here:"
+ : "please see the attached quote and let me know if you have any questions."}
+ </Text>
</Section>
+ <ExternalNotes content={quote.externalNotes} />
+ {digitalQuoteUrl ? (
+ <Section>
+ <Button href={digitalQuoteUrl} className="mb-4">
+ View Digital Quote
+ </Button>
+ </Section>
+ ) : null}
<Section className="bg-gray-50 rounded-lg text-xs">
<Row>
<Column className="p-5" colSpan={2}>
diff --git a/packages/documents/src/email/SalesInvoiceEmail.tsx b/packages/documents/src/email/SalesInvoiceEmail.tsx
index ecc17200da..2c2890d61a 100644
--- a/packages/documents/src/email/SalesInvoiceEmail.tsx
+++ b/packages/documents/src/email/SalesInvoiceEmail.tsx
@@ -19,6 +19,7 @@ import {
getTotal
} from "../utils/sales-invoice";
import { getCurrencyFormatter } from "../utils/shared";
+import ExternalNotes from "./components/ExternalNotes";
import {
EmailThemeProvider,
getEmailInlineStyles,
@@ -115,6 +116,7 @@ const SalesInvoiceEmail = ({
questions.
</Text>
</Section>
+ <ExternalNotes content={salesInvoice.externalNotes} />
<Section className={`bg-gray-50 rounded-lg text-xs`}>
<Row>
<Column className="p-5" colSpan={2}>
diff --git a/packages/documents/src/email/SalesOrderEmail.tsx b/packages/documents/src/email/SalesOrderEmail.tsx
index 9846e33a5f..d430e633c5 100644
--- a/packages/documents/src/email/SalesOrderEmail.tsx
+++ b/packages/documents/src/email/SalesOrderEmail.tsx
@@ -19,6 +19,7 @@ import {
getTotal
} from "../utils/sales-order";
import { getCurrencyFormatter } from "../utils/shared";
+import ExternalNotes from "./components/ExternalNotes";
import {
EmailThemeProvider,
getEmailInlineStyles,
@@ -125,6 +126,7 @@ const SalesOrderEmail = ({
any questions.
</Text>
</Section>
+ <ExternalNotes content={salesOrder.externalNotes} />
<Section className={`bg-gray-50 rounded-lg text-xs`}>
<Row>
<Column className="p-5" colSpan={2}>
diff --git a/packages/documents/src/email/components/ExternalNotes.tsx b/packages/documents/src/email/components/ExternalNotes.tsx
new file mode 100644
index 0000000000..99eb36f3b2
--- /dev/null
+++ b/packages/documents/src/email/components/ExternalNotes.tsx
@@ -0,0 +1,39 @@
+import type { JSONContent } from "@carbon/react";
+import { tiptapToHTML } from "@carbon/utils";
+import { Section, Text } from "@react-email/components";
+import { getEmailInlineStyles, getEmailThemeClasses } from "./Theme";
+
+/**
+ * Renders a document's top-level external notes (Tiptap rich text) directly in
+ * the email body, mirroring the "Notes" block shown in the attached PDF so the
+ * recipient sees them without opening the attachment. Renders nothing when there
+ * are no external notes. Only external notes are ever passed here — internal
+ * notes must never reach the customer/supplier.
+ */
+const ExternalNotes = ({ content }: { content: unknown }) => {
+ const html = tiptapToHTML(content as JSONContent | null | undefined);
+ // tiptapToHTML returns "" for empty/absent docs; also skip notes that are only
+ // empty markup (e.g. a single blank paragraph) so we don't render a bare label.
+ if (!html || html.replace(/<[^>]*>/g, "").trim() === "") return null;
+
+ const themeClasses = getEmailThemeClasses();
+ const lightStyles = getEmailInlineStyles("light");
+
+ return (
+ <Section className="mb-4">
+ <Text
+ className={`uppercase text-[10px] ${themeClasses.mutedText}`}
+ style={{ color: lightStyles.mutedText.color }}
+ >
+ Notes
+ </Text>
+ <div
+ className={`text-sm ${themeClasses.text}`}
+ style={{ color: lightStyles.text.color }}
+ dangerouslySetInnerHTML={{ __html: html }}
+ />
+ </Section>
+ );
+};
+
+export default ExternalNotes;