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: email link to digital quote

Brad Barbindde60ba69a3d
diff --git a/apps/carbon/app/modules/sales/sales.service.ts b/apps/carbon/app/modules/sales/sales.service.ts
index 8f6c79c505..7f11de9e5d 100644
--- a/apps/carbon/app/modules/sales/sales.service.ts
+++ b/apps/carbon/app/modules/sales/sales.service.ts
@@ -7,6 +7,7 @@ import type { GenericQueryFilters } from "~/utils/query";
import { setGenericQueryFilters } from "~/utils/query";
import { sanitize } from "~/utils/supabase";
import { getCurrencyByCode } from "../accounting";
+import { upsertExternalLink } from "../shared/shared.service";
import type {
customerAccountingValidator,
customerContactValidator,
@@ -1535,7 +1536,7 @@ export async function upsertQuote(
const quoteId = insert.data?.[0]?.id;
if (!quoteId) return insert;
- const [shipment, payment, opportunity] = await Promise.all([
+ const [shipment, payment, opportunity, externalLink] = await Promise.all([
client.from("quoteShipment").insert([
{
id: quoteId,
@@ -1558,6 +1559,13 @@ export async function upsertQuote(
client
.from("opportunity")
.insert([{ quoteId, companyId: quote.companyId }]),
+ upsertExternalLink(client, {
+ documentType: "Quote",
+ documentId: quoteId,
+ customerId: quote.customerId,
+ expiresAt: quote.expirationDate,
+ companyId: quote.companyId,
+ }),
]);
if (shipment.error) {
@@ -1572,6 +1580,12 @@ export async function upsertQuote(
await deleteQuote(client, quoteId);
return opportunity;
}
+ if (externalLink.data) {
+ await client
+ .from("quote")
+ .update({ externalLinkId: externalLink.data.id })
+ .eq("id", quoteId);
+ }
return insert;
} else {
diff --git a/apps/carbon/app/routes/external+/quote.$id.tsx b/apps/carbon/app/routes/external+/quote.$id.tsx
index 83efe06455..f1c78dad02 100644
--- a/apps/carbon/app/routes/external+/quote.$id.tsx
+++ b/apps/carbon/app/routes/external+/quote.$id.tsx
@@ -96,7 +96,8 @@ export async function loader({ params }: LoaderFunctionArgs) {
if (
quote.data.expirationDate &&
- new Date(quote.data.expirationDate) < new Date()
+ new Date(quote.data.expirationDate) < new Date() &&
+ quote.data.status === "Sent"
) {
return json({
state: QuoteState.Expired,
diff --git a/package-lock.json b/package-lock.json
index 5a47643d6a..76baccb153 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -32692,6 +32692,7 @@
"react-pdf-tailwind": "~2.3.0"
},
"devDependencies": {
+ "@carbon/auth": "*",
"@carbon/database": "*",
"@carbon/jest": "*",
"@carbon/tsconfig": "*",
diff --git a/packages/documents/package.json b/packages/documents/package.json
index 29940e5f3c..aa07098743 100644
--- a/packages/documents/package.json
+++ b/packages/documents/package.json
@@ -8,6 +8,7 @@
"react-pdf-tailwind": "~2.3.0"
},
"devDependencies": {
+ "@carbon/auth": "*",
"@carbon/database": "*",
"@carbon/jest": "*",
"@carbon/tsconfig": "*",
diff --git a/packages/documents/src/email/QuoteEmail.tsx b/packages/documents/src/email/QuoteEmail.tsx
index 8fde77d7c9..b1314d1d70 100644
--- a/packages/documents/src/email/QuoteEmail.tsx
+++ b/packages/documents/src/email/QuoteEmail.tsx
@@ -1,3 +1,4 @@
+import { VERCEL_URL } from "@carbon/auth";
import type { Database } from "@carbon/database";
import {
Body,
@@ -21,6 +22,10 @@ interface QuoteEmailProps extends Email {
const QuoteEmail = ({ company, quote, recipient, sender }: QuoteEmailProps) => {
const reSubject = `Re: ${quote.quoteId} from ${company.name}`;
+ const digitalQuoteUrl =
+ company.digitalQuoteEnabled && !!quote.externalLinkId && VERCEL_URL
+ ? `${VERCEL_URL}/external/quote/${quote.externalLinkId}`
+ : undefined;
return (
<Html lang="en">
@@ -33,9 +38,9 @@ const QuoteEmail = ({ company, quote, recipient, sender }: QuoteEmailProps) => {
<Section>
<Row>
<Column>
- {company.logoLightIcon ? (
+ {company.logoLight ? (
<Img
- src={company.logoLightIcon}
+ src={company.logoLight}
width="auto"
height="42"
alt={`${company.name} Logo`}
@@ -55,11 +60,28 @@ const QuoteEmail = ({ company, quote, recipient, sender }: QuoteEmailProps) => {
</Row>
</Section>
<Section>
- <Text className="mt-9 mb-10 text-left text-sm font-medium text-gray-900">
- {recipient.firstName ? `Hi ${recipient.firstName},` : "Hi,"}
- please see the attached quote and let me know if you have any
- questions.
- </Text>
+ {digitalQuoteUrl ? (
+ <>
+ <Text className="mt-9 mb-4 text-left text-sm font-medium text-gray-900">
+ {recipient.firstName
+ ? `Hi ${recipient.firstName}, `
+ : "Hi, "}
+ we are pleased to provide you with your digital quote, which
+ is available for review here:
+ </Text>
+ <Link href={digitalQuoteUrl}>
+ <Text className="inline-flex items-center justify-center rounded-md bg-black px-4 py-2 text-sm font-medium text-white shadow hover:bg-gray-800 focus:outline-none focus:ring-2 focus:ring-black focus:ring-offset-2">
+ View Digital Quote
+ </Text>
+ </Link>
+ </>
+ ) : (
+ <Text className="mt-9 mb-10 text-left text-sm font-medium text-gray-900">
+ {recipient.firstName ? `Hi ${recipient.firstName}, ` : "Hi, "}
+ please see the attached quote and let me know if you have any
+ questions.
+ </Text>
+ )}
</Section>
<Section className="rounded-lg bg-gray-50 text-xs">
<Row>