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 customer location
Brad Barbin7286f759455d
diff --git a/apps/carbon/app/components/Form/CustomerLocation.tsx b/apps/carbon/app/components/Form/CustomerLocation.tsxindex afd62408d9..eb2bba8bf5 100644--- a/apps/carbon/app/components/Form/CustomerLocation.tsx+++ b/apps/carbon/app/components/Form/CustomerLocation.tsx@@ -1,13 +1,15 @@import { useFetcher } from "@remix-run/react";-import { useEffect, useMemo } from "react";-import type {- CustomerLocation as CustomerLocationType,- getCustomerLocations,+import { useEffect, useMemo, useRef } from "react";+import {+ CustomerLocationForm,+ type CustomerLocation as CustomerLocationType,+ type getCustomerLocations,} from "~/modules/sales";import { path } from "~/utils/path";+import { useDisclosure } from "@carbon/react";import type { ComboboxProps } from "./Combobox";-import Combobox from "./Combobox";+import CreatableCombobox from "./CreatableCombobox";type CustomerLocationSelectProps = Omit<ComboboxProps,@@ -21,6 +23,10 @@ const CustomerLocation = (props: CustomerLocationSelectProps) => {const customerLocationsFetcher =useFetcher<Awaited<ReturnType<typeof getCustomerLocations>>>();+ const newLocationModal = useDisclosure();+ // const [created, setCreated] = useState<string>("");+ const triggerRef = useRef<HTMLButtonElement>(null);+useEffect(() => {if (props?.customer) {customerLocationsFetcher.load(@@ -50,12 +56,31 @@ const CustomerLocation = (props: CustomerLocationSelectProps) => {};return (- <Combobox- options={options}- {...props}- onChange={onChange}- label={props?.label ?? "Customer Location"}- />+ <>+ <CreatableCombobox+ ref={triggerRef}+ options={options}+ {...props}+ label={props?.label ?? "Customer Location"}+ onChange={onChange}+ onCreateOption={(option) => {+ newLocationModal.onOpen();+ // setCreated(option);+ }}+ />+ {newLocationModal.isOpen && (+ <CustomerLocationForm+ customerId={props.customer!}+ type="modal"+ onClose={() => {+ // setCreated("");+ newLocationModal.onClose();+ triggerRef.current?.click();+ }}+ initialValues={{}}+ />+ )}+ </>);};diff --git a/apps/carbon/app/modules/sales/ui/Customer/CustomerLocationForm.tsx b/apps/carbon/app/modules/sales/ui/Customer/CustomerLocationForm.tsxindex 7865f58c98..f05abc4fb2 100644--- a/apps/carbon/app/modules/sales/ui/Customer/CustomerLocationForm.tsx+++ b/apps/carbon/app/modules/sales/ui/Customer/CustomerLocationForm.tsx@@ -11,7 +11,7 @@ import {} from "@carbon/react";import { ValidatedForm } from "@carbon/remix-validated-form";-import { useFetcher, useNavigate, useParams } from "@remix-run/react";+import { useFetcher } from "@remix-run/react";import type { z } from "zod";import { Hidden, Input, Submit } from "~/components/Form";import { usePermissions } from "~/hooks";@@ -19,15 +19,21 @@ import { customerLocationValidator } from "~/modules/sales";import { path } from "~/utils/path";type CustomerLocationFormProps = {+ customerId: string;initialValues: z.infer<typeof customerLocationValidator>;+ type?: "modal" | "drawer";+ open?: boolean;+ onClose: () => void;};-const CustomerLocationForm = ({ initialValues }: CustomerLocationFormProps) => {+const CustomerLocationForm = ({+ customerId,+ initialValues,+ open = true,+ type = "drawer",+ onClose,+}: CustomerLocationFormProps) => {const fetcher = useFetcher();- const navigate = useNavigate();- const { customerId } = useParams();-- if (!customerId) throw new Error("customerId not found");const permissions = usePermissions();const isEditing = !!initialValues?.id;@@ -35,13 +41,11 @@ const CustomerLocationForm = ({ initialValues }: CustomerLocationFormProps) => {? !permissions.can("update", "sales"): !permissions.can("create", "sales");- const onClose = () => navigate(path.to.customerLocations(customerId));-return (<DraweropenonOpenChange={(open) => {- if (!open) onClose();+ if (!open) onClose?.();}}><DrawerContent>@@ -55,7 +59,11 @@ const CustomerLocationForm = ({ initialValues }: CustomerLocationFormProps) => {}defaultValues={initialValues}fetcher={fetcher}- onSubmit={onClose}+ onSubmit={() => {+ if (type === "modal") {+ onClose?.();+ }+ }}className="flex flex-col h-full"><DrawerHeader>@@ -63,6 +71,7 @@ const CustomerLocationForm = ({ initialValues }: CustomerLocationFormProps) => {</DrawerHeader><DrawerBody><Hidden name="id" />+ <Hidden name="type" value={type} /><Hidden name="addressId" /><VStack spacing={4}><Input name="addressLine1" label="Address Line 1" />diff --git a/apps/carbon/app/modules/sales/ui/Quotation/QuotationLineQuantities.tsx b/apps/carbon/app/modules/sales/ui/Quotation/QuotationLineQuantities.tsxindex 76f75cfcd9..f277590bd6 100644--- a/apps/carbon/app/modules/sales/ui/Quotation/QuotationLineQuantities.tsx+++ b/apps/carbon/app/modules/sales/ui/Quotation/QuotationLineQuantities.tsx@@ -207,11 +207,6 @@ const QuotationLineQuantities = ({// eslint-disable-next-line react-hooks/exhaustive-deps}, [navigate, quotationLine.replenishmentSystem, isEditable, canDelete]);- console.log({- isMade,- replenishmentSystem: quotationLine.replenishmentSystem,- });-const editableComponents = useMemo(() => {const editableCells = {quantity: EditableQuotationLineQuantity(onCellEdit, {diff --git a/apps/carbon/app/routes/x+/customer+/$customerId.locations.$customerLocationId.tsx b/apps/carbon/app/routes/x+/customer+/$customerId.locations.$customerLocationId.tsxindex a0235987bc..a5c1b26b37 100644--- a/apps/carbon/app/routes/x+/customer+/$customerId.locations.$customerLocationId.tsx+++ b/apps/carbon/app/routes/x+/customer+/$customerId.locations.$customerLocationId.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, useParams } from "@remix-run/react";import {CustomerLocationForm,customerLocationValidator,@@ -84,6 +84,10 @@ export async function action({ request, params }: ActionFunctionArgs) {export default function EditCustomerLocationRoute() {const { location } = useLoaderData<typeof loader>();+ const navigate = useNavigate();++ const { customerId } = useParams();+ if (!customerId) throw new Error("customerId not found");const initialValues = {id: location?.id ?? undefined,@@ -99,7 +103,9 @@ export default function EditCustomerLocationRoute() {return (<CustomerLocationFormkey={initialValues.id}+ customerId={customerId}initialValues={initialValues}+ onClose={() => navigate(path.to.customerLocations(customerId))}/>);}diff --git a/apps/carbon/app/routes/x+/customer+/$customerId.locations.new.tsx b/apps/carbon/app/routes/x+/customer+/$customerId.locations.new.tsxindex 316b8b9e4f..a01462fb8a 100644--- a/apps/carbon/app/routes/x+/customer+/$customerId.locations.new.tsx+++ b/apps/carbon/app/routes/x+/customer+/$customerId.locations.new.tsx@@ -1,6 +1,7 @@import { validationError, validator } from "@carbon/remix-validated-form";import type { ActionFunctionArgs } from "@remix-run/node";-import { redirect } from "@remix-run/node";+import { json, redirect } from "@remix-run/node";+import { useNavigate, useParams } from "@remix-run/react";import {CustomerLocationForm,customerLocationValidator,@@ -18,11 +19,14 @@ export async function action({ request, params }: ActionFunctionArgs) {create: "sales",});+ const formData = await request.formData();+ const modal = formData.get("type") === "modal";+const { customerId } = params;if (!customerId) throw notFound("customerId not found");const validation = await validator(customerLocationValidator).validate(- await request.formData()+ formData);if (validation.error) {@@ -36,26 +40,41 @@ export async function action({ request, params }: ActionFunctionArgs) {address,});if (createCustomerLocation.error) {- return redirect(- path.to.customerLocations(customerId),- await flash(- request,- error(- createCustomerLocation.error,- "Failed to create customer location"- )- )- );+ return modal+ ? json(createCustomerLocation)+ : redirect(+ path.to.customerLocations(customerId),+ await flash(+ request,+ error(+ createCustomerLocation.error,+ "Failed to create customer location"+ )+ )+ );}- return redirect(- path.to.customerLocations(customerId),- await flash(request, success("Customer location created"))- );+ return modal+ ? json(createCustomerLocation, { status: 201 })+ : redirect(+ path.to.customerLocations(customerId),+ await flash(request, success("Customer location created"))+ );}export default function CustomerLocationsNewRoute() {+ const navigate = useNavigate();++ const { customerId } = useParams();+ if (!customerId) throw new Error("customerId not found");+const initialValues = {};- return <CustomerLocationForm initialValues={initialValues} />;+ return (+ <CustomerLocationForm+ initialValues={initialValues}+ customerId={customerId}+ onClose={() => navigate(path.to.customerLocations(customerId))}+ />+ );}diff --git a/apps/carbon/app/routes/x+/quote+/$id.details.tsx b/apps/carbon/app/routes/x+/quote+/$id.details.tsxindex 8cd376766a..c62fa7f546 100644--- a/apps/carbon/app/routes/x+/quote+/$id.details.tsx+++ b/apps/carbon/app/routes/x+/quote+/$id.details.tsx@@ -29,8 +29,6 @@ export async function action({ request, params }: ActionFunctionArgs) {await request.formData());- console.log({ validation });-if (validation.error) {return validationError(validation.error);}diff --git a/packages/database/src/seed.ts b/packages/database/src/seed.tsindex 42bbf35594..9ab3094048 100644--- a/packages/database/src/seed.ts+++ b/packages/database/src/seed.ts@@ -1,14 +1,14 @@import { createClient } from "@supabase/supabase-js";import * as dotenv from "dotenv";-import type { Database } from "./types";-import type { Feature, EmployeeType } from "./seed/index";+import type { EmployeeType, Feature } from "./seed/index";import {admin,claims,- features,employeeTypePermissionsDefinitions,employeeTypes,+ features,} from "./seed/index";+import type { Database } from "./types";dotenv.config();