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: ui for digital quote

Brad Barbin9237de49918b
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuotePaymentForm.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuotePaymentForm.tsx
index 95fac27dd8..d6a32b4351 100644
--- a/apps/carbon/app/modules/sales/ui/Quotes/QuotePaymentForm.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuotePaymentForm.tsx
@@ -7,7 +7,7 @@ import {
CardTitle,
HStack,
} from "@carbon/react";
-import { useParams } from "@remix-run/react";
+import { useFetcher, useParams } from "@remix-run/react";
import { useState } from "react";
import type { z } from "zod";
import {
@@ -29,6 +29,7 @@ type QuotePaymentFormProps = {
const QuotePaymentForm = ({ initialValues }: QuotePaymentFormProps) => {
const permissions = usePermissions();
+ const fetcher = useFetcher<{}>();
const [customer, setCustomer] = useState<string | undefined>(
initialValues.invoiceCustomerId
);
@@ -51,6 +52,7 @@ const QuotePaymentForm = ({ initialValues }: QuotePaymentFormProps) => {
action={path.to.quotePayment(initialValues.id)}
validator={quotePaymentValidator}
defaultValues={initialValues}
+ fetcher={fetcher}
>
<CardHeader>
<CardTitle>Payment</CardTitle>
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteShipmentForm.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteShipmentForm.tsx
index 008a1575fa..751ad15397 100644
--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteShipmentForm.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteShipmentForm.tsx
@@ -6,7 +6,7 @@ import {
CardHeader,
CardTitle,
} from "@carbon/react";
-import { useParams } from "@remix-run/react";
+import { useFetcher, useParams } from "@remix-run/react";
import type { z } from "zod";
import {
DatePicker,
@@ -30,6 +30,7 @@ const QuoteShipmentForm = ({
}: // shippingTerms,
QuoteShipmentFormProps) => {
const permissions = usePermissions();
+ const fetcher = useFetcher<{}>();
// const shippingTermOptions = shippingTerms.map((term) => ({
// label: term.name,
@@ -55,6 +56,7 @@ QuoteShipmentFormProps) => {
method="post"
validator={quoteShipmentValidator}
defaultValues={initialValues}
+ fetcher={fetcher}
>
<CardHeader>
<CardTitle>Shipping</CardTitle>
diff --git a/apps/carbon/app/modules/sales/ui/SalesOrder/SalesOrderPaymentForm.tsx b/apps/carbon/app/modules/sales/ui/SalesOrder/SalesOrderPaymentForm.tsx
index c49d0a3f34..8c1ecd99fc 100644
--- a/apps/carbon/app/modules/sales/ui/SalesOrder/SalesOrderPaymentForm.tsx
+++ b/apps/carbon/app/modules/sales/ui/SalesOrder/SalesOrderPaymentForm.tsx
@@ -7,6 +7,7 @@ import {
CardTitle,
HStack,
} from "@carbon/react";
+import { useFetcher } from "@remix-run/react";
import { useState } from "react";
import type { z } from "zod";
import {
@@ -29,6 +30,7 @@ type SalesOrderPaymentFormProps = {
const SalesOrderPaymentForm = ({
initialValues,
}: SalesOrderPaymentFormProps) => {
+ const fetcher = useFetcher<{}>();
const permissions = usePermissions();
const [customer, setCustomer] = useState<string | undefined>(
initialValues.invoiceCustomerId
@@ -43,6 +45,7 @@ const SalesOrderPaymentForm = ({
action={path.to.salesOrderPayment(initialValues.id)}
validator={salesOrderPaymentValidator}
defaultValues={initialValues}
+ fetcher={fetcher}
>
<CardHeader>
<CardTitle>Payment</CardTitle>
diff --git a/apps/carbon/app/modules/sales/ui/SalesOrder/SalesOrderShipmentForm.tsx b/apps/carbon/app/modules/sales/ui/SalesOrder/SalesOrderShipmentForm.tsx
index 25d43b8abd..20345bc266 100644
--- a/apps/carbon/app/modules/sales/ui/SalesOrder/SalesOrderShipmentForm.tsx
+++ b/apps/carbon/app/modules/sales/ui/SalesOrder/SalesOrderShipmentForm.tsx
@@ -6,6 +6,7 @@ import {
CardHeader,
CardTitle,
} from "@carbon/react";
+import { useFetcher } from "@remix-run/react";
import { useState } from "react";
import type { z } from "zod";
import {
@@ -34,6 +35,7 @@ const SalesOrderShipmentForm = ({
}: // shippingTerms,
SalesOrderShipmentFormProps) => {
const permissions = usePermissions();
+ const fetcher = useFetcher<{}>();
const [dropShip, setDropShip] = useState<boolean>(
initialValues.dropShipment ?? false
);
@@ -55,6 +57,7 @@ SalesOrderShipmentFormProps) => {
method="post"
validator={salesOrderShipmentValidator}
defaultValues={initialValues}
+ fetcher={fetcher}
>
<CardHeader>
<CardTitle>Shipping</CardTitle>
diff --git a/apps/carbon/app/routes/external+/quote.$id.tsx b/apps/carbon/app/routes/external+/quote.$id.tsx
index 1f3ebb4a2b..afd0444d74 100644
--- a/apps/carbon/app/routes/external+/quote.$id.tsx
+++ b/apps/carbon/app/routes/external+/quote.$id.tsx
@@ -1,22 +1,50 @@
import { getCarbonServiceRole } from "@carbon/auth";
-// import { getCarbonServiceRole, notFound } from "@carbon/auth";
+import type { JSONContent } from "@carbon/react";
import {
- Avatar,
Button,
Card,
CardContent,
CardHeader,
CardTitle,
- Label,
+ generateHTML,
+ Heading,
+ HStack,
RadioGroup,
RadioGroupItem,
+ Separator,
+ Table,
+ Tbody,
+ Td,
+ Th,
+ Thead,
+ Tr,
+ VStack,
} from "@carbon/react";
+import { useLocale } from "@react-aria/i18n";
import { useLoaderData } from "@remix-run/react";
import { json, type LoaderFunctionArgs } from "@vercel/remix";
import { motion } from "framer-motion";
-import { useState } from "react";
-import { LuChevronDown, LuChevronUp } from "react-icons/lu";
-import { getQuoteByExternalId } from "~/modules/sales";
+import type { Dispatch, SetStateAction } from "react";
+import { useMemo, useState } from "react";
+import { LuChevronDown, LuCreditCard, LuImage, LuTruck } from "react-icons/lu";
+import { getPaymentTermsList } from "~/modules/accounting";
+import { getShippingMethodsList } from "~/modules/inventory";
+import type { QuotationLine, QuotationPrice } from "~/modules/sales";
+import {
+ getQuoteByExternalId,
+ getQuoteCustomerDetails,
+ getQuoteLinePricesByQuoteId,
+ getQuoteLines,
+ getQuotePayment,
+ getQuoteShipment,
+ getSalesTerms,
+} from "~/modules/sales";
+import { getCompany } from "~/modules/settings";
+import { getBase64ImageFromSupabase } from "~/modules/shared";
+
+export const meta = () => {
+ return [{ title: "Digital Quote" }];
+};
enum QuoteState {
Valid,
@@ -53,273 +81,571 @@ export async function loader({ params }: LoaderFunctionArgs) {
});
}
+ const [
+ company,
+ quoteLines,
+ quoteLinePrices,
+ customerDetails,
+ quotePayment,
+ quoteShipment,
+ paymentTerms,
+ terms,
+ shippingMethods,
+ ] = await Promise.all([
+ getCompany(serviceRole, quote.data.companyId),
+ getQuoteLines(serviceRole, quote.data.id),
+ getQuoteLinePricesByQuoteId(serviceRole, quote.data.id),
+ getQuoteCustomerDetails(serviceRole, quote.data.id),
+ getQuotePayment(serviceRole, quote.data.id),
+ getQuoteShipment(serviceRole, quote.data.id),
+ getPaymentTermsList(serviceRole, quote.data.companyId),
+ getSalesTerms(serviceRole, quote.data.companyId),
+ getShippingMethodsList(serviceRole, quote.data.companyId),
+ ]);
+
+ const thumbnailPaths = quoteLines.data?.reduce<Record<string, string | null>>(
+ (acc, line) => {
+ if (line.thumbnailPath) {
+ acc[line.id!] = line.thumbnailPath;
+ }
+ return acc;
+ },
+ {}
+ );
+
+ const thumbnails: Record<string, string | null> =
+ (thumbnailPaths
+ ? await Promise.all(
+ Object.entries(thumbnailPaths).map(([id, path]) => {
+ if (!path) {
+ return null;
+ }
+ return getBase64ImageFromSupabase(serviceRole, path).then(
+ (data) => ({
+ id,
+ data,
+ })
+ );
+ })
+ )
+ : []
+ )?.reduce<Record<string, string | null>>((acc, thumbnail) => {
+ if (thumbnail) {
+ acc[thumbnail.id] = thumbnail.data;
+ }
+ return acc;
+ }, {}) ?? {};
+
return json({
state: QuoteState.Valid,
data: {
quote: quote.data,
+ company: company.data,
+ quoteLines: quoteLines.data,
+ thumbnails: thumbnails,
+ quoteLinePrices: quoteLinePrices.data,
+ customerDetails: customerDetails.data,
+ quotePayment: quotePayment.data,
+ quoteShipment: quoteShipment.data,
+ paymentTerm: paymentTerms.data?.find(
+ (term) => term.id === quotePayment.data?.paymentTermId
+ )?.name,
+ terms: terms.data?.salesTerms ?? "",
+ shippingMethod: shippingMethods.data?.find(
+ (method) => method.id === quoteShipment.data?.shippingMethodId
+ )?.name,
},
});
}
-type OptionType = {
- id: number;
- quantity: number;
- price: number;
- leadTime: string;
-};
-
-type LineItemType = {
- id: number;
- thumbnail: string;
- description: string;
- longDescription: string;
- options: OptionType[];
-};
-
-type QuoteProps = {
- companyName: string;
- companyLogo: string;
- customerName: string;
- customerEmail: string;
- lineItems: LineItemType[];
-};
-
-// Header Component
const Header = ({
- companyName,
- companyLogo,
- customerName,
- customerEmail,
-}: Omit<QuoteProps, "lineItems">) => (
- <CardHeader className="flex flex-col sm:flex-row items-start sm:items-center justify-between space-y-4 sm:space-y-0 pb-7">
+ company,
+ quote,
+ customer,
+}: {
+ company: QuoteData["company"];
+ quote: QuoteData["quote"];
+ customer: QuoteData["customerDetails"];
+}) => (
+ <CardHeader className="flex flex-col sm:flex-row items-start sm:items-start justify-between space-y-4 sm:space-y-0 pb-7">
<div className="flex items-center space-x-4">
- <Avatar size="lg" name={companyName} />
-
<div>
- <CardTitle className="text-3xl">{companyName}</CardTitle>
- <p className="text-lg text-muted-foreground">Digital Quote</p>
+ <CardTitle className="text-3xl">{company?.name ?? ""}</CardTitle>
+
+ {quote?.quoteId && (
+ <p className="text-lg text-muted-foreground">{quote.quoteId}</p>
+ )}
</div>
</div>
- <div className="text-right">
- <p className="text-xl font-medium">{customerName}</p>
- <p className="text-lg text-muted-foreground">{customerEmail}</p>
+ <div className="flex flex-col items-end justify-start">
+ <p className="text-xl font-medium">{customer?.customerName ?? ""}</p>
+ <p className="text-lg text-muted-foreground">{customer?.email ?? ""}</p>
</div>
</CardHeader>
);
-// LineItem Component
-const LineItem = ({
- item,
- isOpen,
- toggleOpen,
- selectedOption,
- onOptionChange,
-}: {
- item: LineItemType;
- isOpen: boolean;
- toggleOpen: () => void;
- selectedOption: number;
- onOptionChange: (optionId: number) => void;
-}) => {
- const currentOption =
- item.options.find((option) => option.id === selectedOption) ||
- item.options[0];
+type SelectedLine = {
+ quantity: number;
+ netUnitPrice: number;
+ convertedNetUnitPrice: number;
+ addOn: number;
+ convertedAddOn: number;
+ leadTime: number;
+};
- return (
- <motion.div
- initial={{ opacity: 0, y: 50 }}
- animate={{ opacity: 1, y: 0 }}
- transition={{ duration: 0.5 }}
- className="border-b border-input py-6"
- >
- <div
- className="flex flex-col sm:flex-row items-start sm:items-center justify-between cursor-pointer"
- onClick={toggleOpen}
- >
- <div className="flex items-center space-x-6 mb-4 sm:mb-0">
- <img
- src={item.thumbnail}
- alt={item.description}
- className="w-24 h-24 object-cover rounded"
- />
- <div>
- <p className="font-medium text-xl mb-2">{item.description}</p>
- <p className="text-muted-foreground">{item.longDescription}</p>
- </div>
- </div>
- <div className="flex items-center space-x-4">
- <p className="font-medium text-xl">
- ${currentOption.price.toFixed(2)}
- </p>
- {isOpen ? <LuChevronUp size={24} /> : <LuChevronDown size={24} />}
- </div>
- </div>
- <motion.div
- initial="collapsed"
- animate={isOpen ? "open" : "collapsed"}
- variants={{
- open: { opacity: 1, height: "auto" },
- collapsed: { opacity: 0, height: 0 },
- }}
- transition={{ duration: 0.3 }}
- className="mt-6 space-y-4 overflow-hidden"
- >
- <RadioGroup
- value={selectedOption.toString()}
- onValueChange={(value) => onOptionChange(parseInt(value))}
- >
- {item.options.map((option) => (
- <div
- key={option.id}
- className="flex items-center space-x-2 p-3 rounded hover:bg-muted/30"
- >
- <RadioGroupItem
- value={option.id.toString()}
- id={`option-${item.id}-${option.id}`}
- />
- <Label
- htmlFor={`option-${item.id}-${option.id}`}
- className="flex-grow cursor-pointer"
- >
- <div className="flex justify-between items-center">
- <span className="text-lg">Qty: {option.quantity}</span>
- <span className="text-lg font-medium">
- ${option.price.toFixed(2)}
- </span>
- <span className="text-lg">Lead time: {option.leadTime}</span>
- </div>
- </Label>
- </div>
- ))}
- </RadioGroup>
- </motion.div>
- </motion.div>
- );
+const deselectedLine: Omit<QuotationPrice, "id" | "quoteLineId"> = {
+ convertedNetExtendedPrice: 0,
+ convertedNetUnitPrice: 0,
+ convertedUnitPrice: 0,
+ createdAt: "",
+ createdBy: "",
+ discountPercent: 0,
+ exchangeRate: 1,
+ leadTime: 0,
+ netExtendedPrice: 0,
+ netUnitPrice: 0,
+ quantity: 0,
+ quoteId: "",
+ unitPrice: 0,
+ updatedAt: null,
+ updatedBy: null,
};
-// LineItems Component
const LineItems = ({
- lineItems,
- selectedOptions,
- onOptionChange,
+ formatter,
+ selectedLines,
+ setSelectedLines,
}: {
- lineItems: LineItemType[];
- selectedOptions: Record<number, number>;
- onOptionChange: (itemId: number, optionId: number) => void;
+ formatter: Intl.NumberFormat;
+ selectedLines: Record<string, SelectedLine>;
+ setSelectedLines: Dispatch<SetStateAction<Record<string, SelectedLine>>>;
}) => {
- const [openItems, setOpenItems] = useState<number[]>([]);
+ const { company, quote, quoteLines, quoteLinePrices, thumbnails } =
+ useLoaderData<typeof loader>().data!;
+
+ const [openItems, setOpenItems] = useState<string[]>([]);
- const toggleOpen = (id: number) => {
+ const pricingByLine = useMemo(
+ () =>
+ quoteLines?.reduce<Record<string, QuotationPrice[]>>((acc, line) => {
+ if (!line.id) {
+ return acc;
+ }
+ acc[line.id!] =
+ quoteLinePrices?.filter((p) => p.quoteLineId === line.id) ?? [];
+ return acc;
+ }, {}) ?? {},
+ [quoteLines, quoteLinePrices]
+ );
+
+ const toggleOpen = (id: string) => {
setOpenItems((prev) =>
prev.includes(id) ? prev.filter((item) => item !== id) : [...prev, id]
);
};
+ const shouldConvertCurrency =
+ quote.currencyCode !== company?.baseCurrencyCode;
+
return (
- <div className="space-y-6">
- {lineItems.map((item) => (
- <LineItem
- key={item.id}
- item={item}
- isOpen={openItems.includes(item.id)}
- toggleOpen={() => toggleOpen(item.id)}
- selectedOption={selectedOptions[item.id]}
- onOptionChange={(optionId) => onOptionChange(item.id, optionId)}
- />
- ))}
- </div>
+ <VStack spacing={8} className="w-full">
+ {quoteLines?.map((line) => {
+ const prices = quoteLinePrices?.find(
+ (price) => price.quoteLineId === line.id
+ );
+
+ if (!line || !prices || !line.id) {
+ return null;
+ }
+
+ return (
+ <motion.div
+ key={line.id}
+ initial={{ opacity: 0, y: 50 }}
+ animate={{ opacity: 1, y: 0 }}
+ transition={{ duration: 0.5 }}
+ className="border-b border-input py-6 w-full"
+ >
+ <HStack spacing={4} className="items-start">
+ {thumbnails[line.id!] ? (
+ <img
+ alt={line.itemReadableId!}
+ className="w-24 h-24 bg-gradient-to-bl from-muted to-muted/40 rounded-lg border-2 border-transparent"
+ src={thumbnails[line.id!] ?? undefined}
+ />
+ ) : (
+ <div className="w-20 h-20 bg-gradient-to-bl from-muted to-muted/40 rounded-lg border-2 border-transparent p-2">
+ <LuImage className="w-16 h-16 text-muted-foreground" />
+ </div>
+ )}
+
+ <VStack spacing={0} className="w-full">
+ <div
+ className="flex flex-col cursor-pointer w-full"
+ onClick={() => toggleOpen(line.id!)}
+ >
+ <div className="flex items-center gap-x-4 justify-between flex-grow">
+ <Heading>{line.itemReadableId}</Heading>
+ <HStack spacing={4}>
+ <span className="font-medium text-xl">
+ {formatter.format(
+ (selectedLines[line.id!]?.convertedNetUnitPrice ??
+ 0) *
+ (selectedLines[line.id!]?.quantity ?? 0) +
+ (selectedLines[line.id!]?.convertedAddOn ?? 0)
+ )}
+ </span>
+ <motion.div
+ animate={{
+ rotate: openItems.includes(line.id) ? 180 : 0,
+ }}
+ transition={{ duration: 0.3 }}
+ >
+ <LuChevronDown size={24} />
+ </motion.div>
+ </HStack>
+ </div>
+ <span className="text-muted-foreground text-base truncate">
+ {line.description}
+ </span>
+ <div
+ className="prose dark:prose-invert text-muted-foreground"
+ dangerouslySetInnerHTML={{
+ __html: generateHTML(line.notes as JSONContent),
+ }}
+ />
+ </div>
+ </VStack>
+ </HStack>
+
+ <motion.div
+ initial="collapsed"
+ animate={openItems.includes(line.id) ? "open" : "collapsed"}
+ variants={{
+ open: { opacity: 1, height: "auto", marginTop: 16 },
+ collapsed: { opacity: 0, height: 0, marginTop: 0 },
+ }}
+ transition={{ duration: 0.3 }}
+ className="w-full overflow-hidden"
+ >
+ <LinePricingOptions
+ formatter={formatter}
+ line={line}
+ options={pricingByLine[line.id!]}
+ quoteCurrency={quote.currencyCode ?? "USD"}
+ quoteExchangeRate={quote.exchangeRate ?? 1}
+ shouldConvertCurrency={shouldConvertCurrency}
+ selectedLine={selectedLines[line.id!]}
+ setSelectedLines={setSelectedLines}
+ />
+ </motion.div>
+ </motion.div>
+ );
+ })}
+ </VStack>
);
};
-// Main Quote Component
-const Quote = ({
- companyName = "Acme Inc.",
- companyLogo = "/placeholder.svg?height=50&width=50",
- customerName = "John Doe",
- customerEmail = "[email protected]",
- lineItems = [
- {
- id: 1,
- thumbnail: "/placeholder.svg?height=200&width=200",
- description: "Premium Widget",
- longDescription:
- "High-quality widget with advanced features for improved productivity.",
- options: [
- { id: 1, quantity: 10, price: 100, leadTime: "1 week" },
- { id: 2, quantity: 20, price: 180, leadTime: "2 weeks" },
- { id: 3, quantity: 50, price: 400, leadTime: "1 month" },
- ],
- },
- {
- id: 2,
- thumbnail: "/placeholder.svg?height=200&width=200",
- description: "Deluxe Gadget",
- longDescription:
- "State-of-the-art gadget designed for maximum efficiency and performance.",
- options: [
- { id: 4, quantity: 5, price: 50, leadTime: "3 days" },
- { id: 5, quantity: 15, price: 130, leadTime: "1 week" },
- { id: 6, quantity: 30, price: 240, leadTime: "2 weeks" },
- ],
+type LinePricingOptionsProps = {
+ line: QuotationLine;
+ options: QuotationPrice[];
+ quoteCurrency: string;
+ shouldConvertCurrency: boolean;
+ quoteExchangeRate: number;
+ formatter: Intl.NumberFormat;
+ selectedLine: SelectedLine;
+ setSelectedLines: Dispatch<SetStateAction<Record<string, SelectedLine>>>;
+};
+
+const LinePricingOptions = ({
+ line,
+ options,
+ quoteCurrency,
+ shouldConvertCurrency,
+ quoteExchangeRate,
+ formatter,
+ selectedLine,
+ setSelectedLines,
+}: LinePricingOptionsProps) => {
+ const [selectedValue, setSelectedValue] = useState(
+ selectedLine.quantity.toString()
+ );
+
+ const additionalChargesByQuantity =
+ line.quantity?.reduce(
+ (acc, quantity) => {
+ const charges = Object.values(line.additionalCharges ?? {}).reduce(
+ (chargeAcc, charge) => {
+ const amount = charge.amounts?.[quantity];
+ return chargeAcc + amount;
+ },
+ 0
+ );
+ acc[quantity] = charges;
+ return acc;
+ },
+ { 0: 0 } as Record<number, number>
+ ) ?? {};
+
+ const convertedAdditionalChargesByQuantity = Object.entries(
+ additionalChargesByQuantity
+ ).reduce<Record<number, number>>(
+ (acc, [quantity, amount]) => {
+ acc[Number(quantity)] = amount * quoteExchangeRate;
+ return acc;
},
- ],
-}: QuoteProps) => {
- const [selectedOptions, setSelectedOptions] = useState<
- Record<number, number>
- >(() =>
- lineItems.reduce(
- (acc, item) => ({ ...acc, [item.id]: item.options[0].id }),
- {}
- )
+ { 0: 0 }
);
- const [taxRate, setTaxRate] = useState(0.1); // 10% tax rate
- const onOptionChange = (itemId: number, optionId: number) => {
- setSelectedOptions((prev) => ({ ...prev, [itemId]: optionId }));
- };
+ return (
+ <VStack spacing={2}>
+ <RadioGroup
+ className="w-full"
+ value={selectedValue}
+ onValueChange={(value) => {
+ const selectedOption =
+ value === "0"
+ ? deselectedLine
+ : options.find((opt) => opt.quantity.toString() === value);
+
+ if (selectedOption) {
+ setSelectedLines((prev) => ({
+ ...prev,
+ [line.id!]: {
+ quantity: selectedOption.quantity,
+ netUnitPrice: selectedOption.netUnitPrice ?? 0,
+ convertedNetUnitPrice:
+ selectedOption.convertedNetUnitPrice ?? 0,
+ addOn:
+ additionalChargesByQuantity[selectedOption.quantity] || 0,
+ convertedAddOn:
+ convertedAdditionalChargesByQuantity[
+ selectedOption.quantity
+ ] || 0,
+ leadTime: selectedOption.leadTime,
+ },
+ }));
+ setSelectedValue(value);
+ }
+ }}
+ >
+ <Table>
+ <Thead>
+ <Tr>
+ <Th></Th>
+ <Th>Quantity</Th>
+ <Th>Unit Price</Th>
+ <Th>Add-Ons</Th>
+ <Th>Lead Time</Th>
+ <Th>Total Price</Th>
+ </Tr>
+ </Thead>
+ <Tbody>
+ {!Array.isArray(options) || options.length === 0 ? (
+ <Tr>
+ <Td colSpan={6} className="text-center py-8">
+ No pricing options found
+ </Td>
+ </Tr>
+ ) : (
+ [...options, deselectedLine].map(
+ (option, index) =>
+ (line?.quantity?.includes(option.quantity) ||
+ option.quantity === 0) && (
+ <Tr key={index}>
+ <Td>
+ <RadioGroupItem
+ value={option.quantity.toString()}
+ id={`${line.id}:${option.quantity.toString()}`}
+ />
+ <label
+ htmlFor={`${line.id}:${option.quantity.toString()}`}
+ className="sr-only"
+ >
+ {option.quantity}
+ </label>
+ </Td>
+ <Td>{option.quantity}</Td>
+ <Td>
+ {formatter.format(option.convertedNetUnitPrice ?? 0)}
+ </Td>
+ <Td>
+ {formatter.format(
+ convertedAdditionalChargesByQuantity[option.quantity]
+ )}
+ </Td>
+ <Td>{option.leadTime} days</Td>
+ <Td>
+ {formatter.format(
+ (option.convertedNetUnitPrice ?? 0) *
+ option.quantity +
+ convertedAdditionalChargesByQuantity[
+ option.quantity
+ ]
+ )}
+ </Td>
+ </Tr>
+ )
+ )
+ )}
+ </Tbody>
+ </Table>
+ </RadioGroup>
+ </VStack>
+ );
+};
+
+const Quote = ({ data }: { data: QuoteData }) => {
+ const {
+ company,
+ customerDetails,
+ paymentTerm,
+ quote,
+ quoteLines,
+ quoteLinePrices,
+ shippingMethod,
+ terms,
+ } = data;
+ const { locale } = useLocale();
+ const formatter = useMemo(
+ () =>
+ new Intl.NumberFormat(locale, {
+ style: "currency",
+ currency: quote.currencyCode ?? "USD",
+ maximumFractionDigits: 4,
+ }),
+ [locale, quote.currencyCode]
+ );
+
+ const [selectedLines, setSelectedLines] = useState<
+ Record<string, SelectedLine>
+ >(() => {
+ return (
+ quoteLines?.reduce<Record<string, SelectedLine>>((acc, line) => {
+ const price = quoteLinePrices?.find(
+ (price) => price.quoteLineId === line.id
+ );
+ if (!line.id || !price) {
+ return acc;
+ }
- const subtotal = lineItems.reduce((sum, item) => {
- const selectedOption = item.options.find(
- (option) => option.id === selectedOptions[item.id]
+ const additionalChargesByQuantity =
+ line.quantity?.reduce((acc, quantity) => {
+ const charges = Object.values(line.additionalCharges ?? {}).reduce(
+ (chargeAcc, charge) => {
+ const amount = charge.amounts?.[quantity];
+ return chargeAcc + amount;
+ },
+ 0
+ );
+ acc[quantity] = charges;
+ return acc;
+ }, {} as Record<number, number>) ?? {};
+
+ const convertedAdditionalChargesByQuantity =
+ Object.entries(additionalChargesByQuantity).reduce<
+ Record<number, number>
+ >((acc, [quantity, amount]) => {
+ acc[Number(quantity)] = amount * (quote.exchangeRate ?? 1);
+ return acc;
+ }, {} as Record<number, number>) ?? {};
+
+ acc[line.id] = {
+ quantity: price.quantity ?? 0,
+ netUnitPrice: price.netUnitPrice ?? 0,
+ convertedNetUnitPrice: price.convertedNetUnitPrice ?? 0,
+ addOn: additionalChargesByQuantity[price.quantity] || 0,
+ convertedAddOn:
+ convertedAdditionalChargesByQuantity[price.quantity] || 0,
+ leadTime: price.leadTime,
+ };
+ return acc;
+ }, {}) ?? {}
+ );
+ });
+
+ const subtotal = Object.values(selectedLines).reduce((acc, line) => {
+ return (
+ acc + line.convertedNetUnitPrice * line.quantity + line.convertedAddOn
);
- return sum + (selectedOption?.price || 0);
}, 0);
- const tax = subtotal * taxRate;
+ const tax = 0;
const total = subtotal + tax;
+ const termsHTML = generateHTML(terms as JSONContent);
+ console.log({ termsHTML });
+
return (
- <Card className="w-full max-w-5xl mx-auto">
- <Header
- companyName={companyName}
- companyLogo={companyLogo}
- customerName={customerName}
- customerEmail={customerEmail}
- />
- <CardContent>
- <LineItems
- lineItems={lineItems}
- selectedOptions={selectedOptions}
- onOptionChange={onOptionChange}
+ <VStack spacing={8} className="w-full items-center p-2 md:p-8">
+ {company?.logo && (
+ <img
+ src={company.logo}
+ alt={company.name}
+ className="h-24 w-auto mx-auto rounded-lg"
/>
- <div className="mt-8 space-y-2">
- <div className="flex justify-between items-center text-sm text-muted-foreground">
- <p>Subtotal:</p>
- <p>${subtotal.toFixed(2)}</p>
- </div>
- <div className="flex justify-between items-center text-sm text-muted-foreground">
- <p>Tax ({(taxRate * 100).toFixed(0)}%):</p>
- <p>${tax.toFixed(2)}</p>
- </div>
- <div className="flex justify-between items-center pt-2">
- <p className="text-2xl font-bold">Total:</p>
- <p className="text-2xl font-bold">${total.toFixed(2)}</p>
- </div>
- </div>
- <Button size="lg" className="w-full mt-6 text-lg">
- Accept Quote
- </Button>
- </CardContent>
- </Card>
+ )}
+ <Card className="w-full max-w-5xl mx-auto">
+ <Header company={company} quote={quote} customer={customerDetails} />
+ <CardContent>
+ <LineItems
+ selectedLines={selectedLines}
+ setSelectedLines={setSelectedLines}
+ formatter={formatter}
+ />
+
+ <VStack spacing={2} className="mt-8">
+ {shippingMethod && (
+ <HStack className="justify-between text-sm text-muted-foreground w-full">
+ <HStack spacing={2}>
+ <LuTruck className="w-5 h-5" />
+ <span>Shipping Method:</span>
+ </HStack>
+ <span className="text-foreground font-bold">
+ {shippingMethod}
+ </span>
+ </HStack>
+ )}
+ {paymentTerm && (
+ <HStack className="justify-between text-sm text-muted-foreground w-full">
+ <HStack spacing={2}>
+ <LuCreditCard className="w-5 h-5" />
+ <span>Payment Term:</span>
+ </HStack>
+ <span className="text-foreground font-bold">{paymentTerm}</span>
+ </HStack>
+ )}
+ {(shippingMethod || paymentTerm) && <Separator />}
+
+ <HStack className="justify-between text-sm text-muted-foreground w-full">
+ <span>Subtotal:</span>
+ <span>{formatter.format(subtotal)}</span>
+ </HStack>
+ {/* <HStack className="justify-between text-sm text-muted-foreground w-full">
+ <span>Tax:</span>
+ <span>{formatter.format(tax)}</span>
+ </HStack> */}
+ <Separator />
+ <HStack className="justify-between text-xl font-bold w-full">
+ <span>Total:</span>
+ <span>{formatter.format(total)}</span>
+ </HStack>
+ </VStack>
+ {company?.digitalQuoteEnabled && (
+ <Button size="lg" className="w-full mt-8 text-lg">
+ Accept Quote
+ </Button>
+ )}
+ </CardContent>
+ </Card>
+ {termsHTML && (
+ <div
+ className="prose dark:prose-invert text-muted-foreground max-w-none"
+ dangerouslySetInnerHTML={{
+ __html: termsHTML,
+ }}
+ />
+ )}
+ </VStack>
);
};
@@ -425,12 +751,24 @@ const ErrorMessage = ({
);
};
+type QuoteData = NonNullable<
+ Awaited<ReturnType<Awaited<ReturnType<typeof loader>>["json"]>>["data"]
+>;
+
export default function ExternalQuote() {
const { state, data } = useLoaderData<typeof loader>();
switch (state) {
case QuoteState.Valid:
- return <pre>{JSON.stringify(data, null, 2)}</pre>;
+ if (data) {
+ return <Quote data={data as QuoteData} />;
+ }
+ return (
+ <ErrorMessage
+ title="Quote not found"
+ message="Oops! The link you're trying to access is not valid."
+ />
+ );
case QuoteState.Expired:
return (
<ErrorMessage
diff --git a/apps/www/app/routes/_index.tsx b/apps/www/app/routes/_index.tsx
index 800a25574a..2121cfc6b3 100644
--- a/apps/www/app/routes/_index.tsx
+++ b/apps/www/app/routes/_index.tsx
@@ -11,7 +11,7 @@ export default function Route() {
<a
id="announcement"
href="https://app.carbonos.dev"
- className="fixed top-10 left-1/2 -translate-x-1/2 group items-center border border-input rounded-full px-4 py-1.5 flex mb-4.5 text-xs hover:bg-alpha-gray-2 dark:hover:bg-gray-900 transition-theme"
+ className="fixed top-10 left-1/2 -translate-x-1/2 group items-center border border-input rounded-full px-4 py-1.5 flex mb-4.5 text-xs hover:bg-alpha-gray-2 dark:hover:bg-background transition-theme"
target="_blank"
rel="noreferrer"
>
diff --git a/packages/react/src/ModelViewer.tsx b/packages/react/src/ModelViewer.tsx
index 31d7145a6c..5d6e47d107 100644
--- a/packages/react/src/ModelViewer.tsx
+++ b/packages/react/src/ModelViewer.tsx
@@ -3,6 +3,7 @@ import { useEffect, useRef, useState } from "react";
import { useMount } from "./hooks";
import { IconButton } from "./IconButton";
import { Spinner } from "./Spinner";
+import { cn } from "./utils/cn";
export const supportedModelTypes = [
"3dm",
@@ -29,12 +30,16 @@ export function ModelViewer({
file,
url,
mode = "dark",
+ className,
onDataUrl,
+ resetZoomButton = true,
}: {
file: File | null;
url: string | null;
mode?: "dark" | "light";
onDataUrl?: (dataUrl: string) => void;
+ resetZoomButton?: boolean;
+ className?: string;
}) {
const parentDiv = useRef<HTMLDivElement>(null);
const viewerRef = useRef<OV.EmbeddedViewer | null>(null);
@@ -195,7 +200,10 @@ export function ModelViewer({
ref={parentDiv}
role={"img"}
aria-label="Canvas showing the model in the 3D Viewer"
- className="h-full w-full items-center justify-center rounded-lg relative border border-border dark:border-0 dark:shadow-[0px_1px_0px_0px_hsla(0,0%,100%,.03)_inset,0px_0px_0px_1px_hsla(0,0%,100%,.03)_inset,0px_0px_0px_1px_rgba(0,0,0,.1),0px_2px_2px_0px_rgba(0,0,0,.1),0px_4px_4px_0px_rgba(0,0,0,.1),0px_8px_8px_0px_rgba(0,0,0,.1)] bg-gradient-to-bl from-card from-50% via-card to-background min-h-[400px] shadow-md"
+ className={cn(
+ "h-full w-full items-center justify-center rounded-lg relative border border-border dark:border-0 dark:shadow-[0px_1px_0px_0px_hsla(0,0%,100%,.03)_inset,0px_0px_0px_1px_hsla(0,0%,100%,.03)_inset,0px_0px_0px_1px_rgba(0,0,0,.1),0px_2px_2px_0px_rgba(0,0,0,.1),0px_4px_4px_0px_rgba(0,0,0,.1),0px_8px_8px_0px_rgba(0,0,0,.1)] bg-gradient-to-bl from-card from-50% via-card to-background min-h-[400px] shadow-md",
+ className
+ )}
>
{isLoading ? (
<div className="absolute inset-0 bg-card h-full w-full flex items-center justify-center">
@@ -204,31 +212,33 @@ export function ModelViewer({
) : (
<>
<pre id="model-viewer-canvas" aria-hidden className="sr-only" />
- <IconButton
- aria-label="Reset zoom"
- className="absolute top-2 right-2"
- icon={
- <svg
- xmlns="http://www.w3.org/2000/svg"
- width="24"
- height="24"
- viewBox="0 0 24 24"
- fill="none"
- stroke="currentColor"
- stroke-width="2"
- stroke-linecap="round"
- stroke-linejoin="round"
- >
- <path d="M3 7V5a2 2 0 0 1 2-2h2" />
- <path d="M17 3h2a2 2 0 0 1 2 2v2" />
- <path d="M21 17v2a2 2 0 0 1-2 2h-2" />
- <path d="M7 21H5a2 2 0 0 1-2-2v-2" />
- <rect width="10" height="8" x="7" y="8" rx="1" />
- </svg>
- }
- variant="ghost"
- onClick={resetZoom}
- />
+ {resetZoomButton && (
+ <IconButton
+ aria-label="Reset zoom"
+ className="absolute top-2 right-2"
+ icon={
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ width="24"
+ height="24"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="2"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ >
+ <path d="M3 7V5a2 2 0 0 1 2-2h2" />
+ <path d="M17 3h2a2 2 0 0 1 2 2v2" />
+ <path d="M21 17v2a2 2 0 0 1-2 2h-2" />
+ <path d="M7 21H5a2 2 0 0 1-2-2v-2" />
+ <rect width="10" height="8" x="7" y="8" rx="1" />
+ </svg>
+ }
+ variant="ghost"
+ onClick={resetZoom}
+ />
+ )}
</>
)}
</div>