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: remove ability to add and delete currency records

Rob Carrington6ba81ee93ad6
diff --git a/apps/carbon/app/modules/accounting/ui/Currencies/CurrenciesTable.tsx b/apps/carbon/app/modules/accounting/ui/Currencies/CurrenciesTable.tsx
index b46e678e9b..fb2565c5bd 100644
--- a/apps/carbon/app/modules/accounting/ui/Currencies/CurrenciesTable.tsx
+++ b/apps/carbon/app/modules/accounting/ui/Currencies/CurrenciesTable.tsx
@@ -2,8 +2,8 @@ import { MenuIcon, MenuItem } from "@carbon/react";
import { useNavigate } from "@remix-run/react";
import type { ColumnDef } from "@tanstack/react-table";
import { memo, useCallback, useMemo } from "react";
-import { LuPencil, LuTrash } from "react-icons/lu";
-import { Hyperlink, New, Table } from "~/components";
+import { LuPencil } from "react-icons/lu";
+import { Hyperlink, Table } from "~/components";
import { usePermissions, useUrlParams } from "~/hooks";
import { useCustomColumns } from "~/hooks/useCustomColumns";
import type { Currency } from "~/modules/accounting";
@@ -64,19 +64,6 @@ const CurrenciesTable = memo(({ data, count }: CurrenciesTableProps) => {
<MenuIcon icon={<LuPencil />} />
Edit Currency
</MenuItem>
- <MenuItem
- disabled={!permissions.can("delete", "accounting")}
- onClick={() => {
- navigate(
- `${path.to.deleteCurrency(
- row.id as string
- )}?${params.toString()}`
- );
- }}
- >
- <MenuIcon icon={<LuTrash />} />
- Delete Currency
- </MenuItem>
</>
);
},
@@ -88,11 +75,6 @@ const CurrenciesTable = memo(({ data, count }: CurrenciesTableProps) => {
data={data}
columns={columns}
count={count}
- primaryAction={
- permissions.can("create", "accounting") && (
- <New label="Currency" to={`new?${params.toString()}`} />
- )
- }
renderContextMenu={renderContextMenu}
/>
);
diff --git a/apps/carbon/app/routes/x+/accounting+/currencies.delete.$currencyId.tsx b/apps/carbon/app/routes/x+/accounting+/currencies.delete.$currencyId.tsx
deleted file mode 100644
index a3cce8e8c3..0000000000
--- a/apps/carbon/app/routes/x+/accounting+/currencies.delete.$currencyId.tsx
+++ /dev/null
@@ -1,73 +0,0 @@
-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 { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
-import { json, redirect } from "@vercel/remix";
-import { ConfirmDelete } from "~/components/Modals";
-import { deleteCurrency, getCurrency } from "~/modules/accounting";
-import { getParams, path } from "~/utils/path";
-
-export async function loader({ request, params }: LoaderFunctionArgs) {
- const { client } = await requirePermissions(request, {
- view: "accounting",
- });
- const { currencyId } = params;
- if (!currencyId) throw notFound("currencyId not found");
-
- const currency = await getCurrency(client, currencyId);
- if (currency.error) {
- throw redirect(
- path.to.currencies,
- await flash(request, error(currency.error, "Failed to get currency"))
- );
- }
-
- return json({ currency: currency.data });
-}
-
-export async function action({ request, params }: ActionFunctionArgs) {
- const { client } = await requirePermissions(request, {
- delete: "accounting",
- });
-
- const { currencyId } = params;
- if (!currencyId) {
- throw redirect(
- `${path.to.currencies}?${getParams(request)}`,
- await flash(request, error(params, "Failed to get an currency id"))
- );
- }
-
- const { error: deleteTypeError } = await deleteCurrency(client, currencyId);
- if (deleteTypeError) {
- throw redirect(
- `${path.to.currencies}?${getParams(request)}`,
- await flash(request, error(deleteTypeError, "Failed to delete currency"))
- );
- }
-
- throw redirect(
- `${path.to.currencies}?${getParams(request)}`,
- await flash(request, success("Successfully deleted currency"))
- );
-}
-
-export default function DeleteCurrencyRoute() {
- const { currencyId } = useParams();
- const { currency } = useLoaderData<typeof loader>();
- const navigate = useNavigate();
-
- if (!currencyId || !currency) return null; // TODO - handle this better (404?)
-
- const onCancel = () => navigate(path.to.currencies);
-
- return (
- <ConfirmDelete
- action={path.to.deleteCurrency(currencyId)}
- name={currency.name}
- text={`Are you sure you want to delete the currency: ${currency.name}? This cannot be undone.`}
- onCancel={onCancel}
- />
- );
-}
diff --git a/apps/carbon/app/routes/x+/accounting+/currencies.new.tsx b/apps/carbon/app/routes/x+/accounting+/currencies.new.tsx
deleted file mode 100644
index b32736f66a..0000000000
--- a/apps/carbon/app/routes/x+/accounting+/currencies.new.tsx
+++ /dev/null
@@ -1,78 +0,0 @@
-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 { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
-import { json, redirect } from "@vercel/remix";
-import {
- CurrencyForm,
- currencyValidator,
- upsertCurrency,
-} from "~/modules/accounting";
-import { setCustomFields } from "~/utils/form";
-import { getParams, path } from "~/utils/path";
-
-export async function loader({ request }: LoaderFunctionArgs) {
- await requirePermissions(request, {
- create: "accounting",
- });
-
- return null;
-}
-
-export async function action({ request }: ActionFunctionArgs) {
- assertIsPost(request);
- const { client, companyId, userId } = await requirePermissions(request, {
- create: "accounting",
- });
-
- const formData = await request.formData();
- const validation = await validator(currencyValidator).validate(formData);
-
- if (validation.error) {
- return validationError(validation.error);
- }
-
- const { id, ...data } = validation.data;
-
- const insertCurrency = await upsertCurrency(client, {
- ...data,
- companyId,
- customFields: setCustomFields(formData),
- createdBy: userId,
- });
- if (insertCurrency.error) {
- return json(
- {},
- await flash(
- request,
- error(insertCurrency.error, "Failed to insert currency")
- )
- );
- }
-
- const currencyId = insertCurrency.data?.id;
- if (!currencyId) {
- return json(
- {},
- await flash(request, error(insertCurrency, "Failed to insert currency"))
- );
- }
-
- throw redirect(
- `${path.to.currencies}?${getParams(request)}`,
- await flash(request, success("Currency created"))
- );
-}
-
-export default function NewCurrencyRoute() {
- const initialValues = {
- name: "",
- code: "",
- symbol: "",
- exchangeRate: 1,
- decimalPlaces: 2,
- };
-
- return <CurrencyForm initialValues={initialValues} />;
-}