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.

refactor: deprecate old quote ui

Brad Barbin68db78afe3ed
diff --git a/apps/carbon/app/modules/sales/ui/Quotations/index.ts b/apps/carbon/app/modules/sales/ui/Quotations/index.ts
deleted file mode 100644
index 7239106d3a..0000000000
--- a/apps/carbon/app/modules/sales/ui/Quotations/index.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-import QuotationsTable from "./QuotationsTable";
-
-export { QuotationsTable };
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteHeader.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteHeader.tsx
new file mode 100644
index 0000000000..bb6ac2fc86
--- /dev/null
+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteHeader.tsx
@@ -0,0 +1,32 @@
+import { Badge, HStack, Heading, VStack } from "@carbon/react";
+
+import { useParams } from "@remix-run/react";
+import { RiProgress4Line } from "react-icons/ri";
+
+import { useRouteData } from "~/hooks";
+import type { Quotation } from "~/modules/sales";
+import { path } from "~/utils/path";
+
+const QuoteHeader = () => {
+ const { quoteId } = useParams();
+ if (!quoteId) throw new Error("quoteId not found");
+
+ const routeData = useRouteData<{ quote: Quotation }>(path.to.quote(quoteId));
+
+ return (
+ <div className="flex flex-shrink-0 items-center justify-between px-4 py-2 bg-card border-b border-border">
+ <VStack spacing={0} className="flex-grow">
+ <HStack>
+ <Heading size="h2">{routeData?.quote?.quoteId}</Heading>
+ <Badge variant="secondary">
+ <Badge variant="secondary">
+ <RiProgress4Line />
+ </Badge>
+ </Badge>
+ </HStack>
+ </VStack>
+ </div>
+ );
+};
+
+export default QuoteHeader;
diff --git a/apps/carbon/app/modules/sales/ui/Quotations/QuotationsTable.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuotesTable.tsx
similarity index 90%
rename from apps/carbon/app/modules/sales/ui/Quotations/QuotationsTable.tsx
rename to apps/carbon/app/modules/sales/ui/Quotes/QuotesTable.tsx
index af35b2de83..e421c1d070 100644
--- a/apps/carbon/app/modules/sales/ui/Quotations/QuotationsTable.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuotesTable.tsx
@@ -27,12 +27,12 @@ import { favoriteSchema } from "~/types/validators";
import { path } from "~/utils/path";
import { QuotationStatus } from "../Quotation";
-type QuotationsTableProps = {
+type QuotesTableProps = {
data: Quotation[];
count: number;
};
-const QuotationsTable = memo(({ data, count }: QuotationsTableProps) => {
+const QuotesTable = memo(({ data, count }: QuotesTableProps) => {
const permissions = usePermissions();
const navigate = useNavigate();
@@ -64,6 +64,11 @@ const QuotationsTable = memo(({ data, count }: QuotationsTableProps) => {
);
const customColumns = useCustomColumns<Quotation>("quote");
const columns = useMemo<ColumnDef<Quotation>[]>(() => {
+ const employeeOptions = people.map((employee) => ({
+ value: employee.id,
+ label: employee.name,
+ }));
+
const defaultColumns: ColumnDef<Quotation>[] = [
{
accessorKey: "quoteId",
@@ -167,6 +172,32 @@ const QuotationsTable = memo(({ data, count }: QuotationsTableProps) => {
pluralHeader: "Statuses",
},
},
+ {
+ accessorKey: "salesPersonId",
+ header: "Sales Person",
+ cell: ({ row }) => (
+ <EmployeeAvatar employeeId={row.original.salesPersonId} />
+ ),
+ meta: {
+ filter: {
+ type: "static",
+ options: employeeOptions,
+ },
+ },
+ },
+ {
+ accessorKey: "estimatorId",
+ header: "Estimator",
+ cell: ({ row }) => (
+ <EmployeeAvatar employeeId={row.original.estimatorId} />
+ ),
+ meta: {
+ filter: {
+ type: "static",
+ options: employeeOptions,
+ },
+ },
+ },
{
id: "assignee",
header: "Assignee",
@@ -176,10 +207,7 @@ const QuotationsTable = memo(({ data, count }: QuotationsTableProps) => {
meta: {
filter: {
type: "static",
- options: people.map((employee) => ({
- value: employee.id,
- label: employee.name,
- })),
+ options: employeeOptions,
},
},
},
@@ -325,9 +353,9 @@ const QuotationsTable = memo(({ data, count }: QuotationsTableProps) => {
);
});
-QuotationsTable.displayName = "QuotationsTable";
+QuotesTable.displayName = "QuotesTable";
-export default QuotationsTable;
+export default QuotesTable;
function useOptimisticFavorite() {
const fetchers = useFetchers();
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/index.ts b/apps/carbon/app/modules/sales/ui/Quotes/index.ts
new file mode 100644
index 0000000000..52783b29a8
--- /dev/null
+++ b/apps/carbon/app/modules/sales/ui/Quotes/index.ts
@@ -0,0 +1,4 @@
+import QuoteHeader from "./QuoteHeader";
+import QuotesTable from "./QuotesTable";
+
+export { QuoteHeader, QuotesTable };
diff --git a/apps/carbon/app/modules/sales/ui/index.ts b/apps/carbon/app/modules/sales/ui/index.ts
index 0bcdbc180a..520433841c 100644
--- a/apps/carbon/app/modules/sales/ui/index.ts
+++ b/apps/carbon/app/modules/sales/ui/index.ts
@@ -1,10 +1,10 @@
import useSalesSubmodules from "./useSalesSubmodules";
export * from "./Customer";
+export * from "./Customers";
export * from "./CustomerStatuses";
export * from "./CustomerTypes";
-export * from "./Customers";
export * from "./Quotation";
-export * from "./Quotations";
+export * from "./Quotes";
export * from "./SalesOrder";
export * from "./SalesOrders";
export * from "./SalesRFQ";
diff --git a/apps/carbon/app/routes/x+/quote+/$quoteId.tsx b/apps/carbon/app/routes/x+/quote+/$quoteId.tsx
new file mode 100644
index 0000000000..41af0cf1fa
--- /dev/null
+++ b/apps/carbon/app/routes/x+/quote+/$quoteId.tsx
@@ -0,0 +1,95 @@
+import {
+ ClientOnly,
+ ResizableHandle,
+ ResizablePanel,
+ ResizablePanelGroup,
+ ScrollArea,
+} from "@carbon/react";
+import type { LoaderFunctionArgs } from "@remix-run/node";
+import { json, redirect } from "@remix-run/node";
+import { Outlet, useParams } from "@remix-run/react";
+import { getQuote, QuoteHeader } from "~/modules/sales";
+import { requirePermissions } from "~/services/auth/auth.server";
+import { flash } from "~/services/session.server";
+import type { Handle } from "~/utils/handle";
+import { path } from "~/utils/path";
+import { error } from "~/utils/result";
+
+export const handle: Handle = {
+ breadcrumb: "Quote",
+ to: path.to.quotes,
+ module: "sales",
+};
+
+export async function loader({ request, params }: LoaderFunctionArgs) {
+ const { client } = await requirePermissions(request, {
+ view: "sales",
+ });
+
+ const { quoteId } = params;
+ if (!quoteId) throw new Error("Could not find quoteId");
+
+ const [quote] = await Promise.all([getQuote(client, quoteId)]);
+
+ if (quote.error) {
+ throw redirect(
+ path.to.items,
+ await flash(request, error(quote.error, "Failed to load quote"))
+ );
+ }
+
+ return json({
+ quote: quote.data,
+ });
+}
+
+export default function QuoteRoute() {
+ const params = useParams();
+ const { quoteId } = params;
+ if (!quoteId) throw new Error("Could not find quoteId");
+
+ return (
+ <div className="flex flex-col h-[calc(100vh-49px)] w-full">
+ <QuoteHeader />
+ <div className="flex h-[calc(100vh-99px)] w-full">
+ <div className="flex h-full w-full overflow-y-auto">
+ <div className="flex flex-grow overflow-hidden">
+ <ClientOnly fallback={null}>
+ {() => (
+ <ResizablePanelGroup direction="horizontal">
+ <ResizablePanel
+ order={1}
+ minSize={10}
+ defaultSize={20}
+ className="bg-card"
+ >
+ <ScrollArea className="h-[calc(100vh-99px)]">
+ <div className="grid h-full overflow-hidden p-2">
+ <QuoteExplorer />
+ </div>
+ </ScrollArea>
+ </ResizablePanel>
+ <ResizableHandle withHandle />
+ <ResizablePanel
+ order={2}
+ minSize={40}
+ defaultSize={60}
+ className="border-t border-border"
+ >
+ <ScrollArea className="h-[calc(100vh-99px)]">
+ <Outlet key={JSON.stringify(params)} />
+ </ScrollArea>
+ </ResizablePanel>
+ </ResizablePanelGroup>
+ )}
+ </ClientOnly>
+ </div>
+ </div>
+ </div>
+ </div>
+ );
+}
+
+function QuoteExplorer() {
+ return null;
+}
diff --git a/apps/carbon/app/routes/x+/quote+/_layout.tsx b/apps/carbon/app/routes/x+/quote+/_layout.tsx
index 24228b8da7..fff96b3839 100644
--- a/apps/carbon/app/routes/x+/quote+/_layout.tsx
+++ b/apps/carbon/app/routes/x+/quote+/_layout.tsx
@@ -1,18 +1,27 @@
-import type { MetaFunction } from "@remix-run/node";
-import { Outlet } from "@remix-run/react";
+import type { LoaderFunctionArgs, MetaFunction } from "@remix-run/node";
+import { json, Outlet } from "@remix-run/react";
+import { requirePermissions } from "~/services/auth/auth.server";
import type { Handle } from "~/utils/handle";
import { path } from "~/utils/path";
export const meta: MetaFunction = () => {
- return [{ title: "Carbon | Quotation" }];
+ return [{ title: "Carbon | Quote" }];
};
export const handle: Handle = {
breadcrumb: "Sales",
- to: path.to.quotes,
+ to: path.to.sales,
module: "sales",
};
-export default function QuotationRoute() {
+export async function loader({ request }: LoaderFunctionArgs) {
+ await requirePermissions(request, {
+ view: "sales",
+ });
+
+ return json({});
+}
+
+export default function QuoteRoute() {
return <Outlet />;
}
diff --git a/apps/carbon/app/routes/x+/quote+/$id._index.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/$id._index.tsx
similarity index 100%
rename from apps/carbon/app/routes/x+/quote+/$id._index.tsx
rename to apps/carbon/app/routes/x+/quote-deprecated+/$id._index.tsx
diff --git a/apps/carbon/app/routes/x+/quote+/$id.convert-to-order.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/$id.convert-to-order.tsx
similarity index 100%
rename from apps/carbon/app/routes/x+/quote+/$id.convert-to-order.tsx
rename to apps/carbon/app/routes/x+/quote-deprecated+/$id.convert-to-order.tsx
diff --git a/apps/carbon/app/routes/x+/quote+/$id.details.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/$id.details.tsx
similarity index 100%
rename from apps/carbon/app/routes/x+/quote+/$id.details.tsx
rename to apps/carbon/app/routes/x+/quote-deprecated+/$id.details.tsx
diff --git a/apps/carbon/app/routes/x+/quote+/$id.external.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/$id.external.tsx
similarity index 100%
rename from apps/carbon/app/routes/x+/quote+/$id.external.tsx
rename to apps/carbon/app/routes/x+/quote-deprecated+/$id.external.tsx
diff --git a/apps/carbon/app/routes/x+/quote+/$id.internal.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/$id.internal.tsx
similarity index 100%
rename from apps/carbon/app/routes/x+/quote+/$id.internal.tsx
rename to apps/carbon/app/routes/x+/quote-deprecated+/$id.internal.tsx
diff --git a/apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.assembly.$assemblyId.delete.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.assembly.$assemblyId.delete.tsx
similarity index 100%
rename from apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.assembly.$assemblyId.delete.tsx
rename to apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.assembly.$assemblyId.delete.tsx
diff --git a/apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.assembly.$assemblyId.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.assembly.$assemblyId.tsx
similarity index 100%
rename from apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.assembly.$assemblyId.tsx
rename to apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.assembly.$assemblyId.tsx
diff --git a/apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.assembly.new.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.assembly.new.tsx
similarity index 100%
rename from apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.assembly.new.tsx
rename to apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.assembly.new.tsx
diff --git a/apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.details.delete.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.details.delete.tsx
similarity index 100%
rename from apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.details.delete.tsx
rename to apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.details.delete.tsx
diff --git a/apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.details.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.details.tsx
similarity index 100%
rename from apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.details.tsx
rename to apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.details.tsx
diff --git a/apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.operation.$operationId.delete.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.operation.$operationId.delete.tsx
similarity index 100%
rename from apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.operation.$operationId.delete.tsx
rename to apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.operation.$operationId.delete.tsx
diff --git a/apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.operation.$operationId.material.new.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.operation.$operationId.material.new.tsx
similarity index 100%
rename from apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.operation.$operationId.material.new.tsx
rename to apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.operation.$operationId.material.new.tsx
diff --git a/apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.operation.$operationId.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.operation.$operationId.tsx
similarity index 100%
rename from apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.operation.$operationId.tsx
rename to apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.operation.$operationId.tsx
diff --git a/apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.operation.new.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.operation.new.tsx
similarity index 100%
rename from apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.operation.new.tsx
rename to apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.$lineId.operation.new.tsx
diff --git a/apps/carbon/app/routes/x+/quote+/$id.lines.delete.$lineId.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.delete.$lineId.tsx
similarity index 100%
rename from apps/carbon/app/routes/x+/quote+/$id.lines.delete.$lineId.tsx
rename to apps/carbon/app/routes/x+/quote-deprecated+/$id.lines.delete.$lineId.tsx
diff --git a/apps/carbon/app/routes/x+/quote+/$id.new.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/$id.new.tsx
similarity index 100%
rename from apps/carbon/app/routes/x+/quote+/$id.new.tsx
rename to apps/carbon/app/routes/x+/quote-deprecated+/$id.new.tsx
diff --git a/apps/carbon/app/routes/x+/quote+/$id.release.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/$id.release.tsx
similarity index 100%
rename from apps/carbon/app/routes/x+/quote+/$id.release.tsx
rename to apps/carbon/app/routes/x+/quote-deprecated+/$id.release.tsx
diff --git a/apps/carbon/app/routes/x+/quote+/$id.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/$id.tsx
similarity index 100%
rename from apps/carbon/app/routes/x+/quote+/$id.tsx
rename to apps/carbon/app/routes/x+/quote-deprecated+/$id.tsx
diff --git a/apps/carbon/app/routes/x+/quote-deprecated+/_layout.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/_layout.tsx
new file mode 100644
index 0000000000..24228b8da7
--- /dev/null
+++ b/apps/carbon/app/routes/x+/quote-deprecated+/_layout.tsx
@@ -0,0 +1,18 @@
+import type { MetaFunction } from "@remix-run/node";
+import { Outlet } from "@remix-run/react";
+import type { Handle } from "~/utils/handle";
+import { path } from "~/utils/path";
+
+export const meta: MetaFunction = () => {
+ return [{ title: "Carbon | Quotation" }];
+};
+
+export const handle: Handle = {
+ breadcrumb: "Sales",
+ to: path.to.quotes,
+ module: "sales",
+};
+
+export default function QuotationRoute() {
+ return <Outlet />;
+}
diff --git a/apps/carbon/app/routes/x+/quote+/delete.$id.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/delete.$id.tsx
similarity index 100%
rename from apps/carbon/app/routes/x+/quote+/delete.$id.tsx
rename to apps/carbon/app/routes/x+/quote-deprecated+/delete.$id.tsx
diff --git a/apps/carbon/app/routes/x+/quote+/new.tsx b/apps/carbon/app/routes/x+/quote-deprecated+/new.tsx
similarity index 100%
rename from apps/carbon/app/routes/x+/quote+/new.tsx
rename to apps/carbon/app/routes/x+/quote-deprecated+/new.tsx
diff --git a/apps/carbon/app/routes/x+/sales+/quotes.tsx b/apps/carbon/app/routes/x+/sales+/quotes.tsx
index d43bdc5978..be55aff930 100644
--- a/apps/carbon/app/routes/x+/sales+/quotes.tsx
+++ b/apps/carbon/app/routes/x+/sales+/quotes.tsx
@@ -2,7 +2,7 @@ import { VStack } from "@carbon/react";
import type { LoaderFunctionArgs } from "@remix-run/node";
import { json, redirect } from "@remix-run/node";
import { Outlet, useLoaderData } from "@remix-run/react";
-import { QuotationsTable, getQuotes } from "~/modules/sales";
+import { QuotesTable, getQuotes } from "~/modules/sales";
import { requirePermissions } from "~/services/auth/auth.server";
import { flash } from "~/services/session.server";
import type { Handle } from "~/utils/handle";
@@ -55,7 +55,7 @@ export default function QuotesRoute() {
return (
<VStack spacing={0} className="h-full">
- <QuotationsTable data={quotes} count={count} />
+ <QuotesTable data={quotes} count={count} />
<Outlet />
</VStack>
);
diff --git a/packages/database/supabase/migrations/20240715043906_quote-rls.sql b/packages/database/supabase/migrations/20240715043906_quote-rls.sql
index 21800bc2de..e34956f494 100644
--- a/packages/database/supabase/migrations/20240715043906_quote-rls.sql
+++ b/packages/database/supabase/migrations/20240715043906_quote-rls.sql
@@ -268,8 +268,8 @@ CREATE POLICY "Employees with sales_delete can delete quote materials" ON "quote
CREATE FUNCTION public.create_quotation_search_result()
RETURNS TRIGGER AS $$
BEGIN
- INSERT INTO public.search(name, description, entity, uuid, link, "companyId")
- VALUES (new."quoteId", new.name, 'Quotation', new.id, '/x/quote/' || new.id, new."companyId");
+ INSERT INTO public.search(name, entity, uuid, link, "companyId")
+ VALUES (new."quoteId", 'Quotation', new.id, '/x/quote/' || new.id, new."companyId");
RETURN new;
END;
$$ LANGUAGE plpgsql SECURITY DEFINER;
@@ -281,8 +281,8 @@ CREATE TRIGGER create_quotation_search_result
CREATE OR REPLACE FUNCTION public.update_quotation_search_result()
RETURNS TRIGGER AS $$
BEGIN
- IF (old."quoteId" <> new."quoteId" OR old."name" <> new."name") THEN
- UPDATE public.search SET name = new."quoteId", description = new.name
+ IF (old."quoteId" <> new."quoteId") THEN
+ UPDATE public.search SET name = new."quoteId"
WHERE entity = 'Quotation' AND uuid = new.id AND "companyId" = new."companyId";
END IF;
RETURN new;
diff --git a/packages/documents/src/pdf/QuotePDF.tsx b/packages/documents/src/pdf/QuotePDF.tsx
index fd03a39ae8..2a63bb8ba7 100644
--- a/packages/documents/src/pdf/QuotePDF.tsx
+++ b/packages/documents/src/pdf/QuotePDF.tsx
@@ -1,4 +1,6 @@
import type { Database } from "@carbon/database";
+import type { JSONContent } from "@carbon/react";
+import { generateHTML } from "@carbon/react";
import { getLocalTimeZone, today } from "@internationalized/date";
import { StyleSheet, Text, View } from "@react-pdf/renderer";
@@ -129,7 +131,9 @@ const QuotePDF = ({
<View style={styles.row}>
<View style={styles.colHalf}>
<Text style={styles.label}>Notes</Text>
- <Text>{quote?.notes}</Text>
+ <Text>
+ {generateHTML((quote?.notes ?? {}) as JSONContent, [])}
+ </Text>
</View>
</View>
)}
diff --git a/packages/react/src/index.tsx b/packages/react/src/index.tsx
index 426099a19a..a69a72578e 100644
--- a/packages/react/src/index.tsx
+++ b/packages/react/src/index.tsx
@@ -109,6 +109,7 @@ import { Heading } from "./Heading";
import { HoverCard, HoverCardContent, HoverCardTrigger } from "./HoverCard";
import { RichText, useRichText } from "./RichText";
+import { generateHTML } from "@tiptap/react";
import { IconButton } from "./IconButton";
import type { InputProps } from "./Input";
import {
@@ -447,6 +448,7 @@ export {
VStack,
buttonVariants,
cn,
+ generateHTML,
getValidChildren,
multiSelectTriggerVariants,
reactNodeToString,