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: sales rfq notes

Brad Barbin8ad8cd6b365d
diff --git a/apps/carbon/app/components/Form/Array.tsx b/apps/carbon/app/components/Form/Array.tsx
index f3cd680873..6f02aadf12 100644
--- a/apps/carbon/app/components/Form/Array.tsx
+++ b/apps/carbon/app/components/Form/Array.tsx
@@ -11,6 +11,7 @@ import {
} from "@carbon/react";
import { useField, useFieldArray } from "@carbon/remix-validated-form";
import { forwardRef, useRef } from "react";
+import { flushSync } from "react-dom";
import { IoMdAdd, IoMdClose } from "react-icons/io";
type FormArrayProps = InputProps & {
@@ -24,9 +25,12 @@ const Array = forwardRef<HTMLInputElement, FormArrayProps>(
const listRef = useRef<HTMLDivElement>(null);
const [items, { push, remove }, error] = useFieldArray<string>(name);
const onAdd = () => {
- push("");
- const lastInput =
- listRef.current?.lastElementChild?.querySelector("input");
+ flushSync(() => {
+ push("");
+ });
+ const lastInput = listRef.current?.querySelectorAll("input")?.[
+ items.length
+ ] as HTMLInputElement | undefined;
lastInput?.focus();
};
diff --git a/apps/carbon/app/components/Form/ArrayNumeric.tsx b/apps/carbon/app/components/Form/ArrayNumeric.tsx
index 330c3a7065..7de63104a5 100644
--- a/apps/carbon/app/components/Form/ArrayNumeric.tsx
+++ b/apps/carbon/app/components/Form/ArrayNumeric.tsx
@@ -16,6 +16,7 @@ import {
} from "@carbon/react";
import { useField, useFieldArray } from "@carbon/remix-validated-form";
import { forwardRef, useRef } from "react";
+import { flushSync } from "react-dom";
import { IoMdAdd, IoMdClose } from "react-icons/io";
import { LuChevronDown, LuChevronUp } from "react-icons/lu";
@@ -23,16 +24,21 @@ type FormArrayNumericProps = InputProps & {
name: string;
label?: string;
isRequired?: boolean;
+ defaults?: number[];
};
const ArrayNumeric = forwardRef<HTMLInputElement, FormArrayNumericProps>(
- ({ name, label, isRequired, ...rest }, ref) => {
+ ({ name, label, isRequired, defaults, ...rest }, ref) => {
const listRef = useRef<HTMLDivElement>(null);
const [items, { push, remove }, error] = useFieldArray<number>(name);
const onAdd = () => {
- push(0);
- const lastInput =
- listRef.current?.lastElementChild?.querySelector("input");
+ flushSync(() => {
+ const next = defaults?.[items.length] ?? 0;
+ push(next);
+ });
+ const lastInput = listRef.current?.querySelectorAll(
+ "input[inputmode='numeric']"
+ )?.[items.length] as HTMLInputElement | undefined;
lastInput?.focus();
};
diff --git a/apps/carbon/app/components/SortableList.tsx b/apps/carbon/app/components/SortableList.tsx
index 7cc9e5dca6..4f374de8b9 100644
--- a/apps/carbon/app/components/SortableList.tsx
+++ b/apps/carbon/app/components/SortableList.tsx
@@ -8,18 +8,19 @@ import {
useDragControls,
} from "framer-motion";
import type { ReactNode } from "react";
-import { useState } from "react";
+import { memo, useState } from "react";
import useMeasure from "react-use-measure";
import { Checkbox, HStack, cn } from "@carbon/react";
import { LuTrash } from "react-icons/lu";
export interface Item {
- id: string;
- title: ReactNode;
checked: boolean;
details?: ReactNode;
+ id: string;
+ isTemporary?: boolean;
order?: "With Previous" | "After Previous";
+ title: ReactNode;
}
interface SortableItem<T> extends Item {
@@ -38,7 +39,7 @@ interface SortableListItemProps<T> {
handleDrag: () => void;
}
-function SortableListItem<T>({
+function _SortableListItem<T>({
item,
items,
order,
@@ -266,7 +267,14 @@ function SortableListItem<T>({
);
}
-SortableListItem.displayName = "SortableListItem";
+const SortableListItem = memo(_SortableListItem, (prevProps, nextProps) => {
+ return (
+ prevProps.item.id === nextProps.item.id &&
+ prevProps.item.checked === nextProps.item.checked &&
+ prevProps.item.order === nextProps.item.order &&
+ prevProps.isExpanded === nextProps.isExpanded
+ );
+}) as typeof _SortableListItem;
export type SortableItemRenderProps<T extends Item> = {
item: T;
diff --git a/apps/carbon/app/modules/sales/sales.models.ts b/apps/carbon/app/modules/sales/sales.models.ts
index dbc6f486d7..7fbfaa7ba4 100644
--- a/apps/carbon/app/modules/sales/sales.models.ts
+++ b/apps/carbon/app/modules/sales/sales.models.ts
@@ -318,7 +318,7 @@ export const salesRfqValidator = z.object({
});
export const salesRfqLineValidator = z.object({
- id: zfd.text(z.string().optional()),
+ id: z.string().min(1, { message: "ID is required" }),
salesRfqId: z.string().min(20, { message: "RFQ is required" }),
customerPartNumber: z.string().min(1, { message: "Part Number is required" }),
customerRevisionId: zfd.text(z.string().optional()),
diff --git a/apps/carbon/app/modules/sales/sales.service.ts b/apps/carbon/app/modules/sales/sales.service.ts
index ac2a46ff20..e97e8500f5 100644
--- a/apps/carbon/app/modules/sales/sales.service.ts
+++ b/apps/carbon/app/modules/sales/sales.service.ts
@@ -1526,13 +1526,12 @@ export async function upsertSalesRFQLine(
client: SupabaseClient<Database>,
salesRfqLine:
- | (Omit<z.infer<typeof salesRfqLineValidator>, "id"> & {
+ | (z.infer<typeof salesRfqLineValidator> & {
companyId: string;
createdBy: string;
customFields?: Json;
})
- | (Omit<z.infer<typeof salesRfqLineValidator>, "id"> & {
- id: string;
+ | (z.infer<typeof salesRfqLineValidator> & {
updatedBy: string;
customFields?: Json;
})
diff --git a/apps/carbon/app/modules/sales/ui/SalesRFQ/SalesRFQLines.tsx b/apps/carbon/app/modules/sales/ui/SalesRFQ/SalesRFQLines.tsx
index f64008f869..878384bc61 100644
--- a/apps/carbon/app/modules/sales/ui/SalesRFQ/SalesRFQLines.tsx
+++ b/apps/carbon/app/modules/sales/ui/SalesRFQ/SalesRFQLines.tsx
@@ -1,4 +1,5 @@
"use client";
+import type { JSONContent } from "@carbon/react";
import {
Badge,
Button,
@@ -7,6 +8,7 @@ import {
CardContent,
CardHeader,
CardTitle,
+ Editor,
HStack,
VStack,
cn,
@@ -15,13 +17,15 @@ import {
useMount,
} from "@carbon/react";
import { ValidatedForm } from "@carbon/remix-validated-form";
+import { getLocalTimeZone, today } from "@internationalized/date";
import { useFetcher, useParams } 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";
import { LuSettings2, LuX } from "react-icons/lu";
import type { z } from "zod";
+import { DirectionAwareTabs } from "~/components/DirectionAwareTabs";
import {
ArrayNumeric,
Hidden,
@@ -41,7 +45,10 @@ import { useSupabase } from "~/lib/supabase";
import { path } from "~/utils/path";
import { salesRfqLineValidator } from "../../sales.models";
-type Line = z.infer<typeof salesRfqLineValidator>;
+type Line = z.infer<typeof salesRfqLineValidator> & {
+ internalNotes: JSONContent;
+ externalNotes: JSONContent;
+};
type ItemWithData = SortableItem & {
data: Line;
@@ -71,6 +78,7 @@ function makeItem(line: Line): ItemWithData {
)}
</VStack>
),
+ isTemporary: false,
checked: false,
details: (
<HStack spacing={2}>
@@ -85,13 +93,15 @@ function makeItem(line: Line): ItemWithData {
};
}
-const initialMethodLine: Omit<Line, "salesRfqId" | "order"> = {
+const initialLine: Omit<Line, "id" | "salesRfqId" | "order"> = {
customerPartNumber: "",
customerRevisionId: "",
itemId: "",
description: "",
quantity: [1],
unitOfMeasureCode: "EA",
+ internalNotes: {} as JSONContent,
+ externalNotes: {} as JSONContent,
};
const SalesRFQLines = ({ lines }: SalesRFQLinesProps) => {
@@ -99,9 +109,14 @@ const SalesRFQLines = ({ lines }: SalesRFQLinesProps) => {
if (!rfqId) throw new Error("rfqId not found");
const fetcher = useFetcher();
+ const { supabase } = useSupabase();
+ const {
+ company: { id: companyId },
+ id: userId,
+ } = useUser();
const [items, setItems] = useState<ItemWithData[]>(makeItems(lines ?? []));
- const [selectedItemId, setSelectedItemId] = useState<string | null>(null);
+ const [selectedLineId, setSelectedLineId] = useState<string | null>(null);
const onToggleItem = (id: string) => {
setItems((prevItems) =>
@@ -112,15 +127,15 @@ const SalesRFQLines = ({ lines }: SalesRFQLinesProps) => {
};
useMount(() => {
- if (lines.length === 0 && !selectedItemId) {
+ if (lines.length === 0 && !selectedLineId) {
onAddItem();
}
});
// we create a temporary item and append it to the list
const onAddItem = () => {
- const temporaryId = Math.random().toString(16).slice(2);
- setSelectedItemId(temporaryId);
+ const id = nanoid();
+ setSelectedLineId(id);
setItems((prevItems) => {
let newOrder = 1;
if (prevItems.length) {
@@ -132,9 +147,11 @@ const SalesRFQLines = ({ lines }: SalesRFQLinesProps) => {
{
title: "",
checked: false,
- id: temporaryId,
+ id: id,
+ isTemporary: true,
data: {
- ...initialMethodLine,
+ ...initialLine,
+ id,
order: newOrder,
salesRfqId: rfqId,
},
@@ -165,7 +182,7 @@ const SalesRFQLines = ({ lines }: SalesRFQLinesProps) => {
},
}));
const updates = newItems.reduce<Record<string, number>>((acc, item) => {
- if (!isTemporaryId(item.id)) {
+ if (!item.isTemporary) {
acc[item.id] = item.data.order;
}
return acc;
@@ -197,6 +214,74 @@ const SalesRFQLines = ({ lines }: SalesRFQLinesProps) => {
});
}, []);
+ const onUploadImage = async (file: File) => {
+ const fileName = `${companyId}/sales-rfqs/${selectedLineId}/${Math.random()
+ .toString(16)
+ .slice(2)}-${file.name}`;
+ const result = await supabase?.storage
+ .from("private")
+ .upload(fileName, file);
+
+ if (result?.error) {
+ throw new Error(result.error.message);
+ }
+
+ if (!result?.data) {
+ throw new Error("Failed to upload image");
+ }
+
+ return `/file/preview/private/${result.data.path}`;
+ };
+
+ const onUpdateInternalNotes = useDebounce(async (content: JSONContent) => {
+ setItems((prevItems) =>
+ prevItems.map((item) =>
+ item.id === selectedLineId
+ ? {
+ ...item,
+ data: {
+ ...item.data,
+ internalNotes: content,
+ },
+ }
+ : item
+ )
+ );
+ await supabase
+ ?.from("salesRfqLine")
+ .update({
+ internalNotes: content,
+ updatedAt: today(getLocalTimeZone()).toString(),
+ updatedBy: userId,
+ })
+ .eq("id", selectedLineId!);
+ }, 1000);
+
+ const onUpdateExternalNotes = useDebounce(async (content: JSONContent) => {
+ setItems((prevItems) =>
+ prevItems.map((item) =>
+ item.id === selectedLineId
+ ? {
+ ...item,
+ data: {
+ ...item.data,
+ externalNotes: content,
+ },
+ }
+ : item
+ )
+ );
+ await supabase
+ ?.from("salesRfqLine")
+ .update({
+ externalNotes: content,
+ updatedAt: today(getLocalTimeZone()).toString(),
+ updatedBy: userId,
+ })
+ .eq("id", selectedLineId!);
+ }, 1000);
+
+ const [tabChangeRerender, setTabChangeRerender] = useState<number>(1);
const renderListItem = ({
item,
items,
@@ -204,14 +289,134 @@ const SalesRFQLines = ({ lines }: SalesRFQLinesProps) => {
onToggleItem,
onRemoveItem,
}: SortableItemRenderProps<ItemWithData>) => {
- const isOpen = item.id === selectedItemId;
+ const isOpen = item.id === selectedLineId;
+
+ const tabs = [
+ {
+ id: 0,
+ label: "Details",
+ content: (
+ <div className="flex w-full flex-col pr-2 py-2">
+ <motion.div
+ initial={{ opacity: 0, filter: "blur(4px)" }}
+ animate={{ opacity: 1, filter: "blur(0px)" }}
+ transition={{
+ type: "spring",
+ bounce: 0.2,
+ duration: 0.75,
+ delay: 0.15,
+ }}
+ >
+ <SalesRFQLineForm
+ item={item}
+ setItems={setItems}
+ setSelectedLineId={setSelectedLineId}
+ />
+ </motion.div>
+ </div>
+ ),
+ },
+ ];
+
+ if (!item.isTemporary) {
+ tabs.push(
+ {
+ id: 1,
+ label: "Model",
+
+ content: (
+ <div className="flex flex-col p-2">
+ <motion.div
+ initial={{ opacity: 0, filter: "blur(4px)" }}
+ animate={{ opacity: 1, filter: "blur(0px)" }}
+ transition={{
+ type: "spring",
+ bounce: 0.2,
+ duration: 0.75,
+ delay: 0.15,
+ }}
+ ></motion.div>
+ </div>
+ ),
+ },
+ {
+ id: 2,
+ label: "Drawing",
+
+ content: (
+ <div className="flex flex-col p-2">
+ <motion.div
+ initial={{ opacity: 0, filter: "blur(4px)" }}
+ animate={{ opacity: 1, filter: "blur(0px)" }}
+ transition={{
+ type: "spring",
+ bounce: 0.2,
+ duration: 0.75,
+ delay: 0.15,
+ }}
+ ></motion.div>
+ </div>
+ ),
+ },
+ {
+ id: 3,
+ label: "Internal Notes",
+
+ content: (
+ <div className="flex flex-col p-2">
+ <motion.div
+ initial={{ opacity: 0, filter: "blur(4px)" }}
+ animate={{ opacity: 1, filter: "blur(0px)" }}
+ transition={{
+ type: "spring",
+ bounce: 0.2,
+ duration: 0.75,
+ delay: 0.15,
+ }}
+ >
+ <Editor
+ initialValue={item.data.internalNotes}
+ onUpload={onUploadImage}
+ onChange={onUpdateInternalNotes}
+ />
+ </motion.div>
+ </div>
+ ),
+ },
+ {
+ id: 4,
+ label: "External Notes",
+
+ content: (
+ <div className="flex flex-col p-2">
+ <motion.div
+ initial={{ opacity: 0, filter: "blur(4px)" }}
+ animate={{ opacity: 1, filter: "blur(0px)" }}
+ transition={{
+ type: "spring",
+ bounce: 0.2,
+ duration: 0.75,
+ delay: 0.15,
+ }}
+ >
+ <Editor
+ initialValue={item.data.externalNotes ?? ({} as JSONContent)}
+ onUpload={onUploadImage}
+ onChange={onUpdateExternalNotes}
+ />
+ </motion.div>
+ </div>
+ ),
+ }
+ );
+ }
return (
<SortableListItem<Line>
item={item}
items={items}
order={order}
- key={item.id}
+ key={`${item.id}:${item.isTemporary}`}
isExpanded={isOpen}
onToggleItem={onToggleItem}
onRemoveItem={onRemoveItem}
@@ -219,7 +424,7 @@ const SalesRFQLines = ({ lines }: SalesRFQLinesProps) => {
className="my-2 "
renderExtra={(item) => (
<div
- key={`${isOpen}`}
+ key={`${isOpen}:${item.isTemporary}`}
className={cn(
"flex h-full flex-col items-center justify-center pl-2",
isOpen ? "py-1" : "py-3 "
@@ -230,15 +435,15 @@ const SalesRFQLines = ({ lines }: SalesRFQLinesProps) => {
onClick={
isOpen
? () => {
- if (isTemporaryId(item.id)) {
+ if (item.isTemporary) {
setItems((prevItems) =>
prevItems.filter((i) => i.id !== item.id)
);
}
- setSelectedItemId(null);
+ setSelectedLineId(null);
}
: () => {
- setSelectedItemId(item.id);
+ setSelectedLineId(item.id);
}
}
key="collapse"
@@ -275,7 +480,7 @@ const SalesRFQLines = ({ lines }: SalesRFQLinesProps) => {
)}
</motion.button>
- <LayoutGroup id={`${item.id}`}>
+ <LayoutGroup id={`${item.id}:${item.isTemporary}`}>
<AnimatePresence mode="popLayout">
{isOpen ? (
<motion.div className="flex w-full flex-col ">
@@ -298,22 +503,13 @@ const SalesRFQLines = ({ lines }: SalesRFQLinesProps) => {
layout
className="w-full "
>
- <motion.div
- initial={{ opacity: 0, filter: "blur(4px)" }}
- animate={{ opacity: 1, filter: "blur(0px)" }}
- transition={{
- type: "spring",
- bounce: 0.2,
- duration: 0.75,
- delay: 0.15,
- }}
- >
- <SalesRFQLineForm
- item={item}
- setItems={setItems}
- setSelectedItemId={setSelectedItemId}
- />
- </motion.div>
+ <DirectionAwareTabs
+ className="mr-auto"
+ tabs={tabs}
+ onChange={() =>
+ setTabChangeRerender(tabChangeRerender + 1)
+ }
+ />
</motion.div>
</div>
</motion.div>
@@ -336,7 +532,7 @@ const SalesRFQLines = ({ lines }: SalesRFQLinesProps) => {
<CardAction>
<Button
variant="secondary"
- isDisabled={selectedItemId !== null}
+ isDisabled={selectedLineId !== null}
onClick={onAddItem}
>
Add Line
@@ -358,18 +554,14 @@ const SalesRFQLines = ({ lines }: SalesRFQLinesProps) => {
export default SalesRFQLines;
-function isTemporaryId(id: string) {
- return id.length < 20;
-}
-
function SalesRFQLineForm({
item,
setItems,
- setSelectedItemId,
+ setSelectedLineId,
}: {
item: ItemWithData;
setItems: Dispatch<SetStateAction<ItemWithData[]>>;
- setSelectedItemId: Dispatch<SetStateAction<string | null>>;
+ setSelectedLineId: Dispatch<SetStateAction<string | null>>;
}) {
const { supabase } = useSupabase();
const salesRfqLineFetcher = useFetcher<{ id: string }>();
@@ -377,27 +569,22 @@ function SalesRFQLineForm({
const { company } = useUser();
useEffect(() => {
- // replace the temporary id with the actual id
if (salesRfqLineFetcher.data && salesRfqLineFetcher.data.id) {
- flushSync(() => {
- setItems((prevItems) =>
- prevItems.map((i) =>
- i.id === item.id
- ? {
- ...i,
- id: salesRfqLineFetcher.data!.id!,
- data: {
- ...i.data,
- ...salesRfqLineFetcher.data,
- },
- }
- : i
- )
+ setItems((prevItems) => {
+ return prevItems.map((i) =>
+ i.id === item.id
+ ? {
+ ...i,
+ isTemporary: false,
+ data: {
+ ...i.data,
+ },
+ }
+ : i
);
});
- setSelectedItemId(null);
}
- }, [item.id, salesRfqLineFetcher.data, setItems, setSelectedItemId]);
+ }, [item.id, salesRfqLineFetcher.data, setItems, setSelectedLineId]);
const [itemData, setItemData] = useState<{
itemId: string;
@@ -435,7 +622,7 @@ function SalesRFQLineForm({
return (
<ValidatedForm
action={
- isTemporaryId(item.id)
+ item.isTemporary
? path.to.newSalesRFQLine(item.data.salesRfqId!)
: path.to.salesRfqLine(item.data.salesRfqId, item.id!)
}
@@ -449,7 +636,13 @@ function SalesRFQLineForm({
prevItems.map((i) =>
i.id === item.id
? {
- ...makeItem({ ...values, description: itemData.description }),
+ ...makeItem({
+ ...values,
+ description: itemData.description,
+ internalNotes: item.data.internalNotes,
+ externalNotes: item.data.externalNotes,
+ }),
+ isTemporary: false,
id: item.id,
}
: i
@@ -457,6 +650,7 @@ function SalesRFQLineForm({
);
}}
>
+ <Hidden name="id" />
<Hidden name="salesRfqId" />
<Hidden name="order" />
<VStack className="pt-4">
@@ -493,7 +687,11 @@ function SalesRFQLineForm({
}))
}
/>
- <ArrayNumeric name="quantity" label="Quantity" />
+ <ArrayNumeric
+ name="quantity"
+ label="Quantity"
+ defaults={[1, 25, 50, 100]}
+ />
</div>
<motion.div
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 d45c157d1c..7e254d8b84 100644
--- a/apps/carbon/app/routes/x+/sales-rfq+/$rfqId.details.tsx
+++ b/apps/carbon/app/routes/x+/sales-rfq+/$rfqId.details.tsx
@@ -1,3 +1,4 @@
+import type { JSONContent } from "@carbon/react";
import { VStack } from "@carbon/react";
import { validationError, validator } from "@carbon/remix-validated-form";
import { parseDate } from "@internationalized/date";
@@ -38,7 +39,15 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
}
return json({
- lines: lines.data ?? [],
+ lines: lines.data.map((line) => ({
+ ...line,
+ customerRevisionId: line.customerRevisionId ?? "",
+ description: line.description ?? "",
+ externalNotes: (line.externalNotes ?? {}) as JSONContent,
+ internalNotes: (line.internalNotes ?? {}) as JSONContent,
+ itemId: line.itemId ?? "",
+ quantity: line.quantity ?? [1],
+ })) ?? [1],
});
}
diff --git a/apps/carbon/app/routes/x+/sales-rfq+/$rfqId.lines.new.tsx b/apps/carbon/app/routes/x+/sales-rfq+/$rfqId.lines.new.tsx
index 0a9d1a5952..a84b708313 100644
--- a/apps/carbon/app/routes/x+/sales-rfq+/$rfqId.lines.new.tsx
+++ b/apps/carbon/app/routes/x+/sales-rfq+/$rfqId.lines.new.tsx
@@ -25,10 +25,8 @@ export async function action({ request, params }: ActionFunctionArgs) {
return validationError(validation.error);
}
- const { id, ...data } = validation.data;
-
const insertLine = await upsertSalesRFQLine(client, {
- ...data,
+ ...validation.data,
companyId,
createdBy: userId,
customFields: setCustomFields(formData),
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index 4d24e1f0ff..e3d3e280c1 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -15700,7 +15700,9 @@ export type Database = {
customerRevisionId: string | null
customFields: Json | null
description: string | null
+ externalNotes: Json | null
id: string
+ internalNotes: Json | null
itemId: string | null
order: number
quantity: number[] | null
@@ -15717,7 +15719,9 @@ export type Database = {
customerRevisionId?: string | null
customFields?: Json | null
description?: string | null
+ externalNotes?: Json | null
id?: string
+ internalNotes?: Json | null
itemId?: string | null
order?: number
quantity?: number[] | null
@@ -15734,7 +15738,9 @@ export type Database = {
customerRevisionId?: string | null
customFields?: Json | null
description?: string | null
+ externalNotes?: Json | null
id?: string
+ internalNotes?: Json | null
itemId?: string | null
order?: number
quantity?: number[] | null
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index 4d24e1f0ff..e3d3e280c1 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -15700,7 +15700,9 @@ export type Database = {
customerRevisionId: string | null
customFields: Json | null
description: string | null
+ externalNotes: Json | null
id: string
+ internalNotes: Json | null
itemId: string | null
order: number
quantity: number[] | null
@@ -15717,7 +15719,9 @@ export type Database = {
customerRevisionId?: string | null
customFields?: Json | null
description?: string | null
+ externalNotes?: Json | null
id?: string
+ internalNotes?: Json | null
itemId?: string | null
order?: number
quantity?: number[] | null
@@ -15734,7 +15738,9 @@ export type Database = {
customerRevisionId?: string | null
customFields?: Json | null
description?: string | null
+ externalNotes?: Json | null
id?: string
+ internalNotes?: Json | null
itemId?: string | null
order?: number
quantity?: number[] | null
diff --git a/packages/database/supabase/migrations/20240704105128_rfq.sql b/packages/database/supabase/migrations/20240704105128_rfq.sql
index 4dcbc78e97..7e8e9752f3 100644
--- a/packages/database/supabase/migrations/20240704105128_rfq.sql
+++ b/packages/database/supabase/migrations/20240704105128_rfq.sql
@@ -53,6 +53,8 @@ CREATE TABLE "salesRfqLine" (
"quantity" NUMERIC(20, 2)[] DEFAULT ARRAY[]::NUMERIC(20, 2)[],
"unitOfMeasureCode" TEXT NOT NULL,
"order" DOUBLE PRECISION NOT NULL DEFAULT 0,
+ "internalNotes" JSON DEFAULT '{}',
+ "externalNotes" JSON DEFAULT '{}',
"companyId" TEXT NOT NULL,
"customFields" JSONB DEFAULT '{}',
"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT now(),
@@ -140,3 +142,38 @@ SELECT
id
FROM "company"
ON CONFLICT DO NOTHING;
+
+-- documents
+
+-- rfq documents
+CREATE POLICY "Sales RFQ documents view requires sales_view" ON storage.objects
+FOR SELECT USING (
+ bucket_id = 'private'
+ AND has_role('employee', (storage.foldername(name))[1])
+ AND has_company_permission('sales_view', (storage.foldername(name))[1])
+ AND (storage.foldername(name))[2] = 'sales-rfq'
+);
+
+CREATE POLICY "Sales RFQ documents insert requires sales_create" ON storage.objects
+FOR INSERT WITH CHECK (
+ bucket_id = 'private'
+ AND has_role('employee', (storage.foldername(name))[1])
+ AND has_company_permission('sales_create', (storage.foldername(name))[1])
+ AND (storage.foldername(name))[2] = 'sales-rfq'
+);
+
+CREATE POLICY "Sales RFQ documents update requires sales_update" ON storage.objects
+FOR UPDATE USING (
+ bucket_id = 'private'
+ AND has_role('employee', (storage.foldername(name))[1])
+ AND has_company_permission('sales_update', (storage.foldername(name))[1])
+ AND (storage.foldername(name))[2] = 'sales-rfq'
+);
+
+CREATE POLICY "Sales RFQ documents delete requires sales_delete" ON storage.objects
+FOR DELETE USING (
+ bucket_id = 'private'
+ AND has_role('employee', (storage.foldername(name))[1])
+ AND has_company_permission('sales_delete', (storage.foldername(name))[1])
+ AND (storage.foldername(name))[2] = 'sales-rfq'
+);