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: inline creation for supplier types

Brad Barbinf4137601531d
diff --git a/apps/carbon/app/components/Editable/EditableQuotationLineQuantity.tsx b/apps/carbon/app/components/Editable/EditableQuotationLineQuantity.tsx
index 8d24d5d5d4..67a61b1530 100644
--- a/apps/carbon/app/components/Editable/EditableQuotationLineQuantity.tsx
+++ b/apps/carbon/app/components/Editable/EditableQuotationLineQuantity.tsx
@@ -41,7 +41,7 @@ const EditableQuotationLineQuantity =
: {
materialCost:
row.quantity === 0
- ? row.materialCost
+ ? row.materialCost * quantity
: (row.materialCost / row.quantity) * quantity,
};
diff --git a/apps/carbon/app/components/Form/Part.tsx b/apps/carbon/app/components/Form/Part.tsx
index ee1bc1e9c3..9575d346d5 100644
--- a/apps/carbon/app/components/Form/Part.tsx
+++ b/apps/carbon/app/components/Form/Part.tsx
@@ -60,7 +60,7 @@ const Part = ({ partReplenishmentSystem, ...props }: PartSelectProps) => {
name: created,
description: "",
partType: "Inventory" as "Inventory",
- replenishmentSystem: "Buy" as "Buy",
+ replenishmentSystem: partReplenishmentSystem ?? ("Buy" as "Buy"),
unitOfMeasureCode: "EA",
blocked: false,
active: false,
diff --git a/apps/carbon/app/components/Form/SupplierType.tsx b/apps/carbon/app/components/Form/SupplierType.tsx
new file mode 100644
index 0000000000..99537f7c2c
--- /dev/null
+++ b/apps/carbon/app/components/Form/SupplierType.tsx
@@ -0,0 +1,67 @@
+import { useDisclosure, useMount } from "@carbon/react";
+import { useFetcher } from "@remix-run/react";
+import { useMemo, useRef, useState } from "react";
+import type { getSupplierTypesList } from "~/modules/purchasing";
+import { SupplierTypeForm } from "~/modules/purchasing";
+import { path } from "~/utils/path";
+import type { ComboboxProps } from "./Combobox";
+import CreatableCombobox from "./CreatableCombobox";
+
+type SupplierTypeSelectProps = Omit<ComboboxProps, "options">;
+
+const SupplierType = (props: SupplierTypeSelectProps) => {
+ const supplierTypeFetcher =
+ useFetcher<Awaited<ReturnType<typeof getSupplierTypesList>>>();
+
+ const newSupplierTypeModal = useDisclosure();
+ const [created, setCreated] = useState<string>("");
+ const triggerRef = useRef<HTMLButtonElement>(null);
+
+ useMount(() => {
+ supplierTypeFetcher.load(path.to.api.supplierTypes);
+ });
+
+ const options = useMemo(
+ () =>
+ supplierTypeFetcher.data?.data
+ ? supplierTypeFetcher.data?.data.map((c) => ({
+ value: c.id,
+ label: c.name,
+ }))
+ : [],
+ [supplierTypeFetcher.data]
+ );
+
+ return (
+ <>
+ <CreatableCombobox
+ ref={triggerRef}
+ options={options}
+ {...props}
+ label={props?.label ?? "SupplierType"}
+ onCreateOption={(option) => {
+ newSupplierTypeModal.onOpen();
+ setCreated(option);
+ }}
+ />
+ {newSupplierTypeModal.isOpen && (
+ <SupplierTypeForm
+ type="modal"
+ onClose={() => {
+ setCreated("");
+ newSupplierTypeModal.onClose();
+ triggerRef.current?.click();
+ }}
+ initialValues={{
+ name: created,
+ color: "#000000",
+ }}
+ />
+ )}
+ </>
+ );
+};
+
+SupplierType.displayName = "SupplierType";
+
+export default SupplierType;
diff --git a/apps/carbon/app/components/Form/index.ts b/apps/carbon/app/components/Form/index.ts
index fc99e28616..a55145d7ad 100644
--- a/apps/carbon/app/components/Form/index.ts
+++ b/apps/carbon/app/components/Form/index.ts
@@ -40,6 +40,7 @@ import Submit from "./Submit";
import Supplier from "./Supplier";
import SupplierContact from "./SupplierContact";
import SupplierLocation from "./SupplierLocation";
+import SupplierType from "./SupplierType";
import TextArea from "./Textarea";
import TimePicker from "./TimePicker";
import Timezone from "./Timezone";
@@ -91,6 +92,7 @@ export {
Supplier,
SupplierContact,
SupplierLocation,
+ SupplierType,
TextArea,
TimePicker,
Timezone,
diff --git a/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierForm.tsx b/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierForm.tsx
index 1b8b9670c4..d6bf7d2735 100644
--- a/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierForm.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierForm.tsx
@@ -14,9 +14,16 @@ import {
import { ValidatedForm } from "@carbon/remix-validated-form";
import { useFetcher } from "@remix-run/react";
import type { z } from "zod";
-import { Employee, Hidden, Input, Select, Submit } from "~/components/Form";
+import {
+ Employee,
+ Hidden,
+ Input,
+ Select,
+ Submit,
+ SupplierType,
+} from "~/components/Form";
import { usePermissions, useRouteData } from "~/hooks";
-import type { SupplierStatus, SupplierType } from "~/modules/purchasing";
+import type { SupplierStatus } from "~/modules/purchasing";
import { supplierValidator } from "~/modules/purchasing";
import { path } from "~/utils/path";
@@ -35,16 +42,9 @@ const SupplierForm = ({
const fetcher = useFetcher();
const routeData = useRouteData<{
- supplierTypes: SupplierType[];
supplierStatuses: SupplierStatus[];
}>(path.to.supplierRoot);
- const supplierTypeOptions =
- routeData?.supplierTypes?.map((type) => ({
- value: type.id,
- label: type.name,
- })) ?? [];
-
const supplierStatusOptions =
routeData?.supplierStatuses?.map((status) => ({
value: status.id,
@@ -93,10 +93,9 @@ const SupplierForm = ({
<Input name="taxId" label="Tax ID" />
</VStack>
<VStack>
- <Select
+ <SupplierType
name="supplierTypeId"
label="Supplier Type"
- options={supplierTypeOptions}
placeholder="Select Supplier Type"
/>
<Select
diff --git a/apps/carbon/app/modules/purchasing/ui/SupplierTypes/SupplierTypeForm.tsx b/apps/carbon/app/modules/purchasing/ui/SupplierTypes/SupplierTypeForm.tsx
index bedd18c7c3..225a4cde33 100644
--- a/apps/carbon/app/modules/purchasing/ui/SupplierTypes/SupplierTypeForm.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/SupplierTypes/SupplierTypeForm.tsx
@@ -1,31 +1,38 @@
import {
Button,
- Drawer,
- DrawerBody,
- DrawerContent,
- DrawerFooter,
- DrawerHeader,
- DrawerTitle,
HStack,
+ ModalDrawer,
+ ModalDrawerBody,
+ ModalDrawerContent,
+ ModalDrawerFooter,
+ ModalDrawerHeader,
+ ModalDrawerProvider,
+ ModalDrawerTitle,
VStack,
} from "@carbon/react";
import { ValidatedForm } from "@carbon/remix-validated-form";
-import { useFetcher, useNavigate } from "@remix-run/react";
+import { useFetcher } from "@remix-run/react";
import type { z } from "zod";
import { Color, Hidden, Input, Submit } from "~/components/Form";
import { usePermissions } from "~/hooks";
import { supplierTypeValidator } from "~/modules/purchasing";
import { path } from "~/utils/path";
-type SupplierTypeFormProps = {
+type DepartmentFormProps = {
initialValues: z.infer<typeof supplierTypeValidator>;
+ type?: "modal" | "drawer";
+ open?: boolean;
+ onClose: () => void;
};
-const SupplierTypeForm = ({ initialValues }: SupplierTypeFormProps) => {
- const fetcher = useFetcher();
+const DepartmentForm = ({
+ initialValues,
+ open = true,
+ type = "drawer",
+ onClose,
+}: DepartmentFormProps) => {
const permissions = usePermissions();
- const navigate = useNavigate();
- const onClose = () => navigate(-1);
+ const fetcher = useFetcher();
const isEditing = initialValues.id !== undefined;
const isDisabled = isEditing
@@ -33,49 +40,57 @@ const SupplierTypeForm = ({ initialValues }: SupplierTypeFormProps) => {
: !permissions.can("create", "purchasing");
return (
- <Drawer
- open
- onOpenChange={(open) => {
- if (!open) onClose();
- }}
- >
- <DrawerContent>
- <ValidatedForm
- validator={supplierTypeValidator}
- method="post"
- action={
- isEditing
- ? path.to.supplierType(initialValues.id!)
- : path.to.newSupplierType
- }
- defaultValues={initialValues}
- fetcher={fetcher}
- className="flex flex-col h-full"
- >
- <DrawerHeader>
- <DrawerTitle>
- {isEditing ? "Edit" : "New"} Supplier Type
- </DrawerTitle>
- </DrawerHeader>
- <DrawerBody>
- <Hidden name="id" />
- <VStack spacing={4}>
- <Input name="name" label="Supplier Type" />
- <Color name="color" label="Color" />
- </VStack>
- </DrawerBody>
- <DrawerFooter>
- <HStack>
- <Submit isDisabled={isDisabled}>Save</Submit>
- <Button size="md" variant="solid" onClick={onClose}>
- Cancel
- </Button>
- </HStack>
- </DrawerFooter>
- </ValidatedForm>
- </DrawerContent>
- </Drawer>
+ <ModalDrawerProvider type={type}>
+ <ModalDrawer
+ open={open}
+ onOpenChange={(open) => {
+ if (!open) onClose?.();
+ }}
+ >
+ <ModalDrawerContent>
+ <ValidatedForm
+ validator={supplierTypeValidator}
+ method="post"
+ action={
+ isEditing
+ ? path.to.supplierType(initialValues.id!)
+ : path.to.newSupplierType
+ }
+ defaultValues={initialValues}
+ fetcher={fetcher}
+ className="flex flex-col h-full"
+ onSubmit={() => {
+ if (type === "modal") {
+ onClose();
+ }
+ }}
+ >
+ <ModalDrawerHeader>
+ <ModalDrawerTitle>
+ {isEditing ? "Edit" : "New"} Supplier Type
+ </ModalDrawerTitle>
+ </ModalDrawerHeader>
+ <ModalDrawerBody>
+ <Hidden name="id" />
+ <Hidden name="type" value={type} />
+ <VStack spacing={4}>
+ <Input name="name" label="Supplier Type" />
+ <Color name="color" label="Color" />
+ </VStack>
+ </ModalDrawerBody>
+ <ModalDrawerFooter>
+ <HStack>
+ <Submit isDisabled={isDisabled}>Save</Submit>
+ <Button size="md" variant="solid" onClick={() => onClose()}>
+ Cancel
+ </Button>
+ </HStack>
+ </ModalDrawerFooter>
+ </ValidatedForm>
+ </ModalDrawerContent>
+ </ModalDrawer>
+ </ModalDrawerProvider>
);
};
-export default SupplierTypeForm;
+export default DepartmentForm;
diff --git a/apps/carbon/app/modules/resources/ui/Departments/DepartmentForm.tsx b/apps/carbon/app/modules/resources/ui/Departments/DepartmentForm.tsx
index 0d04cb84df..ffab8ac137 100644
--- a/apps/carbon/app/modules/resources/ui/Departments/DepartmentForm.tsx
+++ b/apps/carbon/app/modules/resources/ui/Departments/DepartmentForm.tsx
@@ -22,7 +22,7 @@ type DepartmentFormProps = {
initialValues: z.infer<typeof departmentValidator>;
type?: "modal" | "drawer";
open?: boolean;
- onClose: (data?: { id: string; name: string }) => void;
+ onClose: () => void;
};
const DepartmentForm = ({
diff --git a/apps/carbon/app/modules/sales/ui/Quotation/QuotationAssemblyForm.tsx b/apps/carbon/app/modules/sales/ui/Quotation/QuotationAssemblyForm.tsx
index dbbecb4ae2..a7db57fe02 100644
--- a/apps/carbon/app/modules/sales/ui/Quotation/QuotationAssemblyForm.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotation/QuotationAssemblyForm.tsx
@@ -150,7 +150,7 @@ const QuotationAssemblyForm = ({
<VStack>
<Part
name="partId"
- label="Part"
+ label="Manufactured Part"
partReplenishmentSystem="Make"
onChange={(value) => {
onPartChange(value?.value as string);
diff --git a/apps/carbon/app/modules/sales/ui/Quotation/QuotationLineQuantities.tsx b/apps/carbon/app/modules/sales/ui/Quotation/QuotationLineQuantities.tsx
index cffeaad5b2..76f75cfcd9 100644
--- a/apps/carbon/app/modules/sales/ui/Quotation/QuotationLineQuantities.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotation/QuotationLineQuantities.tsx
@@ -207,8 +207,13 @@ const QuotationLineQuantities = ({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [navigate, quotationLine.replenishmentSystem, isEditable, canDelete]);
- const editableComponents = useMemo(
- () => ({
+ console.log({
+ isMade,
+ replenishmentSystem: quotationLine.replenishmentSystem,
+ });
+
+ const editableComponents = useMemo(() => {
+ const editableCells = {
quantity: EditableQuotationLineQuantity(onCellEdit, {
client: supabase,
effects: linePriceEffects.effects[lineId],
@@ -219,12 +224,13 @@ const QuotationLineQuantities = ({
markupPercentage: EditableNumber(onCellEdit, { minValue: 0 }),
unitTaxAmount: EditableNumber(onCellEdit, { minValue: 0 }),
leadTime: EditableNumber(onCellEdit, { minValue: 0 }),
- materialCost: isMade
- ? undefined
- : EditableNumber(onCellEdit, { minValue: 0 }),
- }),
- [isMade, lineId, linePriceEffects.effects, onCellEdit, supabase]
- );
+ };
+ if (!isMade) {
+ // @ts-expect-error
+ editableCells.materialCost = EditableNumber(onCellEdit, { minValue: 0 });
+ }
+ return editableCells;
+ }, [isMade, lineId, linePriceEffects.effects, onCellEdit, supabase]);
const newRowButtonRef = useRef<HTMLButtonElement>(null);
diff --git a/apps/carbon/app/routes/api+/purchasing.supplier-types.ts b/apps/carbon/app/routes/api+/purchasing.supplier-types.ts
new file mode 100644
index 0000000000..199ca67c93
--- /dev/null
+++ b/apps/carbon/app/routes/api+/purchasing.supplier-types.ts
@@ -0,0 +1,12 @@
+import type { LoaderFunctionArgs } from "@remix-run/node";
+import { json } from "@remix-run/node";
+import { getSupplierTypesList } from "~/modules/purchasing";
+import { requirePermissions } from "~/services/auth";
+
+export async function loader({ request }: LoaderFunctionArgs) {
+ const authorized = await requirePermissions(request, {
+ view: "purchasing",
+ });
+
+ return json(await getSupplierTypesList(authorized.client));
+}
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 9aae50d197..83dd095b91 100644
--- a/apps/carbon/app/routes/x+/purchasing+/supplier-types.$supplierTypeId.tsx
+++ b/apps/carbon/app/routes/x+/purchasing+/supplier-types.$supplierTypeId.tsx
@@ -1,7 +1,7 @@
import { validationError, validator } from "@carbon/remix-validated-form";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@remix-run/node";
import { json, redirect } from "@remix-run/node";
-import { useLoaderData } from "@remix-run/react";
+import { useLoaderData, useNavigate } from "@remix-run/react";
import {
SupplierTypeForm,
getSupplierType,
@@ -87,6 +87,7 @@ export async function action({ request }: ActionFunctionArgs) {
export default function EditSupplierTypesRoute() {
const { supplierType } = useLoaderData<typeof loader>();
+ const navigate = useNavigate();
const initialValues = {
id: supplierType.id ?? undefined,
@@ -95,6 +96,10 @@ export default function EditSupplierTypesRoute() {
};
return (
- <SupplierTypeForm key={initialValues.id} initialValues={initialValues} />
+ <SupplierTypeForm
+ key={initialValues.id}
+ initialValues={initialValues}
+ onClose={() => navigate(-1)}
+ />
);
}
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 d2c090a0fd..46a644e336 100644
--- a/apps/carbon/app/routes/x+/purchasing+/supplier-types.new.tsx
+++ b/apps/carbon/app/routes/x+/purchasing+/supplier-types.new.tsx
@@ -1,6 +1,7 @@
import { validationError, validator } from "@carbon/remix-validated-form";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@remix-run/node";
import { json, redirect } from "@remix-run/node";
+import { useNavigate } from "@remix-run/react";
import {
SupplierTypeForm,
supplierTypeValidator,
@@ -9,7 +10,7 @@ import {
import { requirePermissions } from "~/services/auth";
import { flash } from "~/services/session.server";
import { assertIsPost } from "~/utils/http";
-import { path } from "~/utils/path";
+import { path, requestReferrer } from "~/utils/path";
import { error, success } from "~/utils/result";
export async function loader({ request }: LoaderFunctionArgs) {
@@ -26,9 +27,10 @@ export async function action({ request }: ActionFunctionArgs) {
create: "purchasing",
});
- const validation = await validator(supplierTypeValidator).validate(
- await request.formData()
- );
+ const formData = await request.formData();
+ const modal = formData.get("type") === "modal";
+
+ const validation = await validator(supplierTypeValidator).validate(formData);
if (validation.error) {
return validationError(validation.error);
@@ -41,26 +43,36 @@ export async function action({ request }: ActionFunctionArgs) {
createdBy: userId,
});
if (insertSupplierType.error) {
- return json(
- {},
- await flash(
- request,
- error(insertSupplierType.error, "Failed to insert supplier type")
- )
- );
+ return modal
+ ? json(insertSupplierType)
+ : redirect(
+ requestReferrer(request) ?? path.to.supplierTypes,
+ await flash(
+ request,
+ error(insertSupplierType.error, "Failed to insert supplier type")
+ )
+ );
}
- return redirect(
- path.to.supplierTypes,
- await flash(request, success("Supplier type created"))
- );
+ return modal
+ ? json(insertSupplierType, { status: 201 })
+ : redirect(
+ path.to.supplierTypes,
+ await flash(request, success("Supplier type created"))
+ );
}
export default function NewSupplierTypesRoute() {
+ const navigate = useNavigate();
const initialValues = {
name: "",
color: "#000000",
};
- return <SupplierTypeForm initialValues={initialValues} />;
+ return (
+ <SupplierTypeForm
+ initialValues={initialValues}
+ onClose={() => navigate(-1)}
+ />
+ );
}
diff --git a/apps/carbon/app/routes/x+/quote+/$id.tsx b/apps/carbon/app/routes/x+/quote+/$id.tsx
index 7b18ed906b..48483103e0 100644
--- a/apps/carbon/app/routes/x+/quote+/$id.tsx
+++ b/apps/carbon/app/routes/x+/quote+/$id.tsx
@@ -179,7 +179,6 @@ export default function QuotationRoute() {
<TooltipTrigger>
<IconButton
aria-label="Add Quote Line"
- variant="secondary"
icon={<IoMdAdd />}
ref={buttonRef}
onClick={() => navigate(path.to.newQuoteLine(id))}
diff --git a/apps/carbon/app/routes/x+/supplier+/_layout.tsx b/apps/carbon/app/routes/x+/supplier+/_layout.tsx
index ae718b2776..03cabb1988 100644
--- a/apps/carbon/app/routes/x+/supplier+/_layout.tsx
+++ b/apps/carbon/app/routes/x+/supplier+/_layout.tsx
@@ -27,23 +27,17 @@ export async function loader({ request }: LoaderFunctionArgs) {
view: "purchasing",
});
- const [
- supplierTypes,
- supplierStatuses,
- paymentTerms,
- shippingMethods,
- shippingTerms,
- ] = await Promise.all([
- getSupplierTypes(client),
- getSupplierStatuses(client),
- getPaymentTermsList(client),
- getShippingMethodsList(client),
- getShippingTermsList(client),
- ]);
+ const [supplierStatuses, paymentTerms, shippingMethods, shippingTerms] =
+ await Promise.all([
+ getSupplierTypes(client),
+ getSupplierStatuses(client),
+ getPaymentTermsList(client),
+ getShippingMethodsList(client),
+ getShippingTermsList(client),
+ ]);
return json({
supplierStatuses: supplierStatuses.data ?? [],
- supplierTypes: supplierTypes.data ?? [],
paymentTerms: paymentTerms.data ?? [],
shippingMethods: shippingMethods.data ?? [],
shippingTerms: shippingTerms.data ?? [],
diff --git a/apps/carbon/app/utils/path.ts b/apps/carbon/app/utils/path.ts
index cac1255a41..8cfbdb3ea2 100644
--- a/apps/carbon/app/utils/path.ts
+++ b/apps/carbon/app/utils/path.ts
@@ -41,6 +41,7 @@ export const path = {
generatePath(`${api}/purchasing/supplier-contacts?supplierId=${id}`),
supplierLocations: (id: string) =>
generatePath(`${api}/purchasing/supplier-locations?supplierId=${id}`),
+ supplierTypes: `${api}/purchasing/supplier-types`,
unitOfMeasures: `${api}/parts/uoms`,
workCells: (id: string) =>
generatePath(`${api}/resources/work-cells?location=${id}`),