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.

refactor: fix drawer redirect bug in supplier types crud

Brad Barbin3a9b2cf4e5be
diff --git a/apps/carbon/app/modules/purchasing/ui/SupplierTypes/SupplierTypesTable.tsx b/apps/carbon/app/modules/purchasing/ui/SupplierTypes/SupplierTypesTable.tsx
index 488d842d0a..3842b44416 100644
--- a/apps/carbon/app/modules/purchasing/ui/SupplierTypes/SupplierTypesTable.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/SupplierTypes/SupplierTypesTable.tsx
@@ -4,7 +4,7 @@ import type { ColumnDef } from "@tanstack/react-table";
import { memo, useCallback, useMemo } from "react";
import { BsFillPenFill, BsPeopleFill } from "react-icons/bs";
import { IoMdTrash } from "react-icons/io";
-import { Table } from "~/components";
+import { TableNew } from "~/components";
import { usePermissions, useUrlParams } from "~/hooks";
import type { SupplierType } from "~/modules/purchasing";
import { path } from "~/utils/path";
@@ -41,7 +41,7 @@ const SupplierTypesTable = memo(({ data, count }: SupplierTypesTableProps) => {
<>
<MenuItem
onClick={() => {
- navigate(`${path.to.suppliers}?type=${row.id}`);
+ navigate(`${path.to.suppliers}?filter=type:eq:${row.name}`);
}}
>
<MenuIcon icon={<BsPeopleFill />} />
@@ -74,10 +74,13 @@ const SupplierTypesTable = memo(({ data, count }: SupplierTypesTableProps) => {
);
return (
- <Table<SupplierType>
+ <TableNew<SupplierType>
data={data}
columns={columns}
count={count}
+ label="Supplier Type"
+ newPath={path.to.newSupplierType}
+ newPermission={permissions.can("create", "purchasing")}
renderContextMenu={renderContextMenu}
/>
);
diff --git a/apps/carbon/app/modules/purchasing/ui/SupplierTypes/SupplierTypesTableFilters.tsx b/apps/carbon/app/modules/purchasing/ui/SupplierTypes/SupplierTypesTableFilters.tsx
deleted file mode 100644
index 3f17f8a567..0000000000
--- a/apps/carbon/app/modules/purchasing/ui/SupplierTypes/SupplierTypesTableFilters.tsx
+++ /dev/null
@@ -1,25 +0,0 @@
-import { HStack } from "@carbon/react";
-import { New } from "~/components";
-import { TableFilters } from "~/components/Layout";
-import { DebouncedInput } from "~/components/Search";
-import { usePermissions, useUrlParams } from "~/hooks";
-
-const SupplierTypesTableFilters = () => {
- const [params] = useUrlParams();
- const permissions = usePermissions();
-
- return (
- <TableFilters>
- <HStack>
- <DebouncedInput param="name" size="sm" placeholder="Search" />
- </HStack>
- <HStack>
- {permissions.can("create", "purchasing") && (
- <New label="Supplier Type" to={`new?${params.toString()}`} />
- )}
- </HStack>
- </TableFilters>
- );
-};
-
-export default SupplierTypesTableFilters;
diff --git a/apps/carbon/app/modules/purchasing/ui/SupplierTypes/index.ts b/apps/carbon/app/modules/purchasing/ui/SupplierTypes/index.ts
index f0fd2e611b..e0a9bb136d 100644
--- a/apps/carbon/app/modules/purchasing/ui/SupplierTypes/index.ts
+++ b/apps/carbon/app/modules/purchasing/ui/SupplierTypes/index.ts
@@ -1,5 +1,4 @@
import SupplierTypeForm from "./SupplierTypeForm";
import SupplierTypesTable from "./SupplierTypesTable";
-import SupplierTypesTableFilters from "./SupplierTypesTableFilters";
-export { SupplierTypeForm, SupplierTypesTable, SupplierTypesTableFilters };
+export { SupplierTypeForm, SupplierTypesTable };
diff --git a/apps/carbon/app/routes/x+/purchasing+/supplier-types.$supplierTypeId.tsx b/apps/carbon/app/routes/x+/purchasing+/supplier-types.$supplierTypeId.tsx
index 6c404f6e7a..206ac034a5 100644
--- a/apps/carbon/app/routes/x+/purchasing+/supplier-types.$supplierTypeId.tsx
+++ b/apps/carbon/app/routes/x+/purchasing+/supplier-types.$supplierTypeId.tsx
@@ -12,7 +12,7 @@ import { requirePermissions } from "~/services/auth";
import { flash } from "~/services/session.server";
import { getCustomFields, setCustomFields } from "~/utils/form";
import { assertIsPost, notFound } from "~/utils/http";
-import { path } from "~/utils/path";
+import { getParams, path } from "~/utils/path";
import { error, success } from "~/utils/result";
export async function loader({ request, params }: LoaderFunctionArgs) {
@@ -28,7 +28,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
if (supplierType.error) {
return redirect(
- path.to.supplierTypes,
+ `${path.to.supplierTypes}?${getParams(request)}`,
await flash(
request,
error(supplierType.error, "Failed to get supplier type")
@@ -81,7 +81,7 @@ export async function action({ request }: ActionFunctionArgs) {
}
return redirect(
- path.to.supplierTypes,
+ `${path.to.supplierTypes}?${getParams(request)}`,
await flash(request, success("Updated supplier type"))
);
}
diff --git a/apps/carbon/app/routes/x+/purchasing+/supplier-types.delete.$supplierTypeId.tsx b/apps/carbon/app/routes/x+/purchasing+/supplier-types.delete.$supplierTypeId.tsx
index dd459a222f..e7ee0b204c 100644
--- a/apps/carbon/app/routes/x+/purchasing+/supplier-types.delete.$supplierTypeId.tsx
+++ b/apps/carbon/app/routes/x+/purchasing+/supplier-types.delete.$supplierTypeId.tsx
@@ -6,7 +6,7 @@ import { deleteSupplierType, getSupplierType } 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 { getParams, path } from "~/utils/path";
import { error, success } from "~/utils/result";
export async function loader({ request, params }: LoaderFunctionArgs) {
@@ -39,7 +39,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
const { supplierTypeId } = params;
if (!supplierTypeId) {
return redirect(
- path.to.supplierTypes,
+ `${path.to.supplierTypes}?${getParams(request)}`,
await flash(request, error(params, "Failed to get an supplier type id"))
);
}
@@ -50,7 +50,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
);
if (deleteTypeError) {
return redirect(
- path.to.supplierTypes,
+ `${path.to.supplierTypes}?${getParams(request)}`,
await flash(
request,
error(deleteTypeError, "Failed to delete supplier type")
@@ -59,7 +59,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
}
return redirect(
- path.to.supplierTypes,
+ `${path.to.supplierTypes}?${getParams(request)}`,
await flash(request, success("Successfully deleted supplier type"))
);
}
diff --git a/apps/carbon/app/routes/x+/purchasing+/supplier-types.new.tsx b/apps/carbon/app/routes/x+/purchasing+/supplier-types.new.tsx
index e270706fc1..6654a6ca4e 100644
--- a/apps/carbon/app/routes/x+/purchasing+/supplier-types.new.tsx
+++ b/apps/carbon/app/routes/x+/purchasing+/supplier-types.new.tsx
@@ -11,7 +11,7 @@ import { requirePermissions } from "~/services/auth";
import { flash } from "~/services/session.server";
import { setCustomFields } from "~/utils/form";
import { assertIsPost } from "~/utils/http";
-import { path, requestReferrer } from "~/utils/path";
+import { getParams, path } from "~/utils/path";
import { error, success } from "~/utils/result";
export async function loader({ request }: LoaderFunctionArgs) {
@@ -48,7 +48,7 @@ export async function action({ request }: ActionFunctionArgs) {
return modal
? json(insertSupplierType)
: redirect(
- requestReferrer(request) ?? path.to.supplierTypes,
+ `${path.to.supplierTypes}?${getParams(request)}`,
await flash(
request,
error(insertSupplierType.error, "Failed to insert supplier type")
@@ -59,7 +59,7 @@ export async function action({ request }: ActionFunctionArgs) {
return modal
? json(insertSupplierType, { status: 201 })
: redirect(
- path.to.supplierTypes,
+ `${path.to.supplierTypes}?${getParams(request)}`,
await flash(request, success("Supplier type created"))
);
}
diff --git a/apps/carbon/app/routes/x+/purchasing+/supplier-types.tsx b/apps/carbon/app/routes/x+/purchasing+/supplier-types.tsx
index f1e393c3ec..82482f6c47 100644
--- a/apps/carbon/app/routes/x+/purchasing+/supplier-types.tsx
+++ b/apps/carbon/app/routes/x+/purchasing+/supplier-types.tsx
@@ -2,11 +2,7 @@ import { VStack } from "@carbon/react";
import type { LoaderFunctionArgs } from "@remix-run/node";
import { json } from "@remix-run/node";
import { Outlet, useLoaderData } from "@remix-run/react";
-import {
- SupplierTypesTable,
- SupplierTypesTableFilters,
- getSupplierTypes,
-} from "~/modules/purchasing";
+import { SupplierTypesTable, getSupplierTypes } from "~/modules/purchasing";
import { requirePermissions } from "~/services/auth";
import type { Handle } from "~/utils/handle";
import { path } from "~/utils/path";
@@ -25,10 +21,10 @@ export async function loader({ request }: LoaderFunctionArgs) {
const url = new URL(request.url);
const searchParams = new URLSearchParams(url.search);
- const name = searchParams.get("name");
+ const search = searchParams.get("search");
const { limit, offset, sorts } = getGenericQueryFilters(searchParams);
- return json(await getSupplierTypes(client, { name, limit, offset, sorts }));
+ return json(await getSupplierTypes(client, { search, limit, offset, sorts }));
}
export default function SupplierTypesRoute() {
@@ -36,7 +32,6 @@ export default function SupplierTypesRoute() {
return (
<VStack spacing={0} className="h-full">
- <SupplierTypesTableFilters />
<SupplierTypesTable data={data ?? []} count={count ?? 0} />
<Outlet />
</VStack>