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: new table/filter components for payment terms table

Brad Barbin58381a425c9e
diff --git a/apps/carbon/app/modules/account/ui/Profile/ProfileForm.tsx b/apps/carbon/app/modules/account/ui/Profile/ProfileForm.tsx
index 114f3b7028..c3b14b5ce3 100644
--- a/apps/carbon/app/modules/account/ui/Profile/ProfileForm.tsx
+++ b/apps/carbon/app/modules/account/ui/Profile/ProfileForm.tsx
@@ -1,7 +1,7 @@
import { VStack } from "@carbon/react";
import { ValidatedForm } from "@carbon/remix-validated-form";
import { useParams } from "@remix-run/react";
-import { Hidden, Input, TextArea } from "~/components/Form";
+import { Hidden, Input, Submit, TextArea } from "~/components/Form";
import { accountProfileValidator } from "~/modules/account";
import type { User } from "~/modules/users";
import { path } from "~/utils/path";
@@ -34,6 +34,7 @@ const ProfileForm = ({ user }: ProfileFormProps) => {
className="my-2"
/>
<Hidden name="intent" value="about" />
+ <Submit>Save</Submit>
</VStack>
</ValidatedForm>
);
diff --git a/apps/carbon/app/modules/accounting/accounting.models.ts b/apps/carbon/app/modules/accounting/accounting.models.ts
index 26cc7b0268..5229744ad1 100644
--- a/apps/carbon/app/modules/accounting/accounting.models.ts
+++ b/apps/carbon/app/modules/accounting/accounting.models.ts
@@ -345,6 +345,12 @@ export const partLedgerValidator = z.object({
quantity: z.number(),
});
+export const paymentTermsCalculationMethod = [
+ "Net",
+ "End of Month",
+ "Day of Month",
+] as const;
+
export const paymentTermValidator = z.object({
id: zfd.text(z.string().optional()),
name: z.string().min(1, { message: "Name is required" }),
diff --git a/apps/carbon/app/modules/accounting/ui/PaymentTerms/PaymentTermForm.tsx b/apps/carbon/app/modules/accounting/ui/PaymentTerms/PaymentTermForm.tsx
index 46dc33d84d..fdaec49073 100644
--- a/apps/carbon/app/modules/accounting/ui/PaymentTerms/PaymentTermForm.tsx
+++ b/apps/carbon/app/modules/accounting/ui/PaymentTerms/PaymentTermForm.tsx
@@ -23,7 +23,10 @@ import {
} from "~/components/Form";
import { usePermissions } from "~/hooks";
import type { PaymentTermCalculationMethod } from "~/modules/accounting";
-import { paymentTermValidator } from "~/modules/accounting";
+import {
+ paymentTermValidator,
+ paymentTermsCalculationMethod,
+} from "~/modules/accounting";
import { path } from "~/utils/path";
type PaymentTermFormProps = {
@@ -44,12 +47,10 @@ const PaymentTermForm = ({ initialValues }: PaymentTermFormProps) => {
initialValues.calculationMethod
);
- const calculationMethodOptions = ["Net", "End of Month", "Day of Month"].map(
- (v) => ({
- label: v,
- value: v,
- })
- );
+ const calculationMethodOptions = paymentTermsCalculationMethod.map((v) => ({
+ label: v,
+ value: v,
+ }));
return (
<Drawer
diff --git a/apps/carbon/app/modules/accounting/ui/PaymentTerms/PaymentTermsTable.tsx b/apps/carbon/app/modules/accounting/ui/PaymentTerms/PaymentTermsTable.tsx
index d34ce91963..d9b01e1ad3 100644
--- a/apps/carbon/app/modules/accounting/ui/PaymentTerms/PaymentTermsTable.tsx
+++ b/apps/carbon/app/modules/accounting/ui/PaymentTerms/PaymentTermsTable.tsx
@@ -4,9 +4,12 @@ import type { ColumnDef } from "@tanstack/react-table";
import { memo, useCallback, useMemo } from "react";
import { BsFillPenFill } from "react-icons/bs";
import { IoMdTrash } from "react-icons/io";
-import { Table } from "~/components";
+import { New, TableNew } from "~/components";
import { usePermissions, useUrlParams } from "~/hooks";
-import type { PaymentTerm } from "~/modules/accounting";
+import {
+ paymentTermsCalculationMethod,
+ type PaymentTerm,
+} from "~/modules/accounting";
import { path } from "~/utils/path";
type PaymentTermsTableProps = {
@@ -19,13 +22,15 @@ const PaymentTermsTable = memo(({ data, count }: PaymentTermsTableProps) => {
const navigate = useNavigate();
const permissions = usePermissions();
- const columns = useMemo<ColumnDef<(typeof data)[number]>[]>(() => {
+ const columns = useMemo<ColumnDef<PaymentTerm>[]>(() => {
return [
{
accessorKey: "name",
header: "Name",
cell: ({ row }) => (
- <Hyperlink onClick={() => navigate(row.original.id)}>
+ <Hyperlink
+ onClick={() => navigate(`${row.original.id}?${params.toString()}`)}
+ >
{row.original.name}
</Hyperlink>
),
@@ -49,12 +54,21 @@ const PaymentTermsTable = memo(({ data, count }: PaymentTermsTableProps) => {
accessorKey: "calculationMethod",
header: "Calculation Method",
cell: (item) => <Enumerable value={item.getValue<string>()} />,
+ meta: {
+ filter: {
+ type: "static",
+ options: paymentTermsCalculationMethod.map((v) => ({
+ label: <Enumerable value={v} />,
+ value: v,
+ })),
+ },
+ },
},
];
- }, [navigate]);
+ }, [navigate, params]);
const renderContextMenu = useCallback(
- (row: (typeof data)[number]) => {
+ (row: PaymentTerm) => {
return (
<>
<MenuItem
@@ -84,10 +98,15 @@ const PaymentTermsTable = memo(({ data, count }: PaymentTermsTableProps) => {
);
return (
- <Table<(typeof data)[number]>
+ <TableNew<PaymentTerm>
data={data}
columns={columns}
count={count}
+ primaryAction={
+ permissions.can("create", "accounting") && (
+ <New label="Payment Term" to={`new?${params.toString()}`} />
+ )
+ }
renderContextMenu={renderContextMenu}
/>
);
diff --git a/apps/carbon/app/modules/resources/ui/Person/PersonSidebar/usePersonSidebar.tsx b/apps/carbon/app/modules/resources/ui/Person/PersonSidebar/usePersonSidebar.tsx
index 02e4725d7a..774f9da188 100644
--- a/apps/carbon/app/modules/resources/ui/Person/PersonSidebar/usePersonSidebar.tsx
+++ b/apps/carbon/app/modules/resources/ui/Person/PersonSidebar/usePersonSidebar.tsx
@@ -6,7 +6,7 @@ export function usePersonSidebar() {
return [
{
name: "Profile",
- to: "",
+ to: "details",
icon: CgProfile,
},
{
diff --git a/apps/carbon/app/routes/x+/accounting+/payment-terms.$paymentTermId.tsx b/apps/carbon/app/routes/x+/accounting+/payment-terms.$paymentTermId.tsx
index 44f5f71ce2..68ef74a51a 100644
--- a/apps/carbon/app/routes/x+/accounting+/payment-terms.$paymentTermId.tsx
+++ b/apps/carbon/app/routes/x+/accounting+/payment-terms.$paymentTermId.tsx
@@ -13,7 +13,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) {
@@ -66,7 +66,7 @@ export async function action({ request }: ActionFunctionArgs) {
}
return redirect(
- path.to.paymentTerms,
+ `${path.to.paymentTerms}?${getParams(request)}`,
await flash(request, success("Updated payment term"))
);
}
diff --git a/apps/carbon/app/routes/x+/accounting+/payment-terms.delete.$paymentTermId.tsx b/apps/carbon/app/routes/x+/accounting+/payment-terms.delete.$paymentTermId.tsx
index 340c7e728e..dc33b0858b 100644
--- a/apps/carbon/app/routes/x+/accounting+/payment-terms.delete.$paymentTermId.tsx
+++ b/apps/carbon/app/routes/x+/accounting+/payment-terms.delete.$paymentTermId.tsx
@@ -6,7 +6,7 @@ import { deletePaymentTerm, getPaymentTerm } from "~/modules/accounting";
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) {
@@ -19,7 +19,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
const paymentTerm = await getPaymentTerm(client, paymentTermId);
if (paymentTerm.error) {
return redirect(
- path.to.paymentTerms,
+ `${path.to.paymentTerms}?${getParams(request)}`,
await flash(
request,
error(paymentTerm.error, "Failed to get payment term")
@@ -38,7 +38,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
const { paymentTermId } = params;
if (!paymentTermId) {
return redirect(
- path.to.paymentTerms,
+ `${path.to.paymentTerms}?${getParams(request)}`,
await flash(request, error(params, "Failed to get an payment term id"))
);
}
@@ -49,7 +49,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
);
if (deleteTypeError) {
return redirect(
- path.to.paymentTerms,
+ `${path.to.paymentTerms}?${getParams(request)}`,
await flash(
request,
error(deleteTypeError, "Failed to delete payment term")
@@ -58,7 +58,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
}
return redirect(
- path.to.paymentTerms,
+ `${path.to.paymentTerms}?${getParams(request)}`,
await flash(request, success("Successfully deleted payment term"))
);
}
diff --git a/apps/carbon/app/routes/x+/accounting+/payment-terms.new.tsx b/apps/carbon/app/routes/x+/accounting+/payment-terms.new.tsx
index bbc8212048..6dd89b46be 100644
--- a/apps/carbon/app/routes/x+/accounting+/payment-terms.new.tsx
+++ b/apps/carbon/app/routes/x+/accounting+/payment-terms.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 } from "~/utils/path";
+import { getParams, path } from "~/utils/path";
import { error, success } from "~/utils/result";
export async function loader({ request }: LoaderFunctionArgs) {
@@ -69,7 +69,7 @@ export async function action({ request }: ActionFunctionArgs) {
}
return redirect(
- path.to.paymentTerms,
+ `${path.to.paymentTerms}?${getParams(request)}`,
await flash(request, success("Payment term created"))
);
}
diff --git a/apps/carbon/app/routes/x+/accounting+/payment-terms.tsx b/apps/carbon/app/routes/x+/accounting+/payment-terms.tsx
index df6280e7a9..d8de007f66 100644
--- a/apps/carbon/app/routes/x+/accounting+/payment-terms.tsx
+++ b/apps/carbon/app/routes/x+/accounting+/payment-terms.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 {
- PaymentTermsTable,
- PaymentTermsTableFilters,
- getPaymentTerms,
-} from "~/modules/accounting";
+import { PaymentTermsTable, getPaymentTerms } from "~/modules/accounting";
import { requirePermissions } from "~/services/auth";
import type { Handle } from "~/utils/handle";
import { path } from "~/utils/path";
@@ -25,10 +21,13 @@ export async function loader({ request }: LoaderFunctionArgs) {
const url = new URL(request.url);
const searchParams = new URLSearchParams(url.search);
- const name = searchParams.get("name");
- const { limit, offset, sorts } = getGenericQueryFilters(searchParams);
+ const search = searchParams.get("search");
+ const { limit, offset, sorts, filters } =
+ getGenericQueryFilters(searchParams);
- return json(await getPaymentTerms(client, { name, limit, offset, sorts }));
+ return json(
+ await getPaymentTerms(client, { search, limit, offset, sorts, filters })
+ );
}
export default function PaymentTermsRoute() {
@@ -36,7 +35,6 @@ export default function PaymentTermsRoute() {
return (
<VStack spacing={0} className="h-full">
- <PaymentTermsTableFilters />
<PaymentTermsTable data={data ?? []} count={count ?? 0} />
<Outlet />
</VStack>
diff --git a/apps/carbon/app/routes/x+/person+/$personId._index.tsx b/apps/carbon/app/routes/x+/person+/$personId._index.tsx
index 5fc1309989..957905810c 100644
--- a/apps/carbon/app/routes/x+/person+/$personId._index.tsx
+++ b/apps/carbon/app/routes/x+/person+/$personId._index.tsx
@@ -1,36 +1,9 @@
import type { LoaderFunctionArgs } from "@remix-run/node";
-import { json, redirect } from "@remix-run/node";
-import { useLoaderData } from "@remix-run/react";
-import { requirePermissions } from "~/services/auth";
-import { flash } from "~/services/session.server";
+import { redirect } from "@remix-run/node";
import { path } from "~/utils/path";
-import { error } from "~/utils/result";
-
-import { ProfileForm, getAccount } from "~/modules/account";
-
-export async function loader({ request, params }: LoaderFunctionArgs) {
- const { client } = await requirePermissions(request, {
- view: "resources",
- });
+export async function loader({ params }: LoaderFunctionArgs) {
const { personId } = params;
if (!personId) throw new Error("Could not find personId");
-
- const account = await getAccount(client, personId);
- if (account.error) {
- return redirect(
- path.to.people,
- await flash(request, error(account.error, "Failed to load account"))
- );
- }
-
- return json({
- user: account.data,
- });
-}
-
-export default function PersonProfileRoute() {
- const { user } = useLoaderData<typeof loader>();
-
- return <ProfileForm user={user} />;
+ return redirect(path.to.personDetails(personId));
}
diff --git a/apps/carbon/app/routes/x+/person+/$personId.details.tsx b/apps/carbon/app/routes/x+/person+/$personId.details.tsx
new file mode 100644
index 0000000000..95b0cefd9f
--- /dev/null
+++ b/apps/carbon/app/routes/x+/person+/$personId.details.tsx
@@ -0,0 +1,46 @@
+import type { LoaderFunctionArgs } from "@remix-run/node";
+import { json, redirect } from "@remix-run/node";
+import { useLoaderData } from "@remix-run/react";
+import { requirePermissions } from "~/services/auth";
+import { flash } from "~/services/session.server";
+import { path } from "~/utils/path";
+import { error } from "~/utils/result";
+
+import { Card, CardContent, CardHeader, CardTitle } from "@carbon/react";
+import { ProfileForm, getAccount } from "~/modules/account";
+
+export async function loader({ request, params }: LoaderFunctionArgs) {
+ const { client } = await requirePermissions(request, {
+ view: "resources",
+ });
+
+ const { personId } = params;
+ if (!personId) throw new Error("Could not find personId");
+
+ const account = await getAccount(client, personId);
+ if (account.error) {
+ return redirect(
+ path.to.people,
+ await flash(request, error(account.error, "Failed to load account"))
+ );
+ }
+
+ return json({
+ user: account.data,
+ });
+}
+
+export default function PersonProfileRoute() {
+ const { user } = useLoaderData<typeof loader>();
+
+ return (
+ <Card>
+ <CardHeader>
+ <CardTitle>Profile</CardTitle>
+ </CardHeader>
+ <CardContent>
+ <ProfileForm user={user} />
+ </CardContent>
+ </Card>
+ );
+}
diff --git a/apps/carbon/app/utils/path.ts b/apps/carbon/app/utils/path.ts
index 4d30d0e0ed..9e82d64d6e 100644
--- a/apps/carbon/app/utils/path.ts
+++ b/apps/carbon/app/utils/path.ts
@@ -381,6 +381,7 @@ export const path = {
paymentTerms: `${x}/accounting/payment-terms`,
people: `${x}/resources/people`,
person: (id: string) => generatePath(`${x}/person/${id}`),
+ personDetails: (id: string) => generatePath(`${x}/person/${id}/details`),
personJob: (id: string) => generatePath(`${x}/person/${id}/job`),
profile: `${x}/account/profile`,
purchaseInvoice: (id: string) =>