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: refactor rfq layout

Brad Barbinb9e9554027af
diff --git a/apps/carbon/app/components/Empty.tsx b/apps/carbon/app/components/Empty.tsx
new file mode 100644
index 0000000000..4c482b46b3
--- /dev/null
+++ b/apps/carbon/app/components/Empty.tsx
@@ -0,0 +1,13 @@
+import { VStack } from "@carbon/react";
+import type { ReactNode } from "react";
+import { LuGhost } from "react-icons/lu";
+
+export default function Empty({ children }: { children: ReactNode }) {
+ return (
+ <VStack className="w-full h-full justify-center items-center">
+ <LuGhost className="w-12 h-12" />
+ <h3 className="text-base">Pretty empty around here</h3>
+ {children}
+ </VStack>
+ );
+}
diff --git a/apps/carbon/app/components/index.ts b/apps/carbon/app/components/index.ts
index 925f7973a4..ed50afccc6 100644
--- a/apps/carbon/app/components/index.ts
+++ b/apps/carbon/app/components/index.ts
@@ -9,6 +9,7 @@ import CustomerAvatar from "./CustomerAvatar";
import DocumentPreview from "./DocumentPreview";
import EmployeeAvatar from "./EmployeeAvatar";
import EmployeeAvatarGroup from "./EmployeeAvatarGroup";
+import Empty from "./Empty";
import Hyperlink from "./Hyperlink";
import MultiSelect from "./MultiSelect";
import New from "./New";
@@ -31,6 +32,7 @@ export {
DocumentPreview,
EmployeeAvatar,
EmployeeAvatarGroup,
+ Empty,
Hyperlink,
MultiSelect,
New,
diff --git a/apps/carbon/app/modules/items/ui/Item/BillOfProcess.tsx b/apps/carbon/app/modules/items/ui/Item/BillOfProcess.tsx
index 95e9f8ae8f..2488241d22 100644
--- a/apps/carbon/app/modules/items/ui/Item/BillOfProcess.tsx
+++ b/apps/carbon/app/modules/items/ui/Item/BillOfProcess.tsx
@@ -18,6 +18,7 @@ import { ValidatedForm } from "@carbon/remix-validated-form";
import { getLocalTimeZone, today } from "@internationalized/date";
import { useFetcher } from "@remix-run/react";
import { AnimatePresence, LayoutGroup, motion } from "framer-motion";
+import { nanoid } from "nanoid";
import type { Dispatch, SetStateAction } from "react";
import { useCallback, useEffect, useState } from "react";
import { flushSync } from "react-dom";
@@ -234,9 +235,8 @@ const BillOfProcess = ({ makeMethodId, operations }: BillOfProcessProps) => {
}, 3000);
const onUploadImage = async (file: File) => {
- const fileName = `${companyId}/parts/${selectedItemId}/${Math.random()
- .toString(16)
- .slice(2)}-${file.name}`;
+ const fileType = file.name.split(".").pop();
+ const fileName = `${companyId}/parts/${selectedItemId}/${nanoid()}.${fileType}`;
const result = await supabase?.storage
.from("private")
.upload(fileName, file);
diff --git a/apps/carbon/app/modules/sales/sales.service.ts b/apps/carbon/app/modules/sales/sales.service.ts
index c39394bb10..87fe2bb3dd 100644
--- a/apps/carbon/app/modules/sales/sales.service.ts
+++ b/apps/carbon/app/modules/sales/sales.service.ts
@@ -1,6 +1,5 @@
import type { Database, Json } from "@carbon/database";
import { getLocalTimeZone, today } from "@internationalized/date";
-import type { FileObject } from "@supabase/storage-js";
import type { PostgrestError, SupabaseClient } from "@supabase/supabase-js";
import type { z } from "zod";
import { getEmployeeJob } from "~/modules/resources";
@@ -390,45 +389,23 @@ export async function getCustomerTypesList(
.order("name");
}
-export async function getFilesByRfqId(
+export async function getSalesRFQDocuments(
+ client: SupabaseClient<Database>,
+ companyId: string,
+ rfqId: string
+) {
+ return client.storage.from("private").list(`${companyId}/sales-rfq/${rfqId}`);
+}
+
+export async function getSalesRfqLineDocuments(
client: SupabaseClient<Database>,
rfqId: string,
+ lineId: string,
companyId: string
) {
- const lines = await client
- .from("salesRfqLine")
- .select("id")
- .eq("salesRfqId", rfqId);
- if (lines.error) {
- return lines;
- }
- const lineIds = lines.data?.map((line) => line.id);
- const fileQueries = lineIds.map((lineId) =>
- client.storage
- .from("private")
- .list(`${companyId}/sales-rfq/${rfqId}/${lineId}`)
- );
- const files = await Promise.all([...fileQueries]);
-
- return {
- data: {
- files: files.reduce<(FileObject & { salesRfqLineId: string | null })[]>(
- (acc, file, index) => {
- if (file.data) {
- return [
- ...acc,
- ...file.data?.map((f) => ({
- ...f,
- salesRfqLineId: lineIds[index],
- })),
- ];
- }
- return acc;
- },
- []
- ),
- },
- };
+ return client.storage
+ .from("private")
+ .list(`${companyId}/sales-rfq/${rfqId}/${lineId}`);
}
export async function getFilesByQuoteLineId(
diff --git a/apps/carbon/app/modules/sales/types.ts b/apps/carbon/app/modules/sales/types.ts
index ab6d765639..49630f0e1d 100644
--- a/apps/carbon/app/modules/sales/types.ts
+++ b/apps/carbon/app/modules/sales/types.ts
@@ -1,9 +1,5 @@
import type { Database } from "@carbon/database";
-import type { JSONContent } from "@carbon/react";
-import type { z } from "zod";
-import type { ModelUpload } from "../items/types";
import type { QuantityEffect } from "../shared";
-import type { salesRfqLineValidator } from "./sales.models";
import type {
getCustomer,
getCustomerContacts,
@@ -22,6 +18,7 @@ import type {
getSalesOrderExternalDocuments,
getSalesOrderLines,
getSalesOrders,
+ getSalesRFQLines,
getSalesRFQs,
} from "./sales.service";
@@ -135,9 +132,8 @@ export type SalesRFQ = NonNullable<
Awaited<ReturnType<typeof getSalesRFQs>>["data"]
>[number];
-export type SalesRFQLine = z.infer<typeof salesRfqLineValidator> & {
- internalNotes: JSONContent;
- externalNotes: JSONContent;
-} & ModelUpload;
+export type SalesRFQLine = NonNullable<
+ Awaited<ReturnType<typeof getSalesRFQLines>>["data"]
+>[number];
export type SalesRFQStatus = Database["public"]["Enums"]["salesRfqStatus"];
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteExplorer.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteExplorer.tsx
new file mode 100644
index 0000000000..2bf529f8ce
--- /dev/null
+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteExplorer.tsx
@@ -0,0 +1,265 @@
+import {
+ Button,
+ cn,
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuTrigger,
+ HStack,
+ IconButton,
+ Kbd,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+ useDisclosure,
+ useKeyboardShortcuts,
+ useMount,
+ VStack,
+} from "@carbon/react";
+import { prettifyKeyboardShortcut } from "@carbon/utils";
+import { useNavigate, useParams } from "@remix-run/react";
+import { useRef, useState } from "react";
+import { LuChevronsUpDown, LuImage, LuPlus } from "react-icons/lu";
+import { MdMoreVert } from "react-icons/md";
+import { Empty } from "~/components";
+import type { Tree } from "~/components/TreeView";
+import { flattenTree } from "~/components/TreeView";
+import {
+ useOptimisticLocation,
+ usePermissions,
+ useRouteData,
+ useUser,
+} from "~/hooks";
+import { path } from "~/utils/path";
+import type { QuotationLine, QuoteMethod } from "../../types";
+import DeleteQuoteLine from "./DeleteQuoteLine";
+import QuoteBoMExplorer from "./QuoteBoMExplorer";
+import QuoteLineForm from "./QuoteLineForm";
+
+export default function QuoteExplorer() {
+ const { quoteId } = useParams();
+ if (!quoteId) throw new Error("Could not find quoteId");
+ const quoteData = useRouteData<{ lines: QuotationLine[] }>(
+ path.to.quote(quoteId)
+ );
+ const permissions = usePermissions();
+ const { id: userId } = useUser();
+ const quoteLineInitialValues = {
+ quoteId,
+ description: "",
+ estimatorId: userId,
+ itemId: "",
+ itemReadableId: "",
+ methodType: "Make" as const,
+ status: "Draft" as const,
+ quantity: [1],
+ unitOfMeasureCode: "",
+ };
+
+ const newQuoteLineDisclosure = useDisclosure();
+ const deleteLineDisclosure = useDisclosure();
+ const [deleteLine, setDeleteLine] = useState<QuotationLine | null>(null);
+
+ const onDeleteLine = (line: QuotationLine) => {
+ setDeleteLine(line);
+ deleteLineDisclosure.onOpen();
+ };
+
+ const onDeleteCancel = () => {
+ setDeleteLine(null);
+ deleteLineDisclosure.onClose();
+ };
+
+ const newButtonRef = useRef<HTMLButtonElement>(null);
+ useKeyboardShortcuts({
+ "Command+Shift+l": (event: KeyboardEvent) => {
+ event.stopPropagation();
+ newButtonRef.current?.click();
+ },
+ });
+
+ return (
+ <>
+ <VStack className="w-full h-[calc(100vh-99px)] justify-between">
+ <VStack className="flex-1 overflow-y-auto" spacing={0}>
+ {quoteData?.lines && quoteData?.lines?.length > 0 ? (
+ quoteData?.lines.map((line) => (
+ <QuoteLineItem
+ key={line.id}
+ line={line}
+ onDelete={onDeleteLine}
+ />
+ ))
+ ) : (
+ <Empty>
+ {permissions.can("update", "sales") && (
+ <Button
+ leftIcon={<LuPlus />}
+ onClick={newQuoteLineDisclosure.onOpen}
+ >
+ Add Line Item
+ </Button>
+ )}
+ </Empty>
+ )}
+ </VStack>
+ <div className="w-full flex flex-0 sm:flex-row border-t border-border p-4 sm:justify-start sm:space-x-2">
+ <Tooltip>
+ <TooltipTrigger className="w-full">
+ <Button
+ ref={newButtonRef}
+ className="w-full"
+ isDisabled={!permissions.can("update", "sales")}
+ leftIcon={<LuPlus />}
+ onClick={newQuoteLineDisclosure.onOpen}
+ >
+ Add Line Item
+ </Button>
+ </TooltipTrigger>
+ <TooltipContent>
+ <HStack>
+ <span>New Line Item</span>
+ <Kbd>{prettifyKeyboardShortcut("Command+Shift+l")}</Kbd>
+ </HStack>
+ </TooltipContent>
+ </Tooltip>
+ </div>
+ </VStack>
+ {newQuoteLineDisclosure.isOpen && (
+ <QuoteLineForm
+ initialValues={quoteLineInitialValues}
+ type="modal"
+ onClose={newQuoteLineDisclosure.onClose}
+ />
+ )}
+ {deleteLineDisclosure.isOpen && (
+ <DeleteQuoteLine line={deleteLine!} onCancel={onDeleteCancel} />
+ )}
+ </>
+ );
+}
+
+type QuoteLineItemProps = {
+ line: QuotationLine;
+ onDelete: (line: QuotationLine) => void;
+};
+
+function QuoteLineItem({ line, onDelete }: QuoteLineItemProps) {
+ const { quoteId, lineId } = useParams();
+ if (!quoteId) throw new Error("Could not find quoteId");
+ const permissions = usePermissions();
+ const navigate = useNavigate();
+ const disclosure = useDisclosure();
+ const location = useOptimisticLocation();
+
+ useMount(() => {
+ if (lineId === line.id) {
+ disclosure.onOpen();
+ }
+ });
+
+ const quoteData = useRouteData<{ methods: Tree<QuoteMethod>[] }>(
+ path.to.quote(quoteId)
+ );
+
+ const methodTree = quoteData?.methods?.find(
+ (m) => m.data.quoteLineId === line.id
+ );
+ const methods = methodTree ? flattenTree(methodTree) : [];
+
+ const isSelected = lineId === line.id;
+ const onLineClick = (line: QuotationLine) => {
+ if (line.methodType === "Make") {
+ disclosure.onOpen();
+ }
+
+ if (location.pathname !== path.to.quoteLine(quoteId, line.id!)) {
+ // navigate to line
+ navigate(path.to.quoteLine(quoteId, line.id!));
+ }
+ };
+
+ return (
+ <VStack spacing={0}>
+ <HStack
+ className={cn(
+ "w-full p-2 items-center justify-between hover:bg-accent/30 cursor-pointer",
+ !disclosure.isOpen && "border-b border-border",
+ isSelected && "bg-accent/60 hover:bg-accent/50 shadow-inner"
+ )}
+ onClick={() => onLineClick(line)}
+ >
+ <HStack spacing={2}>
+ {line.thumbnailPath ? (
+ <img
+ alt="P2392303"
+ className={cn(
+ "w-10 h-10 bg-gradient-to-bl from-muted to-muted/40 rounded-lg border-2 border-transparent",
+ line.status === "Complete" && "border-green-500",
+ line.status === "In Progress" && "border-yellow-500"
+ )}
+ src={`/file/preview/private/${line.thumbnailPath}`}
+ />
+ ) : (
+ <div
+ className={cn(
+ "w-10 h-10 bg-gradient-to-bl from-muted to-muted/40 rounded-lg border-2 border-transparent p-2",
+ line.status === "Complete" && "border-green-500",
+ line.status === "In Progress" && "border-yellow-500"
+ )}
+ >
+ <LuImage className="w-6 h-6 text-muted-foreground" />
+ </div>
+ )}
+
+ <VStack spacing={0}>
+ <span className="font-semibold">{line.itemReadableId}</span>
+ <span className="font-mono text-muted-foreground text-xs">
+ {line.customerPartId}
+ {line.customerPartRevision && ` (${line.customerPartRevision})`}
+ </span>
+ </VStack>
+ </HStack>
+ <HStack spacing={0}>
+ {line.methodType === "Make" && permissions.can("update", "sales") && (
+ <IconButton
+ aria-label={disclosure.isOpen ? "Hide" : "Show"}
+ icon={<LuChevronsUpDown />}
+ variant="ghost"
+ onClick={(e) => {
+ e.stopPropagation();
+ disclosure.onToggle();
+ }}
+ />
+ )}
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <IconButton
+ aria-label="More"
+ icon={<MdMoreVert />}
+ variant="ghost"
+ onClick={(e) => e.stopPropagation()}
+ />
+ </DropdownMenuTrigger>
+ <DropdownMenuContent>
+ <DropdownMenuItem
+ disabled={!permissions.can("update", "sales")}
+ onClick={(e) => {
+ e.stopPropagation();
+ onDelete(line);
+ }}
+ >
+ Delete Line
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </HStack>
+ </HStack>
+ {disclosure.isOpen && permissions.can("update", "sales") && (
+ <VStack className="border-b border-border">
+ <QuoteBoMExplorer methods={methods} />
+ </VStack>
+ )}
+ </VStack>
+ );
+}
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineNotes.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineNotes.tsx
index 0f4bb1b0b5..f6697f5bc4 100644
--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineNotes.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteLineNotes.tsx
@@ -10,6 +10,7 @@ import {
useDebounce,
} from "@carbon/react";
import { getLocalTimeZone, today } from "@internationalized/date";
+import { nanoid } from "nanoid";
import { usePermissions, useUser } from "~/hooks";
import { useSupabase } from "~/lib/supabase";
import type { QuotationLine } from "~/modules/sales";
@@ -23,9 +24,10 @@ const QuoteLineNotes = ({ line }: { line: QuotationLine }) => {
const { supabase } = useSupabase();
const onUploadImage = async (file: File) => {
- const fileName = `${companyId}/quote-line/${line.id}/${encodeURIComponent(
- file.name
- )}`;
+ const fileType = file.name.split(".").pop();
+ const fileName = `${companyId}/quote-line/${
+ line.id
+ }/${nanoid()}.${fileType}`;
const result = await supabase?.storage
.from("private")
.upload(fileName, file);
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/index.ts b/apps/carbon/app/modules/sales/ui/Quotes/index.ts
index 966fcaecd3..a5202d0fb4 100644
--- a/apps/carbon/app/modules/sales/ui/Quotes/index.ts
+++ b/apps/carbon/app/modules/sales/ui/Quotes/index.ts
@@ -4,6 +4,7 @@ import QuoteBillOfProcess from "./QuoteBillOfProcess";
import QuoteBoMExplorer from "./QuoteBoMExplorer";
import QuoteBreadcrumbs from "./QuoteBreadcrumbs";
import QuoteDocuments from "./QuoteDocuments";
+import QuoteExplorer from "./QuoteExplorer";
import QuoteForm from "./QuoteForm";
import QuoteHeader from "./QuoteHeader";
import QuoteLineCosting from "./QuoteLineCosting";
@@ -22,6 +23,7 @@ export {
QuoteBoMExplorer,
QuoteBreadcrumbs,
QuoteDocuments,
+ QuoteExplorer,
QuoteForm,
QuoteHeader,
QuoteLineCosting,
diff --git a/apps/carbon/app/modules/sales/ui/SalesRFQ/DeleteSalesRFQLine.tsx b/apps/carbon/app/modules/sales/ui/SalesRFQ/DeleteSalesRFQLine.tsx
new file mode 100644
index 0000000000..6c3a1c7aec
--- /dev/null
+++ b/apps/carbon/app/modules/sales/ui/SalesRFQ/DeleteSalesRFQLine.tsx
@@ -0,0 +1,26 @@
+import { useParams } from "@remix-run/react";
+import { ConfirmDelete } from "~/components/Modals";
+import { path } from "~/utils/path";
+import type { SalesRFQLine } from "../../types";
+
+export default function DeleteSalesRFQLine({
+ line,
+ onCancel,
+}: {
+ line: SalesRFQLine;
+ onCancel: () => void;
+}) {
+ const { rfqId } = useParams();
+ if (!rfqId) throw new Error("id not found");
+ if (!line.id) return null;
+
+ return (
+ <ConfirmDelete
+ action={path.to.deleteSalesRfqLine(rfqId, line.id)}
+ name={line.customerPartId ?? "this line"}
+ text={`Are you sure you want to delete the line: ${line.customerPartId}? This cannot be undone.`}
+ onCancel={onCancel}
+ onSubmit={onCancel}
+ />
+ );
+}
diff --git a/apps/carbon/app/modules/sales/ui/SalesRFQ/SalesRFQBreadcrumbs.tsx b/apps/carbon/app/modules/sales/ui/SalesRFQ/SalesRFQBreadcrumbs.tsx
new file mode 100644
index 0000000000..92e1b39115
--- /dev/null
+++ b/apps/carbon/app/modules/sales/ui/SalesRFQ/SalesRFQBreadcrumbs.tsx
@@ -0,0 +1,48 @@
+import { Button, HStack, Menubar } from "@carbon/react";
+import { Link, useParams } from "@remix-run/react";
+import { RiProgress4Line } from "react-icons/ri";
+import { BreadcrumbItem, Breadcrumbs } from "~/components";
+import { useRouteData } from "~/hooks";
+import { path } from "~/utils/path";
+import type { SalesRFQ, SalesRFQLine } from "../../types";
+
+const SalesRFQBreadcrumbs = () => {
+ const { rfqId, lineId } = useParams();
+ if (!rfqId) throw new Error("rfqId not found");
+
+ const routeData = useRouteData<{
+ rfqSummary: SalesRFQ;
+ lines: SalesRFQLine[];
+ }>(path.to.salesRfq(rfqId));
+
+ const line = routeData?.lines.find((line) => line.id === lineId);
+
+ return (
+ <>
+ <Menubar>
+ <HStack className="w-full justify-start">
+ <Breadcrumbs>
+ <BreadcrumbItem>
+ <Button leftIcon={<RiProgress4Line />} variant="ghost" asChild>
+ <Link to={path.to.salesRfqDetails(rfqId)}>
+ {routeData?.rfqSummary?.rfqId}
+ </Link>
+ </Button>
+ </BreadcrumbItem>
+ {line && (
+ <BreadcrumbItem>
+ <Button variant="ghost" asChild>
+ <Link to={path.to.salesRfqLine(rfqId, line.id!)}>
+ {line.itemReadableId}
+ </Link>
+ </Button>
+ </BreadcrumbItem>
+ )}
+ </Breadcrumbs>
+ </HStack>
+ </Menubar>
+ </>
+ );
+};
+
+export default SalesRFQBreadcrumbs;
diff --git a/apps/carbon/app/modules/sales/ui/SalesRFQ/SalesRFQExplorer.tsx b/apps/carbon/app/modules/sales/ui/SalesRFQ/SalesRFQExplorer.tsx
new file mode 100644
index 0000000000..8e36b784ff
--- /dev/null
+++ b/apps/carbon/app/modules/sales/ui/SalesRFQ/SalesRFQExplorer.tsx
@@ -0,0 +1,200 @@
+import {
+ Button,
+ cn,
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuTrigger,
+ HStack,
+ IconButton,
+ Kbd,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+ useDisclosure,
+ useKeyboardShortcuts,
+ VStack,
+} from "@carbon/react";
+import { prettifyKeyboardShortcut } from "@carbon/utils";
+import { useNavigate, useParams } from "@remix-run/react";
+import { useRef, useState } from "react";
+import { LuImage, LuPlus } from "react-icons/lu";
+import { MdMoreVert } from "react-icons/md";
+import { Empty } from "~/components";
+import { useOptimisticLocation, usePermissions, useRouteData } from "~/hooks";
+import { path } from "~/utils/path";
+import type { SalesRFQLine } from "../../types";
+import DeleteSalesRFQLine from "./DeleteSalesRFQLine";
+// import NewSalesRFQLinesForm from "./NewSalesRFQLinesForm";
+
+export default function SalesRFQExplorer() {
+ const { rfqId } = useParams();
+ if (!rfqId) throw new Error("Could not find rfqId");
+ const salesRfqData = useRouteData<{ lines: SalesRFQLine[] }>(
+ path.to.salesRfq(rfqId)
+ );
+ const permissions = usePermissions();
+
+ const newSalesRFQLineDisclosure = useDisclosure();
+ const deleteLineDisclosure = useDisclosure();
+ const [deleteLine, setDeleteLine] = useState<SalesRFQLine | null>(null);
+
+ const onDeleteLine = (line: SalesRFQLine) => {
+ setDeleteLine(line);
+ deleteLineDisclosure.onOpen();
+ };
+
+ const onDeleteCancel = () => {
+ setDeleteLine(null);
+ deleteLineDisclosure.onClose();
+ };
+
+ const newButtonRef = useRef<HTMLButtonElement>(null);
+ useKeyboardShortcuts({
+ "Command+Shift+l": (event: KeyboardEvent) => {
+ event.stopPropagation();
+ newButtonRef.current?.click();
+ },
+ });
+
+ return (
+ <>
+ <VStack className="w-full h-[calc(100vh-99px)] justify-between">
+ <VStack className="flex-1 overflow-y-auto" spacing={0}>
+ {salesRfqData?.lines && salesRfqData?.lines?.length > 0 ? (
+ salesRfqData?.lines.map((line) => (
+ <SalesRFQLineItem
+ key={line.id}
+ line={line}
+ onDelete={onDeleteLine}
+ />
+ ))
+ ) : (
+ <Empty>
+ {permissions.can("update", "sales") && (
+ <Button
+ leftIcon={<LuPlus />}
+ onClick={newSalesRFQLineDisclosure.onOpen}
+ >
+ Add Line Item
+ </Button>
+ )}
+ </Empty>
+ )}
+ </VStack>
+ <div className="w-full flex flex-0 sm:flex-row border-t border-border p-4 sm:justify-start sm:space-x-2">
+ <Tooltip>
+ <TooltipTrigger className="w-full">
+ <Button
+ ref={newButtonRef}
+ className="w-full"
+ isDisabled={!permissions.can("update", "sales")}
+ leftIcon={<LuPlus />}
+ onClick={newSalesRFQLineDisclosure.onOpen}
+ >
+ Add Line Item
+ </Button>
+ </TooltipTrigger>
+ <TooltipContent>
+ <HStack>
+ <span>New Line Item</span>
+ <Kbd>{prettifyKeyboardShortcut("Command+Shift+l")}</Kbd>
+ </HStack>
+ </TooltipContent>
+ </Tooltip>
+ </div>
+ </VStack>
+ {/* {newSalesRFQLineDisclosure.isOpen && (
+ <NewSalesRFQLinesForm
+ rfqId={rfqId}
+ onClose={newSalesRFQLineDisclosure.onClose}
+ />
+ )} */}
+ {deleteLineDisclosure.isOpen && (
+ <DeleteSalesRFQLine line={deleteLine!} onCancel={onDeleteCancel} />
+ )}
+ </>
+ );
+}
+
+type SalesRFQLineItemProps = {
+ line: SalesRFQLine;
+ onDelete: (line: SalesRFQLine) => void;
+};
+
+function SalesRFQLineItem({ line, onDelete }: SalesRFQLineItemProps) {
+ const { rfqId, lineId } = useParams();
+ if (!rfqId) throw new Error("Could not find rfqId");
+ const permissions = usePermissions();
+ const navigate = useNavigate();
+
+ const location = useOptimisticLocation();
+
+ const isSelected = lineId === line.id;
+ const onLineClick = (line: SalesRFQLine) => {
+ if (location.pathname !== path.to.salesRfqLine(rfqId, line.id!)) {
+ // navigate to line
+ navigate(path.to.salesRfqLine(rfqId, line.id!));
+ }
+ };
+
+ return (
+ <VStack spacing={0} className="border-b border-border">
+ <HStack
+ className={cn(
+ "w-full p-2 items-center justify-between hover:bg-accent/30 cursor-pointer",
+ isSelected && "bg-accent/60 hover:bg-accent/50 shadow-inner"
+ )}
+ onClick={() => onLineClick(line)}
+ >
+ <HStack spacing={2}>
+ {line.thumbnailPath ? (
+ <img
+ alt="P2392303"
+ className="w-10 h-10 bg-gradient-to-bl from-muted to-muted/40 rounded-lg border-2 border-transparent"
+ src={`/file/preview/private/${line.thumbnailPath}`}
+ />
+ ) : (
+ <div className="w-10 h-10 bg-gradient-to-bl from-muted to-muted/40 rounded-lg border-2 border-transparent p-2">
+ <LuImage className="w-6 h-6 text-muted-foreground" />
+ </div>
+ )}
+
+ <VStack spacing={0}>
+ <span className="font-semibold">
+ {" "}
+ {line.customerPartId}
+ {line.customerPartRevision && ` (${line.customerPartRevision})`}
+ </span>
+ <span className="font-mono text-muted-foreground text-xs">
+ {line.itemReadableId}
+ </span>
+ </VStack>
+ </HStack>
+ <HStack spacing={0}>
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <IconButton
+ aria-label="More"
+ icon={<MdMoreVert />}
+ variant="ghost"
+ onClick={(e) => e.stopPropagation()}
+ />
+ </DropdownMenuTrigger>
+ <DropdownMenuContent>
+ <DropdownMenuItem
+ disabled={!permissions.can("update", "sales")}
+ onClick={(e) => {
+ e.stopPropagation();
+ onDelete(line);
+ }}
+ >
+ Delete Line
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </HStack>
+ </HStack>
+ </VStack>
+ );
+}
diff --git a/apps/carbon/app/modules/sales/ui/SalesRFQ/SalesRFQLines.tsx b/apps/carbon/app/modules/sales/ui/SalesRFQ/SalesRFQLines.tsx
index 580049664e..edce820f90 100644
--- a/apps/carbon/app/modules/sales/ui/SalesRFQ/SalesRFQLines.tsx
+++ b/apps/carbon/app/modules/sales/ui/SalesRFQ/SalesRFQLines.tsx
@@ -104,7 +104,7 @@ function makeItem(
checked: false,
details: (
<HStack spacing={2}>
- {line.quantity.map((q, i) => (
+ {line.quantity?.map((q, i) => (
<Badge key={i} variant="secondary">
{q}
</Badge>
@@ -273,9 +273,8 @@ const SalesRFQLines = ({ lines, files }: SalesRFQLinesProps) => {
}, []);
const onUploadImage = async (file: File) => {
- const fileName = `${companyId}/sales-rfqs/${selectedLineId}:${Math.random()
- .toString(16)
- .slice(2)}-${file.name}`;
+ const fileType = file.name.split(".").pop();
+ const fileName = `${companyId}/sales-rfqs/${selectedLineId}:${nanoid()}.${fileType}`;
const result = await supabase?.storage
.from("private")
.upload(fileName, file);
diff --git a/apps/carbon/app/modules/sales/ui/SalesRFQs/SalesRFQsTable.tsx b/apps/carbon/app/modules/sales/ui/SalesRFQ/SalesRFQsTable.tsx
similarity index 99%
rename from apps/carbon/app/modules/sales/ui/SalesRFQs/SalesRFQsTable.tsx
rename to apps/carbon/app/modules/sales/ui/SalesRFQ/SalesRFQsTable.tsx
index 2c4951921b..758bdda6f6 100644
--- a/apps/carbon/app/modules/sales/ui/SalesRFQs/SalesRFQsTable.tsx
+++ b/apps/carbon/app/modules/sales/ui/SalesRFQ/SalesRFQsTable.tsx
@@ -25,7 +25,7 @@ import { salesRFQStatusType } from "~/modules/sales";
import { useCustomers, usePeople } from "~/stores";
import { favoriteSchema } from "~/types/validators";
import { path } from "~/utils/path";
-import { SalesRFQStatus } from "../SalesRFQ";
+import { SalesRFQStatus } from ".";
type SalesRFQsTableProps = {
data: SalesRFQ[];
diff --git a/apps/carbon/app/modules/sales/ui/SalesRFQ/index.ts b/apps/carbon/app/modules/sales/ui/SalesRFQ/index.ts
index 3871dfb524..996d7dfc91 100644
--- a/apps/carbon/app/modules/sales/ui/SalesRFQ/index.ts
+++ b/apps/carbon/app/modules/sales/ui/SalesRFQ/index.ts
@@ -1,13 +1,19 @@
+import SalesRFQBreadcrumbs from "./SalesRFQBreadcrumbs";
+import SalesRFQExplorer from "./SalesRFQExplorer";
import SalesRFQForm from "./SalesRFQForm";
import SalesRFQHeader from "./SalesRFQHeader";
import SalesRFQLines from "./SalesRFQLines";
import SalesRFQProperties from "./SalesRFQProperties";
import SalesRFQStatus from "./SalesRFQStatus";
+import SalesRFQsTable from "./SalesRFQsTable";
export {
+ SalesRFQBreadcrumbs,
+ SalesRFQExplorer,
SalesRFQForm,
SalesRFQHeader,
SalesRFQLines,
SalesRFQProperties,
SalesRFQStatus,
+ SalesRFQsTable,
};
diff --git a/apps/carbon/app/modules/sales/ui/SalesRFQs/index.ts b/apps/carbon/app/modules/sales/ui/SalesRFQs/index.ts
deleted file mode 100644
index 56b354b743..0000000000
--- a/apps/carbon/app/modules/sales/ui/SalesRFQs/index.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-import SalesRFQsTable from "./SalesRFQsTable";
-
-export { SalesRFQsTable };
diff --git a/apps/carbon/app/modules/sales/ui/index.ts b/apps/carbon/app/modules/sales/ui/index.ts
index 04f82d5932..1b34d73a12 100644
--- a/apps/carbon/app/modules/sales/ui/index.ts
+++ b/apps/carbon/app/modules/sales/ui/index.ts
@@ -7,5 +7,4 @@ export * from "./Quotes";
export * from "./SalesOrder";
export * from "./SalesOrders";
export * from "./SalesRFQ";
-export * from "./SalesRFQs";
export { useSalesSubmodules };
diff --git a/apps/carbon/app/routes/x+/quote+/$quoteId.details.tsx b/apps/carbon/app/routes/x+/quote+/$quoteId.details.tsx
index a556ebbf73..c63f114a72 100644
--- a/apps/carbon/app/routes/x+/quote+/$quoteId.details.tsx
+++ b/apps/carbon/app/routes/x+/quote+/$quoteId.details.tsx
@@ -15,6 +15,7 @@ import type { ActionFunctionArgs } from "@remix-run/node";
import { redirect } from "@remix-run/node";
import { useParams } from "@remix-run/react";
import type { FileObject } from "@supabase/storage-js";
+import { nanoid } from "nanoid";
import { usePermissions, useRouteData, useUser } from "~/hooks";
import { useSupabase } from "~/lib/supabase";
import type { Quotation } from "~/modules/sales";
@@ -112,9 +113,8 @@ const QuoteNotes = ({ quote }: { quote: Quotation }) => {
const permissions = usePermissions();
const onUploadImage = async (file: File) => {
- const fileName = `${companyId}/quote/${quote.id}/${encodeURIComponent(
- file.name
- )}`;
+ const fileType = file.name.split(".").pop();
+ const fileName = `${companyId}/quote/${quote.id}/${nanoid()}.${fileType}`;
const result = await supabase?.storage
.from("private")
.upload(fileName, file);
diff --git a/apps/carbon/app/routes/x+/quote+/$quoteId.tsx b/apps/carbon/app/routes/x+/quote+/$quoteId.tsx
index b41c91dd85..fbf44ed4a3 100644
--- a/apps/carbon/app/routes/x+/quote+/$quoteId.tsx
+++ b/apps/carbon/app/routes/x+/quote+/$quoteId.tsx
@@ -1,52 +1,22 @@
import {
- Button,
ClientOnly,
- cn,
- DropdownMenu,
- DropdownMenuContent,
- DropdownMenuItem,
- DropdownMenuTrigger,
- HStack,
- IconButton,
- Kbd,
ResizableHandle,
ResizablePanel,
ResizablePanelGroup,
ScrollArea,
- Tooltip,
- TooltipContent,
- TooltipTrigger,
- useDisclosure,
- useKeyboardShortcuts,
- useMount,
VStack,
} from "@carbon/react";
-import { prettifyKeyboardShortcut } from "@carbon/utils";
import type { LoaderFunctionArgs } from "@remix-run/node";
import { json, redirect } from "@remix-run/node";
-import { Outlet, useNavigate, useParams } from "@remix-run/react";
-import { useRef, useState } from "react";
-import { LuChevronsUpDown, LuGhost, LuImage, LuPlus } from "react-icons/lu";
-import { MdMoreVert } from "react-icons/md";
-import type { Tree } from "~/components/TreeView";
-import { flattenTree } from "~/components/TreeView";
+import { Outlet, useParams } from "@remix-run/react";
import {
- useOptimisticLocation,
- usePermissions,
- useRouteData,
- useUser,
-} from "~/hooks";
-import type { QuotationLine, QuoteMethod } from "~/modules/sales";
-import {
- DeleteQuoteLine,
getQuote,
getQuoteDocuments,
getQuoteLines,
getQuoteMethodTrees,
- QuoteBoMExplorer,
QuoteBreadcrumbs,
+ QuoteExplorer,
QuoteHeader,
- QuoteLineForm,
} from "~/modules/sales";
import { requirePermissions } from "~/services/auth/auth.server";
import { flash } from "~/services/session.server";
@@ -134,237 +104,3 @@ export default function QuoteRoute() {
</div>
);
}
-
-function QuoteExplorer() {
- const { quoteId } = useParams();
- if (!quoteId) throw new Error("Could not find quoteId");
- const quoteData = useRouteData<{ lines: QuotationLine[] }>(
- path.to.quote(quoteId)
- );
- const permissions = usePermissions();
- const { id: userId } = useUser();
- const quoteLineInitialValues = {
- quoteId,
- description: "",
- estimatorId: userId,
- itemId: "",
- itemReadableId: "",
- methodType: "Make" as const,
- status: "Draft" as const,
- quantity: [1],
- unitOfMeasureCode: "",
- };
-
- const newQuoteLineDisclosure = useDisclosure();
- const deleteLineDisclosure = useDisclosure();
- const [deleteLine, setDeleteLine] = useState<QuotationLine | null>(null);
-
- const onDeleteLine = (line: QuotationLine) => {
- setDeleteLine(line);
- deleteLineDisclosure.onOpen();
- };
-
- const onDeleteCancel = () => {
- setDeleteLine(null);
- deleteLineDisclosure.onClose();
- };
-
- const newButtonRef = useRef<HTMLButtonElement>(null);
- useKeyboardShortcuts({
- "Command+Shift+l": (event: KeyboardEvent) => {
- event.stopPropagation();
- newButtonRef.current?.click();
- },
- });
-
- return (
- <>
- <VStack className="w-full h-[calc(100vh-99px)] justify-between">
- <VStack className="flex-1 overflow-y-auto" spacing={0}>
- {quoteData?.lines && quoteData?.lines?.length > 0 ? (
- quoteData?.lines.map((line) => (
- <QuoteLineItem
- key={line.id}
- line={line}
- onDelete={onDeleteLine}
- />
- ))
- ) : (
- <EmptyQuote onAdd={newQuoteLineDisclosure.onOpen} />
- )}
- </VStack>
- <div className="w-full flex flex-0 sm:flex-row border-t border-border p-4 sm:justify-start sm:space-x-2">
- <Tooltip>
- <TooltipTrigger className="w-full">
- <Button
- ref={newButtonRef}
- className="w-full"
- isDisabled={!permissions.can("update", "sales")}
- leftIcon={<LuPlus />}
- onClick={newQuoteLineDisclosure.onOpen}
- >
- Add Line Item
- </Button>
- </TooltipTrigger>
- <TooltipContent>
- <HStack>
- <span>New Line Item</span>
- <Kbd>{prettifyKeyboardShortcut("Command+Shift+l")}</Kbd>
- </HStack>
- </TooltipContent>
- </Tooltip>
- </div>
- </VStack>
- {newQuoteLineDisclosure.isOpen && (
- <QuoteLineForm
- initialValues={quoteLineInitialValues}
- type="modal"
- onClose={newQuoteLineDisclosure.onClose}
- />
- )}
- {deleteLineDisclosure.isOpen && (
- <DeleteQuoteLine line={deleteLine!} onCancel={onDeleteCancel} />
- )}
- </>
- );
-}
-
-function EmptyQuote({ onAdd }: { onAdd: () => void }) {
- const permissions = usePermissions();
- return (
- <VStack className="w-full h-full justify-center items-center">
- <LuGhost className="w-12 h-12" />
- <h3 className="text-base">Pretty empty around here</h3>
- {permissions.can("update", "sales") && (
- <Button leftIcon={<LuPlus />} onClick={onAdd}>
- Add Line Item
- </Button>
- )}
- </VStack>
- );
-}
-
-type QuoteLineItemProps = {
- line: QuotationLine;
- onDelete: (line: QuotationLine) => void;
-};
-
-function QuoteLineItem({ line, onDelete }: QuoteLineItemProps) {
- const { quoteId, lineId } = useParams();
- if (!quoteId) throw new Error("Could not find quoteId");
- const permissions = usePermissions();
- const navigate = useNavigate();
- const disclosure = useDisclosure();
- const location = useOptimisticLocation();
-
- useMount(() => {
- if (lineId === line.id) {
- disclosure.onOpen();
- }
- });
-
- const quoteData = useRouteData<{ methods: Tree<QuoteMethod>[] }>(
- path.to.quote(quoteId)
- );
-
- const methodTree = quoteData?.methods?.find(
- (m) => m.data.quoteLineId === line.id
- );
- const methods = methodTree ? flattenTree(methodTree) : [];
-
- const isSelected = lineId === line.id;
- const onLineClick = (line: QuotationLine) => {
- if (line.methodType === "Make") {
- disclosure.onOpen();
- }
-
- if (location.pathname !== path.to.quoteLine(quoteId, line.id!)) {
- // navigate to line
- navigate(path.to.quoteLine(quoteId, line.id!));
- }
- };
-
- return (
- <VStack spacing={0}>
- <HStack
- className={cn(
- "w-full p-2 items-center justify-between hover:bg-accent/30 cursor-pointer",
- !disclosure.isOpen && "border-b border-border",
- isSelected && "bg-accent/60 hover:bg-accent/50 shadow-inner"
- )}
- onClick={() => onLineClick(line)}
- >
- <HStack spacing={2}>
- {line.thumbnailPath ? (
- <img
- alt="P2392303"
- className={cn(
- "w-10 h-10 bg-gradient-to-bl from-muted to-muted/40 rounded-lg border-2 border-transparent",
- line.status === "Complete" && "border-green-500",
- line.status === "In Progress" && "border-yellow-500"
- )}
- src={`/file/preview/private/${line.thumbnailPath}`}
- />
- ) : (
- <div
- className={cn(
- "w-10 h-10 bg-gradient-to-bl from-muted to-muted/40 rounded-lg border-2 border-transparent p-2",
- line.status === "Complete" && "border-green-500",
- line.status === "In Progress" && "border-yellow-500"
- )}
- >
- <LuImage className="w-6 h-6 text-muted-foreground" />
- </div>
- )}
-
- <VStack spacing={0}>
- <span className="font-semibold">{line.itemReadableId}</span>
- <span className="font-mono text-muted-foreground text-xs">
- {line.customerPartId}
- {line.customerPartRevision && ` (${line.customerPartRevision})`}
- </span>
- </VStack>
- </HStack>
- <HStack spacing={0}>
- {line.methodType === "Make" && permissions.can("update", "sales") && (
- <IconButton
- aria-label={disclosure.isOpen ? "Hide" : "Show"}
- icon={<LuChevronsUpDown />}
- variant="ghost"
- onClick={(e) => {
- e.stopPropagation();
- disclosure.onToggle();
- }}
- />
- )}
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <IconButton
- aria-label="More"
- icon={<MdMoreVert />}
- variant="ghost"
- onClick={(e) => e.stopPropagation()}
- />
- </DropdownMenuTrigger>
- <DropdownMenuContent>
- <DropdownMenuItem
- disabled={!permissions.can("update", "sales")}
- onClick={(e) => {
- e.stopPropagation();
- onDelete(line);
- }}
- >
- Delete Line
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
- </HStack>
- </HStack>
- {disclosure.isOpen && permissions.can("update", "sales") && (
- <VStack className="border-b border-border">
- <QuoteBoMExplorer methods={methods} />
- </VStack>
- )}
- </VStack>
- );
-}
diff --git a/apps/carbon/app/routes/x+/sales-rfq+/$rfqId.$lineId.details.tsx b/apps/carbon/app/routes/x+/sales-rfq+/$rfqId.$lineId.details.tsx
new file mode 100644
index 0000000000..5ff566a70f
--- /dev/null
+++ b/apps/carbon/app/routes/x+/sales-rfq+/$rfqId.$lineId.details.tsx
@@ -0,0 +1,179 @@
+import { validationError, validator } from "@carbon/remix-validated-form";
+import type { ActionFunctionArgs, LoaderFunctionArgs } from "@remix-run/node";
+import { json, redirect } from "@remix-run/node";
+import { Outlet, useLoaderData, useParams } from "@remix-run/react";
+import { Fragment, useMemo } from "react";
+import type { Tree } from "~/components/TreeView";
+import { usePermissions, useRouteData } from "~/hooks";
+import { CadModel } from "~/modules/items";
+import type { QuotationPrice, QuoteMethod } from "~/modules/sales";
+import {
+ getFilesByQuoteLineId,
+ getQuoteLine,
+ getQuoteLinePrices,
+ getQuoteOperationsByLine,
+ QuoteLineCosting,
+ QuoteLineDocuments,
+ QuoteLineForm,
+ QuoteLineNotes,
+ quoteLineValidator,
+ upsertQuoteLine,
+ useLineCosts,
+} from "~/modules/sales";
+import { requirePermissions } from "~/services/auth/auth.server";
+import { flash } from "~/services/session.server";
+import { setCustomFields } from "~/utils/form";
+import { assertIsPost } from "~/utils/http";
+import { path } from "~/utils/path";
+import { error } from "~/utils/result";
+
+export const loader = async ({ request, params }: LoaderFunctionArgs) => {
+ const { client, companyId } = await requirePermissions(request, {
+ view: "sales",
+ });
+
+ const { quoteId, lineId } = params;
+ if (!quoteId) throw new Error("Could not find quoteId");
+ if (!lineId) throw new Error("Could not find lineId");
+
+ const [line, operations, files, prices] = await Promise.all([
+ getQuoteLine(client, lineId),
+ getQuoteOperationsByLine(client, lineId),
+ getFilesByQuoteLineId(client, companyId, lineId),
+ getQuoteLinePrices(client, lineId),
+ ]);
+
+ if (line.error) {
+ throw redirect(
+ path.to.quote(quoteId),
+ await flash(request, error(line.error, "Failed to load line"))
+ );
+ }
+
+ return json({
+ line: line.data,
+ operations: operations?.data ?? [],
+ files: files?.data ?? [],
+ pricesByQuantity: (prices?.data ?? []).reduce<
+ Record<number, QuotationPrice>
+ >((acc, price) => {
+ acc[price.quantity] = price;
+ return acc;
+ }, {}),
+ });
+};
+
+export async function action({ request, params }: ActionFunctionArgs) {
+ assertIsPost(request);
+ const { client, userId } = await requirePermissions(request, {
+ create: "sales",
+ });
+
+ const { quoteId, lineId } = params;
+ if (!quoteId) throw new Error("Could not find quoteId");
+ if (!lineId) throw new Error("Could not find lineId");
+
+ const formData = await request.formData();
+
+ const validation = await validator(quoteLineValidator).validate(formData);
+
+ if (validation.error) {
+ return validationError(validation.error);
+ }
+
+ const { id, ...data } = validation.data;
+
+ const updateQuotationLine = await upsertQuoteLine(client, {
+ id: lineId,
+ ...data,
+ updatedBy: userId,
+ customFields: setCustomFields(formData),
+ });
+
+ if (updateQuotationLine.error) {
+ throw redirect(
+ path.to.quoteLine(quoteId, lineId),
+ await flash(
+ request,
+ error(updateQuotationLine.error, "Failed to update quote line")
+ )
+ );
+ }
+
+ throw redirect(path.to.quoteLine(quoteId, lineId));
+}
+
+export default function QuoteLine() {
+ const { line, operations, files } = useLoaderData<typeof loader>();
+ const permissions = usePermissions();
+ const { quoteId, lineId } = useParams();
+ if (!quoteId) throw new Error("Could not find quoteId");
+ if (!lineId) throw new Error("Could not find lineId");
+
+ const quoteData = useRouteData<{ methods: Tree<QuoteMethod>[] }>(
+ path.to.quote(quoteId)
+ );
+
+ const methodTree = useMemo(
+ () => quoteData?.methods?.find((m) => m.data.quoteLineId === line.id),
+ [quoteData, line.id]
+ );
+
+ const getLineCosts = useLineCosts({
+ methodTree,
+ operations,
+ });
+
+ const initialValues = {
+ ...line,
+ id: line.id ?? undefined,
+ quoteId: line.quoteId ?? "",
+ customerPartId: line.customerPartId ?? "",
+ customerPartRevision: line.customerPartRevision ?? "",
+ description: line.description ?? "",
+ estimatorId: line.estimatorId ?? "",
+ itemId: line.itemId ?? "",
+ itemReadableId: line.itemReadableId ?? "",
+ methodType: line.methodType ?? "Make",
+ modelUploadId: line.modelUploadId ?? undefined,
+ status: line.status ?? "Draft",
+ quantity: line.quantity ?? [1],
+ unitOfMeasureCode: line.unitOfMeasureCode ?? "",
+ };
+
+ return (
+ <Fragment key={lineId}>
+ <QuoteLineForm key={lineId} initialValues={initialValues} />
+ {permissions.is("employee") && (
+ <Fragment key={lineId}>
+ <div className="grid grid-cols-1 xl:grid-cols-2 w-full flex-grow gap-2 ">
+ <CadModel
+ autodeskUrn={line?.autodeskUrn ?? null}
+ isReadOnly={!permissions.can("update", "sales")}
+ metadata={{ quoteLineId: line.id ?? undefined }}
+ modelPath={line?.modelPath ?? null}
+ title="CAD Model"
+ uploadClassName="min-h-[360px]"
+ viewerClassName="min-h-[360px]"
+ />
+ <QuoteLineDocuments
+ files={files ?? []}
+ quoteId={quoteId}
+ quoteLineId={lineId}
+ modelUpload={line ?? undefined}
+ />
+ </div>
+ <QuoteLineNotes line={line} />
+ {line.methodType === "Make" && (
+ <QuoteLineCosting
+ quantities={line.quantity ?? [1]}
+ getLineCosts={getLineCosts}
+ />
+ )}
+
+ <Outlet />
+ </Fragment>
+ )}
+ </Fragment>
+ );
+}
diff --git a/apps/carbon/app/routes/x+/sales-rfq+/$rfqId.details.tsx b/apps/carbon/app/routes/x+/sales-rfq+/$rfqId.details.tsx
index 9580be9af6..f58b37eb3e 100644
--- a/apps/carbon/app/routes/x+/sales-rfq+/$rfqId.details.tsx
+++ b/apps/carbon/app/routes/x+/sales-rfq+/$rfqId.details.tsx
@@ -1,18 +1,30 @@
-import { VStack } from "@carbon/react";
+import type { JSONContent } from "@carbon/react";
+import {
+ Card,
+ CardContent,
+ CardHeader,
+ CardTitle,
+ Editor,
+ generateHTML,
+ toast,
+ useDebounce,
+ VStack,
+} from "@carbon/react";
import { validationError, validator } from "@carbon/remix-validated-form";
-import { parseDate } from "@internationalized/date";
+import { getLocalTimeZone, parseDate, today } from "@internationalized/date";
import type { ActionFunctionArgs } from "@remix-run/node";
import { redirect } from "@remix-run/node";
import { useParams } from "@remix-run/react";
import type { FileObject } from "@supabase/storage-js";
-import { useRouteData } from "~/hooks";
+import { nanoid } from "nanoid";
+import { usePermissions, useRouteData, useUser } from "~/hooks";
+import { useSupabase } from "~/lib/supabase";
import type { SalesRFQ, SalesRFQLine, SalesRFQStatus } from "~/modules/sales";
import {
SalesRFQForm,
salesRfqValidator,
upsertSalesRFQ,
} from "~/modules/sales";
-import SalesRFQLines from "~/modules/sales/ui/SalesRFQ/SalesRFQLines";
import { requirePermissions } from "~/services/auth/auth.server";
import { flash } from "~/services/session.server";
import { getCustomFields, setCustomFields } from "~/utils/form";
@@ -89,16 +101,78 @@ export default function SalesRFQDetailsRoute() {
};
return (
- <VStack spacing={2} className="p-2">
+ <VStack spacing={2}>
<SalesRFQForm
key={`${initialValues.id}:${initialValues.status}`}
initialValues={initialValues}
/>
- <SalesRFQLines
- key={initialValues.id}
- lines={rfqData?.lines ?? []}
- files={rfqData?.files ?? []}
- />
+ <SalesRFQNotes salesRfq={rfqData.rfqSummary} />
</VStack>
);
}
+
+const SalesRFQNotes = ({ salesRfq }: { salesRfq: SalesRFQ }) => {
+ const {
+ id: userId,
+ company: { id: companyId },
+ } = useUser();
+ const { supabase } = useSupabase();
+ const permissions = usePermissions();
+
+ const onUploadImage = async (file: File) => {
+ const fileType = file.name.split(".").pop();
+ const fileName = `${companyId}/sales-rfq/${
+ salesRfq.id
+ }/${nanoid()}.${fileType}`;
+
+ const result = await supabase?.storage
+ .from("private")
+ .upload(fileName, file);
+
+ if (result?.error) {
+ toast.error("Failed to upload image");
+ throw new Error(result.error.message);
+ }
+
+ if (!result?.data) {
+ throw new Error("Failed to upload image");
+ }
+
+ return `/file/preview/private/${result.data.path}`;
+ };
+
+ const onUpdateExternalNotes = useDebounce(async (content: JSONContent) => {
+ await supabase
+ ?.from("salesRfq")
+ .update({
+ notes: content,
+ updatedAt: today(getLocalTimeZone()).toString(),
+ updatedBy: userId,
+ })
+ .eq("id", salesRfq.id!);
+ }, 3000);
+
+ return (
+ <Card>
+ <CardHeader>
+ <CardTitle>External Notes</CardTitle>
+ </CardHeader>
+ <CardContent>
+ {permissions.can("update", "sales") ? (
+ <Editor
+ initialValue={(salesRfq.notes ?? {}) as JSONContent}
+ onUpload={onUploadImage}
+ onChange={onUpdateExternalNotes}
+ />
+ ) : (
+ <div
+ className="prose dark:prose-invert"
+ dangerouslySetInnerHTML={{
+ __html: generateHTML(salesRfq.notes as JSONContent),
+ }}
+ />
+ )}
+ </CardContent>
+ </Card>
+ );
+};
diff --git a/apps/carbon/app/routes/x+/sales-rfq+/$rfqId.tsx b/apps/carbon/app/routes/x+/sales-rfq+/$rfqId.tsx
index bf42f30912..e5e176909d 100644
--- a/apps/carbon/app/routes/x+/sales-rfq+/$rfqId.tsx
+++ b/apps/carbon/app/routes/x+/sales-rfq+/$rfqId.tsx
@@ -1,12 +1,22 @@
-import type { JSONContent } from "@carbon/react";
+import {
+ ClientOnly,
+ ResizableHandle,
+ ResizablePanel,
+ ResizablePanelGroup,
+ ScrollArea,
+ VStack,
+ type JSONContent,
+} from "@carbon/react";
import type { LoaderFunctionArgs } from "@remix-run/node";
import { json, redirect } from "@remix-run/node";
import { Outlet } from "@remix-run/react";
+import type { SalesRFQLine } from "~/modules/sales";
import {
+ SalesRFQBreadcrumbs,
+ SalesRFQExplorer,
SalesRFQHeader,
- SalesRFQProperties,
- getFilesByRfqId,
getSalesRFQ,
+ getSalesRFQDocuments,
getSalesRFQLines,
} from "~/modules/sales";
import { requirePermissions } from "~/services/auth/auth.server";
@@ -31,7 +41,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
const [rfqSummary, lines, files] = await Promise.all([
getSalesRFQ(client, rfqId),
getSalesRFQLines(client, rfqId),
- getFilesByRfqId(client, rfqId, companyId),
+ getSalesRFQDocuments(client, rfqId, companyId),
]);
if (rfqSummary.error) {
@@ -54,7 +64,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
return json({
rfqSummary: rfqSummary.data,
lines:
- lines.data.map((line) => ({
+ lines.data.map((line: SalesRFQLine) => ({
...line,
id: line.id ?? "",
order: line.order ?? 0,
@@ -67,7 +77,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
itemId: line.itemId ?? "",
quantity: line.quantity ?? [1],
})) ?? [],
- files: files.data?.files ?? [],
+ documents: files.data ?? [],
});
}
@@ -77,9 +87,36 @@ export default function SalesRFQRoute() {
<SalesRFQHeader />
<div className="flex h-[calc(100vh-99px)] w-full">
<div className="flex h-full w-full overflow-y-auto">
- <Outlet />
+ <div className="flex flex-grow overflow-hidden">
+ <ClientOnly fallback={null}>
+ {() => (
+ <ResizablePanelGroup direction="horizontal">
+ <ResizablePanel
+ order={1}
+ minSize={10}
+ defaultSize={20}
+ className="bg-card h-full"
+ >
+ <ScrollArea className="h-[calc(100vh-99px)]">
+ <div className="grid w-full h-full overflow-hidden">
+ <SalesRFQExplorer />
+ </div>
+ </ScrollArea>
+ </ResizablePanel>
+ <ResizableHandle withHandle />
+ <ResizablePanel order={2}>
+ <ScrollArea className="h-[calc(100vh-99px)]">
+ <VStack spacing={2} className="p-2">
+ <SalesRFQBreadcrumbs />
+ <Outlet />
+ </VStack>
+ </ScrollArea>
+ </ResizablePanel>
+ </ResizablePanelGroup>
+ )}
+ </ClientOnly>
+ </div>
</div>
- <SalesRFQProperties />
</div>
</div>
);
diff --git a/apps/carbon/app/routes/x+/sales-rfq+/_layout.tsx b/apps/carbon/app/routes/x+/sales-rfq+/_layout.tsx
index 894459da28..ada53519b5 100644
--- a/apps/carbon/app/routes/x+/sales-rfq+/_layout.tsx
+++ b/apps/carbon/app/routes/x+/sales-rfq+/_layout.tsx
@@ -1,8 +1,5 @@
-import type { LoaderFunctionArgs, MetaFunction } from "@remix-run/node";
+import type { MetaFunction } from "@remix-run/node";
import { Outlet } from "@remix-run/react";
-import { getUnitOfMeasuresList } from "~/modules/items";
-import { getLocationsList } from "~/modules/resources";
-import { requirePermissions } from "~/services/auth/auth.server";
import type { Handle } from "~/utils/handle";
import { path } from "~/utils/path";
@@ -16,22 +13,6 @@ export const handle: Handle = {
module: "sales",
};
-export async function loader({ request }: LoaderFunctionArgs) {
- const { client, companyId } = await requirePermissions(request, {
- view: "sales",
- });
-
- const [unitOfMeasures, locations] = await Promise.all([
- getUnitOfMeasuresList(client, companyId),
- getLocationsList(client, companyId),
- ]);
-
- return {
- locations: locations?.data ?? [],
- unitOfMeasures: unitOfMeasures?.data ?? [],
- };
-}
-
export default function SalesRFQRoute() {
return <Outlet />;
}
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index 16350fca18..c575b13158 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -15593,10 +15593,10 @@ export type Database = {
customFields: Json | null
employeeId: string | null
expirationDate: string | null
- externalNotes: string | null
id: string
internalNotes: string | null
locationId: string | null
+ notes: Json | null
revisionId: number
rfqDate: string
rfqId: string
@@ -15616,10 +15616,10 @@ export type Database = {
customFields?: Json | null
employeeId?: string | null
expirationDate?: string | null
- externalNotes?: string | null
id?: string
internalNotes?: string | null
locationId?: string | null
+ notes?: Json | null
revisionId?: number
rfqDate: string
rfqId: string
@@ -15639,10 +15639,10 @@ export type Database = {
customFields?: Json | null
employeeId?: string | null
expirationDate?: string | null
- externalNotes?: string | null
id?: string
internalNotes?: string | null
locationId?: string | null
+ notes?: Json | null
revisionId?: number
rfqDate?: string
rfqId?: string
@@ -24901,12 +24901,12 @@ export type Database = {
customFields: Json | null
employeeId: string | null
expirationDate: string | null
- externalNotes: string | null
favorite: boolean | null
id: string | null
internalNotes: string | null
locationId: string | null
locationName: string | null
+ notes: Json | null
quoteId: string | null
revisionId: number | null
rfqDate: string | null
diff --git a/packages/database/supabase/functions/convert/index.ts b/packages/database/supabase/functions/convert/index.ts
index 83bc7121f8..0b38c1ce71 100644
--- a/packages/database/supabase/functions/convert/index.ts
+++ b/packages/database/supabase/functions/convert/index.ts
@@ -82,6 +82,7 @@ serve(async (req: Request) => {
locationId: salesRfq.data?.locationId,
expirationDate: salesRfq.data?.expirationDate,
status: "Draft",
+ notes: salesRfq.data?.notes,
companyId,
createdBy: userId,
},
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index 16350fca18..c575b13158 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -15593,10 +15593,10 @@ export type Database = {
customFields: Json | null
employeeId: string | null
expirationDate: string | null
- externalNotes: string | null
id: string
internalNotes: string | null
locationId: string | null
+ notes: Json | null
revisionId: number
rfqDate: string
rfqId: string
@@ -15616,10 +15616,10 @@ export type Database = {
customFields?: Json | null
employeeId?: string | null
expirationDate?: string | null
- externalNotes?: string | null
id?: string
internalNotes?: string | null
locationId?: string | null
+ notes?: Json | null
revisionId?: number
rfqDate: string
rfqId: string
@@ -15639,10 +15639,10 @@ export type Database = {
customFields?: Json | null
employeeId?: string | null
expirationDate?: string | null
- externalNotes?: string | null
id?: string
internalNotes?: string | null
locationId?: string | null
+ notes?: Json | null
revisionId?: number
rfqDate?: string
rfqId?: string
@@ -24901,12 +24901,12 @@ export type Database = {
customFields: Json | null
employeeId: string | null
expirationDate: string | null
- externalNotes: string | null
favorite: boolean | null
id: string | null
internalNotes: string | null
locationId: string | null
locationName: string | null
+ notes: Json | null
quoteId: string | null
revisionId: number | null
rfqDate: string | null
diff --git a/packages/database/supabase/migrations/20240811231527_convert-rfq.sql b/packages/database/supabase/migrations/20240811231527_convert-rfq.sql
index 9746c73387..0cceecbc0f 100644
--- a/packages/database/supabase/migrations/20240811231527_convert-rfq.sql
+++ b/packages/database/supabase/migrations/20240811231527_convert-rfq.sql
@@ -57,8 +57,15 @@ CREATE POLICY "Employees with sales_delete can delete customer part to item" ON
has_role('employee', "companyId")
);
+
+DROP VIEW "salesRfqs";
+DROP VIEW "salesRfqLines";
+COMMIT;
+
ALTER TABLE "salesRfq"
ADD COLUMN "customerLocationId" TEXT,
+ DROP COLUMN "externalNotes",
+ ADD COLUMN "notes" JSON DEFAULT '{}',
ADD CONSTRAINT "salesRfq_customerLocationId_fkey" FOREIGN KEY ("customerLocationId") REFERENCES "customerLocation" ("id") ON DELETE SET NULL;
ALTER TABLE "salesRfqLine" ENABLE ROW LEVEL SECURITY;
@@ -83,15 +90,10 @@ CREATE POLICY "Employees with sales_delete can delete salesRfqLine" ON "salesRfq
has_role('employee', "companyId")
);
-DROP VIEW "salesRfqs";
-DROP VIEW "salesRfqLines";
-
ALTER TABLE "salesRfqLine"
DROP COLUMN "customerPartNumber",
DROP COLUMN "customerPartRevision";
-COMMIT;
-
ALTER TABLE "salesRfqLine"
ADD COLUMN "customerPartId" TEXT NOT NULL,
ADD COLUMN "customerPartRevision" TEXT;