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.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
feat: inline creation for part group
Brad Barbinef13c33489b9
diff --git a/apps/carbon/app/components/Form/Customer.tsx b/apps/carbon/app/components/Form/Customer.tsxindex 99c4651a14..2b8cf4a130 100644--- a/apps/carbon/app/components/Form/Customer.tsx+++ b/apps/carbon/app/components/Form/Customer.tsx@@ -10,7 +10,7 @@ type CustomerSelectProps = Omit<ComboboxProps, "options">;const Customer = (props: CustomerSelectProps) => {const [suppliers] = useCustomers();const newCustomersModal = useDisclosure();- const [createdCustomer, setCreatedCustomer] = useState<string>("");+ const [created, setCreated] = useState<string>("");const triggerRef = useRef<HTMLButtonElement>(null);const options = useMemo(@@ -31,19 +31,19 @@ const Customer = (props: CustomerSelectProps) => {label={props?.label ?? "Customer"}onCreateOption={(option) => {newCustomersModal.onOpen();- setCreatedCustomer(option);+ setCreated(option);}}/>{newCustomersModal.isOpen && (<CustomerFormtype="modal"onClose={() => {- setCreatedCustomer("");+ setCreated("");newCustomersModal.onClose();triggerRef.current?.click();}}initialValues={{- name: createdCustomer,+ name: created,}}/>)}diff --git a/apps/carbon/app/components/Form/Department.tsx b/apps/carbon/app/components/Form/Department.tsxindex 5ebf286676..e8a56c8541 100644--- a/apps/carbon/app/components/Form/Department.tsx+++ b/apps/carbon/app/components/Form/Department.tsx@@ -14,7 +14,7 @@ const Department = (props: DepartmentSelectProps) => {useFetcher<Awaited<ReturnType<typeof getDepartmentsList>>>();const newDepartmentModal = useDisclosure();- const [createdDepartment, setCreatedDepartment] = useState<string>("");+ const [created, setCreated] = useState<string>("");const triggerRef = useRef<HTMLButtonElement>(null);useMount(() => {@@ -41,19 +41,19 @@ const Department = (props: DepartmentSelectProps) => {label={props?.label ?? "Department"}onCreateOption={(option) => {newDepartmentModal.onOpen();- setCreatedDepartment(option);+ setCreated(option);}}/>{newDepartmentModal.isOpen && (<DepartmentFormtype="modal"onClose={() => {- setCreatedDepartment("");+ setCreated("");newDepartmentModal.onClose();triggerRef.current?.click();}}initialValues={{- name: createdDepartment,+ name: created,color: "#000000",}}/>diff --git a/apps/carbon/app/components/Form/Part.tsx b/apps/carbon/app/components/Form/Part.tsxindex 7c0f66ad6f..ee1bc1e9c3 100644--- a/apps/carbon/app/components/Form/Part.tsx+++ b/apps/carbon/app/components/Form/Part.tsx@@ -12,7 +12,7 @@ type PartSelectProps = Omit<ComboboxProps, "options"> & {const Part = ({ partReplenishmentSystem, ...props }: PartSelectProps) => {const [parts] = useParts();const newPartsModal = useDisclosure();- const [createdPart, setCreatedPart] = useState<string>("");+ const [created, setCreated] = useState<string>("");const triggerRef = useRef<HTMLButtonElement>(null);const options = useMemo(@@ -44,20 +44,20 @@ const Part = ({ partReplenishmentSystem, ...props }: PartSelectProps) => {label={props?.label ?? "Part"}onCreateOption={(option) => {newPartsModal.onOpen();- setCreatedPart(option);+ setCreated(option);}}/>{newPartsModal.isOpen && (<PartFormtype="modal"onClose={() => {- setCreatedPart("");+ setCreated("");newPartsModal.onClose();triggerRef.current?.click();}}initialValues={{id: "",- name: createdPart,+ name: created,description: "",partType: "Inventory" as "Inventory",replenishmentSystem: "Buy" as "Buy",diff --git a/apps/carbon/app/components/Form/PartGroup.tsx b/apps/carbon/app/components/Form/PartGroup.tsxnew file mode 100644index 0000000000..960b1c570d--- /dev/null+++ b/apps/carbon/app/components/Form/PartGroup.tsx@@ -0,0 +1,66 @@+import { useDisclosure, useMount } from "@carbon/react";+import { useFetcher } from "@remix-run/react";+import { useMemo, useRef, useState } from "react";+import type { getPartGroupsList } from "~/modules/parts";+import { PartGroupForm } from "~/modules/parts";+import { path } from "~/utils/path";+import type { ComboboxProps } from "./Combobox";+import CreatableCombobox from "./CreatableCombobox";++type PartGroupSelectProps = Omit<ComboboxProps, "options">;++const PartGroup = (props: PartGroupSelectProps) => {+ const partGroupFetcher =+ useFetcher<Awaited<ReturnType<typeof getPartGroupsList>>>();++ const newPartGroupModal = useDisclosure();+ const [created, setCreated] = useState<string>("");+ const triggerRef = useRef<HTMLButtonElement>(null);++ useMount(() => {+ partGroupFetcher.load(path.to.api.partGroups);+ });++ const options = useMemo(+ () =>+ partGroupFetcher.data?.data+ ? partGroupFetcher.data?.data.map((c) => ({+ value: c.id,+ label: c.name,+ }))+ : [],+ [partGroupFetcher.data]+ );++ return (+ <>+ <CreatableCombobox+ ref={triggerRef}+ options={options}+ {...props}+ label={props?.label ?? "Part Group"}+ onCreateOption={(option) => {+ newPartGroupModal.onOpen();+ setCreated(option);+ }}+ />+ {newPartGroupModal.isOpen && (+ <PartGroupForm+ type="modal"+ onClose={() => {+ setCreated("");+ newPartGroupModal.onClose();+ triggerRef.current?.click();+ }}+ initialValues={{+ name: created,+ }}+ />+ )}+ </>+ );+};++PartGroup.displayName = "PartGroup";++export default PartGroup;diff --git a/apps/carbon/app/components/Form/Supplier.tsx b/apps/carbon/app/components/Form/Supplier.tsxindex 95d4e3ed5c..c0a95a568c 100644--- a/apps/carbon/app/components/Form/Supplier.tsx+++ b/apps/carbon/app/components/Form/Supplier.tsx@@ -10,7 +10,7 @@ type SupplierSelectProps = Omit<ComboboxProps, "options">;const Supplier = (props: SupplierSelectProps) => {const [suppliers] = useSuppliers();const newSuppliersModal = useDisclosure();- const [createdSupplier, setCreatedSupplier] = useState<string>("");+ const [created, setCreated] = useState<string>("");const triggerRef = useRef<HTMLButtonElement>(null);const options = useMemo(@@ -31,19 +31,19 @@ const Supplier = (props: SupplierSelectProps) => {label={props?.label ?? "Supplier"}onCreateOption={(option) => {newSuppliersModal.onOpen();- setCreatedSupplier(option);+ setCreated(option);}}/>{newSuppliersModal.isOpen && (<SupplierFormtype="modal"onClose={() => {- setCreatedSupplier("");+ setCreated("");newSuppliersModal.onClose();triggerRef.current?.click();}}initialValues={{- name: createdSupplier,+ name: created,}}/>)}diff --git a/apps/carbon/app/components/Form/index.ts b/apps/carbon/app/components/Form/index.tsindex 81fc4f5d8b..7a6d0ed8e8 100644--- a/apps/carbon/app/components/Form/index.ts+++ b/apps/carbon/app/components/Form/index.ts@@ -25,6 +25,7 @@ import Location from "./Location";import Number from "./Number";import NumberControlled from "./NumberControlled";import Part from "./Part";+import PartGroup from "./PartGroup";import Password from "./Password";import PhoneInput from "./PhoneInput";import Radios from "./Radios";@@ -74,6 +75,7 @@ export {Number,NumberControlled,Part,+ PartGroup,Password,PhoneInput,Radios,diff --git a/apps/carbon/app/modules/parts/ui/Part/PartForm.tsx b/apps/carbon/app/modules/parts/ui/Part/PartForm.tsxindex 9f094ad916..54a0c1a76d 100644--- a/apps/carbon/app/modules/parts/ui/Part/PartForm.tsx+++ b/apps/carbon/app/modules/parts/ui/Part/PartForm.tsx@@ -20,6 +20,7 @@ import {Hidden,Input,InputControlled,+ PartGroup,Select,Submit,TextArea,@@ -96,12 +97,6 @@ const PartForm = ({ initialValues, type = "card", onClose }: PartFormProps) => {const permissions = usePermissions();const isEditing = !!initialValues.id;- const partGroupOptions =- sharedPartsData?.partGroups.map((partGroup) => ({- label: partGroup.name,- value: partGroup.id,- })) ?? [];-const partTypeOptions =partTypes.map((partType) => ({label: partType,@@ -186,11 +181,7 @@ const PartForm = ({ initialValues, type = "card", onClose }: PartFormProps) => {/></VStack><VStack>- <Combobox- name="partGroupId"- label="Part Group"- options={partGroupOptions}- />+ <PartGroup name="partGroupId" label="Part Group" /><Boolean name="blocked" label="Blocked" />{isEditing && <Boolean name="active" label="Active" />}</VStack>diff --git a/apps/carbon/app/modules/parts/ui/PartGroups/PartGroupForm.tsx b/apps/carbon/app/modules/parts/ui/PartGroups/PartGroupForm.tsxindex 6169be8066..51b8219b86 100644--- a/apps/carbon/app/modules/parts/ui/PartGroups/PartGroupForm.tsx+++ b/apps/carbon/app/modules/parts/ui/PartGroups/PartGroupForm.tsx@@ -1,16 +1,17 @@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 { Hidden, Input, Submit, TextArea } from "~/components/Form";import { usePermissions } from "~/hooks";@@ -19,13 +20,19 @@ import { path } from "~/utils/path";type PartGroupFormProps = {initialValues: z.infer<typeof partGroupValidator>;+ type?: "modal" | "drawer";+ open?: boolean;+ onClose: (data?: { id: string; name: string }) => void;};-const PartGroupForm = ({ initialValues }: PartGroupFormProps) => {- const fetcher = useFetcher();+const PartGroupForm = ({+ initialValues,+ open = true,+ type = "drawer",+ onClose,+}: PartGroupFormProps) => {const permissions = usePermissions();- const navigate = useNavigate();- const onClose = () => navigate(-1);+ const fetcher = useFetcher();const isEditing = initialValues.id !== undefined;const isDisabled = isEditing@@ -33,46 +40,56 @@ const PartGroupForm = ({ initialValues }: PartGroupFormProps) => {: !permissions.can("create", "parts");return (- <Drawer- open- onOpenChange={(open) => {- if (!open) onClose();- }}- >- <DrawerContent>- <ValidatedForm- validator={partGroupValidator}- method="post"- action={- isEditing- ? path.to.partGroup(initialValues.id!)- : path.to.newPartGroup- }- defaultValues={initialValues}- fetcher={fetcher}- className="flex flex-col h-full"- >- <DrawerHeader>- <DrawerTitle>{isEditing ? "Edit" : "New"} Part Group</DrawerTitle>- </DrawerHeader>- <DrawerBody>- <Hidden name="id" />- <VStack spacing={4}>- <Input name="name" label="Part Group" />- <TextArea name="description" label="Description" />- </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={partGroupValidator}+ method="post"+ action={+ isEditing+ ? path.to.partGroup(initialValues.id!)+ : path.to.newPartGroup+ }+ defaultValues={initialValues}+ fetcher={fetcher}+ className="flex flex-col h-full"+ onSubmit={() => {+ if (type === "modal") {+ onClose();+ }+ }}+ >+ <ModalDrawerHeader>+ <ModalDrawerTitle>+ {isEditing ? "Edit" : "New"} Part Group+ </ModalDrawerTitle>+ </ModalDrawerHeader>+ <ModalDrawerBody>+ <Hidden name="id" />+ <Hidden name="type" value={type} />+ <VStack spacing={4}>+ <Input name="name" label="Name" />+ <TextArea name="description" label="Description" />+ </VStack>+ </ModalDrawerBody>+ <ModalDrawerFooter>+ <HStack>+ <Submit isDisabled={isDisabled}>Save</Submit>+ <Button size="md" variant="solid" onClick={() => onClose()}>+ Cancel+ </Button>+ </HStack>+ </ModalDrawerFooter>+ </ValidatedForm>+ </ModalDrawerContent>+ </ModalDrawer>+ </ModalDrawerProvider>);};diff --git a/apps/carbon/app/modules/resources/ui/Departments/DepartmentForm.tsx b/apps/carbon/app/modules/resources/ui/Departments/DepartmentForm.tsxindex 6f88196f69..0d04cb84df 100644--- a/apps/carbon/app/modules/resources/ui/Departments/DepartmentForm.tsx+++ b/apps/carbon/app/modules/resources/ui/Departments/DepartmentForm.tsx@@ -1,12 +1,13 @@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";@@ -39,53 +40,60 @@ const DepartmentForm = ({: !permissions.can("create", "resources");return (- <Drawer- open={open}- onOpenChange={(open) => {- if (!open) onClose?.();- }}- >- <DrawerContent>- <ValidatedForm- validator={departmentValidator}- method="post"- action={- isEditing- ? path.to.department(initialValues.id!)- : path.to.newDepartment- }- defaultValues={initialValues}- fetcher={fetcher}- className="flex flex-col h-full"- onSubmit={() => {- if (type === "modal") {- onClose();+ <ModalDrawerProvider type={type}>+ <ModalDrawer+ open={open}+ onOpenChange={(open) => {+ if (!open) onClose?.();+ }}+ >+ <ModalDrawerContent>+ <ValidatedForm+ validator={departmentValidator}+ method="post"+ action={+ isEditing+ ? path.to.department(initialValues.id!)+ : path.to.newDepartment}- }}- >- <DrawerHeader>- <DrawerTitle>{isEditing ? "Edit" : "New"} Department</DrawerTitle>- </DrawerHeader>- <DrawerBody>- <Hidden name="id" />- <Hidden name="type" value={type} />- <VStack spacing={4}>- <Input name="name" label="Department Name" />- <Color name="color" label="Color" />- <Department name="parentDepartmentId" label="Parent Department" />- </VStack>- </DrawerBody>- <DrawerFooter>- <HStack>- <Submit isDisabled={isDisabled}>Save</Submit>- <Button size="md" variant="solid" onClick={() => onClose()}>- Cancel- </Button>- </HStack>- </DrawerFooter>- </ValidatedForm>- </DrawerContent>- </Drawer>+ defaultValues={initialValues}+ fetcher={fetcher}+ className="flex flex-col h-full"+ onSubmit={() => {+ if (type === "modal") {+ onClose();+ }+ }}+ >+ <ModalDrawerHeader>+ <ModalDrawerTitle>+ {isEditing ? "Edit" : "New"} Department+ </ModalDrawerTitle>+ </ModalDrawerHeader>+ <ModalDrawerBody>+ <Hidden name="id" />+ <Hidden name="type" value={type} />+ <VStack spacing={4}>+ <Input name="name" label="Department Name" />+ <Color name="color" label="Color" />+ <Department+ name="parentDepartmentId"+ label="Parent Department"+ />+ </VStack>+ </ModalDrawerBody>+ <ModalDrawerFooter>+ <HStack>+ <Submit isDisabled={isDisabled}>Save</Submit>+ <Button size="md" variant="solid" onClick={() => onClose()}>+ Cancel+ </Button>+ </HStack>+ </ModalDrawerFooter>+ </ValidatedForm>+ </ModalDrawerContent>+ </ModalDrawer>+ </ModalDrawerProvider>);};diff --git a/apps/carbon/app/routes/api+/parts.groups.ts b/apps/carbon/app/routes/api+/parts.groups.tsnew file mode 100644index 0000000000..824bb722e1--- /dev/null+++ b/apps/carbon/app/routes/api+/parts.groups.ts@@ -0,0 +1,10 @@+import type { LoaderFunctionArgs } from "@remix-run/node";+import { json } from "@remix-run/node";+import { getPartGroupsList } from "~/modules/parts";+import { requirePermissions } from "~/services/auth";++export async function loader({ request }: LoaderFunctionArgs) {+ const authorized = await requirePermissions(request, {});++ return json(await getPartGroupsList(authorized.client));+}diff --git a/apps/carbon/app/routes/api+/resources.equipment-types.tsx b/apps/carbon/app/routes/api+/resources.equipment-types.tssimilarity index 100%rename from apps/carbon/app/routes/api+/resources.equipment-types.tsxrename to apps/carbon/app/routes/api+/resources.equipment-types.tsdiff --git a/apps/carbon/app/routes/x+/parts+/groups.$groupId.tsx b/apps/carbon/app/routes/x+/parts+/groups.$groupId.tsxindex d6dfd8a79f..6bc1d499d6 100644--- a/apps/carbon/app/routes/x+/parts+/groups.$groupId.tsx+++ b/apps/carbon/app/routes/x+/parts+/groups.$groupId.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 {PartGroupForm,getPartGroup,@@ -71,6 +71,7 @@ export async function action({ request, params }: ActionFunctionArgs) {export default function EditPartGroupsRoute() {const { partGroup } = useLoaderData<typeof loader>();+ const navigate = useNavigate();const initialValues = {id: partGroup?.id ?? undefined,@@ -78,5 +79,11 @@ export default function EditPartGroupsRoute() {description: partGroup?.description ?? "",};- return <PartGroupForm key={initialValues.id} initialValues={initialValues} />;+ return (+ <PartGroupForm+ key={initialValues.id}+ initialValues={initialValues}+ onClose={() => navigate(-1)}+ />+ );}diff --git a/apps/carbon/app/routes/x+/parts+/groups.new.tsx b/apps/carbon/app/routes/x+/parts+/groups.new.tsxindex 84796e897a..93a0b67be5 100644--- a/apps/carbon/app/routes/x+/parts+/groups.new.tsx+++ b/apps/carbon/app/routes/x+/parts+/groups.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 {PartGroupForm,partGroupValidator,@@ -26,9 +27,10 @@ export async function action({ request }: ActionFunctionArgs) {create: "parts",});- const validation = await validator(partGroupValidator).validate(- await request.formData()- );+ const formData = await request.formData();+ const modal = formData.get("type") == "modal";++ const validation = await validator(partGroupValidator).validate(formData);if (validation.error) {return validationError(validation.error);@@ -61,17 +63,22 @@ export async function action({ request }: ActionFunctionArgs) {);}- return redirect(- path.to.partGroups,- await flash(request, success("Part group created"))- );+ return modal+ ? json(insertPartGroup, { status: 201 })+ : redirect(+ path.to.partGroups,+ await flash(request, success("Part group created"))+ );}export default function NewPartGroupsRoute() {+ const navigate = useNavigate();const initialValues = {name: "",description: "",};- return <PartGroupForm initialValues={initialValues} />;+ return (+ <PartGroupForm onClose={() => navigate(-1)} initialValues={initialValues} />+ );}diff --git a/apps/carbon/app/utils/path.ts b/apps/carbon/app/utils/path.tsindex 02b6e4eb9d..80b09ac3e7 100644--- a/apps/carbon/app/utils/path.ts+++ b/apps/carbon/app/utils/path.ts@@ -26,6 +26,7 @@ export const path = {groupsByType: (type?: string) =>generatePath(`${api}/users/groups?type=${type}`),locations: `${api}/resources/locations`,+ partGroups: `${api}/parts/groups`,rollback: (table: string, id: string) =>generatePath(`${api}/settings/sequence/rollback?table=${table}¤tSequence=${id}`diff --git a/packages/react/src/ModalDrawer.tsx b/packages/react/src/ModalDrawer.tsxindex 364779ebc2..5db20f439c 100644--- a/packages/react/src/ModalDrawer.tsx+++ b/packages/react/src/ModalDrawer.tsx@@ -9,6 +9,7 @@ import type {import { createContext, forwardRef, useContext } from "react";import {Drawer,+ DrawerBody,DrawerContent,DrawerDescription,DrawerFooter,@@ -71,14 +72,14 @@ const ModalDrawer = forwardRef<ModalDrawer.displayName = "ModalDrawer";const ModalDrawerBody = forwardRef<- ElementRef<typeof ModalBody> | ElementRef<typeof DrawerContent>,+ ElementRef<typeof ModalBody> | ElementRef<typeof DrawerBody>,| ComponentPropsWithoutRef<typeof ModalBody>- | ComponentPropsWithoutRef<typeof DrawerContent>+ | ComponentPropsWithoutRef<typeof DrawerBody>>((props, ref) => {const type = useModalDrawerType();if (type === "drawer") {- return <DrawerContent {...props} ref={ref} />;+ return <DrawerBody {...props} />;}return <ModalBody {...props} />;@@ -86,17 +87,16 @@ const ModalDrawerBody = forwardRef<ModalDrawerBody.displayName = "ModalDrawerBody";const ModalDrawerContent = forwardRef<- ElementRef<typeof ModalContent> | ElementRef<"div">,- | ComponentPropsWithoutRef<typeof ModalContent>- | ComponentPropsWithoutRef<"div">->((props, ref) => {+ ElementRef<typeof ModalContent> | ElementRef<typeof DrawerContent>,+ ComponentPropsWithoutRef<typeof DrawerContent>+>(({ size, ...props }, ref) => {const type = useModalDrawerType();if (type === "drawer") {- return <div {...props} ref={ref} />;+ return <DrawerContent {...props} size={size} ref={ref} />;}- return <ModalContent {...props} ref={ref} />;+ return <ModalContent {...props} size="medium" ref={ref} />;});ModalDrawerContent.displayName = "ModalDrawerContent";