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.

fix: key to sales order line notes

Brad Barbinedf16fae895c
diff --git a/apps/carbon/app/modules/items/ui/Item/ItemNotes.tsx b/apps/carbon/app/modules/items/ui/Item/ItemNotes.tsx
new file mode 100644
index 0000000000..68aa33e5b6
--- /dev/null
+++ b/apps/carbon/app/modules/items/ui/Item/ItemNotes.tsx
@@ -0,0 +1,107 @@
+import { useCarbon } from "@carbon/auth";
+import type { JSONContent } from "@carbon/react";
+import {
+ Card,
+ CardContent,
+ CardDescription,
+ CardHeader,
+ CardTitle,
+ Editor,
+ generateHTML,
+ toast,
+ useDebounce,
+} from "@carbon/react";
+import { getLocalTimeZone, today } from "@internationalized/date";
+import { nanoid } from "nanoid";
+import { useState } from "react";
+import { usePermissions, useUser } from "~/hooks";
+import { getPrivateUrl } from "~/utils/path";
+
+const ItemNotes = ({
+ id,
+ title,
+ subTitle,
+ notes: initialNotes,
+}: {
+ id: string | null;
+ title: string;
+ subTitle: string;
+ notes?: JSONContent;
+}) => {
+ const {
+ id: userId,
+ company: { id: companyId },
+ } = useUser();
+ const { carbon } = useCarbon();
+ const permissions = usePermissions();
+
+ const [notes, setInternalNotes] = useState(initialNotes ?? {});
+
+ const onUploadImage = async (file: File) => {
+ const fileType = file.name.split(".").pop();
+ const fileName = `${companyId}/parts/notes/${nanoid()}.${fileType}`;
+
+ const result = await carbon?.storage.from("private").upload(fileName, file);
+
+ if (result?.error) {
+ toast.error("Failed to upload image");
+ throw new Error(result.error.message);
+ }
+
+ if (!result?.data) {
+ throw new Error("Failed to upload image");
+ }
+
+ return getPrivateUrl(result.data.path);
+ };
+
+ const onUpdateInternalNotes = useDebounce(
+ async (content: JSONContent) => {
+ await carbon
+ ?.from("item")
+ .update({
+ notes: content,
+ updatedAt: today(getLocalTimeZone()).toString(),
+ updatedBy: userId,
+ })
+ .eq("id", id!);
+ },
+ 2500,
+ true
+ );
+
+ if (!id) return null;
+
+ return (
+ <>
+ <Card>
+ <CardHeader>
+ <CardTitle>{title}</CardTitle>
+ <CardDescription>{subTitle}</CardDescription>
+ </CardHeader>
+
+ <CardContent>
+ {permissions.can("update", "sales") ? (
+ <Editor
+ initialValue={(notes ?? {}) as JSONContent}
+ onUpload={onUploadImage}
+ onChange={(value) => {
+ setInternalNotes(value);
+ onUpdateInternalNotes(value);
+ }}
+ />
+ ) : (
+ <div
+ className="prose dark:prose-invert"
+ dangerouslySetInnerHTML={{
+ __html: generateHTML(notes as JSONContent),
+ }}
+ />
+ )}
+ </CardContent>
+ </Card>
+ </>
+ );
+};
+
+export default ItemNotes;
diff --git a/apps/carbon/app/routes/x+/sales-order+/$orderId.$lineId.details.tsx b/apps/carbon/app/routes/x+/sales-order+/$orderId.$lineId.details.tsx
index f813d1f859..fabca2c573 100644
--- a/apps/carbon/app/routes/x+/sales-order+/$orderId.$lineId.details.tsx
+++ b/apps/carbon/app/routes/x+/sales-order+/$orderId.$lineId.details.tsx
@@ -12,7 +12,7 @@ import { Card, CardHeader, CardTitle, Spinner } from "@carbon/react";
import { Await, Outlet, useLoaderData, useParams } from "@remix-run/react";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
import { defer, redirect } from "@vercel/remix";
-import { Suspense } from "react";
+import { Fragment, Suspense } from "react";
import { CadModel } from "~/components";
import { usePermissions, useRouteData } from "~/hooks";
import { getItemReplenishment } from "~/modules/items";
@@ -164,7 +164,7 @@ export default function EditSalesOrderLineRoute() {
};
return (
- <>
+ <Fragment key={lineId}>
<SalesOrderLineForm
key={initialValues.id}
// @ts-ignore
@@ -174,7 +174,7 @@ export default function EditSalesOrderLineRoute() {
id={line.id}
table="salesOrderLine"
title={orderData.salesOrder.salesOrderId ?? ""}
- subTitle={line.customerPartId ?? ""}
+ subTitle={line.itemReadableId ?? ""}
notes={line.notes as JSONContent}
/>
{line.methodType === "Make" && (
@@ -241,6 +241,6 @@ export default function EditSalesOrderLineRoute() {
/>
</div>
<Outlet />
- </>
+ </Fragment>
);
}
diff --git a/package-lock.json b/package-lock.json
index 6c04e3956c..9c7e627482 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -109,8 +109,6 @@
"resend": "^3.1.0",
"spin-delay": "2.0.1",
"tailwind-merge": "^2.2.1",
- "tailwind-scrollbar": "^3.0.5",
- "tailwind-scrollbar-hide": "^1.1.7",
"tailwindcss-animate": "^1.0.7",
"zod": "^3.23.8",
"zod-form-data": "*"
@@ -128,7 +126,6 @@
"nodemon": "^3.0.1",
"npm-run-all": "^4.1.5",
"postcss": "^8.4.33",
- "tailwind-scrollbar": "^3.0.5",
"tailwindcss": "3.3.2",
"typescript": "^5.2.2",
"vite": "^5.3.3",
@@ -170,8 +167,6 @@
"react-hotkeys-hook": "~4.5.0",
"react-icons": "^5.3.0",
"tailwind-merge": "^2.2.1",
- "tailwind-scrollbar": "^3.0.5",
- "tailwind-scrollbar-hide": "^1.1.7",
"tailwindcss-animate": "^1.0.7",
"zod": "^3.23.8",
"zod-form-data": "*"
@@ -186,7 +181,6 @@
"nodemon": "^3.0.1",
"npm-run-all": "^4.1.5",
"postcss": "^8.4.33",
- "tailwind-scrollbar": "^3.0.5",
"tailwindcss": "3.3.2",
"typescript": "^5.2.2",
"vite": "^5.3.3",
@@ -232,8 +226,6 @@
"react-icons": "^5.3.0",
"react-router-dom": "^6.23.1",
"tailwind-merge": "^2.2.1",
- "tailwind-scrollbar": "^3.0.5",
- "tailwind-scrollbar-hide": "^1.1.7",
"tailwindcss-animate": "^1.0.7",
"zod": "^3.23.8",
"zod-form-data": "*"
@@ -248,7 +240,6 @@
"nodemon": "^3.0.1",
"npm-run-all": "^4.1.5",
"postcss": "^8.4.33",
- "tailwind-scrollbar": "^3.0.5",
"tailwindcss": "3.3.2",
"typescript": "^5.2.2",
"vite": "^5.3.3",
@@ -291,8 +282,6 @@
"react-hotkeys-hook": "~4.5.0",
"react-icons": "^5.3.0",
"tailwind-merge": "^2.2.1",
- "tailwind-scrollbar": "^3.0.5",
- "tailwind-scrollbar-hide": "^1.1.7",
"tailwindcss-animate": "^1.0.7",
"zod": "^3.23.8",
"zod-form-data": "*"
@@ -30000,6 +29989,7 @@
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/tailwind-scrollbar/-/tailwind-scrollbar-3.1.0.tgz",
"integrity": "sha512-pmrtDIZeHyu2idTejfV59SbaJyvp1VRjYxAjZBH0jnyrPRo6HL1kD5Glz8VPagasqr6oAx6M05+Tuw429Z8jxg==",
+ "dev": true,
"engines": {
"node": ">=12.13.0"
},
@@ -30007,11 +29997,6 @@
"tailwindcss": "3.x"
}
},
- "node_modules/tailwind-scrollbar-hide": {
- "version": "1.1.7",
- "resolved": "https://registry.npmjs.org/tailwind-scrollbar-hide/-/tailwind-scrollbar-hide-1.1.7.tgz",
- "integrity": "sha512-X324n9OtpTmOMqEgDUEA/RgLrNfBF/jwJdctaPZDzB3mppxJk7TLIDmOreEDm1Bq4R9LSPu4Epf8VSdovNU+iA=="
- },
"node_modules/tailwindcss": {
"version": "3.3.2",
"resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.3.2.tgz",
@@ -33713,8 +33698,6 @@
"postcss": "^8.4.33",
"postcss-nesting": "12.1.5",
"tailwind-merge": "^2.2.1",
- "tailwind-scrollbar": "^3.0.5",
- "tailwind-scrollbar-hide": "^1.1.7",
"tailwindcss": "3.3.2",
"tailwindcss-animate": "^1.0.7"
}
diff --git a/packages/database/supabase/migrations/20241127112815_item-notes.sql b/packages/database/supabase/migrations/20241127112815_item-notes.sql
new file mode 100644
index 0000000000..e2862fa249
--- /dev/null
+++ b/packages/database/supabase/migrations/20241127112815_item-notes.sql
@@ -0,0 +1,125 @@
+ALTER TABLE "item" ADD COLUMN "notes" JSONB DEFAULT '{}';
+
+
+-- Update parts view
+DROP VIEW IF EXISTS "parts";
+CREATE OR REPLACE VIEW "parts" WITH (SECURITY_INVOKER=true) AS
+SELECT
+ i."active",
+ i."assignee",
+ i."defaultMethodType",
+ i."description",
+ i."itemTrackingType",
+ i."name",
+ i."replenishmentSystem",
+ i."unitOfMeasureCode",
+ i."notes",
+ CASE
+ WHEN i."thumbnailPath" IS NULL AND mu."thumbnailPath" IS NOT NULL THEN mu."thumbnailPath"
+ ELSE i."thumbnailPath"
+ END as "thumbnailPath",
+ mu.id as "modelId",
+ mu."autodeskUrn",
+ mu."modelPath",
+ mu."name" as "modelName",
+ mu."size" as "modelSize",
+ p.*,
+ ps."supplierIds",
+ uom.name as "unitOfMeasure"
+FROM "part" p
+INNER JOIN "item" i ON i.id = p."itemId"
+LEFT JOIN (
+ SELECT
+ "itemId",
+ string_agg(ps."supplierPartId", ',') AS "supplierIds"
+ FROM "buyMethod" ps
+ GROUP BY "itemId"
+) ps ON ps."itemId" = p."itemId"
+LEFT JOIN "modelUpload" mu ON mu.id = i."modelUploadId"
+LEFT JOIN "unitOfMeasure" uom ON uom.code = i."unitOfMeasureCode" AND uom."companyId" = i."companyId";
+
+DROP VIEW IF EXISTS "materials";
+CREATE OR REPLACE VIEW "materials" WITH(SECURITY_INVOKER=true) AS
+ SELECT
+ i."active",
+ i."assignee",
+ i."defaultMethodType",
+ i."description",
+ i."itemTrackingType",
+ i."name",
+ i."replenishmentSystem",
+ i."thumbnailPath",
+ i."unitOfMeasureCode",
+ i."notes",
+ m.*,
+ mf."name" AS "materialForm",
+ ms."name" AS "materialSubstance",
+ s."supplierIds",
+ uom.name as "unitOfMeasure"
+ FROM "material" m
+ INNER JOIN "item" i ON i.id = m."itemId"
+ LEFT JOIN (
+ SELECT
+ "itemId",
+ string_agg(s."supplierPartId", ',') AS "supplierIds"
+ FROM "buyMethod" s
+ GROUP BY "itemId"
+ ) s ON s."itemId" = m."itemId"
+ LEFT JOIN "materialForm" mf ON mf.id = m."materialFormId"
+ LEFT JOIN "materialSubstance" ms ON ms.id = m."materialSubstanceId"
+ LEFT JOIN "unitOfMeasure" uom ON uom.code = i."unitOfMeasureCode" AND uom."companyId" = i."companyId";
+
+
+DROP VIEW IF EXISTS "tools";
+CREATE OR REPLACE VIEW "tools" WITH(SECURITY_INVOKER=true) AS
+ SELECT
+ i."active",
+ i."assignee",
+ i."defaultMethodType",
+ i."description",
+ i."itemTrackingType",
+ i."name",
+ i."replenishmentSystem",
+ i."thumbnailPath",
+ i."unitOfMeasureCode",
+ i."notes",
+ t.*,
+ s."supplierIds",
+ uom.name as "unitOfMeasure"
+ FROM "tool" t
+ INNER JOIN "item" i ON i.id = t."itemId"
+ LEFT JOIN (
+ SELECT
+ "itemId",
+ string_agg(s."supplierPartId", ',') AS "supplierIds"
+ FROM "buyMethod" s
+ GROUP BY "itemId"
+ ) s ON s."itemId" = t."itemId"
+ LEFT JOIN "unitOfMeasure" uom ON uom.code = i."unitOfMeasureCode" AND uom."companyId" = i."companyId";
+
+DROP VIEW IF EXISTS "consumables";
+CREATE OR REPLACE VIEW "consumables" WITH(SECURITY_INVOKER=true) AS
+ SELECT
+ i."active",
+ i."assignee",
+ i."defaultMethodType",
+ i."description",
+ i."itemTrackingType",
+ i."name",
+ i."replenishmentSystem",
+ i."thumbnailPath",
+ i."unitOfMeasureCode",
+ i."notes",
+ c.*,
+ s."supplierIds",
+ uom.name as "unitOfMeasure"
+ FROM "consumable" c
+ INNER JOIN "item" i ON i.id = c."itemId"
+ LEFT JOIN (
+ SELECT
+ "itemId",
+ string_agg(s."supplierPartId", ',') AS "supplierIds"
+ FROM "buyMethod" s
+ GROUP BY "itemId"
+ ) s ON s."itemId" = c."itemId"
+ LEFT JOIN "unitOfMeasure" uom ON uom.code = i."unitOfMeasureCode" AND uom."companyId" = i."companyId";