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: quote rls and new button refactor

Brad Barbinc13969b87a0c
diff --git a/apps/carbon/app/components/Grid/Grid.tsx b/apps/carbon/app/components/Grid/Grid.tsx
index d18c525b01..d56b722ef4 100644
--- a/apps/carbon/app/components/Grid/Grid.tsx
+++ b/apps/carbon/app/components/Grid/Grid.tsx
@@ -416,7 +416,7 @@ const Grid = <T extends object>({
);
})}
{rows.length === 0 && !onNewRow && (
- <Tr className="h-10 hover:bg-zinc-100 dark:hover:bg-zinc-900">
+ <Tr className="h-10 hover:bg-muted/50">
<Td colSpan={24}>
<p className="text-muted-foreground text-center w-full">
No Data
@@ -427,7 +427,7 @@ const Grid = <T extends object>({
{onNewRow && (
<Tr
onClick={onNewRow}
- className="cursor-pointer h-10 hover:bg-zinc-100 dark:hover:bg-zinc-900"
+ className="cursor-pointer h-10 hover:bg-muted/50"
>
<Td colSpan={24}>
<HStack className="items-start h-6">
diff --git a/apps/carbon/app/components/Grid/components/Cell.tsx b/apps/carbon/app/components/Grid/components/Cell.tsx
index 0296d3d29a..765ca12b8b 100644
--- a/apps/carbon/app/components/Grid/components/Cell.tsx
+++ b/apps/carbon/app/components/Grid/components/Cell.tsx
@@ -48,7 +48,7 @@ const Cell = <T extends object>({
className={cn(
"relative border-r border-border px-4 py-2 whitespace-nowrap text-sm outline-none",
wasEdited && "bg-yellow-100 dark:bg-yellow-900",
- !hasEditableTableCellComponent && "bg-zinc-50 dark:bg-zinc-950",
+ !hasEditableTableCellComponent && "bg-muted/50",
hasError && "ring-inset ring-2 ring-red-500",
isSelected && "ring-inset ring-2 ring-ring"
)}
diff --git a/apps/carbon/app/components/Layout/Topbar/useCreate.tsx b/apps/carbon/app/components/Layout/Topbar/useCreate.tsx
index fe8a13f2cf..c234bb3575 100644
--- a/apps/carbon/app/components/Layout/Topbar/useCreate.tsx
+++ b/apps/carbon/app/components/Layout/Topbar/useCreate.tsx
@@ -61,5 +61,5 @@ export default function useCreate(): Route[] {
return links;
}, [permissions]);
- return result;
+ return result.sort((a, b) => a.name.localeCompare(b.name));
}
diff --git a/apps/carbon/app/components/New.tsx b/apps/carbon/app/components/New.tsx
new file mode 100644
index 0000000000..6b20ec9361
--- /dev/null
+++ b/apps/carbon/app/components/New.tsx
@@ -0,0 +1,27 @@
+import { Button, useKeyboardShortcuts } from "@carbon/react";
+import { Link } from "@remix-run/react";
+import { useRef } from "react";
+import { IoMdAdd } from "react-icons/io";
+
+type NewProps = {
+ label?: string;
+ to: string;
+};
+
+const New = ({ label, to }: NewProps) => {
+ const buttonRef = useRef<HTMLButtonElement>(null);
+ useKeyboardShortcuts({
+ n: (event: KeyboardEvent) => {
+ event.stopPropagation();
+ buttonRef.current?.click();
+ },
+ });
+
+ return (
+ <Button asChild leftIcon={<IoMdAdd />} ref={buttonRef}>
+ <Link to={to}>New {label}</Link>
+ </Button>
+ );
+};
+
+export default New;
diff --git a/apps/carbon/app/components/Search/Search/Search.tsx b/apps/carbon/app/components/Search/Search/Search.tsx
index 1552a3b28d..133b391aec 100644
--- a/apps/carbon/app/components/Search/Search/Search.tsx
+++ b/apps/carbon/app/components/Search/Search/Search.tsx
@@ -1,3 +1,4 @@
+import type { Database } from "@carbon/database";
import {
Button,
Command,
@@ -43,17 +44,7 @@ import type { Authenticated, Route } from "~/types";
type SearchResult = {
id: number;
name: string;
- entity:
- | "Person"
- | "Resource"
- | "Customer"
- | "Supplier"
- | "Job"
- | "Part"
- | "Purchase Order"
- | "Sales Order"
- | "Document"
- | null;
+ entity: Database["public"]["Enums"]["searchEntity"] | null;
uuid: string | null;
link: string;
description: string | null;
@@ -105,7 +96,7 @@ const SearchModal = ({
const result = await supabase
?.from("search")
.select()
- .textSearch("fts", `${search}:*`)
+ .textSearch("fts", `*${search}:*`)
.limit(20);
if (result?.data) {
@@ -243,6 +234,9 @@ function ResultIcon({ entity }: { entity: SearchResult["entity"] | "Module" }) {
return <CgProfile className="w-4 h-4 mr-2 " />;
case "Purchase Order":
return <BsCartDash className="w-4 h-4 mr-2 " />;
+ case "Opportunity":
+ case "Lead":
+ case "Quotation":
case "Sales Order":
return <BsCartPlus className="w-4 h-4 mr-2 " />;
case "Supplier":
diff --git a/apps/carbon/app/components/Table/components/Cell.tsx b/apps/carbon/app/components/Table/components/Cell.tsx
index 84a7624c69..b5b45fe44a 100644
--- a/apps/carbon/app/components/Table/components/Cell.tsx
+++ b/apps/carbon/app/components/Table/components/Cell.tsx
@@ -51,9 +51,7 @@ const Cell = <T extends object>({
className={cn(
"relative px-4 whitespace-nowrap text-sm outline-none",
wasEdited && "bg-yellow-100 dark:bg-yellow-900",
- isEditing &&
- !hasEditableTableCellComponent &&
- "bg-zinc-50 dark:bg-zinc-950",
+ isEditing && !hasEditableTableCellComponent && "bg-muted/50",
isEditMode && "border-border border-r",
hasError && "ring-inset ring-2 ring-red-500",
isSelected && "ring-inset ring-2 ring-ring"
diff --git a/apps/carbon/app/components/index.ts b/apps/carbon/app/components/index.ts
index 0af7473cc1..8d8fa51559 100644
--- a/apps/carbon/app/components/index.ts
+++ b/apps/carbon/app/components/index.ts
@@ -5,6 +5,7 @@ import Combobox from "./Combobox";
import Contact from "./Contact";
import CreatableCombobox from "./CreateableCombobox";
import MultiSelect from "./MultiSelect";
+import New from "./New";
import Select from "./Select";
import Table from "./Table";
@@ -18,6 +19,7 @@ export {
Contact,
CreatableCombobox,
MultiSelect,
+ New,
Select,
Table,
};
diff --git a/apps/carbon/app/modules/accounting/ui/AccountCategories/AccountCategoriesTableFilters.tsx b/apps/carbon/app/modules/accounting/ui/AccountCategories/AccountCategoriesTableFilters.tsx
index 677d1db1b5..f88d20aaf8 100644
--- a/apps/carbon/app/modules/accounting/ui/AccountCategories/AccountCategoriesTableFilters.tsx
+++ b/apps/carbon/app/modules/accounting/ui/AccountCategories/AccountCategoriesTableFilters.tsx
@@ -1,7 +1,5 @@
-import { Button, HStack } from "@carbon/react";
-import { Link } from "@remix-run/react";
-import { IoMdAdd } from "react-icons/io";
-import { Select } from "~/components";
+import { HStack } from "@carbon/react";
+import { New, Select } from "~/components";
import { TableFilters } from "~/components/Layout";
import { DebouncedInput } from "~/components/Search";
import { usePermissions, useUrlParams } from "~/hooks";
@@ -44,9 +42,7 @@ const AccountCategoriesTableFilters = () => {
</HStack>
<HStack>
{permissions.can("update", "resources") && (
- <Button asChild leftIcon={<IoMdAdd />}>
- <Link to={`new?${params.toString()}`}>New Account Category</Link>
- </Button>
+ <New label="Account Category" to={`new?${params.toString()}`} />
)}
</HStack>
</TableFilters>
diff --git a/apps/carbon/app/modules/accounting/ui/ChartOfAccounts/ChartOfAccountsTableFilters.tsx b/apps/carbon/app/modules/accounting/ui/ChartOfAccounts/ChartOfAccountsTableFilters.tsx
index 68f5428be2..900956beff 100644
--- a/apps/carbon/app/modules/accounting/ui/ChartOfAccounts/ChartOfAccountsTableFilters.tsx
+++ b/apps/carbon/app/modules/accounting/ui/ChartOfAccounts/ChartOfAccountsTableFilters.tsx
@@ -8,10 +8,8 @@ import {
PopoverTrigger,
} from "@carbon/react";
import { parseDate } from "@internationalized/date";
-import { Link } from "@remix-run/react";
-import { IoMdAdd } from "react-icons/io";
import { MdCalendarMonth, MdClose } from "react-icons/md";
-import { Select } from "~/components";
+import { New, Select } from "~/components";
import { TableFilters } from "~/components/Layout";
import { usePermissions, useUrlParams } from "~/hooks";
import { incomeBalanceTypes } from "~/modules/accounting";
@@ -85,9 +83,7 @@ const ChartOfAccountsTableFilters = () => {
</HStack>
<HStack>
{permissions.can("create", "accounting") && (
- <Button asChild leftIcon={<IoMdAdd />}>
- <Link to={`new?${params.toString()}`}>New Account</Link>
- </Button>
+ <New label="Account" to={`new?${params.toString()}`} />
)}
</HStack>
</TableFilters>
diff --git a/apps/carbon/app/modules/accounting/ui/Currencies/CurrenciesTableFilters.tsx b/apps/carbon/app/modules/accounting/ui/Currencies/CurrenciesTableFilters.tsx
index e6d79ba683..37eb97e3bb 100644
--- a/apps/carbon/app/modules/accounting/ui/Currencies/CurrenciesTableFilters.tsx
+++ b/apps/carbon/app/modules/accounting/ui/Currencies/CurrenciesTableFilters.tsx
@@ -1,6 +1,5 @@
-import { Button, HStack } from "@carbon/react";
-import { Link } from "@remix-run/react";
-import { IoMdAdd } from "react-icons/io";
+import { HStack } from "@carbon/react";
+import { New } from "~/components";
import { TableFilters } from "~/components/Layout";
import { DebouncedInput } from "~/components/Search";
import { usePermissions, useUrlParams } from "~/hooks";
@@ -16,9 +15,7 @@ const CurrenciesTableFilters = () => {
</HStack>
<HStack>
{permissions.can("create", "accounting") && (
- <Button asChild leftIcon={<IoMdAdd />}>
- <Link to={`new?${params.toString()}`}>New Currency</Link>
- </Button>
+ <New label="Currency" to={`new?${params.toString()}`} />
)}
</HStack>
</TableFilters>
diff --git a/apps/carbon/app/modules/accounting/ui/PaymentTerms/PaymentTermsTableFilters.tsx b/apps/carbon/app/modules/accounting/ui/PaymentTerms/PaymentTermsTableFilters.tsx
index 33b9c52258..ddaf965b0c 100644
--- a/apps/carbon/app/modules/accounting/ui/PaymentTerms/PaymentTermsTableFilters.tsx
+++ b/apps/carbon/app/modules/accounting/ui/PaymentTerms/PaymentTermsTableFilters.tsx
@@ -1,6 +1,5 @@
-import { Button, HStack } from "@carbon/react";
-import { Link } from "@remix-run/react";
-import { IoMdAdd } from "react-icons/io";
+import { HStack } from "@carbon/react";
+import { New } from "~/components";
import { TableFilters } from "~/components/Layout";
import { DebouncedInput } from "~/components/Search";
import { usePermissions, useUrlParams } from "~/hooks";
@@ -16,9 +15,7 @@ const PaymentTermsTableFilters = () => {
</HStack>
<HStack>
{permissions.can("create", "accounting") && (
- <Button leftIcon={<IoMdAdd />}>
- <Link to={`new?${params.toString()}`}>New Payment Term</Link>
- </Button>
+ <New label="Payment Term" to={`new?${params.toString()}`} />
)}
</HStack>
</TableFilters>
diff --git a/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptsTableFilters.tsx b/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptsTableFilters.tsx
index 7c12de78fc..a10f848043 100644
--- a/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptsTableFilters.tsx
+++ b/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptsTableFilters.tsx
@@ -1,7 +1,5 @@
-import { Button, HStack } from "@carbon/react";
-import { Link } from "@remix-run/react";
-import { IoMdAdd } from "react-icons/io";
-import { Combobox } from "~/components";
+import { HStack } from "@carbon/react";
+import { Combobox, New } from "~/components";
import { TableFilters } from "~/components/Layout";
import { DebouncedInput } from "~/components/Search";
import { usePermissions, useUrlParams } from "~/hooks";
@@ -54,9 +52,7 @@ const ReceiptsTableFilters = ({ locations }: ReceiptsTableFiltersProps) => {
</HStack>
<HStack>
{permissions.can("create", "inventory") && (
- <Button asChild leftIcon={<IoMdAdd />}>
- <Link to={`new?${params.toString()}`}>New Receipt</Link>
- </Button>
+ <New label="Receipt" to={`new?${params.toString()}`} />
)}
</HStack>
</TableFilters>
diff --git a/apps/carbon/app/modules/inventory/ui/ShippingMethods/ShippingMethodsTableFilters.tsx b/apps/carbon/app/modules/inventory/ui/ShippingMethods/ShippingMethodsTableFilters.tsx
index a57ba2b200..e78fc778f6 100644
--- a/apps/carbon/app/modules/inventory/ui/ShippingMethods/ShippingMethodsTableFilters.tsx
+++ b/apps/carbon/app/modules/inventory/ui/ShippingMethods/ShippingMethodsTableFilters.tsx
@@ -1,6 +1,5 @@
-import { Button, HStack } from "@carbon/react";
-import { Link } from "@remix-run/react";
-import { IoMdAdd } from "react-icons/io";
+import { HStack } from "@carbon/react";
+import { New } from "~/components";
import { TableFilters } from "~/components/Layout";
import { DebouncedInput } from "~/components/Search";
import { usePermissions, useUrlParams } from "~/hooks";
@@ -16,9 +15,7 @@ const ShippingMethodsTableFilters = () => {
</HStack>
<HStack>
{permissions.can("create", "inventory") && (
- <Button asChild leftIcon={<IoMdAdd />}>
- <Link to={`new?${params.toString()}`}>New Shipping Method</Link>
- </Button>
+ <New label="Shipping Method" to={`new?${params.toString()}`} />
)}
</HStack>
</TableFilters>
diff --git a/apps/carbon/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceLines/PurchaseInvoiceLines.tsx b/apps/carbon/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceLines/PurchaseInvoiceLines.tsx
index 713dcefa72..75b68ef597 100644
--- a/apps/carbon/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceLines/PurchaseInvoiceLines.tsx
+++ b/apps/carbon/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceLines/PurchaseInvoiceLines.tsx
@@ -1,5 +1,4 @@
import {
- Button,
Card,
CardAction,
CardContent,
@@ -13,12 +12,13 @@ import {
HStack,
IconButton,
} from "@carbon/react";
-import { Link, Outlet, useNavigate, useParams } from "@remix-run/react";
+import { Outlet, useNavigate, useParams } from "@remix-run/react";
import type { ColumnDef } from "@tanstack/react-table";
import { useMemo } from "react";
import { BsFillPenFill } from "react-icons/bs";
import { IoMdTrash } from "react-icons/io";
import { MdMoreHoriz } from "react-icons/md";
+import { New } from "~/components";
import {
EditableNumber,
EditablePurchaseInvoiceLineNumber,
@@ -200,13 +200,7 @@ const PurchaseInvoiceLines = () => {
<CardHeader>
<CardTitle>Purchase Invoice Lines</CardTitle>
</CardHeader>
- <CardAction>
- {canEdit && isEditable && (
- <Button asChild>
- <Link to="new">New</Link>
- </Button>
- )}
- </CardAction>
+ <CardAction>{canEdit && isEditable && <New to="new" />}</CardAction>
</HStack>
<CardContent>
<Grid<PurchaseInvoiceLine>
diff --git a/apps/carbon/app/modules/invoicing/ui/PurchaseInvoices/PurchaseInvoicesTableFilters.tsx b/apps/carbon/app/modules/invoicing/ui/PurchaseInvoices/PurchaseInvoicesTableFilters.tsx
index 5589e6a383..7950d27506 100644
--- a/apps/carbon/app/modules/invoicing/ui/PurchaseInvoices/PurchaseInvoicesTableFilters.tsx
+++ b/apps/carbon/app/modules/invoicing/ui/PurchaseInvoices/PurchaseInvoicesTableFilters.tsx
@@ -1,7 +1,5 @@
-import { Button, HStack } from "@carbon/react";
-import { Link } from "@remix-run/react";
-import { IoMdAdd } from "react-icons/io";
-import { Combobox, Select } from "~/components";
+import { HStack } from "@carbon/react";
+import { Combobox, New, Select } from "~/components";
import { TableFilters } from "~/components/Layout";
import { DebouncedInput } from "~/components/Search";
import { usePermissions, useUrlParams } from "~/hooks";
@@ -55,9 +53,7 @@ const PurchaseInvoicesTableFilters = () => {
</HStack>
<HStack>
{permissions.can("create", "invoicing") && (
- <Button asChild leftIcon={<IoMdAdd />}>
- <Link to={path.to.newPurchaseInvoice}>New Purchase Invoice</Link>
- </Button>
+ <New label="Purchase Invoice" to={path.to.newPurchaseInvoice} />
)}
</HStack>
</TableFilters>
diff --git a/apps/carbon/app/modules/parts/ui/Part/PartSuppliers/PartSuppliers.tsx b/apps/carbon/app/modules/parts/ui/Part/PartSuppliers/PartSuppliers.tsx
index 0c121b55a7..11eb9b52be 100644
--- a/apps/carbon/app/modules/parts/ui/Part/PartSuppliers/PartSuppliers.tsx
+++ b/apps/carbon/app/modules/parts/ui/Part/PartSuppliers/PartSuppliers.tsx
@@ -1,5 +1,4 @@
import {
- Button,
Card,
CardAction,
CardContent,
@@ -7,9 +6,10 @@ import {
CardTitle,
HStack,
} from "@carbon/react";
-import { Link, Outlet, useNavigate } from "@remix-run/react";
+import { Outlet, useNavigate } from "@remix-run/react";
import type { ColumnDef } from "@tanstack/react-table";
import { useMemo } from "react";
+import { New } from "~/components";
import {
EditableList,
EditableNumber,
@@ -109,13 +109,7 @@ const PartSuppliers = ({ partSuppliers }: PartSuppliersProps) => {
<CardHeader>
<CardTitle>Suppliers</CardTitle>
</CardHeader>
- <CardAction>
- {canEdit && (
- <Button asChild>
- <Link to="new">New</Link>
- </Button>
- )}
- </CardAction>
+ <CardAction>{canEdit && <New to="new" />}</CardAction>
</HStack>
<CardContent>
<Grid<PartSupplier>
diff --git a/apps/carbon/app/modules/parts/ui/PartGroups/PartGroupsTableFilters.tsx b/apps/carbon/app/modules/parts/ui/PartGroups/PartGroupsTableFilters.tsx
index 66058c9cb3..5166f5eb98 100644
--- a/apps/carbon/app/modules/parts/ui/PartGroups/PartGroupsTableFilters.tsx
+++ b/apps/carbon/app/modules/parts/ui/PartGroups/PartGroupsTableFilters.tsx
@@ -1,6 +1,5 @@
-import { Button, HStack } from "@carbon/react";
-import { Link } from "@remix-run/react";
-import { IoMdAdd } from "react-icons/io";
+import { HStack } from "@carbon/react";
+import { New } from "~/components";
import { TableFilters } from "~/components/Layout";
import { DebouncedInput } from "~/components/Search";
import { usePermissions, useUrlParams } from "~/hooks";
@@ -16,9 +15,7 @@ const PartGroupsTableFilters = () => {
</HStack>
<HStack>
{permissions.can("create", "parts") && (
- <Button asChild leftIcon={<IoMdAdd />}>
- <Link to={`new?${params.toString()}`}>New Part Group</Link>
- </Button>
+ <New label="Part Group" to={`new?${params.toString()}`} />
)}
</HStack>
</TableFilters>
diff --git a/apps/carbon/app/modules/parts/ui/Parts/PartsTableFilters.tsx b/apps/carbon/app/modules/parts/ui/Parts/PartsTableFilters.tsx
index bea343f525..7ae08a633c 100644
--- a/apps/carbon/app/modules/parts/ui/Parts/PartsTableFilters.tsx
+++ b/apps/carbon/app/modules/parts/ui/Parts/PartsTableFilters.tsx
@@ -1,7 +1,5 @@
-import { Button, HStack } from "@carbon/react";
-import { Link } from "@remix-run/react";
-import { IoMdAdd } from "react-icons/io";
-import { Combobox, Select } from "~/components";
+import { HStack } from "@carbon/react";
+import { Combobox, New, Select } from "~/components";
import { TableFilters } from "~/components/Layout";
import { DebouncedInput } from "~/components/Search";
import { usePermissions, useUrlParams } from "~/hooks";
@@ -59,9 +57,7 @@ const PartsTableFilters = ({ partGroups }: PartsTableFiltersProps) => {
</HStack>
<HStack>
{permissions.can("create", "parts") && (
- <Button asChild leftIcon={<IoMdAdd />}>
- <Link to={path.to.newPart}>New Part</Link>
- </Button>
+ <New to={path.to.newPart} label="Part" />
)}
</HStack>
</TableFilters>
diff --git a/apps/carbon/app/modules/parts/ui/Service/ServiceSuppliers/ServiceSuppliers.tsx b/apps/carbon/app/modules/parts/ui/Service/ServiceSuppliers/ServiceSuppliers.tsx
index 15283e82b8..59115e106c 100644
--- a/apps/carbon/app/modules/parts/ui/Service/ServiceSuppliers/ServiceSuppliers.tsx
+++ b/apps/carbon/app/modules/parts/ui/Service/ServiceSuppliers/ServiceSuppliers.tsx
@@ -1,5 +1,4 @@
import {
- Button,
Card,
CardAction,
CardContent,
@@ -7,9 +6,10 @@ import {
CardTitle,
HStack,
} from "@carbon/react";
-import { Link, Outlet, useNavigate } from "@remix-run/react";
+import { Outlet, useNavigate } from "@remix-run/react";
import type { ColumnDef } from "@tanstack/react-table";
import { useMemo } from "react";
+import { New } from "~/components";
import { EditableText } from "~/components/Editable";
import Grid from "~/components/Grid";
import type { ServiceSupplier } from "~/modules/parts";
@@ -73,13 +73,7 @@ const ServiceSuppliers = ({ serviceSuppliers }: ServiceSuppliersProps) => {
<CardHeader>
<CardTitle>Suppliers</CardTitle>
</CardHeader>
- <CardAction>
- {canEdit && (
- <Button asChild>
- <Link to="new">New</Link>
- </Button>
- )}
- </CardAction>
+ <CardAction>{canEdit && <New to="new" />}</CardAction>
</HStack>
<CardContent>
<Grid<ServiceSupplier>
diff --git a/apps/carbon/app/modules/parts/ui/Services/ServicesTableFilters.tsx b/apps/carbon/app/modules/parts/ui/Services/ServicesTableFilters.tsx
index 95f93508f7..3084a2bfc8 100644
--- a/apps/carbon/app/modules/parts/ui/Services/ServicesTableFilters.tsx
+++ b/apps/carbon/app/modules/parts/ui/Services/ServicesTableFilters.tsx
@@ -1,7 +1,5 @@
-import { Button, HStack } from "@carbon/react";
-import { Link } from "@remix-run/react";
-import { IoMdAdd } from "react-icons/io";
-import { Combobox, Select } from "~/components";
+import { HStack } from "@carbon/react";
+import { Combobox, New, Select } from "~/components";
import { TableFilters } from "~/components/Layout";
import { DebouncedInput } from "~/components/Search";
import { usePermissions, useUrlParams } from "~/hooks";
@@ -63,9 +61,7 @@ const ServicesTableFilters = ({ partGroups }: ServicesTableFiltersProps) => {
</HStack>
<HStack>
{permissions.can("create", "parts") && (
- <Button asChild leftIcon={<IoMdAdd />}>
- <Link to={path.to.newService}>New Service</Link>
- </Button>
+ <New label="Service" to={path.to.newService} />
)}
</HStack>
</TableFilters>
diff --git a/apps/carbon/app/modules/parts/ui/UnitOfMeasure/UnitOfMeasuresTableFilters.tsx b/apps/carbon/app/modules/parts/ui/UnitOfMeasure/UnitOfMeasuresTableFilters.tsx
index cf2702289a..aa8c17e8b2 100644
--- a/apps/carbon/app/modules/parts/ui/UnitOfMeasure/UnitOfMeasuresTableFilters.tsx
+++ b/apps/carbon/app/modules/parts/ui/UnitOfMeasure/UnitOfMeasuresTableFilters.tsx
@@ -1,6 +1,5 @@
-import { Button, HStack } from "@carbon/react";
-import { Link } from "@remix-run/react";
-import { IoMdAdd } from "react-icons/io";
+import { HStack } from "@carbon/react";
+import { New } from "~/components";
import { TableFilters } from "~/components/Layout";
import { DebouncedInput } from "~/components/Search";
import { usePermissions, useUrlParams } from "~/hooks";
@@ -15,9 +14,7 @@ const UnitOfMeasuresTableFilters = () => {
</HStack>
<HStack>
{permissions.can("create", "parts") && (
- <Button asChild leftIcon={<IoMdAdd />}>
- <Link to={`new?${params.toString()}`}>New Unit of Measure</Link>
- </Button>
+ <New label="Unit of Measure" to={`new?${params.toString()}`} />
)}
</HStack>
</TableFilters>
diff --git a/apps/carbon/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderForm.tsx b/apps/carbon/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderForm.tsx
index d55cdafe7d..004b361141 100644
--- a/apps/carbon/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderForm.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderForm.tsx
@@ -82,6 +82,7 @@ const PurchaseOrderForm = ({ initialValues }: PurchaseOrderFormProps) => {
>
<VStack>
<Supplier
+ autoFocus
name="supplierId"
label="Supplier"
onChange={(newValue) =>
diff --git a/apps/carbon/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLines/PurchaseOrderLines.tsx b/apps/carbon/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLines/PurchaseOrderLines.tsx
index a61e27b086..2fdfa0ad73 100644
--- a/apps/carbon/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLines/PurchaseOrderLines.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLines/PurchaseOrderLines.tsx
@@ -1,5 +1,4 @@
import {
- Button,
Card,
CardAction,
CardContent,
@@ -14,12 +13,13 @@ import {
HStack,
IconButton,
} from "@carbon/react";
-import { Link, Outlet, useNavigate, useParams } from "@remix-run/react";
+import { Outlet, useNavigate, useParams } from "@remix-run/react";
import type { ColumnDef } from "@tanstack/react-table";
import { useMemo } from "react";
import { BsFillPenFill } from "react-icons/bs";
import { IoMdTrash } from "react-icons/io";
import { MdMoreHoriz } from "react-icons/md";
+import { New } from "~/components";
import {
EditableNumber,
EditablePurchaseOrderLineNumber,
@@ -288,13 +288,7 @@ const PurchaseOrderLines = () => {
<CardHeader>
<CardTitle>Purchase Order Lines</CardTitle>
</CardHeader>
- <CardAction>
- {canEdit && isEditable && (
- <Button asChild>
- <Link to="new">New</Link>
- </Button>
- )}
- </CardAction>
+ <CardAction>{canEdit && isEditable && <New to="new" />}</CardAction>
</HStack>
<CardContent>
diff --git a/apps/carbon/app/modules/purchasing/ui/PurchaseOrders/PurchaseOrdersTableFilters.tsx b/apps/carbon/app/modules/purchasing/ui/PurchaseOrders/PurchaseOrdersTableFilters.tsx
index 435ec696f3..06cc9fa6e3 100644
--- a/apps/carbon/app/modules/purchasing/ui/PurchaseOrders/PurchaseOrdersTableFilters.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/PurchaseOrders/PurchaseOrdersTableFilters.tsx
@@ -1,7 +1,5 @@
-import { Button, HStack } from "@carbon/react";
-import { Link } from "@remix-run/react";
-import { IoMdAdd } from "react-icons/io";
-import { Combobox, Select } from "~/components";
+import { HStack } from "@carbon/react";
+import { Combobox, New, Select } from "~/components";
import { TableFilters } from "~/components/Layout";
import { DebouncedInput } from "~/components/Search";
import { usePermissions, useUrlParams } from "~/hooks";
@@ -55,9 +53,7 @@ const PurchaseOrdersTableFilters = () => {
</HStack>
<HStack>
{permissions.can("create", "purchasing") && (
- <Button asChild leftIcon={<IoMdAdd />}>
- <Link to={path.to.newPurchaseOrder}>New Purchase Order</Link>
- </Button>
+ <New label="Purchase Order" to={path.to.newPurchaseOrder} />
)}
</HStack>
</TableFilters>
diff --git a/apps/carbon/app/modules/purchasing/ui/RequestForQuotes/RequestForQuotesTableFilters.tsx b/apps/carbon/app/modules/purchasing/ui/RequestForQuotes/RequestForQuotesTableFilters.tsx
index 973071744c..30e77895c7 100644
--- a/apps/carbon/app/modules/purchasing/ui/RequestForQuotes/RequestForQuotesTableFilters.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/RequestForQuotes/RequestForQuotesTableFilters.tsx
@@ -1,7 +1,5 @@
-import { Button, HStack } from "@carbon/react";
-import { Link } from "@remix-run/react";
-import { IoMdAdd } from "react-icons/io";
-import { Combobox, Select } from "~/components";
+import { HStack } from "@carbon/react";
+import { Combobox, New, Select } from "~/components";
import { TableFilters } from "~/components/Layout";
import { DebouncedInput } from "~/components/Search";
import { usePermissions, useUrlParams } from "~/hooks";
@@ -76,9 +74,7 @@ const RequestForQuotesTableFilters = () => {
</HStack>
<HStack>
{permissions.can("create", "purchasing") && (
- <Button asChild leftIcon={<IoMdAdd />}>
- <Link to={path.to.newRequestForQuote}>New RFQ</Link>
- </Button>
+ <New label="RFQ" to={path.to.newRequestForQuote} />
)}
</HStack>
</TableFilters>
diff --git a/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierContacts.tsx b/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierContacts.tsx
index d88662c263..1557d91cf5 100644
--- a/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierContacts.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierContacts.tsx
@@ -1,5 +1,4 @@
import {
- Button,
Card,
CardAction,
CardContent,
@@ -8,11 +7,11 @@ import {
HStack,
useDisclosure,
} from "@carbon/react";
-import { Link, Outlet, useNavigate, useParams } from "@remix-run/react";
+import { Outlet, useNavigate, useParams } from "@remix-run/react";
import { useCallback, useState } from "react";
import { BsFillPenFill } from "react-icons/bs";
import { IoMdAdd, IoMdTrash } from "react-icons/io";
-import { Contact } from "~/components";
+import { Contact, New } from "~/components";
import { ConfirmDelete } from "~/components/Modals";
import { usePermissions } from "~/hooks";
import type { SupplierContact } from "~/modules/purchasing/types";
@@ -93,13 +92,7 @@ const SupplierContacts = ({ contacts }: SupplierContactsProps) => {
<CardHeader>
<CardTitle>Contacts</CardTitle>
</CardHeader>
- <CardAction>
- {canEdit && (
- <Button asChild>
- <Link to="new">New</Link>
- </Button>
- )}
- </CardAction>
+ <CardAction>{canEdit && <New to="new" />}</CardAction>
</HStack>
<CardContent>
{isEmpty ? (
diff --git a/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierLocations.tsx b/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierLocations.tsx
index d956cf2d24..15c79913c1 100644
--- a/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierLocations.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierLocations.tsx
@@ -1,5 +1,4 @@
import {
- Button,
Card,
CardAction,
CardContent,
@@ -8,11 +7,11 @@ import {
HStack,
useDisclosure,
} from "@carbon/react";
-import { Link, Outlet, useNavigate, useParams } from "@remix-run/react";
+import { Outlet, useNavigate, useParams } from "@remix-run/react";
import { useCallback, useState } from "react";
import { BsFillPenFill } from "react-icons/bs";
import { IoMdAdd, IoMdTrash } from "react-icons/io";
-import { Address } from "~/components";
+import { Address, New } from "~/components";
import { ConfirmDelete } from "~/components/Modals";
import { usePermissions } from "~/hooks";
import type { SupplierLocation } from "~/modules/purchasing/types";
@@ -80,13 +79,7 @@ const SupplierLocations = ({ locations }: SupplierLocationsProps) => {
<CardHeader>
<CardTitle>Locations</CardTitle>
</CardHeader>
- <CardAction>
- {canEdit && (
- <Button asChild>
- <Link to="new">New</Link>
- </Button>
- )}
- </CardAction>
+ <CardAction>{canEdit && <New to="new" />}</CardAction>
</HStack>
<CardContent>
{isEmpty ? (
diff --git a/apps/carbon/app/modules/purchasing/ui/SupplierTypes/SupplierTypesTableFilters.tsx b/apps/carbon/app/modules/purchasing/ui/SupplierTypes/SupplierTypesTableFilters.tsx
index 10ba7b429c..3f17f8a567 100644
--- a/apps/carbon/app/modules/purchasing/ui/SupplierTypes/SupplierTypesTableFilters.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/SupplierTypes/SupplierTypesTableFilters.tsx
@@ -1,6 +1,5 @@
-import { Button, HStack } from "@carbon/react";
-import { Link } from "@remix-run/react";
-import { IoMdAdd } from "react-icons/io";
+import { HStack } from "@carbon/react";
+import { New } from "~/components";
import { TableFilters } from "~/components/Layout";
import { DebouncedInput } from "~/components/Search";
import { usePermissions, useUrlParams } from "~/hooks";
@@ -16,9 +15,7 @@ const SupplierTypesTableFilters = () => {
</HStack>
<HStack>
{permissions.can("create", "purchasing") && (
- <Button asChild leftIcon={<IoMdAdd />}>
- <Link to={`new?${params.toString()}`}>New Supplier Type</Link>
- </Button>
+ <New label="Supplier Type" to={`new?${params.toString()}`} />
)}
</HStack>
</TableFilters>
diff --git a/apps/carbon/app/modules/purchasing/ui/Suppliers/SuppliersTableFilters.tsx b/apps/carbon/app/modules/purchasing/ui/Suppliers/SuppliersTableFilters.tsx
index 86909068d8..e109e3ee41 100644
--- a/apps/carbon/app/modules/purchasing/ui/Suppliers/SuppliersTableFilters.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/Suppliers/SuppliersTableFilters.tsx
@@ -1,7 +1,5 @@
-import { Button, HStack } from "@carbon/react";
-import { Link } from "@remix-run/react";
-import { IoMdAdd } from "react-icons/io";
-import { Combobox, Select } from "~/components";
+import { HStack } from "@carbon/react";
+import { Combobox, New, Select } from "~/components";
import { TableFilters } from "~/components/Layout";
import { DebouncedInput } from "~/components/Search";
import { usePermissions, useUrlParams } from "~/hooks";
@@ -63,9 +61,7 @@ const SuppliersTableFilters = ({
</HStack>
<HStack>
{permissions.can("create", "purchasing") && (
- <Button leftIcon={<IoMdAdd />} asChild>
- <Link to={path.to.newSupplier}>New Supplier</Link>
- </Button>
+ <New label="Supplier" to={path.to.newSupplier} />
)}
</HStack>
</TableFilters>
diff --git a/apps/carbon/app/modules/sales/sales.service.ts b/apps/carbon/app/modules/sales/sales.service.ts
index cea56f0e38..509afadab8 100644
--- a/apps/carbon/app/modules/sales/sales.service.ts
+++ b/apps/carbon/app/modules/sales/sales.service.ts
@@ -52,6 +52,13 @@ export async function deleteQuote(
return client.from("quote").delete().eq("id", quoteId);
}
+export async function deleteQuoteLine(
+ client: SupabaseClient<Database>,
+ quoteLineId: string
+) {
+ return client.from("quoteLine").delete().eq("id", quoteLineId);
+}
+
export async function getCustomer(
client: SupabaseClient<Database>,
customerId: string
diff --git a/apps/carbon/app/modules/sales/ui/Customer/CustomerContacts.tsx b/apps/carbon/app/modules/sales/ui/Customer/CustomerContacts.tsx
index 133716b347..ad0b5ab8e1 100644
--- a/apps/carbon/app/modules/sales/ui/Customer/CustomerContacts.tsx
+++ b/apps/carbon/app/modules/sales/ui/Customer/CustomerContacts.tsx
@@ -1,5 +1,4 @@
import {
- Button,
Card,
CardAction,
CardContent,
@@ -8,11 +7,11 @@ import {
HStack,
useDisclosure,
} from "@carbon/react";
-import { Link, Outlet, useNavigate, useParams } from "@remix-run/react";
+import { Outlet, useNavigate, useParams } from "@remix-run/react";
import { useCallback, useState } from "react";
import { BsFillPenFill } from "react-icons/bs";
import { IoMdAdd, IoMdTrash } from "react-icons/io";
-import { Contact } from "~/components";
+import { Contact, New } from "~/components";
import { ConfirmDelete } from "~/components/Modals";
import { usePermissions } from "~/hooks";
import type { CustomerContact } from "~/modules/sales/types";
@@ -82,13 +81,7 @@ const CustomerContacts = ({ contacts }: CustomerContactsProps) => {
<CardHeader>
<CardTitle>Contacts</CardTitle>
</CardHeader>
- <CardAction>
- {canEdit && (
- <Button asChild>
- <Link to="new">New</Link>
- </Button>
- )}
- </CardAction>
+ <CardAction>{canEdit && <New to="new" />}</CardAction>
</HStack>
<CardContent>
{isEmpty ? (
diff --git a/apps/carbon/app/modules/sales/ui/Customer/CustomerLocations.tsx b/apps/carbon/app/modules/sales/ui/Customer/CustomerLocations.tsx
index 2c8d184a01..61190ef03b 100644
--- a/apps/carbon/app/modules/sales/ui/Customer/CustomerLocations.tsx
+++ b/apps/carbon/app/modules/sales/ui/Customer/CustomerLocations.tsx
@@ -1,5 +1,4 @@
import {
- Button,
Card,
CardAction,
CardContent,
@@ -8,11 +7,11 @@ import {
HStack,
useDisclosure,
} from "@carbon/react";
-import { Link, Outlet, useNavigate, useParams } from "@remix-run/react";
+import { Outlet, useNavigate, useParams } from "@remix-run/react";
import { useCallback, useState } from "react";
import { BsFillPenFill } from "react-icons/bs";
import { IoMdTrash } from "react-icons/io";
-import { Address } from "~/components";
+import { Address, New } from "~/components";
import { ConfirmDelete } from "~/components/Modals";
import { usePermissions } from "~/hooks";
import type { CustomerLocation } from "~/modules/sales";
@@ -68,13 +67,7 @@ const CustomerLocations = ({ locations }: CustomerLocationsProps) => {
<CardHeader>
<CardTitle>Locations</CardTitle>
</CardHeader>
- <CardAction>
- {canEdit && (
- <Button asChild>
- <Link to="new">New</Link>
- </Button>
- )}
- </CardAction>
+ <CardAction>{canEdit && <New to="new" />}</CardAction>
</HStack>
<CardContent>
{isEmpty ? (
diff --git a/apps/carbon/app/modules/sales/ui/Quotation/QuotationDocuments/QuotationDocuments.tsx b/apps/carbon/app/modules/sales/ui/Quotation/QuotationDocuments/QuotationDocuments.tsx
index 383724132d..bc2d67edff 100644
--- a/apps/carbon/app/modules/sales/ui/Quotation/QuotationDocuments/QuotationDocuments.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotation/QuotationDocuments/QuotationDocuments.tsx
@@ -43,6 +43,8 @@ const QuotationDocuments = ({
id,
});
+ console.log({ attachments, isExternal, id });
+
return (
<>
<Card>
diff --git a/apps/carbon/app/modules/sales/ui/Quotation/QuotationForm.tsx b/apps/carbon/app/modules/sales/ui/Quotation/QuotationForm.tsx
index b8e5a185b2..7f897ee25f 100644
--- a/apps/carbon/app/modules/sales/ui/Quotation/QuotationForm.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotation/QuotationForm.tsx
@@ -67,6 +67,7 @@ const QuotationForm = ({ initialValues }: QuotationFormProps) => {
>
<VStack>
<Customer
+ autoFocus
name="customerId"
label="Customer"
onChange={(value) => setCustomer(value?.value as string)}
diff --git a/apps/carbon/app/modules/sales/ui/Quotations/QuotationsTableFilters.tsx b/apps/carbon/app/modules/sales/ui/Quotations/QuotationsTableFilters.tsx
index 29239cee18..8d37d4ac34 100644
--- a/apps/carbon/app/modules/sales/ui/Quotations/QuotationsTableFilters.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotations/QuotationsTableFilters.tsx
@@ -1,7 +1,5 @@
-import { Button, HStack } from "@carbon/react";
-import { Link } from "@remix-run/react";
-import { IoMdAdd } from "react-icons/io";
-import { Combobox, Select } from "~/components";
+import { HStack } from "@carbon/react";
+import { Combobox, New, Select } from "~/components";
import { TableFilters } from "~/components/Layout";
import { DebouncedInput } from "~/components/Search";
import { usePermissions, useUrlParams } from "~/hooks";
@@ -74,9 +72,7 @@ const QuotesTableFilters = () => {
</HStack>
<HStack>
{permissions.can("create", "sales") && (
- <Button asChild leftIcon={<IoMdAdd />}>
- <Link to={path.to.newQuote}>New Quote</Link>
- </Button>
+ <New to={path.to.newQuote} label="Quote" />
)}
</HStack>
</TableFilters>
diff --git a/apps/carbon/app/routes/x+/quote+/$id.internal.tsx b/apps/carbon/app/routes/x+/quote+/$id.internal.tsx
index 5607128e12..aeffa92aa9 100644
--- a/apps/carbon/app/routes/x+/quote+/$id.internal.tsx
+++ b/apps/carbon/app/routes/x+/quote+/$id.internal.tsx
@@ -15,7 +15,7 @@ export default function QuotationInternalDocumentsRoute() {
const routeData = useRouteData<{
internalDocuments: QuotationAttachment[];
- }>(path.to.purchaseOrder(id));
+ }>(path.to.quote(id));
return (
<QuotationDocuments
diff --git a/apps/carbon/app/routes/x+/quote+/$id.lines.delete.$lineId.tsx b/apps/carbon/app/routes/x+/quote+/$id.lines.delete.$lineId.tsx
new file mode 100644
index 0000000000..f387ef2a9a
--- /dev/null
+++ b/apps/carbon/app/routes/x+/quote+/$id.lines.delete.$lineId.tsx
@@ -0,0 +1,81 @@
+import type { ActionFunctionArgs, LoaderFunctionArgs } from "@remix-run/node";
+import { json, redirect } from "@remix-run/node";
+import { useLoaderData, useNavigate, useParams } from "@remix-run/react";
+import { ConfirmDelete } from "~/components/Modals";
+import { deleteQuoteLine, getQuoteLine } from "~/modules/sales";
+import { requirePermissions } from "~/services/auth";
+import { flash } from "~/services/session.server";
+import { notFound } from "~/utils/http";
+import { path } from "~/utils/path";
+import { error, success } from "~/utils/result";
+
+export async function loader({ request, params }: LoaderFunctionArgs) {
+ const { client } = await requirePermissions(request, {
+ delete: "sales",
+ });
+ const { lineId, id } = params;
+ if (!lineId) throw notFound("lineId not found");
+ if (!id) throw notFound("id not found");
+
+ const quotationLine = await getQuoteLine(client, lineId);
+ if (quotationLine.error) {
+ return redirect(
+ path.to.quoteLines(id),
+ await flash(
+ request,
+ error(quotationLine.error, "Failed to get quotation line")
+ )
+ );
+ }
+
+ return json({ quotationLine: quotationLine.data });
+}
+
+export async function action({ request, params }: ActionFunctionArgs) {
+ const { client } = await requirePermissions(request, {
+ delete: "sales",
+ });
+
+ const { lineId, id } = params;
+ if (!lineId) throw notFound("Could not find lineId");
+ if (!id) throw notFound("Could not find id");
+
+ const { error: deleteTypeError } = await deleteQuoteLine(client, lineId);
+ if (deleteTypeError) {
+ return redirect(
+ path.to.quoteLines(id),
+ await flash(
+ request,
+ error(deleteTypeError, "Failed to delete quotation line")
+ )
+ );
+ }
+
+ return redirect(
+ path.to.quoteLines(id),
+ await flash(request, success("Successfully deleted quotation line"))
+ );
+}
+
+export default function DeleteQuoteLineRoute() {
+ const { lineId, id } = useParams();
+ const { quotationLine } = useLoaderData<typeof loader>();
+ const navigate = useNavigate();
+
+ if (!quotationLine) return null;
+ if (!lineId) throw notFound("Could not find lineId");
+ if (!id) throw notFound("Could not find id");
+
+ const onCancel = () => navigate(path.to.quoteLines(id));
+
+ return (
+ <ConfirmDelete
+ action={path.to.deleteQuoteLine(id, lineId)}
+ name="Quote Line"
+ text={`Are you sure you want to delete the quotation line for ${
+ quotationLine.quantity ?? 0
+ } ${quotationLine.description ?? ""}? This cannot be undone.`}
+ onCancel={onCancel}
+ />
+ );
+}
diff --git a/apps/carbon/app/routes/x+/quote+/$orderId.lines.delete.$lineId.tsx b/apps/carbon/app/routes/x+/quote+/$orderId.lines.delete.$lineId.tsx
deleted file mode 100644
index b7c86bf169..0000000000
--- a/apps/carbon/app/routes/x+/quote+/$orderId.lines.delete.$lineId.tsx
+++ /dev/null
@@ -1,87 +0,0 @@
-import type { ActionFunctionArgs, LoaderFunctionArgs } from "@remix-run/node";
-import { json, redirect } from "@remix-run/node";
-import { useLoaderData, useNavigate, useParams } from "@remix-run/react";
-import { ConfirmDelete } from "~/components/Modals";
-import {
- deletePurchaseOrderLine,
- getPurchaseOrderLine,
-} from "~/modules/purchasing";
-import { requirePermissions } from "~/services/auth";
-import { flash } from "~/services/session.server";
-import { notFound } from "~/utils/http";
-import { path } from "~/utils/path";
-import { error, success } from "~/utils/result";
-
-export async function loader({ request, params }: LoaderFunctionArgs) {
- const { client } = await requirePermissions(request, {
- delete: "purchasing",
- });
- const { lineId, orderId } = params;
- if (!lineId) throw notFound("lineId not found");
- if (!orderId) throw notFound("orderId not found");
-
- const purchaseOrderLine = await getPurchaseOrderLine(client, lineId);
- if (purchaseOrderLine.error) {
- return redirect(
- path.to.purchaseOrderLines(orderId),
- await flash(
- request,
- error(purchaseOrderLine.error, "Failed to get purchase order line")
- )
- );
- }
-
- return json({ purchaseOrderLine: purchaseOrderLine.data });
-}
-
-export async function action({ request, params }: ActionFunctionArgs) {
- const { client } = await requirePermissions(request, {
- delete: "purchasing",
- });
-
- const { lineId, orderId } = params;
- if (!lineId) throw notFound("Could not find lineId");
- if (!orderId) throw notFound("Could not find orderId");
-
- const { error: deleteTypeError } = await deletePurchaseOrderLine(
- client,
- lineId
- );
- if (deleteTypeError) {
- return redirect(
- path.to.purchaseOrderLines(orderId),
- await flash(
- request,
- error(deleteTypeError, "Failed to delete purchase order line")
- )
- );
- }
-
- return redirect(
- path.to.purchaseOrderLines(orderId),
- await flash(request, success("Successfully deleted purchase order line"))
- );
-}
-
-export default function DeletePurchaseOrderLineRoute() {
- const { lineId, orderId } = useParams();
- const { purchaseOrderLine } = useLoaderData<typeof loader>();
- const navigate = useNavigate();
-
- if (!purchaseOrderLine) return null;
- if (!lineId) throw notFound("Could not find lineId");
- if (!orderId) throw notFound("Could not find orderId");
-
- const onCancel = () => navigate(path.to.purchaseOrderLines(orderId));
-
- return (
- <ConfirmDelete
- action={path.to.deletePurchaseOrderLine(orderId, lineId)}
- name="Purchase Order Line"
- text={`Are you sure you want to delete the purchase order line for ${
- purchaseOrderLine.purchaseQuantity ?? 0
- } ${purchaseOrderLine.description ?? ""}? This cannot be undone.`}
- onCancel={onCancel}
- />
- );
-}
diff --git a/apps/carbon/app/utils/path.ts b/apps/carbon/app/utils/path.ts
index 88555a8f61..8f653a937d 100644
--- a/apps/carbon/app/utils/path.ts
+++ b/apps/carbon/app/utils/path.ts
@@ -168,6 +168,8 @@ export const path = {
deletePurchaseOrderLine: (orderId: string, lineId: string) =>
generatePath(`${x}/purchase-order/${orderId}/lines/delete/${lineId}`),
deleteQuote: (id: string) => generatePath(`${x}/quote/delete/${id}`),
+ deleteQuoteLine: (id: string, lineId: string) =>
+ generatePath(`${x}/quote/${id}/lines/delete/${lineId}`),
deleteReceipt: (id: string) =>
generatePath(`${x}/inventory/receipts/delete/${id}`),
deleteRequestForQuote: (id: string) =>
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index f8bb4f551c..8445f75e40 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -12038,7 +12038,13 @@ export interface Database {
| "Job"
| "Part"
| "Purchase Order"
+ | "Lead"
+ | "Opportunity"
+ | "Quotation"
| "Sales Order"
+ | "Request for Quotation"
+ | "Sales Invoice"
+ | "Purchase Invoice"
| "Document";
serviceType: "Internal" | "External";
shippingCarrier: "UPS" | "FedEx" | "USPS" | "DHL" | "Other";
diff --git a/packages/database/supabase/migrations/20230123212853_search.sql b/packages/database/supabase/migrations/20230123212853_search.sql
index a6e31de0d4..29c31eefab 100644
--- a/packages/database/supabase/migrations/20230123212853_search.sql
+++ b/packages/database/supabase/migrations/20230123212853_search.sql
@@ -1,5 +1,5 @@
-CREATE TYPE "searchEntity" AS enum ('Resource', 'Person', 'Customer', 'Supplier', 'Job', 'Part', 'Purchase Order', 'Sales Order', 'Document');
+CREATE TYPE "searchEntity" AS ENUM ('Resource', 'Person', 'Customer', 'Supplier', 'Job', 'Part', 'Purchase Order', 'Lead', 'Opportunity', 'Quotation', 'Sales Order', 'Request for Quotation', 'Sales Invoice', 'Purchase Invoice', 'Document');
CREATE TABLE search (
id BIGINT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
diff --git a/packages/database/supabase/migrations/20230330024716_parts.sql b/packages/database/supabase/migrations/20230330024716_parts.sql
index 426687e910..9475b0c04b 100644
--- a/packages/database/supabase/migrations/20230330024716_parts.sql
+++ b/packages/database/supabase/migrations/20230330024716_parts.sql
@@ -241,6 +241,18 @@ CREATE TRIGGER update_part_search_result
FOR EACH ROW EXECUTE PROCEDURE public.update_part_search_result();
+CREATE FUNCTION public.delete_part_search_result()
+RETURNS TRIGGER AS $$
+BEGIN
+ DELETE FROM public.search WHERE entity = 'Part' AND uuid = old.id;
+ RETURN old;
+END;
+$$ LANGUAGE plpgsql SECURITY DEFINER;
+
+CREATE TRIGGER delete_part_search_result
+ AFTER DELETE on public.part
+ FOR EACH ROW EXECUTE PROCEDURE public.delete_part_search_result();
+
CREATE TABLE "partCost" (
"partId" TEXT NOT NULL,
"costingMethod" "partCostingMethod" NOT NULL,
diff --git a/packages/database/supabase/migrations/20230702114301_purchasing-rls.sql b/packages/database/supabase/migrations/20230702114301_purchasing-rls.sql
index 5e5dbff4f4..940f35ddb7 100644
--- a/packages/database/supabase/migrations/20230702114301_purchasing-rls.sql
+++ b/packages/database/supabase/migrations/20230702114301_purchasing-rls.sql
@@ -42,6 +42,22 @@ CREATE POLICY "Employees with purchasing_delete can delete purchase orders" ON "
FOR DELETE
USING (coalesce(get_my_claim('purchasing_delete')::boolean, false) = true AND (get_my_claim('role'::text)) = '"employee"'::jsonb);
+
+CREATE POLICY "Suppliers with purchasing_view can search for their own purchase orders" ON "search"
+ FOR SELECT
+ USING (
+ coalesce(get_my_claim('purchasing_view')::boolean, false) = true
+ AND (get_my_claim('role'::text)) = '"supplier"'::jsonb
+ AND entity = 'Purchase Order'
+ AND uuid IN (
+ SELECT id FROM "purchaseOrder" WHERE "supplierId" IN (
+ SELECT "supplierId" FROM "purchaseOrder" WHERE "supplierId" IN (
+ SELECT "supplierId" FROM "supplierAccount" WHERE id::uuid = auth.uid()
+ )
+ )
+ )
+ );
+
-- Search
CREATE FUNCTION public.create_purchase_order_search_result()
@@ -72,21 +88,18 @@ CREATE TRIGGER update_purchase_order_search_result
AFTER UPDATE on public."purchaseOrder"
FOR EACH ROW EXECUTE PROCEDURE public.update_purchase_order_search_result();
+CREATE FUNCTION public.delete_purchase_order_search_result()
+RETURNS TRIGGER AS $$
+BEGIN
+ DELETE FROM public.search WHERE entity = 'Purchase Order' AND uuid = old.id;
+ RETURN old;
+END;
+$$ LANGUAGE plpgsql SECURITY DEFINER;
+
+CREATE TRIGGER delete_purchase_order_search_result
+ AFTER DELETE on public."purchaseOrder"
+ FOR EACH ROW EXECUTE PROCEDURE public.delete_purchase_order_search_result();
-CREATE POLICY "Suppliers with purchasing_view can search for their own purchase orders" ON "search"
- FOR SELECT
- USING (
- coalesce(get_my_claim('purchasing_view')::boolean, false) = true
- AND (get_my_claim('role'::text)) = '"supplier"'::jsonb
- AND entity = 'Purchase Order'
- AND uuid IN (
- SELECT id FROM "purchaseOrder" WHERE "supplierId" IN (
- SELECT "supplierId" FROM "purchaseOrder" WHERE "supplierId" IN (
- SELECT "supplierId" FROM "supplierAccount" WHERE id::uuid = auth.uid()
- )
- )
- )
- );
-- Purchase Order Status History
diff --git a/packages/database/supabase/migrations/20240213043906_quote-rls.sql b/packages/database/supabase/migrations/20240213043906_quote-rls.sql
new file mode 100644
index 0000000000..f336a832fc
--- /dev/null
+++ b/packages/database/supabase/migrations/20240213043906_quote-rls.sql
@@ -0,0 +1,175 @@
+ALTER TABLE "quote" ENABLE ROW LEVEL SECURITY;
+
+CREATE POLICY "Employees with sales_view can view quotes" ON "quote"
+ FOR SELECT
+ USING (
+ coalesce(get_my_claim('sales_view')::boolean, false) = true
+ AND (get_my_claim('role'::text)) = '"employee"'::jsonb);
+
+CREATE POLICY "Customers with sales_view can their own quotes" ON "quote"
+ FOR SELECT
+ USING (
+ coalesce(get_my_claim('sales_view')::boolean, false) = true
+ AND (get_my_claim('role'::text)) = '"customer"'::jsonb
+ AND "customerId" IN (
+ SELECT "customerId" FROM "customerAccount" WHERE id::uuid = auth.uid()
+ )
+ );
+
+CREATE POLICY "Employees with sales_create can create quotes" ON "quote"
+ FOR INSERT
+ WITH CHECK (coalesce(get_my_claim('sales_create')::boolean,false) AND (get_my_claim('role'::text)) = '"employee"'::jsonb);
+
+
+CREATE POLICY "Employees with sales_update can update quotes" ON "quote"
+ FOR UPDATE
+ USING (coalesce(get_my_claim('sales_update')::boolean,false) AND (get_my_claim('role'::text)) = '"employee"'::jsonb);
+
+CREATE POLICY "Customers with sales_update can their own quotes" ON "quote"
+ FOR UPDATE
+ USING (
+ coalesce(get_my_claim('sales_update')::boolean, false) = true
+ AND (get_my_claim('role'::text)) = '"customer"'::jsonb
+ AND "customerId" IN (
+ SELECT "customerId" FROM "customerAccount" WHERE id::uuid = auth.uid()
+ )
+ );
+
+CREATE POLICY "Employees with sales_delete can delete quotes" ON "quote"
+ FOR DELETE
+ USING (coalesce(get_my_claim('sales_delete')::boolean, false) = true AND (get_my_claim('role'::text)) = '"employee"'::jsonb);
+
+
+CREATE POLICY "Customers with sales_view can search for their own quotes" ON "search"
+ FOR SELECT
+ USING (
+ coalesce(get_my_claim('sales_view')::boolean, false) = true
+ AND (get_my_claim('role'::text)) = '"customer"'::jsonb
+ AND entity = 'Quotation'
+ AND uuid IN (
+ SELECT id FROM "quote" WHERE "customerId" IN (
+ SELECT "customerId" FROM "quote" WHERE "customerId" IN (
+ SELECT "customerId" FROM "customerAccount" WHERE id::uuid = auth.uid()
+ )
+ )
+ )
+ );
+
+-- Quotation Lines
+
+ALTER TABLE "quoteLine" ENABLE ROW LEVEL SECURITY;
+
+CREATE POLICY "Employees with sales_view can view quote lines" ON "quoteLine"
+ FOR SELECT
+ USING (coalesce(get_my_claim('sales_view')::boolean, false) = true AND (get_my_claim('role'::text)) = '"employee"'::jsonb);
+
+CREATE POLICY "Customers with sales_view can their own quote lines" ON "quoteLine"
+ FOR SELECT
+ USING (
+ coalesce(get_my_claim('sales_view')::boolean, false) = true
+ AND (get_my_claim('role'::text)) = '"customer"'::jsonb
+ AND "quoteId" IN (
+ SELECT id FROM "quote" WHERE "customerId" IN (
+ SELECT "customerId" FROM "quote" WHERE "customerId" IN (
+ SELECT "customerId" FROM "customerAccount" WHERE id::uuid = auth.uid()
+ )
+ )
+ )
+ );
+
+CREATE POLICY "Employees with sales_create can create quote lines" ON "quoteLine"
+ FOR INSERT
+ WITH CHECK (coalesce(get_my_claim('sales_create')::boolean,false) AND (get_my_claim('role'::text)) = '"employee"'::jsonb);
+
+CREATE POLICY "Customers with sales_create can create lines on their own quote" ON "quoteLine"
+ FOR INSERT
+ WITH CHECK (
+ coalesce(get_my_claim('sales_create')::boolean, false) = true
+ AND (get_my_claim('role'::text)) = '"customer"'::jsonb
+ AND "quoteId" IN (
+ SELECT id FROM "quote" WHERE "customerId" IN (
+ SELECT "customerId" FROM "quote" WHERE "customerId" IN (
+ SELECT "customerId" FROM "customerAccount" WHERE id::uuid = auth.uid()
+ )
+ )
+ )
+ );
+
+CREATE POLICY "Employees with sales_update can update quote lines" ON "quoteLine"
+ FOR UPDATE
+ USING (coalesce(get_my_claim('sales_update')::boolean,false) AND (get_my_claim('role'::text)) = '"employee"'::jsonb);
+
+CREATE POLICY "Customers with sales_update can their own quote lines" ON "quoteLine"
+ FOR UPDATE
+ USING (
+ coalesce(get_my_claim('sales_update')::boolean, false) = true
+ AND (get_my_claim('role'::text)) = '"customer"'::jsonb
+ AND "quoteId" IN (
+ SELECT id FROM "quote" WHERE "customerId" IN (
+ SELECT "customerId" FROM "quote" WHERE "customerId" IN (
+ SELECT "customerId" FROM "customerAccount" WHERE id::uuid = auth.uid()
+ )
+ )
+ )
+ );
+
+CREATE POLICY "Employees with sales_delete can delete quote lines" ON "quoteLine"
+ FOR DELETE
+ USING (coalesce(get_my_claim('sales_delete')::boolean, false) = true AND (get_my_claim('role'::text)) = '"employee"'::jsonb);
+
+CREATE POLICY "Customers with sales_delete can delete lines on their own quote" ON "quoteLine"
+ FOR DELETE
+ USING (
+ coalesce(get_my_claim('sales_delete')::boolean, false) = true
+ AND (get_my_claim('role'::text)) = '"customer"'::jsonb
+ AND "quoteId" IN (
+ SELECT id FROM "quote" WHERE "customerId" IN (
+ SELECT "customerId" FROM "quote" WHERE "customerId" IN (
+ SELECT "customerId" FROM "customerAccount" WHERE id::uuid = auth.uid()
+ )
+ )
+ )
+ );
+
+
+-- Search
+
+CREATE FUNCTION public.create_quotation_search_result()
+RETURNS TRIGGER AS $$
+BEGIN
+ INSERT INTO public.search(name, description, entity, uuid, link)
+ VALUES (new."quoteId", new.name, 'Quotation', new.id, '/x/quote/' || new.id);
+ RETURN new;
+END;
+$$ LANGUAGE plpgsql SECURITY DEFINER;
+
+CREATE TRIGGER create_quotation_search_result
+ AFTER INSERT on public."quote"
+ FOR EACH ROW EXECUTE PROCEDURE public.create_quotation_search_result();
+
+CREATE FUNCTION public.update_quotation_search_result()
+RETURNS TRIGGER AS $$
+BEGIN
+ IF (old."quoteId" <> new."quoteId" OR old."name" <> new."name") THEN
+ UPDATE public.search SET name = new."quoteId", description = new.description
+ WHERE entity = 'Quotation' AND uuid = new.id;
+ END IF;
+ RETURN new;
+END;
+$$ LANGUAGE plpgsql SECURITY DEFINER;
+
+CREATE TRIGGER update_quotation_search_result
+ AFTER UPDATE on public."quote"
+ FOR EACH ROW EXECUTE PROCEDURE public.update_quotation_search_result();
+
+CREATE FUNCTION public.delete_quotation_search_result()
+RETURNS TRIGGER AS $$
+BEGIN
+ DELETE FROM public.search WHERE entity = 'Quotation' AND uuid = old.id;
+ RETURN old;
+END;
+$$ LANGUAGE plpgsql SECURITY DEFINER;
+
+CREATE TRIGGER delete_quotation_search_result
+ AFTER DELETE on public."quote"
+ FOR EACH ROW EXECUTE PROCEDURE public.delete_quotation_search_result();
\ No newline at end of file
diff --git a/packages/database/supabase/seed.sql b/packages/database/supabase/seed.sql
index b81283c965..e589977292 100644
--- a/packages/database/supabase/seed.sql
+++ b/packages/database/supabase/seed.sql
@@ -181,11 +181,11 @@ VALUES
INSERT INTO "sequence" ("table", "name", "prefix", "suffix", "next", "size", "step")
VALUES
- ('purchaseOrder', 'Purchase Order', 'PO-', NULL, 0, 6, 1),
- ('purchaseInvoice', 'Purchase Invoice', 'AP-', NULL, 0, 6, 1),
- ('receipt', 'Receipt', 'RE-', NULL, 0, 6, 1),
- ('requestForQuote', 'Request For Quote', 'RFQ-', NULL, 0, 6, 1),
- ('quote', 'Quote', 'QUO-', NULL, 0, 6, 1);
+ ('purchaseOrder', 'Purchase Order', 'PO', NULL, 0, 6, 1),
+ ('purchaseInvoice', 'Purchase Invoice', 'AP', NULL, 0, 6, 1),
+ ('receipt', 'Receipt', 'RE', NULL, 0, 6, 1),
+ ('requestForQuote', 'Request For Quote', 'RFQ', NULL, 0, 6, 1),
+ ('quote', 'Quote', 'QUO', NULL, 0, 6, 1);
-- account categories
diff --git a/packages/react/src/Kbd.tsx b/packages/react/src/Kbd.tsx
index 1a61e8ba6c..7847435f2e 100644
--- a/packages/react/src/Kbd.tsx
+++ b/packages/react/src/Kbd.tsx
@@ -8,7 +8,7 @@ const Kbd = forwardRef<ElementRef<"kbd">, ComponentPropsWithoutRef<"kbd">>(
<kbd
ref={ref}
className={cn(
- "bg-muted rounded-md border border-input border-b-[3px] text-[0.8em] font-mono font-bold px-[0.8em] whitespace-nowrap",
+ "bg-muted text-foreground rounded-md border border-input border-b-[3px] text-[0.8em] font-mono font-bold px-[0.8em] whitespace-nowrap",
className
)}
{...props}
diff --git a/packages/utils/src/themes.ts b/packages/utils/src/themes.ts
index f862fe270e..5e2c12a69c 100644
--- a/packages/utils/src/themes.ts
+++ b/packages/utils/src/themes.ts
@@ -343,7 +343,7 @@ export const themes = [
ring: "221.2 83.2% 53.3%",
},
dark: {
- background: "222.2 84% 4.9%",
+ background: "222.2 84% 7.5%",
foreground: "210 40% 98%",
card: "222.2 84% 8.9%",
"card-foreground": "210 40% 98%",