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.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
Background thumbnail upload (#124)
Brad Barbin62cff00e6666
diff --git a/.env.example b/.env.exampleindex 27defb8b3f..52900df897 100644--- a/.env.example+++ b/.env.example@@ -3,6 +3,8 @@ NOVU_SECRET_KEY="********************"POSTHOG_API_HOST="https://us.posthog.com"POSTHOG_PROJECT_PUBLIC_KEY="********************"+RESEND_API_KEY="************************"+SLACK_BOT_TOKEN="***********************"SESSION_SECRET="************************"diff --git a/apps/carbon/app/components/CadModel.tsx b/apps/carbon/app/components/CadModel.tsxindex 2a220025bd..e061a578f1 100644--- a/apps/carbon/app/components/CadModel.tsx+++ b/apps/carbon/app/components/CadModel.tsx@@ -12,8 +12,7 @@ import {import { convertKbToString } from "@carbon/utils";import { useFetcher } from "@remix-run/react";import { nanoid } from "nanoid";-import { useEffect, useState } from "react";-import { flushSync } from "react-dom";+import { useState } from "react";import { useDropzone } from "react-dropzone";import { LuUploadCloud } from "react-icons/lu";import { useUser } from "~/hooks";@@ -53,75 +52,9 @@ const CadModel = ({const fetcher = useFetcher<{}>();const [file, setFile] = useState<File | null>(null);- const [id, setId] = useState<string | null>(null);- const [dataUrl, setDataUrl] = useState<string | null>(null);-- const uploadThumbnail = async () => {- if (!dataUrl) return;- if (!id) return;- if (!carbon) return;-- const base64Data = dataUrl.split(",")[1];- const byteCharacters = atob(base64Data);- const byteNumbers = new Array(byteCharacters.length);-- for (let i = 0; i < byteCharacters.length; i++) {- byteNumbers[i] = byteCharacters.charCodeAt(i);- }-- const byteArray = new Uint8Array(byteNumbers);- const thumbnailFile = new File([byteArray], "thumbnail.png", {- type: "image/png",- });-- if (!carbon) {- toast.error("Failed to initialize carbon client");- return;- }-- const thumbnailId = nanoid();- const thumbnailPath = `${companyId}/thumbnails/${thumbnailId}.png`;-- const thumbnailUpload = await carbon.storage- .from("private")- .upload(thumbnailPath, thumbnailFile, {- upsert: true,- contentType: "image/png",- });-- if (thumbnailUpload.error) {- toast.error("Failed to upload thumbnail");- }-- const update = await carbon- .from("modelUpload")- .update({- thumbnailPath: thumbnailUpload.data!.path,- })- .eq("id", id);-- if (update.error) {- toast.error("Failed to update model upload");- }- };-- // we want to upload the thumbnail after the file is uploaded- useEffect(() => {- if (file && modelPath && dataUrl && id) {- uploadThumbnail();- }- // eslint-disable-next-line react-hooks/exhaustive-deps- }, [dataUrl, file, id, modelPath]);-- const onDataUrl = (dataUrl: string) => {- setDataUrl(dataUrl);- };const onFileChange = async (file: File | null) => {const modelId = nanoid();- flushSync(() => {- setId(modelId);- });setFile(file);@@ -190,7 +123,6 @@ const CadModel = ({file={file}url={modelPath ? getPrivateUrl(modelPath) : null}mode={mode}- onDataUrl={onDataUrl}className={viewerClassName}/>) : (@@ -269,7 +201,7 @@ const CadModelUpload = ({<div{...getRootProps()}className={cn(- "group flex flex-col flex-grow rounded-lg border border-border bg-gradient-to-tr from-background to-card text-card-foreground shadow-sm w-full",+ "group flex flex-col flex-grow rounded-lg border border-border bg-gradient-to-tr from-background to-card text-card-foreground shadow-sm w-full min-h-[400px] ",!hasFile &&"cursor-pointer hover:border-primary/30 hover:border-dashed hover:to-primary/10 hover:via-card border-2 border-dashed",classNamediff --git a/apps/carbon/app/routes/api+/model.upload.ts b/apps/carbon/app/routes/api+/model.upload.tsindex 8cfa7c63f7..4a49f1d178 100644--- a/apps/carbon/app/routes/api+/model.upload.ts+++ b/apps/carbon/app/routes/api+/model.upload.ts@@ -1,6 +1,8 @@// import { error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";+import { tasks } from "@trigger.dev/sdk/v3";import { json, type ActionFunctionArgs } from "@vercel/remix";+import type { modelThumbnailTask } from "~/trigger/model-thumbnail";export const config = { runtime: "nodejs" };@@ -72,6 +74,11 @@ export async function action({ request }: ActionFunctionArgs) {throw new Error("Failed to record upload: " + modelRecord.error.message);}+ await tasks.trigger<typeof modelThumbnailTask>("model-thumbnail", {+ companyId,+ modelId,+ });+return json({success: true,});diff --git a/apps/carbon/app/routes/api+/subscribe.tsx b/apps/carbon/app/routes/api+/subscribe.tsxnew file mode 100644index 0000000000..f767933c15--- /dev/null+++ b/apps/carbon/app/routes/api+/subscribe.tsx@@ -0,0 +1,37 @@+import { getSlackClient } from "~/lib/slack.server";++import { validator } from "@carbon/form";+import { json, type ActionFunctionArgs } from "@vercel/remix";+import { z } from "zod";++export const config = { runtime: "nodejs" };++export const emailValidator = z.object({+ email: z.string().email(),+});++export async function action({ request }: ActionFunctionArgs) {+ const formData = await request.formData();+ const validation = await validator(emailValidator).validate(formData);++ if (validation.error) {+ return json(+ { success: false, message: "Email is required" },+ { status: 400 }+ );+ }++ const slackClient = getSlackClient();+ await slackClient.sendMessage({+ channel: "#leads",+ text: "New lead from website",+ blocks: [+ {+ type: "section",+ text: { type: "mrkdwn", text: `New lead: ${validation.data.email}` },+ },+ ],+ });++ return json({ success: true, message: "Email submitted" });+}diff --git a/apps/carbon/app/routes/x+/sales-rfq+/$rfqId.drag.tsx b/apps/carbon/app/routes/x+/sales-rfq+/$rfqId.drag.tsxindex eb6fe0ed3d..c8d318ce07 100644--- a/apps/carbon/app/routes/x+/sales-rfq+/$rfqId.drag.tsx+++ b/apps/carbon/app/routes/x+/sales-rfq+/$rfqId.drag.tsx@@ -8,6 +8,7 @@ import { salesRfqDragValidator, upsertSalesRFQLine } from "~/modules/sales";import type { modelThumbnailTask } from "~/trigger/model-thumbnail";import { setCustomFields } from "~/utils/form";import { path } from "~/utils/path";+export const config = { runtime: "nodejs" };export async function action({ request, params }: ActionFunctionArgs) {diff --git a/apps/www/app/root.tsx b/apps/www/app/root.tsxindex 1a43cc8d6b..f0b4e5d973 100644--- a/apps/www/app/root.tsx+++ b/apps/www/app/root.tsx@@ -1,4 +1,4 @@-import { Button, Heading } from "@carbon/react";+import { Button, Heading, Toaster } from "@carbon/react";import {Links,Meta,@@ -49,6 +49,7 @@ function Document({<body className="h-full w-full flex flex-col bg-background text-foreground antialiased selection:bg-[#00cc9937] selection:text-[#007763fd] dark:selection:bg-[#00fff61d] dark:selection:text-[#67ffded2]">{children}+ <Toaster /><ScrollRestoration /><Scripts /><Analytics />diff --git a/apps/www/app/routes/_index.tsx b/apps/www/app/routes/_index.tsxindex 2121cfc6b3..6366dd4e29 100644--- a/apps/www/app/routes/_index.tsx+++ b/apps/www/app/routes/_index.tsx@@ -1,6 +1,29 @@-import { LuMoveUpRight } from "react-icons/lu";+import { LuMoveUpRight, LuSend } from "react-icons/lu";++import { getAppUrl } from "@carbon/auth";+import { Input, Submit, ValidatedForm } from "@carbon/form";+import { toast } from "@carbon/react";+import { useFetcher } from "@remix-run/react";+import { useEffect } from "react";+import { z } from "zod";++const emailValidator = z.object({+ email: z.string().email(),+});export default function Route() {+ const fetcher = useFetcher<{ success: boolean; message: string }>();++ useEffect(() => {+ if (!fetcher.data) return;++ if (fetcher.data.success) {+ toast.success("Email submitted");+ } else {+ toast.error(fetcher.data.message ?? "Failed to submit email");+ }+ }, [fetcher.data]);+return (<><header className="flex select-none items-center bg-background pl-5 pr-4 border-b h-[52px] border-transparent">@@ -32,26 +55,32 @@ export default function Route() {<divid="intro"- className="flex flex-col pt-[28dvh] mx-auto w-container text-center"+ className="flex flex-col pt-[24dvh] mx-auto w-container text-center"><imgsrc="https://app.carbonos.dev/carbon-logo-light.png"alt="CarbonOS"- className="w-64 mx-auto"+ className="max-w-64 w-[25dvh] mx-auto"/>- {/* <h1 className="text-[3rem] sm:text-[6rem] md:text-[10rem] lg:text-[14rem] font-bold tracking-tighter lg:tracking-[-0.75rem] text-foreground">- CarbonOS- </h1> */}- {/* <p className="mb-6 text-center text-muted-foreground">- Realtime, collaborative, and powerful manufacturing software.- </p> */}- {/* <Button- className="rounded-full w-fit mx-auto"- size="lg"- rightIcon={<LuMoveUpRight />}++ <ValidatedForm+ action={`${getAppUrl()}/api/subscribe`}+ validator={emailValidator}+ fetcher={fetcher}+ method="post"+ className="flex flex-col gap-3 my-8">- Get Started- </Button> */}+ <Input name="email" label="Email" />+ <Submit+ className="h-10"+ variant="secondary"+ leftIcon={<LuSend />}+ isLoading={fetcher.state !== "idle"}+ isDisabled={fetcher.state !== "idle"}+ >+ Get Updates+ </Submit>+ </ValidatedForm></div></div></>diff --git a/apps/www/tsconfig.json b/apps/www/tsconfig.jsonindex ac163dacdb..4a7f493d67 100644--- a/apps/www/tsconfig.json+++ b/apps/www/tsconfig.json@@ -4,7 +4,8 @@"**/*.ts","**/*.tsx","app/modules/documents/documents.service.ts",- "../carbon/app/components/Breadcrumb.tsx"+ "../carbon/app/components/Breadcrumb.tsx",+ "../carbon/app/routes/api+/subscribe.tsx"],"compilerOptions": {"lib": ["dom", "dom.iterable", "ESNext"],diff --git a/packages/react/src/ModelViewer.tsx b/packages/react/src/ModelViewer.tsxindex 441e4acaa4..c2099e9f93 100644--- a/packages/react/src/ModelViewer.tsx+++ b/packages/react/src/ModelViewer.tsx@@ -57,7 +57,7 @@ export function ModelViewer({if (viewerRef.current === null) {let viewer = new OV.EmbeddedViewer(parentDiv.current, {camera: new OV.Camera(- new OV.Coord3D(0, 0, 100),+ new OV.Coord3D(100, 100, 100),new OV.Coord3D(0, 0, 0),new OV.Coord3D(0, 1, 0),45.0@@ -81,22 +81,17 @@ export function ModelViewer({const center = boundingSphere.center;const radius = boundingSphere.radius;const camera = viewer3D.GetCamera();- const direction = new OV.Coord3D(0, 0, 1);+ const direction = new OV.Coord3D(1, 1, 1);const eye = new OV.Coord3D(- center.x + direction.x * radius * 2.5,- center.y + direction.y * radius * 2.5,- center.z + direction.z * radius * 2.5+ center.x + direction.x * radius * 1.5,+ center.y + direction.y * radius * 1.5,+ center.z + direction.z * radius * 1.5);camera.center = center;camera.eye = eye;camera.up = new OV.Coord3D(0, 1, 0);viewer3D.SetCamera(camera);}-- if (onDataUrl) {- const dataUrl = viewer3D.GetImageAsDataUrl(300, 300, true);- onDataUrl?.(dataUrl);- }}setIsLoading(false);@@ -147,11 +142,11 @@ export function ModelViewer({const center = boundingSphere.center;const radius = boundingSphere.radius;const camera = viewer3D.GetCamera();- const direction = new OV.Coord3D(0, 0, 1);+ const direction = new OV.Coord3D(1, 1, 1);const eye = new OV.Coord3D(- center.x + direction.x * radius * 2.5,- center.y + direction.y * radius * 2.5,- center.z + direction.z * radius * 2.5+ center.x + direction.x * radius * 1.5,+ center.y + direction.y * radius * 1.5,+ center.z + direction.z * radius * 1.5);camera.center = center;camera.eye = eye;