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.

feat: render the external notes on the quote PDF

Rob Carringtonf351b52502cc
diff --git a/packages/documents/src/pdf/QuotePDF.tsx b/packages/documents/src/pdf/QuotePDF.tsx
index e77e207fc9..42b76d9c15 100644
--- a/packages/documents/src/pdf/QuotePDF.tsx
+++ b/packages/documents/src/pdf/QuotePDF.tsx
@@ -2,10 +2,11 @@ import type { Database } from "@carbon/database";
import { getLocalTimeZone, today } from "@internationalized/date";
import { Image, StyleSheet, Text, View } from "@react-pdf/renderer";
+import type { JSONContent } from "@carbon/react";
import type { PDF } from "../types";
import { getLineDescription, getLineDescriptionDetails } from "../utils/quote";
import { formatAddress } from "../utils/shared";
-import { Header, Summary, Template } from "./components";
+import { Header, Note, Summary, Template } from "./components";
interface QuotePDFProps extends PDF {
quote: Database["public"]["Views"]["quotes"]["Row"];
@@ -228,6 +229,7 @@ const QuotePDF = ({
);
})}
</View>
+ <Note note={(quote.externalNotes ?? {}) as JSONContent} />
</View>
</Template>
);
diff --git a/packages/documents/src/pdf/components/Note.tsx b/packages/documents/src/pdf/components/Note.tsx
new file mode 100644
index 0000000000..2546b961df
--- /dev/null
+++ b/packages/documents/src/pdf/components/Note.tsx
@@ -0,0 +1,154 @@
+import type { JSONContent } from "@carbon/react";
+import { Image, StyleSheet, Text, View } from "@react-pdf/renderer";
+
+const convertTiptapJSON = (
+ node: JSONContent,
+ index?: number,
+ parentNodeType?: string
+) => {
+ console.log({ node });
+ switch (node.type) {
+ case "doc":
+ return (
+ <View style={{ fontSize: 11 }}>
+ <View style={styles.thead}>
+ <Text>Notes</Text>
+ </View>
+ {node.content.map((child, index) => convertTiptapJSON(child))}
+ </View>
+ );
+
+ case "heading":
+ return (
+ <Text
+ key={`heading-${node.attrs.level}`}
+ style={{
+ fontSize: 16 - node.attrs.level * 2,
+ fontWeight: "bold",
+ marginBottom: 10,
+ }}
+ >
+ {node.content.map((child) => convertTiptapJSON(child))}
+ </Text>
+ );
+
+ case "paragraph":
+ return (
+ <Text key="paragraph" style={{ marginBottom: 10 }}>
+ {node.content?.map((child) => convertTiptapJSON(child)) || ""}
+ </Text>
+ );
+
+ case "bulletList":
+ return (
+ <View key="bulletList" style={{ marginLeft: 20 }}>
+ {node.content.map((child, index) =>
+ convertTiptapJSON(child, index, "bulletList")
+ )}
+ </View>
+ );
+
+ case "orderedList":
+ return (
+ <View key="orderedList" style={{ marginLeft: 20 }}>
+ {node.content.map((child, index) =>
+ convertTiptapJSON(child, index, "orderedList")
+ )}
+ </View>
+ );
+
+ case "listItem":
+ const indicator = parentNodeType == "orderedList" ? `${index + 1}.` : "•";
+ return (
+ <View
+ key={`listItem-${index}`}
+ style={{ flexDirection: "row", marginBottom: 5 }}
+ >
+ <Text style={{ marginRight: 5 }}> {indicator} </Text>
+ <View>
+ {node.content.map((child, index) => convertTiptapJSON(child))}
+ </View>
+ </View>
+ );
+
+ case "taskList":
+ return (
+ <View key="taskList" style={{ marginLeft: 20 }}>
+ {node.content.map((child, index) => convertTiptapJSON(child, index))}
+ </View>
+ );
+
+ case "taskItem":
+ return (
+ <View
+ key={`taskItem-${index}`}
+ style={{ flexDirection: "row", marginBottom: 5 }}
+ >
+ <Text style={{ marginRight: 5 }}>•</Text>
+ <View>
+ {node.content.map((child, index) => convertTiptapJSON(child))}
+ </View>
+ </View>
+ );
+
+ case "text":
+ return node.text;
+
+ case "image":
+ return (
+ <Image
+ key="image"
+ src={node.attrs.src}
+ style={{
+ width: node.attrs.width || "auto",
+ height: node.attrs.height || "auto",
+ }}
+ />
+ );
+
+ default:
+ return null;
+ }
+};
+
+const Note = ({ note }: { note: JSONContent }) => {
+ if (!note || !("content" in note)) return null;
+ return <View>{convertTiptapJSON(note)}</View>;
+};
+
+export default Note;
+
+const styles = StyleSheet.create({
+ thead: {
+ flexGrow: 1,
+ flexDirection: "row",
+ justifyContent: "space-between",
+ alignItems: "center",
+ marginTop: "20px",
+ padding: "6px 3px 6px 3px",
+ borderTop: 1,
+ borderTopColor: "#CCCCCC",
+ borderTopStyle: "solid",
+ borderBottom: 1,
+ borderBottomColor: "#CCCCCC",
+ borderBottomStyle: "solid",
+ fontSize: 9,
+ fontWeight: 700,
+ color: "#7d7d7d",
+ textTransform: "uppercase",
+ },
+ tfoot: {
+ flexGrow: 1,
+ flexDirection: "row",
+ justifyContent: "space-between",
+ alignItems: "center",
+ padding: "6px 3px 6px 3px",
+ borderTopStyle: "solid",
+ borderBottom: 1,
+ borderBottomColor: "#CCCCCC",
+ borderBottomStyle: "solid",
+ fontWeight: 700,
+ color: "#7d7d7d",
+ textTransform: "uppercase",
+ },
+});
diff --git a/packages/documents/src/pdf/components/index.ts b/packages/documents/src/pdf/components/index.ts
index f3f4578981..9ff3219a93 100644
--- a/packages/documents/src/pdf/components/index.ts
+++ b/packages/documents/src/pdf/components/index.ts
@@ -1,7 +1,8 @@
import Header from "./Header";
+import Note from "./Note";
+import QuoteHeader from "./QuoteHeader";
+import QuoteSummary from "./QuoteSummary";
import Summary from "./Summary";
import Template from "./Template";
-import QuoteSummary from "./QuoteSummary";
-import QuoteHeader from "./QuoteHeader";
-export { Header, Summary, Template, QuoteSummary, QuoteHeader };
+export { Header, Note, QuoteHeader, QuoteSummary, Summary, Template };
diff --git a/packages/react/src/Editor/components/NodeSelector.tsx b/packages/react/src/Editor/components/NodeSelector.tsx
index 74879b285f..d9986b8aaf 100644
--- a/packages/react/src/Editor/components/NodeSelector.tsx
+++ b/packages/react/src/Editor/components/NodeSelector.tsx
@@ -5,13 +5,11 @@ import {
LuCheck,
LuCheckSquare,
LuChevronDown,
- LuCode,
LuHeading1,
LuHeading2,
LuHeading3,
LuListOrdered,
LuText,
- LuTextQuote,
} from "react-icons/lu";
import { Popover } from "@radix-ui/react-popover";
@@ -78,20 +76,13 @@ const items: SelectorItem[] = [
editor.chain().focus().clearNodes().toggleOrderedList().run(),
isActive: (editor) => editor.isActive("orderedList"),
},
- {
- name: "Quote",
- icon: LuTextQuote,
- command: (editor) =>
- editor.chain().focus().clearNodes().toggleBlockquote().run(),
- isActive: (editor) => editor.isActive("blockquote"),
- },
- {
- name: "Code",
- icon: LuCode,
- command: (editor) =>
- editor.chain().focus().clearNodes().toggleCodeBlock().run(),
- isActive: (editor) => editor.isActive("codeBlock"),
- },
+ // {
+ // name: "Code",
+ // icon: LuCode,
+ // command: (editor) =>
+ // editor.chain().focus().clearNodes().toggleCodeBlock().run(),
+ // isActive: (editor) => editor.isActive("codeBlock"),
+ // },
];
interface NodeSelectorProps {
open: boolean;
diff --git a/packages/react/src/Editor/slash.tsx b/packages/react/src/Editor/slash.tsx
index c757e526d2..d7bb1254b8 100644
--- a/packages/react/src/Editor/slash.tsx
+++ b/packages/react/src/Editor/slash.tsx
@@ -2,31 +2,19 @@ import type { EditorView } from "@tiptap/pm/view";
import { createSuggestionItems } from "novel/extensions";
import {
LuCheckSquare,
- LuCode,
LuHeading1,
LuHeading2,
LuHeading3,
LuImage,
LuList,
LuListOrdered,
- LuMessageSquarePlus,
LuText,
- LuTextQuote,
} from "react-icons/lu";
export const getSuggestionItems = (
uploadFn: (file: File, view: EditorView, pos: number) => void
) => {
return createSuggestionItems([
- {
- title: "Send Feedback",
- description: "Let us know how we can improve.",
- icon: <LuMessageSquarePlus size={18} />,
- command: ({ editor, range }) => {
- editor.chain().focus().deleteRange(range).run();
- window.open("/feedback", "_blank");
- },
- },
{
title: "Text",
description: "Just start typing with plain text.",
@@ -110,28 +98,14 @@ export const getSuggestionItems = (
editor.chain().focus().deleteRange(range).toggleOrderedList().run();
},
},
- {
- title: "Quote",
- description: "Capture a quote.",
- searchTerms: ["blockquote"],
- icon: <LuTextQuote size={18} />,
- command: ({ editor, range }) =>
- editor
- .chain()
- .focus()
- .deleteRange(range)
- .toggleNode("paragraph", "paragraph")
- .toggleBlockquote()
- .run(),
- },
- {
- title: "Code",
- description: "Capture a code snippet.",
- searchTerms: ["codeblock"],
- icon: <LuCode size={18} />,
- command: ({ editor, range }) =>
- editor.chain().focus().deleteRange(range).toggleCodeBlock().run(),
- },
+ // {
+ // title: "Code",
+ // description: "Capture a code snippet.",
+ // searchTerms: ["codeblock"],
+ // icon: <LuCode size={18} />,
+ // command: ({ editor, range }) =>
+ // editor.chain().focus().deleteRange(range).toggleCodeBlock().run(),
+ // },
{
title: "Image",
description: "Upload an image from your computer.",