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: begin to wire up quote explorer

Brad Barbin07c92eb8c900
diff --git a/apps/carbon/app/modules/documents/ui/Documents/DocumentsTable.tsx b/apps/carbon/app/modules/documents/ui/Documents/DocumentsTable.tsx
index 0afd7a8080..e9518504bc 100644
--- a/apps/carbon/app/modules/documents/ui/Documents/DocumentsTable.tsx
+++ b/apps/carbon/app/modules/documents/ui/Documents/DocumentsTable.tsx
@@ -22,7 +22,7 @@ import { convertKbToString } from "@carbon/utils";
import { useRevalidator } from "@remix-run/react";
import type { ColumnDef } from "@tanstack/react-table";
import { memo, useCallback, useEffect, useMemo, useState } from "react";
-import { BsFillPenFill, BsStar, BsStarFill } from "react-icons/bs";
+import { BsBookmark, BsBookmarkFill, BsFillPenFill } from "react-icons/bs";
import { IoMdAdd, IoMdTrash } from "react-icons/io";
import { RxCheck } from "react-icons/rx";
import { VscOpenPreview } from "react-icons/vsc";
@@ -150,12 +150,12 @@ const DocumentsTable = memo(({ data, count, labels }: DocumentsTableProps) => {
cell: ({ row }) => (
<HStack>
{row.original.favorite ? (
- <BsStarFill
+ <BsBookmarkFill
className="cursor-pointer w-4 h-4 text-yellow-400"
onClick={() => onFavorite(row.original)}
/>
) : (
- <BsStar
+ <BsBookmark
className="cursor-pointer w-4 h-4 text-muted-foreground"
onClick={() => onFavorite(row.original)}
/>
@@ -305,7 +305,7 @@ const DocumentsTable = memo(({ data, count, labels }: DocumentsTableProps) => {
return [
// {
// label: "Add to Favorites",
- // icon: <BsStar />,
+ // icon: <BsBookmark />,
// onClick: (selected: Document[]) => {
// console.log("move to favorites", selected);
// },
@@ -364,7 +364,7 @@ const DocumentsTable = memo(({ data, count, labels }: DocumentsTableProps) => {
onFavorite(row);
}}
>
- <MenuIcon icon={<BsStar />} />
+ <MenuIcon icon={<BsBookmark />} />
Favorite
</MenuItem>
<MenuItem
diff --git a/apps/carbon/app/modules/documents/ui/useDocumentsSubmodules.tsx b/apps/carbon/app/modules/documents/ui/useDocumentsSubmodules.tsx
index e151b77485..b5846dcc15 100644
--- a/apps/carbon/app/modules/documents/ui/useDocumentsSubmodules.tsx
+++ b/apps/carbon/app/modules/documents/ui/useDocumentsSubmodules.tsx
@@ -1,4 +1,4 @@
-import { BsClock, BsFolder, BsFolderPlus, BsStar } from "react-icons/bs";
+import { BsBookmark, BsClock, BsFolder, BsFolderPlus } from "react-icons/bs";
import { IoMdTrash } from "react-icons/io";
import type { Route } from "~/types";
import { path } from "~/utils/path";
@@ -25,7 +25,7 @@ const documentsRoutes: Route[] = [
name: "Starred",
to: path.to.documents,
q: "starred",
- icon: <BsStar />,
+ icon: <BsBookmark />,
},
{
name: "Trash",
diff --git a/apps/carbon/app/modules/purchasing/ui/PurchaseOrders/PurchaseOrdersTable.tsx b/apps/carbon/app/modules/purchasing/ui/PurchaseOrders/PurchaseOrdersTable.tsx
index eec1f2c327..3ae64c5c45 100644
--- a/apps/carbon/app/modules/purchasing/ui/PurchaseOrders/PurchaseOrdersTable.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/PurchaseOrders/PurchaseOrdersTable.tsx
@@ -8,7 +8,7 @@ import {
import { useFetcher, useFetchers } from "@remix-run/react";
import type { ColumnDef } from "@tanstack/react-table";
import { memo, useMemo, useState } from "react";
-import { BsFillPenFill, BsStar, BsStarFill } from "react-icons/bs";
+import { BsBookmark, BsBookmarkFill, BsFillPenFill } from "react-icons/bs";
import { IoMdTrash } from "react-icons/io";
import { MdCallReceived } from "react-icons/md";
import { Avatar, Table } from "~/components";
@@ -70,7 +70,7 @@ const PurchaseOrdersTable = memo(
<input type="hidden" name="id" value={row.original.id!} />
<input type="hidden" name="favorite" value="unfavorite" />
<button type="submit">
- <BsStarFill
+ <BsBookmarkFill
className="text-yellow-400 cursor-pointer h-4 w-4"
type="submit"
/>
@@ -84,7 +84,7 @@ const PurchaseOrdersTable = memo(
<input type="hidden" name="id" value={row.original.id!} />
<input type="hidden" name="favorite" value="favorite" />
<button type="submit">
- <BsStar
+ <BsBookmark
className="text-yellow-400 cursor-pointer h-4 w-4"
type="submit"
/>
diff --git a/apps/carbon/app/modules/purchasing/ui/RequestForQuotes/RequestForQuotesTable.tsx b/apps/carbon/app/modules/purchasing/ui/RequestForQuotes/RequestForQuotesTable.tsx
index 573f65937e..97ff774eff 100644
--- a/apps/carbon/app/modules/purchasing/ui/RequestForQuotes/RequestForQuotesTable.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/RequestForQuotes/RequestForQuotesTable.tsx
@@ -8,7 +8,7 @@ import {
import { useFetcher, useFetchers, useNavigate } from "@remix-run/react";
import type { ColumnDef } from "@tanstack/react-table";
import { memo, useMemo, useState } from "react";
-import { BsFillPenFill, BsStar, BsStarFill } from "react-icons/bs";
+import { BsBookmark, BsBookmarkFill, BsFillPenFill } from "react-icons/bs";
import { IoMdTrash } from "react-icons/io";
import { Avatar, Table } from "~/components";
import { ConfirmDelete } from "~/components/Modals";
@@ -68,7 +68,7 @@ const RequestForQuotesTable = memo(
<input type="hidden" name="id" value={row.original.id!} />
<input type="hidden" name="favorite" value="unfavorite" />
<button type="submit">
- <BsStarFill
+ <BsBookmarkFill
className="text-yellow-400 cursor-pointer h-4 w-4"
type="submit"
/>
@@ -82,7 +82,7 @@ const RequestForQuotesTable = memo(
<input type="hidden" name="id" value={row.original.id!} />
<input type="hidden" name="favorite" value="favorite" />
<button type="submit">
- <BsStar
+ <BsBookmark
className="text-yellow-400 cursor-pointer h-4 w-4"
type="submit"
/>
diff --git a/apps/carbon/app/modules/sales/ui/Quotation/QuotationLineForm.tsx b/apps/carbon/app/modules/sales/ui/Quotation/QuotationLineForm.tsx
index 12c650b4b2..07f9fcd954 100644
--- a/apps/carbon/app/modules/sales/ui/Quotation/QuotationLineForm.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotation/QuotationLineForm.tsx
@@ -34,11 +34,7 @@ import {
import { usePermissions, useRouteData } from "~/hooks";
import { useSupabase } from "~/lib/supabase";
import type { Quotation } from "~/modules/sales";
-import {
- quotationLineValidator,
- quoteLineStatusType,
- useQuotation,
-} from "~/modules/sales";
+import { quotationLineValidator, quoteLineStatusType } from "~/modules/sales";
import type { TypeOfValidator } from "~/types/validators";
import { path } from "~/utils/path";
@@ -51,9 +47,6 @@ const QuotationLineForm = ({ initialValues }: QuotationLineFormProps) => {
const permissions = usePermissions();
const { supabase } = useSupabase();
- const [quote] = useQuotation();
- console.log({ storedQuote: quote });
-
const { id } = useParams();
if (!id) throw new Error("id not found");
diff --git a/apps/carbon/app/modules/sales/ui/Quotation/useQuotation.tsx b/apps/carbon/app/modules/sales/ui/Quotation/useQuotation.tsx
index a051072ed9..26ab7d7695 100644
--- a/apps/carbon/app/modules/sales/ui/Quotation/useQuotation.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotation/useQuotation.tsx
@@ -1,6 +1,8 @@
-import { atom } from "nanostores";
+import { useStore as useValue } from "@nanostores/react";
+import { atom, computed } from "nanostores";
import { useNanoStore } from "~/hooks";
import type {
+ Quotation,
QuotationAssembly,
QuotationLine,
QuotationMaterial,
@@ -8,6 +10,7 @@ import type {
} from "~/modules/sales";
type Quote = {
+ quote?: Quotation;
lines: QuotationLine[];
assemblies: QuotationAssembly[];
operations: QuotationOperation[];
@@ -15,10 +18,31 @@ type Quote = {
};
const $quotationStore = atom<Quote>({
+ quote: undefined,
lines: [],
assemblies: [],
operations: [],
materials: [],
});
+const $quotationMenuStore = computed($quotationStore, (store) => {
+ if (!store.quote) return [];
+ const menu = [
+ {
+ id: store.quote.id,
+ label: store.quote.quoteId,
+ type: "parent",
+ children: store.lines.map((line) => ({
+ id: line.id,
+ label: line.partId,
+ type: "line",
+ meta: line,
+ })),
+ },
+ ];
+
+ return menu;
+});
+
export const useQuotation = () => useNanoStore<Quote>($quotationStore);
+export const useQuotationMenu = () => useValue($quotationMenuStore);
diff --git a/apps/carbon/app/modules/sales/ui/Quotations/QuotationsTable.tsx b/apps/carbon/app/modules/sales/ui/Quotations/QuotationsTable.tsx
index ad1d222b8c..ce0f5aff3d 100644
--- a/apps/carbon/app/modules/sales/ui/Quotations/QuotationsTable.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotations/QuotationsTable.tsx
@@ -8,7 +8,7 @@ import {
import { useFetcher, useFetchers, useNavigate } from "@remix-run/react";
import type { ColumnDef } from "@tanstack/react-table";
import { memo, useMemo, useState } from "react";
-import { BsFillPenFill, BsStar, BsStarFill } from "react-icons/bs";
+import { BsBookmark, BsBookmarkFill, BsFillPenFill } from "react-icons/bs";
import { IoMdTrash } from "react-icons/io";
import { Avatar, Table } from "~/components";
import { ConfirmDelete } from "~/components/Modals";
@@ -62,7 +62,7 @@ const QuotationsTable = memo(({ data, count }: QuotationsTableProps) => {
<input type="hidden" name="id" value={row.original.id!} />
<input type="hidden" name="favorite" value="unfavorite" />
<button type="submit">
- <BsStarFill
+ <BsBookmarkFill
className="text-yellow-400 cursor-pointer h-4 w-4"
type="submit"
/>
@@ -73,7 +73,7 @@ const QuotationsTable = memo(({ data, count }: QuotationsTableProps) => {
<input type="hidden" name="id" value={row.original.id!} />
<input type="hidden" name="favorite" value="favorite" />
<button type="submit">
- <BsStar
+ <BsBookmark
className="text-yellow-400 cursor-pointer h-4 w-4"
type="submit"
/>
diff --git a/apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.operation.$operationId.tsx b/apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.operation.$operationId.tsx
index 6bae7b9d6b..1e25784305 100644
--- a/apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.operation.$operationId.tsx
+++ b/apps/carbon/app/routes/x+/quote+/$id.lines.$lineId.operation.$operationId.tsx
@@ -9,7 +9,6 @@ import {
getQuoteOperation,
quotationOperationValidator,
upsertQuoteOperation,
- useQuotation,
} from "~/modules/sales";
import { requirePermissions } from "~/services/auth";
import { flash } from "~/services/session.server";
@@ -103,8 +102,6 @@ export async function action({ request, params }: ActionFunctionArgs) {
export default function QuoteOperation() {
const { quoteOperation, quoteMaterials } = useLoaderData<typeof loader>();
- const [quote] = useQuotation();
- console.log({ storedQuote: quote });
const initialValues = {
id: quoteOperation.id,
diff --git a/apps/carbon/app/routes/x+/quote+/$id.tsx b/apps/carbon/app/routes/x+/quote+/$id.tsx
index e9b0ee85a8..5de6baa504 100644
--- a/apps/carbon/app/routes/x+/quote+/$id.tsx
+++ b/apps/carbon/app/routes/x+/quote+/$id.tsx
@@ -10,14 +10,16 @@ import {
TooltipContent,
TooltipTrigger,
VStack,
- useMount,
+ cn,
} from "@carbon/react";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@remix-run/node";
import { json, redirect } from "@remix-run/node";
+import type { Params } from "@remix-run/react";
import {
Link,
Outlet,
useLoaderData,
+ useLocation,
useNavigate,
useParams,
} from "@remix-run/react";
@@ -47,6 +49,7 @@ import { AiOutlinePartition } from "react-icons/ai";
import { HiOutlineCube } from "react-icons/hi";
import { LuClock } from "react-icons/lu";
import { RxChevronDown } from "react-icons/rx";
+import { useQuotationMenu } from "~/modules/sales/ui/Quotation/useQuotation";
export const handle: Handle = {
breadcrumb: "Quotations",
@@ -109,6 +112,7 @@ export async function action({ request }: ActionFunctionArgs) {
export default function QuotationRoute() {
const {
+ quotation,
quotationLines,
quotationAssemblies,
quotationMaterials,
@@ -118,6 +122,7 @@ export default function QuotationRoute() {
useEffect(() => {
setQuotation({
+ quote: quotation,
lines: quotationLines,
assemblies: quotationAssemblies,
materials: quotationMaterials,
@@ -129,6 +134,7 @@ export default function QuotationRoute() {
quotationMaterials,
quotationOperations,
setQuotation,
+ quotation,
]);
const navigate = useNavigate();
@@ -204,124 +210,129 @@ type BillOfMaterialNode = {
parentId?: string;
label: string;
type: BillOfMaterialNodeType;
+ meta?: any;
children?: BillOfMaterialNode[];
};
-const data: BillOfMaterialNode[] = [
- {
- id: "0",
- label: "QUO000001",
- type: "parent",
- children: [
- {
- id: "cneklo3nm0lgr74492e0",
- label: "P00001233",
- type: "line",
- children: [
- {
- id: "cneklo3nm0lgr74492e0",
- label: "Assemblies",
- type: "assemblies",
- children: [
- {
- id: "4",
- label: "F5000123",
- type: "assembly",
- children: [
- {
- id: "5",
- label: "Assemblies",
- type: "assemblies",
- children: [],
- },
- {
- id: "6",
- label: "Operations",
- type: "operations",
- children: [
- {
- id: "7",
- label: "OP0003",
- type: "operation",
- children: [
- {
- id: "8",
- label: "Materials",
- type: "materials",
- children: [
- {
- id: "9",
- label: "RAW000001",
- type: "material",
- },
- {
- id: "10",
- label: "FAS000002",
- type: "material",
- },
- ],
- },
- ],
- },
- ],
- },
- ],
- },
- ],
- },
- {
- id: "cneklo3nm0lgr74492e0",
- label: "Operations",
- type: "operations",
- children: [
- {
- id: "12",
- label: "OP0001",
- type: "operation",
- children: [
- {
- id: "13",
- label: "Materials",
- type: "materials",
- children: [
- {
- id: "14",
- label: "RAW000003",
- type: "material",
- },
- ],
- },
- ],
- },
- {
- id: "13",
- label: "OP0002",
- type: "operation",
- children: [
- {
- id: "13",
- label: "Materials",
- type: "materials",
- },
- ],
- },
- ],
- },
- ],
- },
- ],
- },
-];
+// const data: BillOfMaterialNode[] = [
+// {
+// id: "0",
+// label: "QUO000001",
+// type: "parent",
+// children: [
+// {
+// id: "cneklo3nm0lgr74492e0",
+// label: "P00001233",
+// type: "line",
+// children: [
+// {
+// id: "cneklo3nm0lgr74492e0",
+// label: "Assemblies",
+// type: "assemblies",
+// children: [
+// {
+// id: "4",
+// label: "F5000123",
+// type: "assembly",
+// children: [
+// {
+// id: "5",
+// label: "Assemblies",
+// type: "assemblies",
+// children: [],
+// },
+// {
+// id: "6",
+// label: "Operations",
+// type: "operations",
+// children: [
+// {
+// id: "7",
+// label: "OP0003",
+// type: "operation",
+// children: [
+// {
+// id: "8",
+// label: "Materials",
+// type: "materials",
+// children: [
+// {
+// id: "9",
+// label: "RAW000001",
+// type: "material",
+// },
+// {
+// id: "10",
+// label: "FAS000002",
+// type: "material",
+// },
+// ],
+// },
+// ],
+// },
+// ],
+// },
+// ],
+// },
+// ],
+// },
+// {
+// id: "cneklo3nm0lgr74492e0",
+// label: "Operations",
+// type: "operations",
+// children: [
+// {
+// id: "12",
+// label: "OP0001",
+// type: "operation",
+// children: [
+// {
+// id: "13",
+// label: "Materials",
+// type: "materials",
+// children: [
+// {
+// id: "14",
+// label: "RAW000003",
+// type: "material",
+// },
+// ],
+// },
+// ],
+// },
+// {
+// id: "13",
+// label: "OP0002",
+// type: "operation",
+// children: [
+// {
+// id: "13",
+// label: "Materials",
+// type: "materials",
+// },
+// ],
+// },
+// ],
+// },
+// ],
+// },
+// ],
+// },
+// ];
const BillOfMaterialItem = ({
type,
id,
parentId,
label,
-}: Omit<BillOfMaterialNode, "children">) => {
- const { id: quoteId } = useParams();
- if (!quoteId) throw new Error("id not found");
-
+ meta,
+ params,
+ pathname,
+}: Omit<BillOfMaterialNode, "children"> & {
+ params: Params<string>;
+ pathname: string;
+}) => {
+ let isActive = false;
switch (type) {
case "assemblies":
return (
@@ -330,7 +341,7 @@ const BillOfMaterialItem = ({
className="w-full justify-between text-muted-foreground"
asChild
>
- <Link to={path.to.newQuoteAssembly(quoteId, id, parentId)}>
+ <Link to={path.to.newQuoteAssembly(params.id!, id, parentId)}>
<span>{label}</span>
<IoMdAdd />
</Link>
@@ -353,21 +364,34 @@ const BillOfMaterialItem = ({
className="w-full justify-between text-muted-foreground"
asChild
>
- <Link to={path.to.newQuoteOperation(quoteId, id, parentId)}>
+ <Link to={path.to.newQuoteOperation(params.id!, id, parentId)}>
<span>{label}</span>
<IoMdAdd />
</Link>
</Button>
);
case "line":
+ isActive = pathname === path.to.quoteLine(params.id!, id);
+ console.log(meta);
return (
- <Button variant="primary" className="flex-1 justify-between" asChild>
- <Link to={path.to.quoteLine(quoteId, id)} prefetch="intent">
+ <Button
+ variant={isActive ? "primary" : "ghost"}
+ className="flex-1 justify-between"
+ asChild
+ >
+ <Link to={path.to.quoteLine(params.id!, id)} prefetch="intent">
<span className="flex justify-start">
<AiOutlinePartition className="w-4 h-4 mr-2" />
{label}
</span>
- <span className="bg-green-500 rounded-full h-2 w-2 inline-block ml-2" />
+ <span
+ className={cn(
+ "rounded-full h-2 w-2 inline-block ml-2",
+ meta?.status === "Complete" && "bg-green-500",
+ meta?.status === "In Progress" && "bg-orange-500",
+ meta?.status === "Draft" && "bg-zinc-500"
+ )}
+ />
</Link>
</Button>
);
@@ -402,9 +426,14 @@ const BillOfMaterialItem = ({
</Button>
);
case "parent":
+ isActive = pathname === path.to.quoteDetails(id);
return (
- <Button variant="ghost" className="flex-1 justify-start" asChild>
- <Link to={path.to.quote(quoteId)} prefetch="intent">
+ <Button
+ variant={isActive ? "primary" : "ghost"}
+ className="flex-1 justify-start"
+ asChild
+ >
+ <Link to={path.to.quote(params.id!)} prefetch="intent">
{label}
</Link>
</Button>
@@ -415,23 +444,13 @@ const BillOfMaterialItem = ({
};
const BillOfMaterialExplorer = () => {
- const [expandedNodes, setExpandedNodes] = useState<Record<string, boolean>>(
- {}
- );
-
- useMount(() => {
- const map: Record<string, boolean> = {};
- const traverse = (node: BillOfMaterialNode[]) => {
- node.forEach((n) => {
- map[n.id] = true; // open all nodes by default;
- if (n.children) {
- traverse(n.children);
- }
- });
- };
+ const { pathname } = useLocation();
+ const params = useParams();
+ if (!params.id) throw new Error("id not found");
- traverse(data);
- setExpandedNodes(map);
+ const menu = useQuotationMenu() as BillOfMaterialNode[];
+ const [expandedNodes, setExpandedNodes] = useState<Record<string, boolean>>({
+ [params.id]: true,
});
const toggleNode = (id: string) => {
@@ -442,10 +461,10 @@ const BillOfMaterialExplorer = () => {
};
const renderBillOfMaterial = (
- data: BillOfMaterialNode[],
+ menu: BillOfMaterialNode[],
level: number = 0
) => {
- return data.map((node) => {
+ return menu.map((node) => {
return (
<div className="w-full" role="group" key={node.id}>
<HStack
@@ -474,6 +493,9 @@ const BillOfMaterialExplorer = () => {
id={node.id}
label={node.label}
parentId={node.parentId}
+ params={params}
+ pathname={pathname}
+ meta={node.meta}
/>
</HStack>
{node.children &&
@@ -486,7 +508,7 @@ const BillOfMaterialExplorer = () => {
return (
<div className="w-full h-full overflow-auto" role="tree">
- {renderBillOfMaterial(data)}
+ {renderBillOfMaterial(menu)}
</div>
);
};
diff --git a/packages/database/supabase/migrations/20240206224405_quotes.sql b/packages/database/supabase/migrations/20240206224405_quotes.sql
index 30dd2f07e9..35937d5a69 100644
--- a/packages/database/supabase/migrations/20240206224405_quotes.sql
+++ b/packages/database/supabase/migrations/20240206224405_quotes.sql
@@ -106,7 +106,6 @@ CREATE TABLE "quoteLineQuantity" (
CONSTRAINT "quoteLineQuantity_updatedBy_fkey" FOREIGN KEY ("updatedBy") REFERENCES "user" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
-CREATE INDEX "quoteLineQuantity_quoteId_idx" ON "quoteLineQuantity" ("quoteId");
CREATE INDEX "quoteLineQuantity_quoteLineId_idx" ON "quoteLineQuantity" ("quoteLineId");
CREATE TABLE "quoteAssembly" (