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: expose customer types and supplier types in the ui

Brad Barbin9a14a23af29c
diff --git a/apps/erp/app/components/Form/CustomerType.tsx b/apps/erp/app/components/Form/CustomerType.tsx
index 926a606149..105cd0b0df 100644
--- a/apps/erp/app/components/Form/CustomerType.tsx
+++ b/apps/erp/app/components/Form/CustomerType.tsx
@@ -3,8 +3,6 @@ import { CreatableCombobox } from "@carbon/form";
import { useDisclosure, useMount } from "@carbon/react";
import { useFetcher } from "@remix-run/react";
import { useMemo, useRef, useState } from "react";
-import { useRouteData } from "~/hooks";
-import type { SupplierStatus } from "~/modules/purchasing";
import type { getCustomerTypesList } from "~/modules/sales";
import { CustomerTypeForm } from "~/modules/sales/ui/CustomerTypes";
import { path } from "~/utils/path";
@@ -55,31 +53,18 @@ export const useCustomerTypes = () => {
const customerTypeFetcher =
useFetcher<Awaited<ReturnType<typeof getCustomerTypesList>>>();
- const sharedCustomerData = useRouteData<{
- customerTypes: SupplierStatus[];
- }>(path.to.customerRoot);
-
- const hasSupplierData = sharedCustomerData?.customerTypes;
-
useMount(() => {
- if (!hasSupplierData) customerTypeFetcher.load(path.to.api.customerTypes);
+ customerTypeFetcher.load(path.to.api.customerTypes);
});
const options = useMemo(() => {
- const dataSource =
- (hasSupplierData
- ? sharedCustomerData.customerTypes
- : customerTypeFetcher.data?.data) ?? [];
+ const dataSource = customerTypeFetcher.data?.data ?? [];
return dataSource.map((c) => ({
value: c.id,
label: c.name,
}));
- }, [
- customerTypeFetcher.data?.data,
- hasSupplierData,
- sharedCustomerData?.customerTypes,
- ]);
+ }, [customerTypeFetcher.data?.data]);
return options;
};
diff --git a/apps/erp/app/components/Form/SupplierType.tsx b/apps/erp/app/components/Form/SupplierType.tsx
index 21cb77c98b..b4c177ff58 100644
--- a/apps/erp/app/components/Form/SupplierType.tsx
+++ b/apps/erp/app/components/Form/SupplierType.tsx
@@ -3,11 +3,7 @@ import { CreatableCombobox } from "@carbon/form";
import { useDisclosure, useMount } from "@carbon/react";
import { useFetcher } from "@remix-run/react";
import { useMemo, useRef, useState } from "react";
-import { useRouteData } from "~/hooks";
-import type {
- SupplierType as SupplierTypeType,
- getSupplierTypesList,
-} from "~/modules/purchasing";
+import type { getSupplierTypesList } from "~/modules/purchasing";
import SupplierTypeForm from "~/modules/purchasing/ui/SupplierTypes/SupplierTypeForm";
import { path } from "~/utils/path";
@@ -58,31 +54,18 @@ export const useSupplierTypes = () => {
const supplierTypeFetcher =
useFetcher<Awaited<ReturnType<typeof getSupplierTypesList>>>();
- const sharedSupplierData = useRouteData<{
- supplierTypes: SupplierTypeType[];
- }>(path.to.supplierRoot);
-
- const hasSupplierData = sharedSupplierData?.supplierTypes;
-
useMount(() => {
- if (!hasSupplierData) supplierTypeFetcher.load(path.to.api.supplierTypes);
+ supplierTypeFetcher.load(path.to.api.supplierTypes);
});
const options = useMemo(() => {
- const dataSource =
- (hasSupplierData
- ? sharedSupplierData.supplierTypes
- : supplierTypeFetcher.data?.data) ?? [];
+ const dataSource = supplierTypeFetcher.data?.data ?? [];
return dataSource.map((c) => ({
value: c.id,
label: c.name,
}));
- }, [
- supplierTypeFetcher.data?.data,
- hasSupplierData,
- sharedSupplierData?.supplierTypes,
- ]);
+ }, [supplierTypeFetcher.data?.data]);
return options;
};
diff --git a/apps/erp/app/modules/purchasing/purchasing.models.ts b/apps/erp/app/modules/purchasing/purchasing.models.ts
index a7078f21b2..b7df670bac 100644
--- a/apps/erp/app/modules/purchasing/purchasing.models.ts
+++ b/apps/erp/app/modules/purchasing/purchasing.models.ts
@@ -208,6 +208,7 @@ export const supplierValidator = z.object({
id: zfd.text(z.string().optional()),
name: z.string().min(1, { message: "Name is required" }),
supplierStatusId: zfd.text(z.string().optional()),
+ supplierTypeId: zfd.text(z.string().optional()),
accountManagerId: zfd.text(z.string().optional()),
currencyCode: zfd.text(z.string().optional()),
phone: zfd.text(z.string().optional()),
diff --git a/apps/erp/app/modules/purchasing/ui/Supplier/SupplierForm.tsx b/apps/erp/app/modules/purchasing/ui/Supplier/SupplierForm.tsx
index 55dedce76b..73b141719b 100644
--- a/apps/erp/app/modules/purchasing/ui/Supplier/SupplierForm.tsx
+++ b/apps/erp/app/modules/purchasing/ui/Supplier/SupplierForm.tsx
@@ -24,6 +24,7 @@ import {
Input,
Submit,
SupplierStatus,
+ SupplierType,
} from "~/components/Form";
import { usePermissions } from "~/hooks";
import type { Supplier } from "~/modules/purchasing";
@@ -105,6 +106,12 @@ const SupplierForm = ({
placeholder="Select Supplier Status"
/>
+ <SupplierType
+ name="supplierTypeId"
+ label="Supplier Type"
+ placeholder="Select Supplier Type"
+ />
+
<Employee name="accountManagerId" label="Account Manager" />
<Currency name="currencyCode" label="Currency" />
diff --git a/apps/erp/app/modules/purchasing/ui/Supplier/SupplierHeader.tsx b/apps/erp/app/modules/purchasing/ui/Supplier/SupplierHeader.tsx
index 7354f19296..1b4720f6f5 100644
--- a/apps/erp/app/modules/purchasing/ui/Supplier/SupplierHeader.tsx
+++ b/apps/erp/app/modules/purchasing/ui/Supplier/SupplierHeader.tsx
@@ -19,6 +19,7 @@ import { z } from "zod";
import { EmployeeAvatar } from "~/components";
import { Enumerable } from "~/components/Enumerable";
import { Tags } from "~/components/Form";
+import { useSupplierTypes } from "~/components/Form/SupplierType";
import { useRouteData } from "~/hooks";
import type { SupplierDetail, SupplierStatus } from "~/modules/purchasing";
import type { action } from "~/routes/x+/settings+/tags";
@@ -34,6 +35,11 @@ const SupplierHeader = () => {
tags: { name: string }[];
}>(path.to.supplier(supplierId));
+ const supplierTypes = useSupplierTypes();
+ const supplierType = supplierTypes?.find(
+ (type) => type.value === routeData?.supplier?.supplierTypeId
+ )?.label;
+
const sharedSupplierData = useRouteData<{
supplierStatuses: SupplierStatus[];
}>(path.to.supplierRoot);
@@ -83,6 +89,12 @@ const SupplierHeader = () => {
{supplierStatus ? <Enumerable value={supplierStatus!} /> : "-"}
</CardAttributeValue>
</CardAttribute>
+ <CardAttribute>
+ <CardAttributeLabel>Type</CardAttributeLabel>
+ <CardAttributeValue>
+ {supplierType ? <Enumerable value={supplierType!} /> : "-"}
+ </CardAttributeValue>
+ </CardAttribute>
<CardAttribute>
<CardAttributeLabel>Account Manager</CardAttributeLabel>
<CardAttributeValue>
diff --git a/apps/erp/app/modules/purchasing/ui/Supplier/SuppliersTable.tsx b/apps/erp/app/modules/purchasing/ui/Supplier/SuppliersTable.tsx
index 7aada34e31..e82366800e 100644
--- a/apps/erp/app/modules/purchasing/ui/Supplier/SuppliersTable.tsx
+++ b/apps/erp/app/modules/purchasing/ui/Supplier/SuppliersTable.tsx
@@ -11,6 +11,7 @@ import {
LuPencil,
LuPhone,
LuPrinter,
+ LuShapes,
LuStar,
LuTag,
LuUser,
@@ -23,6 +24,7 @@ import {
Table,
} from "~/components";
import { Enumerable } from "~/components/Enumerable";
+import { useSupplierTypes } from "~/components/Form/SupplierType";
import { usePermissions } from "~/hooks";
import { useCustomColumns } from "~/hooks/useCustomColumns";
import type { Supplier, SupplierStatus } from "~/modules/purchasing";
@@ -41,6 +43,7 @@ const SuppliersTable = memo(
const navigate = useNavigate();
const permissions = usePermissions();
const [people] = usePeople();
+ const supplierTypes = useSupplierTypes();
const customColumns = useCustomColumns<Supplier>("supplier");
const columns = useMemo<ColumnDef<Supplier>[]>(() => {
@@ -74,6 +77,27 @@ const SuppliersTable = memo(
icon: <LuStar />,
},
},
+ {
+ accessorKey: "supplierTypeId",
+ header: "Type",
+ cell: (item) => {
+ if (!item.getValue<string>()) return null;
+ const supplierType = supplierTypes?.find(
+ (type) => type.value === item.getValue<string>()
+ )?.label;
+ return <Enumerable value={supplierType ?? ""} />;
+ },
+ meta: {
+ icon: <LuShapes />,
+ filter: {
+ type: "static",
+ options: supplierTypes?.map((type) => ({
+ value: type.value,
+ label: <Enumerable value={type.label} />,
+ })),
+ },
+ },
+ },
{
id: "accountManagerId",
header: "Account Manager",
@@ -230,7 +254,7 @@ const SuppliersTable = memo(
];
return [...defaultColumns, ...customColumns];
- }, [supplierStatuses, people, tags, customColumns]);
+ }, [supplierStatuses, supplierTypes, people, tags, customColumns]);
const renderContextMenu = useMemo(
// eslint-disable-next-line react/display-name
diff --git a/apps/erp/app/modules/purchasing/ui/usePurchasingSubmodules.tsx b/apps/erp/app/modules/purchasing/ui/usePurchasingSubmodules.tsx
index e09c1248a6..95137cab3a 100644
--- a/apps/erp/app/modules/purchasing/ui/usePurchasingSubmodules.tsx
+++ b/apps/erp/app/modules/purchasing/ui/usePurchasingSubmodules.tsx
@@ -4,6 +4,7 @@ import {
LuLayoutList,
LuPackageSearch,
LuShapes,
+ LuStar,
} from "react-icons/lu";
import { usePermissions } from "~/hooks";
import { useSavedViews } from "~/hooks/useSavedViews";
@@ -52,12 +53,12 @@ const purchasingRoutes: AuthenticatedRouteGroup[] = [
role: "employee",
icon: <LuShapes />,
},
- // {
- // name: "Types",
- // to: path.to.supplierTypes,
- // role: "employee",
- // icon: <LuStar />,
- // },
+ {
+ name: "Types",
+ to: path.to.supplierTypes,
+ role: "employee",
+ icon: <LuStar />,
+ },
],
},
];
diff --git a/apps/erp/app/modules/sales/sales.models.ts b/apps/erp/app/modules/sales/sales.models.ts
index 9e5a372aa9..6223586cd7 100644
--- a/apps/erp/app/modules/sales/sales.models.ts
+++ b/apps/erp/app/modules/sales/sales.models.ts
@@ -62,6 +62,7 @@ export const customerValidator = z.object({
id: zfd.text(z.string().optional()),
name: z.string().min(1, { message: "Name is required" }),
customerStatusId: zfd.text(z.string().optional()),
+ customerTypeId: zfd.text(z.string().optional()),
accountManagerId: zfd.text(z.string().optional()),
currencyCode: zfd.text(z.string().optional()),
taxPercent: zfd.numeric(
diff --git a/apps/erp/app/modules/sales/ui/Customer/CustomerForm.tsx b/apps/erp/app/modules/sales/ui/Customer/CustomerForm.tsx
index f35cfc2a34..ce9aafa780 100644
--- a/apps/erp/app/modules/sales/ui/Customer/CustomerForm.tsx
+++ b/apps/erp/app/modules/sales/ui/Customer/CustomerForm.tsx
@@ -20,6 +20,7 @@ import {
Currency,
CustomFormFields,
CustomerStatus,
+ CustomerType,
Employee,
Hidden,
Input,
@@ -105,7 +106,11 @@ const CustomerForm = ({
label="Customer Status"
placeholder="Select Customer Status"
/>
-
+ <CustomerType
+ name="customerTypeId"
+ label="Customer Type"
+ placeholder="Select Customer Type"
+ />
<Employee name="accountManagerId" label="Account Manager" />
<Currency name="currencyCode" label="Currency" />
diff --git a/apps/erp/app/modules/sales/ui/Customer/CustomerHeader.tsx b/apps/erp/app/modules/sales/ui/Customer/CustomerHeader.tsx
index 17fed0d6d1..13058b8767 100644
--- a/apps/erp/app/modules/sales/ui/Customer/CustomerHeader.tsx
+++ b/apps/erp/app/modules/sales/ui/Customer/CustomerHeader.tsx
@@ -23,6 +23,7 @@ import { useRouteData } from "~/hooks";
import type { action } from "~/routes/x+/settings+/tags";
import { path } from "~/utils/path";
import type { CustomerDetail, CustomerStatus } from "../../types";
+import { useCustomerTypes } from "~/components/Form/CustomerType";
const CustomerHeader = () => {
const { customerId } = useParams();
@@ -34,10 +35,14 @@ const CustomerHeader = () => {
tags: { name: string }[];
}>(path.to.customer(customerId));
+ const customerTypes = useCustomerTypes();
+ const customerType = customerTypes?.find(
+ (type) => type.value === routeData?.customer?.customerTypeId
+ )?.label;
+
const sharedCustomerData = useRouteData<{
customerStatuses: CustomerStatus[];
}>(path.to.customerRoot);
-
const customerStatus = sharedCustomerData?.customerStatuses?.find(
(status) => status.id === routeData?.customer?.customerStatusId
)?.name;
@@ -83,6 +88,12 @@ const CustomerHeader = () => {
{customerStatus ? <Enumerable value={customerStatus!} /> : "-"}
</CardAttributeValue>
</CardAttribute>
+ <CardAttribute>
+ <CardAttributeLabel>Type</CardAttributeLabel>
+ <CardAttributeValue>
+ {customerType ? <Enumerable value={customerType!} /> : "-"}
+ </CardAttributeValue>
+ </CardAttribute>
<CardAttribute>
<CardAttributeLabel>Account Manager</CardAttributeLabel>
<CardAttributeValue>
diff --git a/apps/erp/app/modules/sales/ui/Customers/CustomersTable.tsx b/apps/erp/app/modules/sales/ui/Customers/CustomersTable.tsx
index cc3f0fca82..c7181ae2ed 100644
--- a/apps/erp/app/modules/sales/ui/Customers/CustomersTable.tsx
+++ b/apps/erp/app/modules/sales/ui/Customers/CustomersTable.tsx
@@ -17,6 +17,7 @@ import {
LuPencil,
LuPhone,
LuPrinter,
+ LuShapes,
LuStar,
LuTag,
LuTrash,
@@ -36,6 +37,7 @@ import { useCustomColumns } from "~/hooks/useCustomColumns";
import { usePeople } from "~/stores";
import { path } from "~/utils/path";
import type { Customer, CustomerStatus } from "../../types";
+import { useCustomerTypes } from "~/components/Form/CustomerType";
type CustomersTableProps = {
data: Customer[];
@@ -54,6 +56,8 @@ const CustomersTable = memo(
null
);
+ const customerTypes = useCustomerTypes();
+
const customColumns = useCustomColumns<Customer>("customer");
const columns = useMemo<ColumnDef<Customer>[]>(() => {
const defaultColumns: ColumnDef<Customer>[] = [
@@ -86,6 +90,27 @@ const CustomersTable = memo(
icon: <LuStar />,
},
},
+ {
+ accessorKey: "customerTypeId",
+ header: "Type",
+ cell: (item) => {
+ if (!item.getValue<string>()) return null;
+ const customerType = customerTypes?.find(
+ (type) => type.value === item.getValue<string>()
+ )?.label;
+ return <Enumerable value={customerType ?? ""} />;
+ },
+ meta: {
+ icon: <LuShapes />,
+ filter: {
+ type: "static",
+ options: customerTypes?.map((type) => ({
+ value: type.value,
+ label: <Enumerable value={type.label} />,
+ })),
+ },
+ },
+ },
{
id: "accountManagerId",
header: "Account Manager",
@@ -212,7 +237,7 @@ const CustomersTable = memo(
];
return [...defaultColumns, ...customColumns];
- }, [customerStatuses, people, customColumns, tags]);
+ }, [customerStatuses, customerTypes, people, customColumns, tags]);
const renderContextMenu = useMemo(
// eslint-disable-next-line react/display-name
diff --git a/apps/erp/app/modules/sales/ui/useSalesSubmodules.tsx b/apps/erp/app/modules/sales/ui/useSalesSubmodules.tsx
index 6e6a8bfcaf..df5c0e6d2b 100644
--- a/apps/erp/app/modules/sales/ui/useSalesSubmodules.tsx
+++ b/apps/erp/app/modules/sales/ui/useSalesSubmodules.tsx
@@ -1,4 +1,4 @@
-import { LuBan, LuSquareUser, LuStar } from "react-icons/lu";
+import { LuBan, LuShapes, LuSquareUser, LuStar } from "react-icons/lu";
import {
RiProgress2Line,
RiProgress4Line,
@@ -42,6 +42,12 @@ const salesRoutes: AuthenticatedRouteGroup[] = [
{
name: "Configure",
routes: [
+ {
+ name: "No Quote Reasons",
+ to: path.to.noQuoteReasons,
+ role: "employee",
+ icon: <LuBan />,
+ },
{
name: "Statuses",
to: path.to.customerStatuses,
@@ -49,17 +55,11 @@ const salesRoutes: AuthenticatedRouteGroup[] = [
icon: <LuStar />,
},
{
- name: "No Quote Reasons",
- to: path.to.noQuoteReasons,
+ name: "Types",
+ to: path.to.customerTypes,
role: "employee",
- icon: <LuBan />,
+ icon: <LuShapes />,
},
- // {
- // name: "Types",
- // to: path.to.customerTypes,
- // role: "employee",
- // icon: <LuShapes />,
- // },
],
},
];
diff --git a/apps/erp/app/routes/api+/purchasing.supplier-types.ts b/apps/erp/app/routes/api+/purchasing.supplier-types.ts
index 9ed82236e1..38bc5a9c60 100644
--- a/apps/erp/app/routes/api+/purchasing.supplier-types.ts
+++ b/apps/erp/app/routes/api+/purchasing.supplier-types.ts
@@ -1,7 +1,9 @@
import { requirePermissions } from "@carbon/auth/auth.server";
-import type { LoaderFunctionArgs } from "@vercel/remix";
+import type { ClientLoaderFunctionArgs } from "@remix-run/react";
+import type { LoaderFunctionArgs, SerializeFrom } from "@vercel/remix";
import { json } from "@vercel/remix";
import { getSupplierTypesList } from "~/modules/purchasing";
+import { getCompanyId, supplierTypesQuery } from "~/utils/react-query";
export async function loader({ request }: LoaderFunctionArgs) {
const { client, companyId } = await requirePermissions(request, {
@@ -10,3 +12,24 @@ export async function loader({ request }: LoaderFunctionArgs) {
return json(await getSupplierTypesList(client, companyId));
}
+
+export async function clientLoader({ serverLoader }: ClientLoaderFunctionArgs) {
+ const companyId = getCompanyId();
+
+ if (!companyId) {
+ return await serverLoader<typeof loader>();
+ }
+
+ const queryKey = supplierTypesQuery(companyId).queryKey;
+ const data =
+ window?.clientCache?.getQueryData<SerializeFrom<typeof loader>>(queryKey);
+
+ if (!data) {
+ const serverData = await serverLoader<typeof loader>();
+ window?.clientCache?.setQueryData(queryKey, serverData);
+ return serverData;
+ }
+
+ return data;
+}
+clientLoader.hydrate = true;
diff --git a/apps/erp/app/routes/api+/sales.customer-types.ts b/apps/erp/app/routes/api+/sales.customer-types.ts
index a6bd194870..7cbfac9689 100644
--- a/apps/erp/app/routes/api+/sales.customer-types.ts
+++ b/apps/erp/app/routes/api+/sales.customer-types.ts
@@ -1,7 +1,9 @@
import { requirePermissions } from "@carbon/auth/auth.server";
-import type { LoaderFunctionArgs } from "@vercel/remix";
+import type { ClientLoaderFunctionArgs } from "@remix-run/react";
+import type { LoaderFunctionArgs, SerializeFrom } from "@vercel/remix";
import { json } from "@vercel/remix";
import { getCustomerTypesList } from "~/modules/sales";
+import { customerTypesQuery, getCompanyId } from "~/utils/react-query";
export async function loader({ request }: LoaderFunctionArgs) {
const { client, companyId } = await requirePermissions(request, {
@@ -10,3 +12,24 @@ export async function loader({ request }: LoaderFunctionArgs) {
return json(await getCustomerTypesList(client, companyId));
}
+
+export async function clientLoader({ serverLoader }: ClientLoaderFunctionArgs) {
+ const companyId = getCompanyId();
+
+ if (!companyId) {
+ return await serverLoader<typeof loader>();
+ }
+
+ const queryKey = customerTypesQuery(companyId).queryKey;
+ const data =
+ window?.clientCache?.getQueryData<SerializeFrom<typeof loader>>(queryKey);
+
+ if (!data) {
+ const serverData = await serverLoader<typeof loader>();
+ window?.clientCache?.setQueryData(queryKey, serverData);
+ return serverData;
+ }
+
+ return data;
+}
+clientLoader.hydrate = true;
diff --git a/apps/erp/app/routes/x+/purchasing+/supplier-types.$supplierTypeId.tsx b/apps/erp/app/routes/x+/purchasing+/supplier-types.$supplierTypeId.tsx
index 17ac4e0716..434592e7a5 100644
--- a/apps/erp/app/routes/x+/purchasing+/supplier-types.$supplierTypeId.tsx
+++ b/apps/erp/app/routes/x+/purchasing+/supplier-types.$supplierTypeId.tsx
@@ -2,7 +2,12 @@ import { assertIsPost, error, notFound, success } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
import { validationError, validator } from "@carbon/form";
-import { useLoaderData, useNavigate } from "@remix-run/react";
+import type {
+ ClientActionFunctionArgs} from "@remix-run/react";
+import {
+ useLoaderData,
+ useNavigate,
+} from "@remix-run/react";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
import { json, redirect } from "@vercel/remix";
import {
@@ -13,6 +18,7 @@ import {
import { SupplierTypeForm } from "~/modules/purchasing/ui/SupplierTypes";
import { getCustomFields, setCustomFields } from "~/utils/form";
import { getParams, path } from "~/utils/path";
+import { getCompanyId , supplierTypesQuery } from "~/utils/react-query";
export async function loader({ request, params }: LoaderFunctionArgs) {
const { client } = await requirePermissions(request, {
@@ -46,6 +52,14 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
});
}
+export async function clientAction({ serverAction }: ClientActionFunctionArgs) {
+ window.clientCache?.setQueryData(
+ supplierTypesQuery(getCompanyId()).queryKey,
+ null
+ );
+ return await serverAction();
+}
+
export async function action({ request }: ActionFunctionArgs) {
assertIsPost(request);
const { client, userId } = await requirePermissions(request, {
diff --git a/apps/erp/app/routes/x+/purchasing+/supplier-types.delete.$supplierTypeId.tsx b/apps/erp/app/routes/x+/purchasing+/supplier-types.delete.$supplierTypeId.tsx
index afc30effa3..9f93d55c9f 100644
--- a/apps/erp/app/routes/x+/purchasing+/supplier-types.delete.$supplierTypeId.tsx
+++ b/apps/erp/app/routes/x+/purchasing+/supplier-types.delete.$supplierTypeId.tsx
@@ -1,12 +1,19 @@
import { error, notFound, success } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
-import { useLoaderData, useNavigate, useParams } from "@remix-run/react";
+import type {
+ ClientActionFunctionArgs} from "@remix-run/react";
+import {
+ useLoaderData,
+ useNavigate,
+ useParams,
+} from "@remix-run/react";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
import { json, redirect } from "@vercel/remix";
import { ConfirmDelete } from "~/components/Modals";
import { deleteSupplierType, getSupplierType } from "~/modules/purchasing";
import { getParams, path } from "~/utils/path";
+import { supplierTypesQuery , getCompanyId } from "~/utils/react-query";
export async function loader({ request, params }: LoaderFunctionArgs) {
const { client } = await requirePermissions(request, {
@@ -63,6 +70,14 @@ export async function action({ request, params }: ActionFunctionArgs) {
);
}
+export async function clientAction({ serverAction }: ClientActionFunctionArgs) {
+ window.clientCache?.setQueryData(
+ supplierTypesQuery(getCompanyId()).queryKey,
+ null
+ );
+ return await serverAction();
+}
+
export default function DeleteSupplierTypeRoute() {
const { supplierTypeId } = useParams();
const { supplierType } = useLoaderData<typeof loader>();
diff --git a/apps/erp/app/routes/x+/purchasing+/supplier-types.new.tsx b/apps/erp/app/routes/x+/purchasing+/supplier-types.new.tsx
index 4042ce6c16..ce7b521876 100644
--- a/apps/erp/app/routes/x+/purchasing+/supplier-types.new.tsx
+++ b/apps/erp/app/routes/x+/purchasing+/supplier-types.new.tsx
@@ -2,6 +2,7 @@ import { assertIsPost, error, success } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
import { validationError, validator } from "@carbon/form";
+import type { ClientActionFunctionArgs} from "@remix-run/react";
import { useNavigate } from "@remix-run/react";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
import { json, redirect } from "@vercel/remix";
@@ -12,6 +13,7 @@ import {
import { SupplierTypeForm } from "~/modules/purchasing/ui/SupplierTypes";
import { setCustomFields } from "~/utils/form";
import { getParams, path } from "~/utils/path";
+import { getCompanyId, supplierTypesQuery } from "~/utils/react-query";
export async function loader({ request }: LoaderFunctionArgs) {
await requirePermissions(request, {
@@ -64,6 +66,14 @@ export async function action({ request }: ActionFunctionArgs) {
);
}
+export async function clientAction({ serverAction }: ClientActionFunctionArgs) {
+ window.clientCache?.setQueryData(
+ supplierTypesQuery(getCompanyId()).queryKey,
+ null
+ );
+ return await serverAction();
+}
+
export default function NewSupplierTypesRoute() {
const navigate = useNavigate();
const initialValues = {
diff --git a/apps/erp/app/routes/x+/sales+/customer-types.$customerTypeId.tsx b/apps/erp/app/routes/x+/sales+/customer-types.$customerTypeId.tsx
index b489ac25c1..c5b4eff3c6 100644
--- a/apps/erp/app/routes/x+/sales+/customer-types.$customerTypeId.tsx
+++ b/apps/erp/app/routes/x+/sales+/customer-types.$customerTypeId.tsx
@@ -2,7 +2,12 @@ import { assertIsPost, error, notFound, success } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
import { validationError, validator } from "@carbon/form";
-import { useLoaderData, useNavigate } from "@remix-run/react";
+import type {
+ ClientActionFunctionArgs} from "@remix-run/react";
+import {
+ useLoaderData,
+ useNavigate,
+} from "@remix-run/react";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
import { json, redirect } from "@vercel/remix";
import {
@@ -13,6 +18,7 @@ import {
import { CustomerTypeForm } from "~/modules/sales/ui/CustomerTypes";
import { getCustomFields, setCustomFields } from "~/utils/form";
import { getParams, path } from "~/utils/path";
+import { customerTypesQuery, getCompanyId } from "~/utils/react-query";
export async function loader({ request, params }: LoaderFunctionArgs) {
const { client } = await requirePermissions(request, {
@@ -76,6 +82,14 @@ export async function action({ request }: ActionFunctionArgs) {
);
}
+export async function clientAction({ serverAction }: ClientActionFunctionArgs) {
+ window.clientCache?.setQueryData(
+ customerTypesQuery(getCompanyId()).queryKey,
+ null
+ );
+ return await serverAction();
+}
+
export default function EditCustomerTypesRoute() {
const { customerType } = useLoaderData<typeof loader>();
const navigate = useNavigate();
diff --git a/apps/erp/app/routes/x+/sales+/customer-types.delete.$customerTypeId.tsx b/apps/erp/app/routes/x+/sales+/customer-types.delete.$customerTypeId.tsx
index e5911ce4f0..2dbc46ade9 100644
--- a/apps/erp/app/routes/x+/sales+/customer-types.delete.$customerTypeId.tsx
+++ b/apps/erp/app/routes/x+/sales+/customer-types.delete.$customerTypeId.tsx
@@ -1,12 +1,19 @@
import { error, notFound, success } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
-import { useLoaderData, useNavigate, useParams } from "@remix-run/react";
+import type {
+ ClientActionFunctionArgs} from "@remix-run/react";
+import {
+ useLoaderData,
+ useNavigate,
+ useParams,
+} from "@remix-run/react";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
import { json, redirect } from "@vercel/remix";
import { ConfirmDelete } from "~/components/Modals";
import { deleteCustomerType, getCustomerType } from "~/modules/sales";
import { getParams, path } from "~/utils/path";
+import { customerTypesQuery, getCompanyId } from "~/utils/react-query";
export async function loader({ request, params }: LoaderFunctionArgs) {
const { client } = await requirePermissions(request, {
@@ -62,6 +69,14 @@ export async function action({ request, params }: ActionFunctionArgs) {
);
}
+export async function clientAction({ serverAction }: ClientActionFunctionArgs) {
+ window.clientCache?.setQueryData(
+ customerTypesQuery(getCompanyId()).queryKey,
+ null
+ );
+ return await serverAction();
+}
+
export default function DeleteCustomerTypeRoute() {
const { customerTypeId } = useParams();
const { customerType } = useLoaderData<typeof loader>();
diff --git a/apps/erp/app/routes/x+/sales+/customer-types.new.tsx b/apps/erp/app/routes/x+/sales+/customer-types.new.tsx
index e1861d304e..64290c42be 100644
--- a/apps/erp/app/routes/x+/sales+/customer-types.new.tsx
+++ b/apps/erp/app/routes/x+/sales+/customer-types.new.tsx
@@ -2,6 +2,7 @@ import { assertIsPost, error, success } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
import { validationError, validator } from "@carbon/form";
+import type { ClientActionFunctionArgs} from "@remix-run/react";
import { useNavigate } from "@remix-run/react";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
import { json, redirect } from "@vercel/remix";
@@ -9,6 +10,7 @@ import { customerTypeValidator, upsertCustomerType } from "~/modules/sales";
import { CustomerTypeForm } from "~/modules/sales/ui/CustomerTypes";
import { setCustomFields } from "~/utils/form";
import { getParams, path } from "~/utils/path";
+import { customerTypesQuery, getCompanyId } from "~/utils/react-query";
export async function loader({ request }: LoaderFunctionArgs) {
await requirePermissions(request, {
@@ -61,6 +63,14 @@ export async function action({ request }: ActionFunctionArgs) {
);
}
+export async function clientAction({ serverAction }: ClientActionFunctionArgs) {
+ window.clientCache?.setQueryData(
+ customerTypesQuery(getCompanyId()).queryKey,
+ null
+ );
+ return await serverAction();
+}
+
export default function NewCustomerTypesRoute() {
const navigate = useNavigate();
const initialValues = {
diff --git a/apps/erp/app/utils/react-query.ts b/apps/erp/app/utils/react-query.ts
index fe097a1960..bbf78c3813 100644
--- a/apps/erp/app/utils/react-query.ts
+++ b/apps/erp/app/utils/react-query.ts
@@ -38,6 +38,11 @@ export const customerLocationsQuery = (customerId: string) => ({
staleTime: RefreshRate.Low,
});
+export const customerTypesQuery = (companyId: string | null) => ({
+ queryKey: ["customerTypes", companyId ?? "null"],
+ staleTime: RefreshRate.Low,
+});
+
export const docsQuery = () => ({
queryKey: ["docs"],
staleTime: RefreshRate.Never,
@@ -89,6 +94,11 @@ export const supplierLocationsQuery = (supplierId: string) => ({
staleTime: RefreshRate.Low,
});
+export const supplierTypesQuery = (companyId: string | null) => ({
+ queryKey: ["supplierTypes", companyId ?? "null"],
+ staleTime: RefreshRate.Low,
+});
+
export const uomsQuery = (companyId: string | null) => ({
queryKey: ["uoms", companyId ?? "null"],
staleTime: RefreshRate.Medium,