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: add configure button to make method tools

Brad Barbinbd67c813ab14
diff --git a/apps/erp/app/components/Form/Item.tsx b/apps/erp/app/components/Form/Item.tsx
index 4212328157..c3a3e9b6cb 100644
--- a/apps/erp/app/components/Form/Item.tsx
+++ b/apps/erp/app/components/Form/Item.tsx
@@ -37,7 +37,7 @@ import { useItems } from "~/stores";
import { MethodItemTypeIcon } from "../Icons";
type ItemSelectProps = Omit<ComboboxProps, "options" | "type" | "inline"> & {
- disabledItems?: string[];
+ blacklist?: string[];
includeInactive?: boolean;
inline?: boolean;
isConfigured?: boolean;
@@ -45,6 +45,7 @@ type ItemSelectProps = Omit<ComboboxProps, "options" | "type" | "inline"> & {
type: MethodItemType | "Item";
typeFieldName?: string;
validItemTypes?: MethodItemType[];
+ whitelist?: string[];
onConfigure?: () => void;
onTypeChange?: (type: MethodItemType | "Item") => void;
};
@@ -75,7 +76,7 @@ const Item = ({
// biome-ignore lint/correctness/useExhaustiveDependencies: suppressed due to migration
const options = useMemo(() => {
- const results = items
+ let results = items
.filter((item) => {
// Filter by type
// @ts-ignore
@@ -105,18 +106,21 @@ const Item = ({
helper: item.name
}));
- if (props.disabledItems) {
- return results.filter(
- (item) => !props.disabledItems?.includes(item.value)
- );
+ if (props.whitelist) {
+ results = results.filter((item) => props.whitelist?.includes(item.value));
+ }
+
+ if (props.blacklist) {
+ return results.filter((item) => !props.blacklist?.includes(item.value));
}
return results;
}, [
items,
props?.includeInactive,
- props.disabledItems,
+ props.blacklist,
props.replenishmentSystem,
+ props.whitelist,
type
]);
diff --git a/apps/erp/app/modules/items/ui/Item/BillOfMaterial.tsx b/apps/erp/app/modules/items/ui/Item/BillOfMaterial.tsx
index 7f708fe4d6..1b0b579b4b 100644
--- a/apps/erp/app/modules/items/ui/Item/BillOfMaterial.tsx
+++ b/apps/erp/app/modules/items/ui/Item/BillOfMaterial.tsx
@@ -724,7 +724,7 @@ function MaterialForm({
<div className="grid w-full gap-x-8 gap-y-4 grid-cols-1 lg:grid-cols-3">
<Item
- disabledItems={[params.itemId!]}
+ blacklist={[params.itemId!]}
name="itemId"
label={itemType}
includeInactive
diff --git a/apps/erp/app/modules/items/ui/Item/MakeMethodTools.tsx b/apps/erp/app/modules/items/ui/Item/MakeMethodTools.tsx
index c2a9906764..138fbf5011 100644
--- a/apps/erp/app/modules/items/ui/Item/MakeMethodTools.tsx
+++ b/apps/erp/app/modules/items/ui/Item/MakeMethodTools.tsx
@@ -1,3 +1,4 @@
+import { useCarbon } from "@carbon/auth";
// biome-ignore lint/suspicious/noShadowRestrictedNames: suppressed due to migration
import { Number, Submit, ValidatedForm } from "@carbon/form";
import {
@@ -29,6 +30,7 @@ import {
ModalTitle,
toast,
useDisclosure,
+ useMount,
VStack
} from "@carbon/react";
import { useEffect, useState } from "react";
@@ -49,7 +51,7 @@ import {
import { Link, useFetcher, useParams } from "react-router";
import { Hidden, Item } from "~/components/Form";
import { Confirm } from "~/components/Modals";
-import { usePermissions } from "~/hooks";
+import { usePermissions, useUser } from "~/hooks";
import type { MethodItemType } from "~/modules/shared";
import { path } from "~/utils/path";
import {
@@ -89,6 +91,34 @@ const MakeMethodTools = ({
}, [fetcher.data?.error]);
const [includeInactive, setIncludeInactive] = useState<boolean>(true);
+ const [configurableItemIds, setConfigurableItemIds] = useState<string[]>([]);
+
+ const { carbon } = useCarbon();
+ const {
+ company: { id: companyId }
+ } = useUser();
+
+ const getConfigurableItems = async () => {
+ if (carbon) {
+ // TODO: cache these in client loader called through fetcher
+ const { data, error } = await carbon
+ .from("itemReplenishment")
+ .select("itemId")
+ .eq("requiresConfiguration", true)
+ .eq("companyId", companyId);
+
+ if (error) {
+ console.error(error);
+ return;
+ }
+
+ setConfigurableItemIds(data?.map((d) => d.itemId) ?? []);
+ }
+ };
+
+ useMount(() => {
+ getConfigurableItems();
+ });
const getMethodModal = useDisclosure();
const saveMethodModal = useDisclosure();
@@ -277,6 +307,7 @@ const MakeMethodTools = ({
name="sourceId"
label="Source Method"
type={type}
+ blacklist={configurableItemIds}
includeInactive={includeInactive}
replenishmentSystem="Make"
/>
@@ -346,7 +377,7 @@ const MakeMethodTools = ({
label="Target Method"
type={type}
includeInactive={includeInactive}
- disabledItems={[itemId]}
+ blacklist={[itemId, ...configurableItemIds]}
replenishmentSystem="Make"
/>
<div className="flex items-center space-x-2">
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobBillOfMaterial.tsx b/apps/erp/app/modules/production/ui/Jobs/JobBillOfMaterial.tsx
index f281ebdd6b..7c62905260 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobBillOfMaterial.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobBillOfMaterial.tsx
@@ -801,7 +801,7 @@ function MaterialForm({
<div className="grid w-full gap-x-8 gap-y-4 grid-cols-1 lg:grid-cols-3">
<Item
- disabledItems={[params.itemId!]}
+ blacklist={[params.itemId!]}
isReadOnly={isDisabled}
name="itemId"
label={itemType}
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobMakeMethodTools.tsx b/apps/erp/app/modules/production/ui/Jobs/JobMakeMethodTools.tsx
index 190a9f74b0..c769e848e9 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobMakeMethodTools.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobMakeMethodTools.tsx
@@ -27,26 +27,27 @@ import {
VStack
} from "@carbon/react";
import { labelSizes } from "@carbon/utils";
-import { Suspense, useEffect, useState } from "react";
+import { useEffect, useState } from "react";
import {
LuGitBranch,
LuGitFork,
LuGitMerge,
LuQrCode,
+ LuSettings,
LuSquareStack,
LuTriangleAlert
} from "react-icons/lu";
import { RiProgress4Line } from "react-icons/ri";
-import { Await, Link, useFetcher, useLocation, useParams } from "react-router";
+import { Link, useFetcher, useLocation, useParams } from "react-router";
import { ConfiguratorModal } from "~/components/Configurator/ConfiguratorForm";
import { Hidden, Item, Submit } from "~/components/Form";
import type { Tree } from "~/components/TreeView";
import { usePermissions, useRouteData, useUser } from "~/hooks";
-import type {
- ConfigurationParameter,
- ConfigurationParameterGroup
+import {
+ type ConfigurationParameter,
+ type ConfigurationParameterGroup,
+ getConfigurationParameters
} from "~/modules/items";
-import { getConfigurationParameters } from "~/modules/items";
import { getLinkToItemDetails } from "~/modules/items/ui/Item/ItemForm";
import MakeMethodVersionStatus from "~/modules/items/ui/Item/MakeMethodVersionStatus";
import { QuoteLineMethodForm } from "~/modules/sales/ui/Quotes/QuoteLineMethodForm";
@@ -64,10 +65,6 @@ const JobMakeMethodTools = ({ makeMethod }: { makeMethod?: JobMakeMethod }) => {
const routeData = useRouteData<{
job: Job;
method: Tree<JobMethod>;
- configurationParameters: Promise<{
- groups: ConfigurationParameterGroup[];
- parameters: ConfigurationParameter[];
- }>;
}>(path.to.job(jobId));
const materialRouteData = useRouteData<{
@@ -94,7 +91,13 @@ const JobMakeMethodTools = ({ makeMethod }: { makeMethod?: JobMakeMethod }) => {
const hasMethods = methodTree?.children && methodTree.children.length > 0;
const isGetMethodLoading =
- fetcher.state !== "idle" && fetcher.formAction === path.to.jobMethodGet;
+ fetcher.state !== "idle" &&
+ fetcher.formAction === path.to.jobMethodGet &&
+ !fetcher.formData?.get("configuration");
+ const isConfigureLoading =
+ fetcher.state !== "idle" &&
+ fetcher.formAction === path.to.jobMethodGet &&
+ !!fetcher.formData?.get("configuration");
const isSaveMethodLoading =
fetcher.state !== "idle" && fetcher.formAction === path.to.jobMethodSave;
@@ -117,35 +120,67 @@ const JobMakeMethodTools = ({ makeMethod }: { makeMethod?: JobMakeMethod }) => {
const { carbon } = useCarbon();
+ const configureSelectModal = useDisclosure();
const configuratorModal = useDisclosure();
- const [isConfigured, setIsConfigured] = useState(false);
- const getIsConfigured = async () => {
- if (isJobMethod && routeData?.job.itemId && carbon) {
+
+ // State for configurable items
+ const [configurableItemIds, setConfigurableItemIds] = useState<string[]>([]);
+ const [selectedConfigureItemId, setSelectedConfigureItemId] = useState<
+ string | null
+ >(null);
+ const [configurationParameters, setConfigurationParameters] = useState<{
+ groups: ConfigurationParameterGroup[];
+ parameters: ConfigurationParameter[];
+ }>({ groups: [], parameters: [] });
+
+ const getConfigurableItems = async () => {
+ if (carbon) {
+ // TODO: cache these in client loader called through fetcher
const { data, error } = await carbon
.from("itemReplenishment")
- .select("requiresConfiguration")
- .eq("itemId", routeData.job.itemId)
- .single();
+ .select("itemId")
+ .eq("requiresConfiguration", true)
+ .eq("companyId", companyId);
if (error) {
console.error(error);
+ return;
}
- setIsConfigured(data?.requiresConfiguration ?? false);
+ setConfigurableItemIds(data?.map((d) => d.itemId) ?? []);
}
};
- useMount(() => {
- getIsConfigured();
- });
+ const handleConfigureItemSelect = async (itemId: string | null) => {
+ if (!itemId || !carbon) return;
+
+ setSelectedConfigureItemId(itemId);
+
+ // Fetch configuration parameters for the selected item
+ const params = await getConfigurationParameters(carbon, itemId, companyId);
+ setConfigurationParameters(params);
+
+ configureSelectModal.onClose();
+ configuratorModal.onOpen();
+ };
const saveConfiguration = async (configuration: Record<string, any>) => {
configuratorModal.onClose();
- fetcher.submit(JSON.stringify(configuration), {
- method: "post",
- action: path.to.jobConfigure(jobId),
- encType: "application/json"
- });
+ const sourceId = selectedConfigureItemId;
+ setSelectedConfigureItemId(null);
+ setConfigurationParameters({ groups: [], parameters: [] });
+ fetcher.submit(
+ {
+ type: "item",
+ targetId: jobId,
+ sourceId,
+ configuration: JSON.stringify(configuration)
+ },
+ {
+ method: "post",
+ action: path.to.jobMethodGet
+ }
+ );
};
const navigateToTrackingLabels = (
@@ -187,16 +222,6 @@ const JobMakeMethodTools = ({ makeMethod }: { makeMethod?: JobMakeMethod }) => {
const [selectedMakeMethod, setSelectedMakeMethod] = useState<string | null>(
null
);
- const [sourceItemRequiresConfiguration, setSourceItemRequiresConfiguration] =
- useState(false);
- const [
- sourceItemConfigurationParameters,
- setSourceItemConfigurationParameters
- ] = useState<{
- groups: ConfigurationParameterGroup[];
- parameters: ConfigurationParameter[];
- }>({ groups: [], parameters: [] });
- const [pendingGetMethodData, setPendingGetMethodData] = useState<any>(null);
const getMakeMethods = async (itemId: string) => {
setMakeMethods([]);
@@ -234,6 +259,7 @@ const JobMakeMethodTools = ({ makeMethod }: { makeMethod?: JobMakeMethod }) => {
if (isJobMethod && routeData?.job.itemId) {
getMakeMethods(routeData.job.itemId);
}
+ getConfigurableItems();
});
return (
@@ -262,19 +288,16 @@ const JobMakeMethodTools = ({ makeMethod }: { makeMethod?: JobMakeMethod }) => {
Save Method
</MenubarItem>
- {isConfigured && isJobMethod && (
+ {configurableItemIds.length > 0 && (
<MenubarItem
- leftIcon={<LuGitMerge />}
+ leftIcon={<LuSettings />}
isDisabled={
- isDisabled || !permissions.can("update", "production")
- }
- isLoading={
- fetcher.state !== "idle" &&
- fetcher.formAction === path.to.jobConfigure(jobId)
+ isDisabled ||
+ !permissions.can("update", "production") ||
+ isConfigureLoading
}
- onClick={() => {
- configuratorModal.onOpen();
- }}
+ isLoading={isConfigureLoading}
+ onClick={configureSelectModal.onOpen}
>
Configure
</MenubarItem>
@@ -325,73 +348,7 @@ const JobMakeMethodTools = ({ makeMethod }: { makeMethod?: JobMakeMethod }) => {
fetcher={fetcher}
action={path.to.jobMethodGet}
validator={getJobMethodValidator}
- onSubmit={async (data, e) => {
- if (e) {
- e.preventDefault();
- e.stopPropagation();
- }
-
- const sourceId = data.sourceId as string;
- // Get type from the form element since it's not in validated data
- const formElement = e?.target as HTMLFormElement;
- const formData = new FormData(formElement);
- const type = formData.get("type") as string;
-
- // Only check configuration for "item" and "method" types, not "quoteLine"
- if (
- sourceId &&
- carbon &&
- (type === "item" || type === "method")
- ) {
- // Store the form data for later use (include type which isn't in validated data)
- setPendingGetMethodData({ ...data, type });
-
- // Check if the source item requires configuration
- const { data: replenishmentData } = await carbon
- .from("itemReplenishment")
- .select("requiresConfiguration, companyId")
- .eq("itemId", sourceId)
- .single();
-
- if (replenishmentData?.requiresConfiguration) {
- // Get configuration parameters for the source item
- const companyId = replenishmentData?.companyId;
- if (!companyId) {
- toast.error("Unable to get company ID");
- return;
- }
- const configParams = await getConfigurationParameters(
- carbon,
- sourceId,
- companyId
- );
-
- setSourceItemRequiresConfiguration(true);
- setSourceItemConfigurationParameters(configParams);
- getMethodModal.onClose();
- configuratorModal.onOpen();
- } else {
- // No configuration needed, proceed with normal submission
- fetcher.submit(
- { ...data, type },
- {
- method: "post",
- action: path.to.jobMethodGet
- }
- );
- getMethodModal.onClose();
- }
- } else {
- // No sourceId, no carbon, or type is "quoteLine" - proceed with normal submission
- // Need to include type for jobs since it's not in validated data
- const dataWithType = type ? { ...data, type } : data;
- fetcher.submit(dataWithType, {
- method: "post",
- action: path.to.jobMethodGet
- });
- getMethodModal.onClose();
- }
- }}
+ onSubmit={getMethodModal.onClose}
>
<ModalHeader>
<ModalTitle>Get Method</ModalTitle>
@@ -430,6 +387,7 @@ const JobMakeMethodTools = ({ makeMethod }: { makeMethod?: JobMakeMethod }) => {
name="sourceId"
label="Source Method"
type={(routeData?.job.itemType ?? "Part") as "Part"}
+ blacklist={configurableItemIds}
includeInactive={includeInactive === true}
replenishmentSystem="Make"
/>
@@ -529,6 +487,7 @@ const JobMakeMethodTools = ({ makeMethod }: { makeMethod?: JobMakeMethod }) => {
name="itemId"
label="Target Method"
type={(routeData?.job?.itemType ?? "Part") as "Part"}
+ blacklist={configurableItemIds}
onChange={(value) => {
if (value) {
getMakeMethods(value?.value);
@@ -593,69 +552,67 @@ const JobMakeMethodTools = ({ makeMethod }: { makeMethod?: JobMakeMethod }) => {
</ModalContent>
</Modal>
)}
- {configuratorModal.isOpen && (
- <Suspense fallback={null}>
- {sourceItemRequiresConfiguration ? (
- // Configurator for source item when getting method
- <ConfiguratorModal
- open
- destructive
- initialValues={{} as Record<string, any>}
- groups={sourceItemConfigurationParameters.groups}
- parameters={sourceItemConfigurationParameters.parameters}
- onClose={() => {
- configuratorModal.onClose();
- setSourceItemRequiresConfiguration(false);
- setSourceItemConfigurationParameters({
- groups: [],
- parameters: []
- });
- }}
- onSubmit={(config: Record<string, any>) => {
- // Submit the get method with configuration
- if (pendingGetMethodData) {
- const dataWithConfig = {
- ...pendingGetMethodData,
- configuration: JSON.stringify(config)
- };
-
- fetcher.submit(dataWithConfig, {
- method: "post",
- action: path.to.jobMethodGet
- });
-
- setPendingGetMethodData(null);
- }
-
- configuratorModal.onClose();
- setSourceItemRequiresConfiguration(false);
- setSourceItemConfigurationParameters({
- groups: [],
- parameters: []
- });
- }}
- />
- ) : (
- // Regular configurator for job configuration
- <Await resolve={routeData?.configurationParameters}>
- {(configurationParameters) => (
- <ConfiguratorModal
- open
- destructive
- initialValues={
- (routeData?.job.configuration || {}) as Record<string, any>
- }
- groups={configurationParameters?.groups ?? []}
- parameters={configurationParameters?.parameters ?? []}
- onClose={configuratorModal.onClose}
- onSubmit={(config: Record<string, any>) => {
- saveConfiguration(config);
+ {configureSelectModal.isOpen && (
+ <Modal
+ open
+ onOpenChange={(open) => {
+ if (!open) {
+ configureSelectModal.onClose();
+ }
+ }}
+ >
+ <ModalContent>
+ <ValidatedForm
+ validator={getJobMethodValidator}
+ onSubmit={() => {}}
+ >
+ <ModalHeader>
+ <ModalTitle>Configure Item</ModalTitle>
+ <ModalDescription>Select an item to configure</ModalDescription>
+ </ModalHeader>
+ <ModalBody>
+ <Item
+ name="sourceId"
+ label="Item"
+ type={(routeData?.job?.itemType ?? "Part") as "Part"}
+ includeInactive={includeInactive === true}
+ whitelist={configurableItemIds}
+ replenishmentSystem="Make"
+ onChange={(value) => {
+ if (value) {
+ handleConfigureItemSelect(value.value);
+ }
}}
/>
- )}
- </Await>
- )}
- </Suspense>
+ </ModalBody>
+ <ModalFooter>
+ <Button
+ onClick={configureSelectModal.onClose}
+ variant="secondary"
+ >
+ Cancel
+ </Button>
+ </ModalFooter>
+ </ValidatedForm>
+ </ModalContent>
+ </Modal>
+ )}
+ {configuratorModal.isOpen && (
+ <ConfiguratorModal
+ open
+ destructive
+ initialValues={{}}
+ groups={configurationParameters.groups}
+ parameters={configurationParameters.parameters}
+ onClose={() => {
+ configuratorModal.onClose();
+ setSelectedConfigureItemId(null);
+ setConfigurationParameters({ groups: [], parameters: [] });
+ }}
+ onSubmit={(config: Record<string, any>) => {
+ saveConfiguration(config);
+ }}
+ />
)}
</>
);
diff --git a/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfMaterial.tsx b/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfMaterial.tsx
index 336ab2e220..92798f18b3 100644
--- a/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfMaterial.tsx
+++ b/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfMaterial.tsx
@@ -759,7 +759,7 @@ function MaterialForm({
<div className="grid w-full gap-x-8 gap-y-4 grid-cols-1 lg:grid-cols-3">
<Item
- disabledItems={[params.itemId!]}
+ blacklist={[params.itemId!]}
isReadOnly={isDisabled}
name="itemId"
label={itemType}
diff --git a/apps/erp/app/modules/sales/ui/Quotes/QuoteMakeMethodTools.tsx b/apps/erp/app/modules/sales/ui/Quotes/QuoteMakeMethodTools.tsx
index df20223275..2b762e3271 100644
--- a/apps/erp/app/modules/sales/ui/Quotes/QuoteMakeMethodTools.tsx
+++ b/apps/erp/app/modules/sales/ui/Quotes/QuoteMakeMethodTools.tsx
@@ -25,7 +25,7 @@ import {
useMount,
VStack
} from "@carbon/react";
-import { Suspense, useEffect, useState } from "react";
+import { useEffect, useState } from "react";
import {
LuGitBranch,
LuGitFork,
@@ -35,16 +35,16 @@ import {
LuTriangleAlert
} from "react-icons/lu";
import { RiProgress4Line } from "react-icons/ri";
-import { Await, Link, useFetcher, useLocation, useParams } from "react-router";
+import { Link, useFetcher, useLocation, useParams } from "react-router";
import { ConfiguratorModal } from "~/components/Configurator/ConfiguratorForm";
import { Hidden, Item, Submit } from "~/components/Form";
import type { Tree } from "~/components/TreeView";
import { usePermissions, useRouteData, useUser } from "~/hooks";
-import type {
- ConfigurationParameter,
- ConfigurationParameterGroup
+import {
+ type ConfigurationParameter,
+ type ConfigurationParameterGroup,
+ getConfigurationParameters
} from "~/modules/items";
-import { getConfigurationParameters } from "~/modules/items";
import { getLinkToItemDetails } from "~/modules/items/ui/Item/ItemForm";
import MakeMethodVersionStatus from "~/modules/items/ui/Item/MakeMethodVersionStatus";
import type { MethodItemType } from "~/modules/shared/types";
@@ -81,13 +81,6 @@ const QuoteMakeMethodTools = () => {
? getLinkToItemDetails(itemType as MethodItemType, itemId)
: null;
- const lineData = useRouteData<{
- configurationParameters: Promise<{
- groups: ConfigurationParameterGroup[];
- parameters: ConfigurationParameter[];
- }>;
- }>(path.to.quoteLineMethod(quoteId, lineId!, methodId!));
-
const line = routeData?.lines.find((line) => line.id === lineId);
const { pathname } = useLocation();
@@ -97,7 +90,13 @@ const QuoteMakeMethodTools = () => {
const hasMethods = methodTree?.children && methodTree.children.length > 0;
const isGetMethodLoading =
- fetcher.state !== "idle" && fetcher.formAction === path.to.quoteMethodGet;
+ fetcher.state !== "idle" &&
+ fetcher.formAction === path.to.quoteMethodGet &&
+ !fetcher.formData?.get("configuration");
+ const isConfigureLoading =
+ fetcher.state !== "idle" &&
+ fetcher.formAction === path.to.quoteMethodGet &&
+ !!fetcher.formData?.get("configuration");
const isSaveMethodLoading =
fetcher.state !== "idle" && fetcher.formAction === path.to.quoteMethodSave;
@@ -122,35 +121,67 @@ const QuoteMakeMethodTools = () => {
const { carbon } = useCarbon();
+ const configureSelectModal = useDisclosure();
const configuratorModal = useDisclosure();
- const [isConfigured, setIsConfigured] = useState(false);
- const getIsConfigured = async () => {
- if (isQuoteLineMethod && line?.itemId && carbon) {
+
+ // State for configurable items
+ const [configurableItemIds, setConfigurableItemIds] = useState<string[]>([]);
+ const [selectedConfigureItemId, setSelectedConfigureItemId] = useState<
+ string | null
+ >(null);
+ const [configurationParameters, setConfigurationParameters] = useState<{
+ groups: ConfigurationParameterGroup[];
+ parameters: ConfigurationParameter[];
+ }>({ groups: [], parameters: [] });
+
+ const getConfigurableItems = async () => {
+ // TODO: cache these in client loader called through fetcher
+ if (carbon) {
const { data, error } = await carbon
.from("itemReplenishment")
- .select("requiresConfiguration")
- .eq("itemId", line.itemId)
- .single();
+ .select("itemId")
+ .eq("requiresConfiguration", true)
+ .eq("companyId", companyId);
if (error) {
console.error(error);
+ return;
}
- setIsConfigured(data?.requiresConfiguration ?? false);
+ setConfigurableItemIds(data?.map((d) => d.itemId) ?? []);
}
};
- useMount(() => {
- getIsConfigured();
- });
+ const handleConfigureItemSelect = async (itemId: string | null) => {
+ if (!itemId || !carbon) return;
+
+ setSelectedConfigureItemId(itemId);
+
+ // Fetch configuration parameters for the selected item
+ const params = await getConfigurationParameters(carbon, itemId, companyId);
+ setConfigurationParameters(params);
+
+ configureSelectModal.onClose();
+ configuratorModal.onOpen();
+ };
const saveConfiguration = async (configuration: Record<string, any>) => {
configuratorModal.onClose();
- fetcher.submit(JSON.stringify(configuration), {
- method: "post",
- action: path.to.quoteLineConfigure(quoteId, lineId!),
- encType: "application/json"
- });
+ const sourceId = selectedConfigureItemId;
+ setSelectedConfigureItemId(null);
+ setConfigurationParameters({ groups: [], parameters: [] });
+ fetcher.submit(
+ {
+ type: "item",
+ targetId: `${quoteId}:${lineId}`,
+ sourceId,
+ configuration: JSON.stringify(configuration)
+ },
+ {
+ method: "post",
+ action: path.to.quoteMethodGet
+ }
+ );
};
const {
@@ -162,16 +193,6 @@ const QuoteMakeMethodTools = () => {
const [selectedMakeMethod, setSelectedMakeMethod] = useState<string | null>(
null
);
- const [sourceItemRequiresConfiguration, setSourceItemRequiresConfiguration] =
- useState(false);
- const [
- sourceItemConfigurationParameters,
- setSourceItemConfigurationParameters
- ] = useState<{
- groups: ConfigurationParameterGroup[];
- parameters: ConfigurationParameter[];
- }>({ groups: [], parameters: [] });
- const [pendingGetMethodData, setPendingGetMethodData] = useState<any>(null);
const getMakeMethods = async (itemId: string) => {
setMakeMethods([]);
@@ -209,6 +230,7 @@ const QuoteMakeMethodTools = () => {
if (isQuoteLineMethod && line?.itemId) {
getMakeMethods(line.itemId);
}
+ getConfigurableItems();
});
return (
@@ -237,18 +259,14 @@ const QuoteMakeMethodTools = () => {
>
Save Method
</MenubarItem>
- {isConfigured && isQuoteLineMethod && (
+ {configurableItemIds.length > 0 && (
<MenubarItem
leftIcon={<LuSettings />}
- isDisabled={!permissions.can("update", "sales")}
- isLoading={
- fetcher.state !== "idle" &&
- fetcher.formAction ===
- path.to.quoteLineConfigure(quoteId, lineId!)
+ isDisabled={
+ !permissions.can("update", "sales") || isConfigureLoading
}
- onClick={() => {
- configuratorModal.onOpen();
- }}
+ isLoading={isConfigureLoading}
+ onClick={configureSelectModal.onOpen}
>
Configure
</MenubarItem>
@@ -279,65 +297,7 @@ const QuoteMakeMethodTools = () => {
fetcher={fetcher}
action={path.to.quoteMethodGet}
validator={getMethodValidator}
- onSubmit={async (data, e) => {
- if (e) {
- e.preventDefault();
- e.stopPropagation();
- }
-
- const sourceId = data.sourceId as string;
- const type = data.type as string;
-
- // Only check configuration for "item" and "method" types, not "quoteLine"
- if (
- sourceId &&
- carbon &&
- (type === "item" || type === "method")
- ) {
- // Store the form data for later use
- setPendingGetMethodData(data);
-
- // Check if the source item requires configuration
- const { data: replenishmentData } = await carbon
- .from("itemReplenishment")
- .select("requiresConfiguration, companyId")
- .eq("itemId", sourceId)
- .single();
-
- if (replenishmentData?.requiresConfiguration) {
- // Get configuration parameters for the source item
- const companyId = replenishmentData?.companyId;
- if (!companyId) {
- toast.error("Unable to get company ID");
- return;
- }
- const configParams = await getConfigurationParameters(
- carbon,
- sourceId,
- companyId
- );
-
- setSourceItemRequiresConfiguration(true);
- setSourceItemConfigurationParameters(configParams);
- getMethodModal.onClose();
- configuratorModal.onOpen();
- } else {
- // No configuration needed, proceed with normal submission
- fetcher.submit(data, {
- method: "post",
- action: path.to.quoteMethodGet
- });
- getMethodModal.onClose();
- }
- } else {
- // No sourceId, no carbon, or type is "quoteLine" - proceed with normal submission
- fetcher.submit(data, {
- method: "post",
- action: path.to.quoteMethodGet
- });
- getMethodModal.onClose();
- }
- }}
+ onSubmit={getMethodModal.onClose}
>
<ModalHeader>
<ModalTitle>Get Method</ModalTitle>
@@ -365,6 +325,7 @@ const QuoteMakeMethodTools = () => {
name="sourceId"
label="Source Method"
type={(line?.itemType ?? "Part") as "Part"}
+ blacklist={configurableItemIds}
includeInactive={includeInactive === true}
replenishmentSystem="Make"
/>
@@ -406,6 +367,7 @@ const QuoteMakeMethodTools = () => {
name="sourceId"
label="Source Method"
type={(line?.itemType ?? "Part") as "Part"}
+ blacklist={configurableItemIds}
includeInactive={includeInactive === true}
replenishmentSystem="Make"
/>
@@ -504,6 +466,7 @@ const QuoteMakeMethodTools = () => {
name="itemId"
label="Target Method"
type={(line?.itemType ?? "Part") as "Part"}
+ blacklist={configurableItemIds}
onChange={(value) => {
if (value) {
getMakeMethods(value?.value);
@@ -558,69 +521,64 @@ const QuoteMakeMethodTools = () => {
</ModalContent>
</Modal>
)}
- {configuratorModal.isOpen && (
- <Suspense fallback={null}>
- {sourceItemRequiresConfiguration ? (
- // Configurator for source item when getting method
- <ConfiguratorModal
- open
- destructive
- initialValues={{} as Record<string, any>}
- groups={sourceItemConfigurationParameters.groups}
- parameters={sourceItemConfigurationParameters.parameters}
- onClose={() => {
- configuratorModal.onClose();
- setSourceItemRequiresConfiguration(false);
- setSourceItemConfigurationParameters({
- groups: [],
- parameters: []
- });
- }}
- onSubmit={(config: Record<string, any>) => {
- // Submit the get method with configuration
- if (pendingGetMethodData) {
- const dataWithConfig = {
- ...pendingGetMethodData,
- configuration: JSON.stringify(config)
- };
-
- fetcher.submit(dataWithConfig, {
- method: "post",
- action: path.to.quoteMethodGet
- });
-
- setPendingGetMethodData(null);
- }
-
- configuratorModal.onClose();
- setSourceItemRequiresConfiguration(false);
- setSourceItemConfigurationParameters({
- groups: [],
- parameters: []
- });
- }}
- />
- ) : (
- // Regular configurator for line configuration
- <Await resolve={lineData?.configurationParameters}>
- {(configurationParameters) => (
- <ConfiguratorModal
- open
- destructive
- initialValues={
- (line?.configuration || {}) as Record<string, any>
- }
- groups={configurationParameters?.groups ?? []}
- parameters={configurationParameters?.parameters ?? []}
- onClose={configuratorModal.onClose}
- onSubmit={(config: Record<string, any>) => {
- saveConfiguration(config);
+ {configureSelectModal.isOpen && (
+ <Modal
+ open
+ onOpenChange={(open) => {
+ if (!open) {
+ configureSelectModal.onClose();
+ }
+ }}
+ >
+ <ModalContent>
+ <ValidatedForm validator={getMethodValidator} onSubmit={() => {}}>
+ <ModalHeader>
+ <ModalTitle>Configure Item</ModalTitle>
+ <ModalDescription>Select an item to configure</ModalDescription>
+ </ModalHeader>
+ <ModalBody>
+ <Item
+ name="sourceId"
+ label="Item"
+ type={(line?.itemType ?? "Part") as "Part"}
+ includeInactive={includeInactive === true}
+ whitelist={configurableItemIds}
+ replenishmentSystem="Make"
+ onChange={(value) => {
+ if (value) {
+ handleConfigureItemSelect(value.value);
+ }
}}
/>
- )}
- </Await>
- )}
- </Suspense>
+ </ModalBody>
+ <ModalFooter>
+ <Button
+ onClick={configureSelectModal.onClose}
+ variant="secondary"
+ >
+ Cancel
+ </Button>
+ </ModalFooter>
+ </ValidatedForm>
+ </ModalContent>
+ </Modal>
+ )}
+ {configuratorModal.isOpen && (
+ <ConfiguratorModal
+ open
+ destructive
+ initialValues={{}}
+ groups={configurationParameters.groups}
+ parameters={configurationParameters.parameters}
+ onClose={() => {
+ configuratorModal.onClose();
+ setSelectedConfigureItemId(null);
+ setConfigurationParameters({ groups: [], parameters: [] });
+ }}
+ onSubmit={(config: Record<string, any>) => {
+ saveConfiguration(config);
+ }}
+ />
)}
</>
);
diff --git a/apps/erp/app/routes/x+/customer+/$customerId.details.tsx b/apps/erp/app/routes/x+/customer+/$customerId.details.tsx
index 5847c357b0..d87c5d6d2e 100644
--- a/apps/erp/app/routes/x+/customer+/$customerId.details.tsx
+++ b/apps/erp/app/routes/x+/customer+/$customerId.details.tsx
@@ -14,7 +14,7 @@ import { path } from "~/utils/path";
export async function action({ request }: ActionFunctionArgs) {
assertIsPost(request);
const { client, userId } = await requirePermissions(request, {
- create: "sales"
+ update: "sales"
});
const formData = await request.formData();
diff --git a/packages/ee/src/paperless-parts/lib/lib.ts b/packages/ee/src/paperless-parts/lib/lib.ts
index 0ef4094085..d260b957aa 100644
--- a/packages/ee/src/paperless-parts/lib/lib.ts
+++ b/packages/ee/src/paperless-parts/lib/lib.ts
@@ -1947,15 +1947,15 @@ export async function createPartFromComponent(
operation
] of component.shop_operations.entries()) {
if (operation.category === "operation") {
- // Check if operation is blacklisted
+ // Check if operation is ed
const operationName =
operation.operation_definition_name ?? operation.name;
if (billOfProcessBlackList.length > 0 && operationName) {
- const isBlacklisted = billOfProcessBlackList.some((blacklistedName) =>
- operationName.toLowerCase().includes(blacklistedName.toLowerCase())
+ const isBlacklisted = billOfProcessBlackList.some((edName) =>
+ operationName.toLowerCase().includes(edName.toLowerCase())
);
if (isBlacklisted) {
- console.log(`Skipping blacklisted operation: ${operationName}`);
+ console.log(`Skipping ed operation: ${operationName}`);
continue;
}
}
@@ -2932,7 +2932,7 @@ export async function insertQuoteLines(
const operationName =
operation.operation_definition_name ?? operation.name;
- // Check blacklist
+ // Check
if (operationName && billOfProcessBlackList.length > 0) {
const isBlacklisted = billOfProcessBlackList.some((bl) =>
operationName.toLowerCase().includes(bl.toLowerCase())