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.

6.5 KB
Raw Blame
// SPDX-License-Identifier: AGPL-3.0-only
// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
// including ports, remain AGPLv3; serving them over a network requires releasing their source.

import type { Database } from "@carbon/database";
import { getAppUrl } from "@carbon/env";
import { formatDate } from "@carbon/utils";
import { Body, Column, Img, Preview, Row, Section, Text } from "react-email";
import type { CompanySettings, Email } from "../types";
import { getQuoteDisplayId } from "../utils/quote";
import { DocumentCard, documentCardStyles } from "./components/DocumentCard";
import { detailText, labelText } from "./components/documentStyles";
import ExternalNotes from "./components/ExternalNotes";
import {
  Button,
  EmailThemeProvider,
  getEmailInlineStyles,
  getEmailThemeClasses,
  HeadStyle
} from "./components/Theme";

interface QuoteEmailProps extends Email {
  quote: Database["public"]["Tables"]["quote"]["Row"];
  companySettings: CompanySettings;
}

const QuoteEmail = ({
  company,
  companySettings,
  locale,
  quote,
  recipient,
  sender
}: QuoteEmailProps) => {
  const digitalQuoteUrl =
    companySettings.digitalQuoteEnabled && quote.externalLinkId
      ? `${getAppUrl()}/share/quote/${quote.externalLinkId}` // the VERCEL_URL variable was giving us a preview branch
      : undefined;

  const preview = (
    <Preview>{`${getQuoteDisplayId(quote)} from ${company.name}`}</Preview>
  );
  const themeClasses = getEmailThemeClasses();
  const lightStyles = getEmailInlineStyles("light");

  return (
    <EmailThemeProvider
      preview={preview}
      additionalHeadContent={<HeadStyle css={documentCardStyles} />}
    >
      <Body
        className={`my-auto mx-auto font-sans ${themeClasses.body}`}
        style={lightStyles.body}
      >
        <DocumentCard>
          <Section>
            <Row>
              <Column>
                {company.logoLightIcon ? (
                  <Img
                    src={company.logoLightIcon}
                    width="auto"
                    height="42"
                    alt={`${company.name} Logo`}
                  />
                ) : (
                  <Text
                    className={`text-3xl font-bold ${themeClasses.text}`}
                    style={{ color: lightStyles.text.color }}
                  >
                    {company.name}
                  </Text>
                )}
              </Column>
              <Column className="text-right">
                <Text
                  className={themeClasses.text}
                  style={{
                    margin: 0,
                    paddingLeft: "16px",
                    fontSize: "22px",
                    lineHeight: "28px",
                    color: lightStyles.text.color
                  }}
                >
                  Quote
                </Text>
              </Column>
            </Row>
          </Section>
          <Section>
            <Text
              className={`text-left text-sm font-medium ${themeClasses.text} my-9`}
              style={{ color: lightStyles.text.color }}
            >
              {recipient.firstName ? `Hi ${recipient.firstName}, ` : "Hi, "}
              {digitalQuoteUrl
                ? "we are pleased to provide you with your digital quote, which is available for review here:"
                : "please see the attached quote and let me know if you have any questions."}
            </Text>
          </Section>
          {digitalQuoteUrl ? (
            <Section>
              <Button href={digitalQuoteUrl} className="mb-4">
                View Digital Quote
              </Button>
            </Section>
          ) : null}
          <ExternalNotes content={quote.externalNotes} />
          <Section className="bg-gray-50 rounded-[8px] text-xs email-panel">
            <Row>
              <Column className="p-5 align-top" colSpan={2}>
                <Section>
                  <Row>
                    <Column>
                      <Text
                        className={`${themeClasses.mutedText} uppercase`}
                        style={{
                          ...labelText,
                          color: lightStyles.mutedText.color
                        }}
                      >
                        Reference Number
                      </Text>
                      <Text style={detailText}>
                        {quote.customerReference ?? "-"}
                      </Text>
                    </Column>
                  </Row>

                  <Row>
                    <Column>
                      <Text
                        className={`${themeClasses.mutedText} uppercase`}
                        style={{
                          ...labelText,
                          color: lightStyles.mutedText.color
                        }}
                      >
                        Quote ID
                      </Text>
                      <Text style={detailText}>{getQuoteDisplayId(quote)}</Text>
                    </Column>
                    <Column>
                      <Text
                        className={`${themeClasses.mutedText} uppercase`}
                        style={{
                          ...labelText,
                          color: lightStyles.mutedText.color
                        }}
                      >
                        Expiration Date
                      </Text>
                      <Text style={detailText}>
                        {quote.expirationDate
                          ? formatDate(quote.expirationDate, undefined, locale)
                          : "-"}
                      </Text>
                    </Column>
                  </Row>
                </Section>
              </Column>
            </Row>
          </Section>

          <Section>
            <Row>
              <Column className="text-center">
                {company.logoLightIcon ? (
                  <Img
                    src={company.logoLightIcon}
                    width="60"
                    height="auto"
                    alt={`${company.name} Logo`}
                  />
                ) : (
                  <Text
                    className={`text-3xl font-bold ${themeClasses.text}`}
                    style={{ color: lightStyles.text.color }}
                  >
                    {company.name}
                  </Text>
                )}
              </Column>
            </Row>
          </Section>
        </DocumentCard>
      </Body>
    </EmailThemeProvider>
  );
};

export default QuoteEmail;