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.

Add notes to external supplier quotes

Bakuto34489d31b1e6
diff --git a/apps/erp/app/routes/api+/purchasing.digital-quote.$id.tsx b/apps/erp/app/routes/api+/purchasing.digital-quote.$id.tsx
index 41aa78e634..923c6f5c75 100644
--- a/apps/erp/app/routes/api+/purchasing.digital-quote.$id.tsx
+++ b/apps/erp/app/routes/api+/purchasing.digital-quote.$id.tsx
@@ -279,6 +279,45 @@ export async function action({ request, params }: ActionFunctionArgs) {
};
}
+ case "updateNotes": {
+ const lineId = formData.get("lineId");
+ const notesRaw = formData.get("notes");
+
+ if (!lineId || typeof lineId !== "string") {
+ return { success: false, message: "Invalid line ID" };
+ }
+
+ let notes = null;
+ if (notesRaw && typeof notesRaw === "string") {
+ try {
+ notes = JSON.parse(notesRaw);
+ // biome-ignore lint/correctness/noUnusedVariables: suppressed
+ } catch (e) {
+ return { success: false, message: "Invalid notes format" };
+ }
+ }
+
+ // Update the supplierQuoteLine with the new notes
+ const updateResult = await serviceRole
+ .from("supplierQuoteLine")
+ .update({
+ externalNotes: notes,
+ updatedAt: new Date().toISOString()
+ })
+ .eq("id", lineId)
+ .eq("supplierQuoteId", quote.data.id);
+
+ if (updateResult.error) {
+ console.error("Failed to update notes", updateResult.error);
+ return { success: false, message: "Failed to update notes" };
+ }
+
+ return {
+ success: true,
+ message: "Notes updated successfully"
+ };
+ }
+
default:
return { success: false, message: "Invalid intent" };
}
diff --git a/apps/erp/app/routes/share+/supplier-quote.$id.tsx b/apps/erp/app/routes/share+/supplier-quote.$id.tsx
index d2f396610e..b66794d8fd 100644
--- a/apps/erp/app/routes/share+/supplier-quote.$id.tsx
+++ b/apps/erp/app/routes/share+/supplier-quote.$id.tsx
@@ -12,6 +12,7 @@ import {
generateHTML,
Heading,
HStack,
+ Label,
Modal,
ModalBody,
ModalContent,
@@ -32,6 +33,7 @@ import {
useDisclosure,
VStack
} from "@carbon/react";
+import { Editor } from "@carbon/react/Editor";
import { useMode } from "@carbon/remix";
import { formatDate } from "@carbon/utils";
import { useLocale } from "@react-aria/i18n";
@@ -211,13 +213,120 @@ const Header = ({ company, quote }: { company: any; quote: any }) => (
</CardHeader>
);
+const NotesEditorModal = ({
+ notes,
+ onSave,
+ quoteStatus
+}: {
+ notes: JSONContent;
+ onSave: (content: JSONContent) => void;
+ quoteStatus: SupplierQuote["status"];
+}) => {
+ const isDraft = quoteStatus === "Draft";
+ const modal = useDisclosure();
+
+ const [editorContent, setEditorContent] = useState<JSONContent>(notes ?? {});
+
+ const handleEditorChange = (value: JSONContent) => {
+ setEditorContent(value);
+ };
+
+ const handleSave = () => {
+ onSave(editorContent);
+ modal.onClose();
+ };
+
+ const handleCancel = () => {
+ setEditorContent(notes ?? {});
+ modal.onClose();
+ };
+
+ // For non-Draft status, show rendered content (if any)
+ if (!isDraft && notes && Object.keys(notes).length > 0) {
+ return (
+ <div
+ className="prose dark:prose-invert mt-2 text-muted-foreground"
+ dangerouslySetInnerHTML={{
+ __html: generateHTML(notes)
+ }}
+ />
+ );
+ }
+
+ // For Draft status, show button to open modal
+ if (isDraft) {
+ return (
+ <>
+ <div className="mt-3">
+ <Button
+ variant="secondary"
+ size="sm"
+ onClick={(e) => {
+ e.stopPropagation();
+ modal.onOpen();
+ }}
+ >
+ {notes && Object.keys(notes).length > 0
+ ? "Edit Notes"
+ : "Add Notes"}
+ </Button>
+ </div>
+
+ {modal.isOpen && (
+ <Modal
+ open
+ onOpenChange={(open) => {
+ if (!open) handleCancel();
+ }}
+ >
+ <ModalOverlay />
+ <ModalContent
+ className="max-w-4xl"
+ onClick={(e) => e.stopPropagation()}
+ >
+ <ModalHeader>
+ <ModalTitle>Edit Notes</ModalTitle>
+ <ModalDescription>
+ Add or edit notes for this line item
+ </ModalDescription>
+ </ModalHeader>
+ <ModalBody>
+ <VStack spacing={4} className="w-full">
+ <div className="flex flex-col gap-2 w-full">
+ <Label>Notes</Label>
+ <Editor
+ initialValue={editorContent}
+ onChange={handleEditorChange}
+ className="min-h-[300px] p-4 border rounded-lg transition-colors"
+ disableFileUpload
+ />
+ </div>
+ </VStack>
+ </ModalBody>
+ <ModalFooter>
+ <Button variant="secondary" onClick={handleCancel}>
+ Cancel
+ </Button>
+ <Button onClick={handleSave}>Save Notes</Button>
+ </ModalFooter>
+ </ModalContent>
+ </Modal>
+ )}
+ </>
+ );
+ }
+
+ return null;
+};
+
const LineItems = ({
currencyCode,
locale,
selectedLines,
setSelectedLines,
quoteStatus,
- quoteLinePrices
+ quoteLinePrices,
+ onSaveNotes
}: {
currencyCode: string;
locale: string;
@@ -227,6 +336,7 @@ const LineItems = ({
>;
quoteStatus: SupplierQuote["status"];
quoteLinePrices: SupplierQuoteLinePrice[];
+ onSaveNotes: (lineId: string, content: JSONContent) => void;
}) => {
const { quoteLines, thumbnails } = useLoaderData<typeof loader>().data!;
const [openItems, setOpenItems] = useState<string[]>(() =>
@@ -288,18 +398,11 @@ const LineItems = ({
<span className="text-muted-foreground text-base truncate">
{line.description}
</span>
-
- {line.externalNotes &&
- Object.keys(line.externalNotes).length > 0 && (
- <div
- className="prose dark:prose-invert mt-2 text-muted-foreground"
- dangerouslySetInnerHTML={{
- __html: generateHTML(
- line.externalNotes as JSONContent
- )
- }}
- />
- )}
+ <NotesEditorModal
+ notes={(line.externalNotes as JSONContent) || {}}
+ onSave={(content) => onSaveNotes(line.id!, content)}
+ quoteStatus={quoteStatus}
+ />
</div>
</VStack>
</HStack>
@@ -715,6 +818,22 @@ const Quote = ({
return {};
});
+ // Handler to save notes for a line
+ const handleSaveNotes = (lineId: string, content: JSONContent) => {
+ // Use fetcher to save
+ fetcher.submit(
+ {
+ intent: "updateNotes",
+ lineId,
+ notes: JSON.stringify(content)
+ },
+ {
+ method: "post",
+ action: path.to.api.digitalSupplierQuote(id)
+ }
+ );
+ };
+
// Calculate grand total for display (all selected quantities across all lines)
const eachSelectedLineHasPricingAndLeadTime =
Object.values(selectedLines).every((lineSelections) => {
@@ -754,6 +873,7 @@ const Quote = ({
setSelectedLines={setSelectedLines}
quoteStatus={quote.status}
quoteLinePrices={quoteLinePrices}
+ onSaveNotes={handleSaveNotes}
/>
<div className="flex flex-col gap-2">
{(quote?.status as string) === "Draft" && (