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: method material form ui
Brad Barbin048583f940aa
diff --git a/apps/carbon/app/components/Form/Item.tsx b/apps/carbon/app/components/Form/Item.tsxindex 422692e981..d688599547 100644--- a/apps/carbon/app/components/Form/Item.tsx+++ b/apps/carbon/app/components/Form/Item.tsx@@ -8,6 +8,7 @@ import CreatableCombobox from "./CreatableCombobox";type ItemSelectProps = Omit<ComboboxProps, "options" | "type"> & {type: Database["public"]["Enums"]["itemType"];+ disabledItems?: string[];};const Item = ({ type, ...props }: ItemSelectProps) => {@@ -16,17 +17,23 @@ const Item = ({ type, ...props }: ItemSelectProps) => {const [created, setCreated] = useState<string>("");const triggerRef = useRef<HTMLButtonElement>(null);- const options = useMemo(- () =>+ const options = useMemo(() => {+ const results =items.filter((item) => item.type === type).map((item) => ({value: item.id,label: item.readableId,helper: item.name,- })) ?? [],- [items, type]- );+ })) ?? [];+ if (props.disabledItems) {+ return results.filter(+ (item) => !props.disabledItems?.includes(item.value)+ );+ }++ return results;+ }, [items, props.disabledItems, type]);return (<>diff --git a/apps/carbon/app/components/Form/UnitOfMeasure.tsx b/apps/carbon/app/components/Form/UnitOfMeasure.tsxindex 9dd01a9f9d..927c13b4d2 100644--- a/apps/carbon/app/components/Form/UnitOfMeasure.tsx+++ b/apps/carbon/app/components/Form/UnitOfMeasure.tsx@@ -26,7 +26,7 @@ const UnitOfMeasure = (props: UnitOfMeasureSelectProps) => {ref={triggerRef}options={options}{...props}- label={props?.label ?? "Item Group"}+ label={props?.label ?? "Unit of Measure"}onCreateOption={(option) => {newUnitOfMeasureModal.onOpen();setCreated(option);diff --git a/apps/carbon/app/modules/items/items.models.ts b/apps/carbon/app/modules/items/items.models.tsindex 1bb0d659a1..76aa1c9f57 100644--- a/apps/carbon/app/modules/items/items.models.ts+++ b/apps/carbon/app/modules/items/items.models.ts@@ -15,17 +15,14 @@ export const defaultWorkInstruction = {};export const itemInventoryTypes = ["Inventory", "Non-Inventory"] as const;-export const partReplenishmentSystems = [- "Buy",- "Make",- "Buy and Make",-] as const;+export const itemCostingMethods = ["Standard","Average","FIFO","LIFO",] as const;+export const itemReorderingPolicies = ["Manual Reorder","Demand-Based Reorder",@@ -33,11 +30,28 @@ export const itemReorderingPolicies = ["Maximum Quantity",] as const;+export const methodItemType = [+ "Part",+ "Material",+ "Tool",+ "Fixture",+ "Consumable",+ "Service",+] as const;++export const methodType = ["Buy", "Make", "Pick"] as const;+export const methodOperationOrders = ["After Previous","With Previous",] as const;+export const partReplenishmentSystems = [+ "Buy",+ "Make",+ "Buy and Make",+] as const;+export const partManufacturingPolicies = ["Make to Stock","Make to Order",@@ -102,6 +116,29 @@ export const materialValidator = itemValidator.merge(}));+export const methodMaterialValidator = z.object({+ id: zfd.text(z.string().optional()),+ makeMethodId: z.string().min(20, { message: "Make method is required" }),+ order: zfd.numeric(z.number().min(0)),+ itemType: z.enum(methodItemType, {+ errorMap: (issue, ctx) => ({+ message: "Item type is required",+ }),+ }),+ methodType: z.enum(methodType, {+ errorMap: (issue, ctx) => ({+ message: "Method type is required",+ }),+ }),+ itemId: z.string().min(20, { message: "Item is required" }),+ itemReadableId: z.string().min(1, { message: "Item ID is required" }),+ description: z.string().min(1, { message: "Description is required" }),+ quantity: zfd.numeric(z.number().min(0)),+ unitOfMeasureCode: z+ .string()+ .min(1, { message: "Unit of Measure is required" }),+});+export const methodOperationValidator = z.object({id: zfd.text(z.string().optional()),makeMethodId: z.string().min(0, { message: "Make method is required" }),diff --git a/apps/carbon/app/modules/items/types.ts b/apps/carbon/app/modules/items/types.tsindex 9a4d7ee5ee..8ed7337c2f 100644--- a/apps/carbon/app/modules/items/types.ts+++ b/apps/carbon/app/modules/items/types.ts@@ -1,4 +1,5 @@import type { Database } from "@carbon/database";+import type { methodItemType, methodType } from "./items.models";import type {getBuyMethods,getConsumables,@@ -70,6 +71,8 @@ export type Material = NonNullable<Awaited<ReturnType<typeof getMaterials>>["data"]>[number];+export type MethodItemType = (typeof methodItemType)[number];+export type MethodMaterial = NonNullable<Awaited<ReturnType<typeof getMethodMaterials>>["data"]>[number];@@ -78,6 +81,8 @@ export type MethodOperation = NonNullable<Awaited<ReturnType<typeof getMethodOperations>>["data"]>[number];+export type MethodType = (typeof methodType)[number];+export type Part = NonNullable<Awaited<ReturnType<typeof getParts>>["data"]>[number];diff --git a/apps/carbon/app/modules/items/ui/Item/BillOfMaterial.tsx b/apps/carbon/app/modules/items/ui/Item/BillOfMaterial.tsxnew file mode 100644index 0000000000..3b18076dc0--- /dev/null+++ b/apps/carbon/app/modules/items/ui/Item/BillOfMaterial.tsx@@ -0,0 +1,601 @@+"use client";+import {+ Button,+ Card,+ CardAction,+ CardContent,+ CardHeader,+ CardTitle,+ HStack,+ VStack,+ cn,+ toast,+ useDebounce,+} from "@carbon/react";+import { ValidatedForm } from "@carbon/remix-validated-form";+import { useFetcher, useParams } from "@remix-run/react";+import { AnimatePresence, LayoutGroup, motion } from "framer-motion";+import type { Dispatch, SetStateAction } from "react";+import { useCallback, useEffect, useState } from "react";+import { flushSync } from "react-dom";+import { LuSettings2, LuX } from "react-icons/lu";+import type { z } from "zod";+import {+ Hidden,+ InputControlled,+ Item,+ Number,+ Select,+ SelectControlled,+ Submit,+ UnitOfMeasure,+} from "~/components/Form";+import type {+ Item as SortableItem,+ SortableItemRenderProps,+} from "~/components/SortableList";+import { SortableList, SortableListItem } from "~/components/SortableList";+import { useUser } from "~/hooks";+import { useSupabase } from "~/lib/supabase";+import { path } from "~/utils/path";+import { methodItemType, methodMaterialValidator } from "../../items.models";+import type { MethodItemType, MethodType } from "../../types";++type Material = z.infer<typeof methodMaterialValidator>;++type ItemWithData = SortableItem & {+ data: Material;+};++type BillOfMaterialProps = {+ makeMethodId: string;+ materials: Material[];+};++function makeItems(materials: Material[]): ItemWithData[] {+ return materials.map(makeItem);+}++function makeItem(material: Material): ItemWithData {+ return {+ id: material.id!,+ text: material.description ?? "",+ checked: false,+ data: material,+ };+}++const initialMethodMaterial: Omit<Material, "makeMethodId" | "order"> = {+ itemId: "",+ itemReadableId: "",+ itemType: "Part" as const,+ methodType: "Buy" as const,+ description: "",+ quantity: 1,+ unitOfMeasureCode: "EA",+};++const BillOfMaterial = ({ makeMethodId, materials }: BillOfMaterialProps) => {+ const { supabase } = useSupabase();+ const sortOrderFetcher = useFetcher();++ const [items, setItems] = useState<ItemWithData[]>(+ makeItems(materials ?? [])+ );+ const [selectedItemId, setSelectedItemId] = useState<string | null>(null);++ const onToggleItem = (id: string) => {+ setItems((prevItems) =>+ prevItems.map((item) =>+ item.id === id ? { ...item, checked: !item.checked } : item+ )+ );+ };++ // we create a temporary item and append it to the list+ const onAddItem = () => {+ const temporaryId = Math.random().toString(16).slice(2);+ setSelectedItemId(temporaryId);+ setItems((prevItems) => {+ let newOrder = 1;+ if (prevItems.length) {+ newOrder = prevItems[prevItems.length - 1].data.order + 1;+ }++ return [+ ...prevItems,+ {+ text: "",+ checked: false,+ id: temporaryId,+ data: {+ ...initialMethodMaterial,+ order: newOrder,+ makeMethodId,+ },+ },+ ];+ });+ };++ const onRemoveItem = async (id: string) => {+ // get the item and it's order in the list+ const itemIndex = items.findIndex((i) => i.id === id);+ const item = items[itemIndex];++ setItems((prevItems) => prevItems.filter((item) => item.id !== id));++ const response = await supabase+ ?.from("methodMaterial")+ .delete()+ .eq("id", id);+ if (response?.error) {+ // add the item back to the list if there was an error+ setItems((prevItems) => {+ const updatedItems = [...prevItems];+ updatedItems.splice(itemIndex, 0, item);+ return updatedItems;+ });+ }+ };++ const onReorder = (items: ItemWithData[]) => {+ const newItems = items.map((item, index) => ({+ ...item,+ data: {+ ...item.data,+ order: index + 1,+ },+ }));+ const updates = newItems.reduce<Record<string, number>>((acc, item) => {+ if (!isTemporaryId(item.id)) {+ acc[item.id] = item.data.order;+ }+ return acc;+ }, {});++ setItems(newItems);+ updateSortOrder(updates);+ };++ const updateSortOrder = useDebounce((updates: Record<string, number>) => {+ let formData = new FormData();+ formData.append("updates", JSON.stringify(updates));+ sortOrderFetcher.submit(formData, {+ method: "post",+ action: path.to.methodMaterialsOrder(makeMethodId),+ });+ }, 1000);++ const onCloseOnDrag = useCallback(() => {+ setItems((prevItems) => {+ const updatedItems = prevItems.map((item) =>+ item.checked ? { ...item, checked: false } : item+ );+ return updatedItems.some(+ (item, index) => item.checked !== prevItems[index].checked+ )+ ? updatedItems+ : prevItems;+ });+ }, []);++ const renderListItem = ({+ item,+ items,+ order,+ onToggleItem,+ onRemoveItem,+ }: SortableItemRenderProps<ItemWithData>) => {+ const isOpen = item.id === selectedItemId;++ return (+ <SortableListItem<Material>+ item={item}+ items={items}+ order={order}+ key={item.id}+ isExpanded={isOpen}+ onToggleItem={onToggleItem}+ onRemoveItem={onRemoveItem}+ handleDrag={onCloseOnDrag}+ className="my-2 "+ renderExtra={(item) => (+ <div+ key={`${isOpen}`}+ className={cn(+ "flex h-full w-full flex-col items-center justify-center gap-2 ",+ isOpen ? "py-1 px-1" : "py-3 "+ )}+ >+ <motion.button+ layout+ onClick={+ isOpen+ ? () => {+ if (isTemporaryId(item.id)) {+ setItems((prevItems) =>+ prevItems.filter((i) => i.id !== item.id)+ );+ }+ setSelectedItemId(null);+ }+ : () => {+ setSelectedItemId(item.id);+ }+ }+ key="collapse"+ className={cn(+ isOpen+ ? "absolute right-3 top-3 z-10 "+ : "relative z-10 ml-auto mr-3 "+ )}+ >+ {isOpen ? (+ <motion.span+ initial={{ opacity: 0, filter: "blur(4px)" }}+ animate={{ opacity: 1, filter: "blur(0px)" }}+ exit={{ opacity: 1, filter: "blur(0px)" }}+ transition={{+ type: "spring",+ duration: 1.95,+ }}+ >+ <LuX className="h-5 w-5 text-foreground" />+ </motion.span>+ ) : (+ <motion.span+ initial={{ opacity: 0, filter: "blur(4px)" }}+ animate={{ opacity: 1, filter: "blur(0px)" }}+ exit={{ opacity: 1, filter: "blur(0px)" }}+ transition={{+ type: "spring",+ duration: 0.95,+ }}+ >+ <LuSettings2 className="stroke-1 h-5 w-5 text-foreground/80 hover:stroke-primary/70 " />+ </motion.span>+ )}+ </motion.button>++ <LayoutGroup id={`${item.id}`}>+ <AnimatePresence mode="popLayout">+ {isOpen ? (+ <motion.div className="flex w-full flex-col ">+ <div className=" w-full p-2">+ <motion.div+ initial={{+ y: 0,+ opacity: 0,+ filter: "blur(4px)",+ }}+ animate={{+ y: 0,+ opacity: 1,+ filter: "blur(0px)",+ }}+ transition={{+ type: "spring",+ duration: 0.15,+ }}+ layout+ className="w-full "+ >+ <motion.div+ initial={{ opacity: 0, filter: "blur(4px)" }}+ animate={{ opacity: 1, filter: "blur(0px)" }}+ transition={{+ type: "spring",+ bounce: 0.2,+ duration: 0.75,+ delay: 0.15,+ }}+ >+ <MaterialForm+ item={item}+ setItems={setItems}+ setSelectedItemId={setSelectedItemId}+ />+ </motion.div>+ </motion.div>+ </div>+ </motion.div>+ ) : null}+ </AnimatePresence>+ </LayoutGroup>+ </div>+ )}+ />+ );+ };++ return (+ <Card>+ <HStack className="justify-between">+ <CardHeader>+ <CardTitle>Bill of Materials</CardTitle>+ </CardHeader>++ <CardAction>+ <Button+ variant="secondary"+ isDisabled={selectedItemId !== null}+ onClick={onAddItem}+ >+ Add Material+ </Button>+ </CardAction>+ </HStack>+ <CardContent>+ <SortableList+ items={items}+ onReorder={onReorder}+ onToggleItem={onToggleItem}+ onRemoveItem={onRemoveItem}+ renderItem={renderListItem}+ />+ </CardContent>+ </Card>+ );+};++export default BillOfMaterial;++function isTemporaryId(id: string) {+ return id.length < 20;+}++function MaterialForm({+ item,+ setItems,+ setSelectedItemId,+}: {+ item: ItemWithData;+ setItems: Dispatch<SetStateAction<ItemWithData[]>>;+ setSelectedItemId: Dispatch<SetStateAction<string | null>>;+}) {+ const { supabase } = useSupabase();+ const methodMaterialFetcher = useFetcher<{ id: string }>();+ const params = useParams();+ const { company } = useUser();++ useEffect(() => {+ // replace the temporary id with the actual id+ if (methodMaterialFetcher.data && methodMaterialFetcher.data.id) {+ flushSync(() => {+ setItems((prevItems) =>+ prevItems.map((i) =>+ i.id === item.id+ ? {+ ...i,+ id: methodMaterialFetcher.data!.id!,+ data: {+ ...i.data,+ ...methodMaterialFetcher.data,+ },+ }+ : i+ )+ );+ });+ setSelectedItemId(null);+ }+ }, [item.id, methodMaterialFetcher.data, setItems, setSelectedItemId]);++ const [itemType, setItemType] = useState<MethodItemType>(item.data.itemType);+ const [itemData, setItemData] = useState<{+ itemId: string;+ itemReadableId: string;+ methodType: MethodType;+ description: string;+ unitOfMeasureCode: string;+ quantity: number;+ }>({+ itemId: item.data.itemId ?? "",+ itemReadableId: item.data.itemReadableId ?? "",+ methodType: item.data.methodType ?? "",+ description: item.data.description ?? "",+ unitOfMeasureCode: item.data.unitOfMeasureCode ?? "EA",+ quantity: item.data.quantity ?? 1,+ });+ const [methodTypeOptions, setMethodTypeOptions] = useState<MethodType[]>([+ "Buy",+ "Pick",+ ]);++ const onTypeChange = (value: MethodItemType) => {+ setItemType(value);+ setItemData({+ itemId: "",+ itemReadableId: "",+ methodType: "" as "Buy",+ quantity: 1,+ description: "",+ unitOfMeasureCode: "EA",+ });+ };++ const onItemChange = async (itemId: string) => {+ if (!supabase) return;+ if (itemId === params.itemId) {+ toast.error("An item cannot be added to itself.");+ return;+ }++ switch (itemType) {+ case "Part":+ const [partItem, part] = await Promise.all([+ supabase+ .from("item")+ .select("name, readableId, unitOfMeasureCode, pullFromInventory")+ .eq("id", itemId)+ .eq("companyId", company.id)+ .single(),+ supabase+ .from("part")+ .select("replenishmentSystem")+ .eq("itemId", itemId)+ .eq("companyId", company.id)+ .single(),+ ]);+ let partMethodType: MethodType = "Buy";++ if (part.data?.replenishmentSystem === "Buy") {+ setMethodTypeOptions(["Buy", "Pick"]);+ partMethodType = partItem.data?.pullFromInventory ? "Pick" : "Buy";+ }++ if (part.data?.replenishmentSystem === "Make") {+ setMethodTypeOptions(["Make", "Pick"]);+ partMethodType = partItem.data?.pullFromInventory ? "Pick" : "Make";+ }++ if (part.data?.replenishmentSystem === "Buy and Make") {+ setMethodTypeOptions(["Buy", "Make", "Pick"]);+ partMethodType = partItem.data?.pullFromInventory ? "Pick" : "Make";+ }++ setItemData((d) => ({+ ...d,+ itemId,+ itemReadableId: partItem.data?.readableId ?? "",+ description: partItem.data?.name ?? "",+ unitOfMeasureCode: partItem.data?.unitOfMeasureCode ?? "EA",+ methodType: partMethodType,+ }));+ break;+ case "Consumable":+ case "Material":+ case "Tool":+ case "Fixture":+ const item = await supabase+ .from("item")+ .select("name, readableId, unitOfMeasureCode, pullFromInventory")+ .eq("id", itemId)+ .eq("companyId", company.id)+ .single();++ setMethodTypeOptions(["Buy", "Pick"]);+ const methodType = item.data?.pullFromInventory ? "Pick" : "Buy";++ setItemData((d) => ({+ ...d,+ itemId,+ itemReadableId: item.data?.readableId ?? "",+ description: item.data?.name ?? "",+ unitOfMeasureCode: item.data?.unitOfMeasureCode ?? "EA",+ methodType: methodType,+ }));+ break;+ case "Service":+ break;+ default:+ throw new Error(`Invalid item type: ${itemType}`);+ }+ };++ return (+ <ValidatedForm+ action={+ isTemporaryId(item.id)+ ? path.to.newMethodMaterial(item.data.makeMethodId!)+ : path.to.methodMaterial(item.data.makeMethodId, item.id!)+ }+ method="post"+ defaultValues={item.data}+ validator={methodMaterialValidator}+ className="w-full"+ fetcher={methodMaterialFetcher}+ onSubmit={(values) => {+ setItems((prevItems) =>+ prevItems.map((i) =>+ i.id === item.id+ ? {+ ...makeItem(values),+ id: item.id,+ }+ : i+ )+ );+ }}+ >+ <Hidden name="makeMethodId" />+ <Hidden name="itemReadableId" value={itemData.itemReadableId} />+ <Hidden name="order" />+ <VStack className="pt-4">+ <div className="grid w-full gap-x-8 gap-y-4 grid-cols-1 lg:grid-cols-3">+ <Select+ name="itemType"+ label="Type"+ options={methodItemType.map((value) => ({+ value,+ label: value,+ }))}+ onChange={(value) => {+ onTypeChange(value?.value as MethodItemType);+ }}+ />+ <Item+ disabledItems={[params.itemId!]}+ name="itemId"+ label={itemType}+ // @ts-ignore+ type={itemType}+ onChange={(value) => {+ onItemChange(value?.value as string);+ }}+ />+ <SelectControlled+ name="methodType"+ label="Method"+ value={itemData.methodType}+ options={methodTypeOptions.map((value) => ({+ value,+ label: value,+ }))}+ onChange={(newValue) =>+ setItemData((d) => ({+ ...d,+ methodType: (newValue?.value ?? "Buy") as MethodType,+ }))+ }+ />+ <InputControlled+ name="description"+ label="Description"+ value={itemData.description}+ onChange={(newValue) => {+ setItemData((d) => ({ ...d, description: newValue }));+ }}+ />+ <Number name="quantity" label="Quantity" />+ <UnitOfMeasure+ name="unitOfMeasureCode"+ value={itemData.unitOfMeasureCode}+ onChange={(newValue) =>+ setItemData((d) => ({+ ...d,+ unitOfMeasureCode: newValue?.value ?? "EA",+ }))+ }+ />+ </div>++ <motion.div+ className="flex w-full items-center justify-end p-2"+ initial={{ opacity: 0, filter: "blur(4px)" }}+ animate={{ opacity: 1, filter: "blur(0px)" }}+ transition={{+ type: "spring",+ bounce: 0,+ duration: 0.55,+ }}+ >+ <motion.div layout className="ml-auto mr-1 pt-2">+ <Submit>Save</Submit>+ </motion.div>+ </motion.div>+ </VStack>+ </ValidatedForm>+ );+}diff --git a/apps/carbon/app/modules/items/ui/Item/MethodBadge.tsx b/apps/carbon/app/modules/items/ui/Item/MethodBadge.tsxindex a087575656..b355660043 100644--- a/apps/carbon/app/modules/items/ui/Item/MethodBadge.tsx+++ b/apps/carbon/app/modules/items/ui/Item/MethodBadge.tsx@@ -1,6 +1,7 @@import { Badge, HStack, cn } from "@carbon/react";import { Link } from "@remix-run/react";import { LuExternalLink } from "react-icons/lu";+import type { MethodType } from "../../types";import { MethodIcon } from "./MethodIcon";type MethodBadgeProps = {@@ -28,7 +29,7 @@ export function MethodBadge({ type, text, to, className }: MethodBadgeProps) {);}-function getBadgeColor(type: "Buy" | "Make" | "Pick") {+function getBadgeColor(type: MethodType) {return type === "Buy"? "bg-blue-500 hover:bg-blue-600 text-white": type === "Make"diff --git a/apps/carbon/app/modules/items/ui/Item/index.ts b/apps/carbon/app/modules/items/ui/Item/index.tsindex bea12dddb3..96ec0d9ca6 100644--- a/apps/carbon/app/modules/items/ui/Item/index.ts+++ b/apps/carbon/app/modules/items/ui/Item/index.ts@@ -1,3 +1,4 @@+import BillOfMaterial from "./BillOfMaterial";import BillOfProcess from "./BillOfProcess";import BuyMethodForm from "./BuyMethodForm";import BuyMethods from "./BuyMethods";@@ -10,6 +11,7 @@ import { MethodIcon } from "./MethodIcon";import PickMethodForm from "./PickMethodForm";export {+ BillOfMaterial,BillOfProcess,BuyMethodForm,BuyMethods,diff --git a/apps/carbon/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm.tsx b/apps/carbon/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm.tsxindex 4045516abe..4f25064ac1 100644--- a/apps/carbon/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm.tsx+++ b/apps/carbon/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm.tsx@@ -31,7 +31,7 @@ import {} from "~/components/Form";import { usePermissions, useRouteData, useUser } from "~/hooks";import { useSupabase } from "~/lib/supabase";-import type { getShelvesList } from "~/modules/items";+import { methodItemType, type getShelvesList } from "~/modules/items";import type {PurchaseOrder,PurchaseOrderLineType,@@ -290,14 +290,8 @@ const PurchaseOrderLineForm = ({onTypeChange(value?.value as PurchaseOrderLineType);}}/>- {[- "Part",- "Service",- "Material",- "Tool",- "Fixture",- "Consumable",- ].includes(type) && (+ {/* @ts-ignore */}+ {methodItemType.includes(type) && (<Itemname="itemId"label={type}diff --git a/apps/carbon/app/modules/users/ui/useUsersSubmodules.tsx b/apps/carbon/app/modules/users/ui/useUsersSubmodules.tsxindex a887d57090..a733a91085 100644--- a/apps/carbon/app/modules/users/ui/useUsersSubmodules.tsx+++ b/apps/carbon/app/modules/users/ui/useUsersSubmodules.tsx@@ -1,4 +1,10 @@-import { LuFileBadge2, LuGroup, LuUsers } from "react-icons/lu";+import {+ LuContainer,+ LuFileBadge2,+ LuGroup,+ LuUserSquare,+ LuUsers,+} from "react-icons/lu";import type { RouteGroup } from "~/types";import { path } from "~/utils/path";@@ -11,16 +17,16 @@ const usersRoutes: RouteGroup[] = [to: path.to.employeeAccounts,icon: <LuUsers />,},- // {- // name: "Customers",- // to: path.to.customerAccounts,- // icon: <LuUserSquare />,- // },- // {- // name: "Suppliers",- // to: path.to.supplierAccounts,- // icon: <LuContainer />,- // },+ {+ name: "Customers",+ to: path.to.customerAccounts,+ icon: <LuUserSquare />,+ },+ {+ name: "Suppliers",+ to: path.to.supplierAccounts,+ icon: <LuContainer />,+ },{name: "Groups",to: path.to.groups,diff --git a/apps/carbon/app/routes/x+/part+/$itemId.manufacturing.method.tsx b/apps/carbon/app/routes/x+/part+/$itemId.manufacturing.method.tsxindex 95a002207e..697ee211e5 100644--- a/apps/carbon/app/routes/x+/part+/$itemId.manufacturing.method.tsx+++ b/apps/carbon/app/routes/x+/part+/$itemId.manufacturing.method.tsx@@ -1,3 +1,4 @@+import type { JSONContent } from "@carbon/react";import {ResizableHandle,ResizablePanel,@@ -9,11 +10,14 @@ import type { ActionFunctionArgs, LoaderFunctionArgs } from "@remix-run/node";import { json, useLoaderData, useParams } from "@remix-run/react";import { redirect } from "remix-typedjson";+import type { MethodItemType, MethodType } from "~/modules/items";import {+ BillOfMaterial,BillOfProcess,PartManufacturingForm,getItemManufacturing,getMakeMethod,+ getMethodMaterials,getMethodOperations,partManufacturingValidator,upsertItemManufacturing,@@ -58,10 +62,10 @@ export async function loader({ request, params }: LoaderFunctionArgs) {);}- const methodOperations = await getMethodOperations(- client,- makeMethod.data.id- );+ const [methodMaterials, methodOperations] = await Promise.all([+ getMethodMaterials(client, makeMethod.data.id),+ getMethodOperations(client, makeMethod.data.id),+ ]);if (methodOperations.error) {throw redirect(path.to.partDetails(itemId),@@ -71,14 +75,33 @@ export async function loader({ request, params }: LoaderFunctionArgs) {));}+ if (methodMaterials.error) {+ throw redirect(+ path.to.partDetails(itemId),+ await flash(+ request,+ error(methodMaterials.error, "Failed to load method materials")+ )+ );+ }return json({partManufacturing: partManufacturing.data,makeMethod: makeMethod.data,+ methodMaterials:+ methodMaterials.data?.map((m) => ({+ ...m,+ methodType: m.methodType as MethodType,+ itemType: m.itemType as MethodItemType,+ })) ?? [],methodOperations:methodOperations.data?.map((operation) => ({...operation,equipmentTypeId: operation.equipmentTypeId ?? undefined,+ methodOperationWorkInstruction:+ operation.methodOperationWorkInstruction as {+ content: JSONContent | null;+ },})) ?? [],});}@@ -127,7 +150,7 @@ export async function action({ request, params }: ActionFunctionArgs) {}export default function MakeMethodRoute() {- const { makeMethod, partManufacturing, methodOperations } =+ const { makeMethod, methodMaterials, methodOperations, partManufacturing } =useLoaderData<typeof loader>();const { itemId } = useParams();if (!itemId) throw new Error("Could not find itemId");@@ -154,6 +177,11 @@ export default function MakeMethodRoute() {key={itemId}initialValues={manufacturingInitialValues}/>+ <BillOfMaterial+ key={itemId}+ makeMethodId={makeMethodId}+ materials={methodMaterials}+ /><BillOfProcesskey={itemId}makeMethodId={makeMethodId}@@ -165,7 +193,7 @@ export default function MakeMethodRoute() {<ResizableHandle withHandle /><ResizablePanelorder={3}- minSize={20}+ minSize={10}defaultSize={20}className="bg-card">diff --git a/apps/carbon/app/routes/x+/part+/$itemId.manufacturing.tsx b/apps/carbon/app/routes/x+/part+/$itemId.manufacturing.tsxindex 101514b5a0..b6f0cedb52 100644--- a/apps/carbon/app/routes/x+/part+/$itemId.manufacturing.tsx+++ b/apps/carbon/app/routes/x+/part+/$itemId.manufacturing.tsx@@ -20,6 +20,7 @@ import { Outlet, useParams } from "@remix-run/react";import { useRef, useState } from "react";import { LuChevronDown, LuChevronUp, LuPlus, LuSearch } from "react-icons/lu";import { typedjson, useTypedLoaderData } from "remix-typedjson";+import type { MethodType } from "~/modules/items";import { MethodIcon } from "~/modules/items";import { requirePermissions } from "~/services/auth/auth.server";@@ -34,7 +35,7 @@ type Method = {readableId: string;description: string;quantity: number;- fulfillmentMethod: "Buy" | "Make" | "Pick";+ fulfillmentMethod: MethodType;isInherited: boolean;isRoot: boolean;};@@ -131,7 +132,7 @@ export default function PartManufacturing() {<ResizablePanelGroup direction="horizontal"><ResizablePanelorder={1}- minSize={20}+ minSize={10}defaultSize={20}className="bg-card">diff --git a/apps/carbon/app/utils/path.ts b/apps/carbon/app/utils/path.tsindex 5b404b003b..d458a8300f 100644--- a/apps/carbon/app/utils/path.ts+++ b/apps/carbon/app/utils/path.ts@@ -354,6 +354,10 @@ export const path = {materialSubstance: (id: string) =>generatePath(`${x}/items/substances/${id}`),materialSubstances: `${x}/items/substances`,+ methodMaterial: (makeMethodId: string, id: string) =>+ generatePath(`${x}/items/methods/${makeMethodId}/material/${id}`),+ methodMaterialsOrder: (makeMethodId: string) =>+ generatePath(`${x}/items/methods/${makeMethodId}/material/order`),methodOperation: (makeMethodId: string, id: string) =>generatePath(`${x}/items/methods/${makeMethodId}/operation/${id}`),methodOperationsOrder: (makeMethodId: string) =>@@ -400,6 +404,8 @@ export const path = {newHoliday: `${x}/resources/holidays/new`,newLocation: `${x}/resources/locations/new`,newMaterial: `${x}/material/new`,+ newMethodMaterial: (id: string) =>+ generatePath(`${x}/items/methods/${id}/material/new`),newMethodOperation: (id: string) =>generatePath(`${x}/items/methods/${id}/operation/new`),newNote: `${x}/shared/notes/new`,@@ -450,7 +456,7 @@ export const path = {newServiceSupplier: (id: string) =>generatePath(`${x}/service/${id}/purchasing/new`),newSupplier: `${x}/supplier/new`,- newSupplierAccount: `${x}/users/purchasing/new`,+ newSupplierAccount: `${x}/users/suppliers/new`,newSupplierContact: (id: string) =>generatePath(`${x}/supplier/${id}/contacts/new`),newSupplierLocation: (id: string) =>diff --git a/packages/database/src/types.ts b/packages/database/src/types.tsindex 878dd9dced..cd523f5163 100644--- a/packages/database/src/types.ts+++ b/packages/database/src/types.ts@@ -8177,11 +8177,14 @@ export type Database = {createdAt: stringcreatedBy: stringcustomFields: Json | null+ description: stringid: stringitemId: string+ itemReadableId: stringitemType: stringmakeMethodId: stringmethodType: Database["public"]["Enums"]["methodType"]+ order: numberquantity: numberunitOfMeasureCode: stringupdatedAt: string | null@@ -8192,11 +8195,14 @@ export type Database = {createdAt?: stringcreatedBy: stringcustomFields?: Json | null+ description: stringid?: stringitemId: string+ itemReadableId: stringitemType?: stringmakeMethodId: stringmethodType?: Database["public"]["Enums"]["methodType"]+ order?: numberquantity: numberunitOfMeasureCode: stringupdatedAt?: string | null@@ -8207,11 +8213,14 @@ export type Database = {createdAt?: stringcreatedBy?: stringcustomFields?: Json | null+ description?: stringid?: stringitemId?: string+ itemReadableId?: stringitemType?: stringmakeMethodId?: stringmethodType?: Database["public"]["Enums"]["methodType"]+ order?: numberquantity?: numberunitOfMeasureCode?: stringupdatedAt?: string | nulldiff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.tsindex 878dd9dced..cd523f5163 100644--- a/packages/database/supabase/functions/lib/types.ts+++ b/packages/database/supabase/functions/lib/types.ts@@ -8177,11 +8177,14 @@ export type Database = {createdAt: stringcreatedBy: stringcustomFields: Json | null+ description: stringid: stringitemId: string+ itemReadableId: stringitemType: stringmakeMethodId: stringmethodType: Database["public"]["Enums"]["methodType"]+ order: numberquantity: numberunitOfMeasureCode: stringupdatedAt: string | null@@ -8192,11 +8195,14 @@ export type Database = {createdAt?: stringcreatedBy: stringcustomFields?: Json | null+ description: stringid?: stringitemId: string+ itemReadableId: stringitemType?: stringmakeMethodId: stringmethodType?: Database["public"]["Enums"]["methodType"]+ order?: numberquantity: numberunitOfMeasureCode: stringupdatedAt?: string | null@@ -8207,11 +8213,14 @@ export type Database = {createdAt?: stringcreatedBy?: stringcustomFields?: Json | null+ description?: stringid?: stringitemId?: string+ itemReadableId?: stringitemType?: stringmakeMethodId?: stringmethodType?: Database["public"]["Enums"]["methodType"]+ order?: numberquantity?: numberunitOfMeasureCode?: stringupdatedAt?: string | nulldiff --git a/packages/database/supabase/migrations/20240621114604_method-rls.sql b/packages/database/supabase/migrations/20240621114604_method-rls.sqlindex c196da6c5b..557ace2c40 100644--- a/packages/database/supabase/migrations/20240621114604_method-rls.sql+++ b/packages/database/supabase/migrations/20240621114604_method-rls.sql@@ -1,6 +1,9 @@ALTER TABLE "makeMethod" ADD COLUMN "customFields" JSONB;ALTER TABLE "methodOperation" ADD COLUMN "customFields" JSONB;ALTER TABLE "methodMaterial" ADD COLUMN "customFields" JSONB;+ALTER TABLE "methodMaterial" ADD COLUMN "itemReadableId" TEXT NOT NULL;+ALTER TABLE "methodMaterial" ADD COLUMN "description" TEXT NOT NULL;+ALTER TABLE "methodMaterial" ADD COLUMN "order" DOUBLE PRECISION NOT NULL DEFAULT 1;INSERT INTO "customFieldTable" ("table", "module", "name")VALUES