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 setting for how to consume kanbans

Brad Barbinf929dadccbff
diff --git a/apps/erp/app/modules/inventory/inventory.models.ts b/apps/erp/app/modules/inventory/inventory.models.ts
index ea5873c875..2fc70dddba 100644
--- a/apps/erp/app/modules/inventory/inventory.models.ts
+++ b/apps/erp/app/modules/inventory/inventory.models.ts
@@ -45,12 +45,6 @@ export const itemLedgerDocumentTypes = [
"Direct Transfer",
] as const;
-export enum KanbanOutput {
- Label,
- QRCode,
- Link,
-}
-
export const trackedEntityStatus = [
"Available",
"Consumed",
diff --git a/apps/erp/app/modules/inventory/ui/Kanbans/KanbansTable.tsx b/apps/erp/app/modules/inventory/ui/Kanbans/KanbansTable.tsx
index 679c338e59..ba62ad1a1f 100644
--- a/apps/erp/app/modules/inventory/ui/Kanbans/KanbansTable.tsx
+++ b/apps/erp/app/modules/inventory/ui/Kanbans/KanbansTable.tsx
@@ -48,6 +48,7 @@ import {
import { Enumerable } from "~/components/Enumerable";
import { useLocations } from "~/components/Form/Location";
import { usePermissions, useUrlParams } from "~/hooks";
+import type { kanbanOutputTypes } from "~/modules/settings/settings.models";
import { useSuppliers } from "~/stores";
import { useItems } from "~/stores/items";
import { usePeople } from "~/stores/people";
@@ -58,6 +59,7 @@ type KanbansTableProps = {
data: Kanban[];
count: number;
locationId: string;
+ kanbanOutput: (typeof kanbanOutputTypes)[number];
};
const defaultColumnVisibility = {
@@ -68,118 +70,128 @@ const defaultColumnVisibility = {
updatedAt: false,
};
-const KanbansTable = memo(({ data, count, locationId }: KanbansTableProps) => {
- const [params] = useUrlParams();
+const KanbansTable = memo(
+ ({ data, count, locationId, kanbanOutput }: KanbansTableProps) => {
+ const [params] = useUrlParams();
- const permissions = usePermissions();
- const [people] = usePeople();
- const [items] = useItems();
- const [suppliers] = useSuppliers();
- const locations = useLocations();
+ const permissions = usePermissions();
+ const [people] = usePeople();
+ const [items] = useItems();
+ const [suppliers] = useSuppliers();
+ const locations = useLocations();
- const columns = useMemo<ColumnDef<Kanban>[]>(
- () => [
- {
- accessorKey: "itemId",
- header: "Item",
- cell: ({ row }) => (
- <HStack className="py-1">
- <Hyperlink to={`${path.to.kanban(row.original.id!)}?${params}`}>
- <VStack spacing={0}>
- {row.original.name}
- <div className="text-muted-foreground text-xs">
- {row.original.readableIdWithRevision}
- </div>
- </VStack>
- </Hyperlink>
- </HStack>
- ),
- meta: {
- filter: {
- type: "static",
- options: items?.map((item) => ({
- value: item.id,
- label: item.readableIdWithRevision,
- })),
+ const columns = useMemo<ColumnDef<Kanban>[]>(
+ () => [
+ {
+ accessorKey: "itemId",
+ header: "Item",
+ cell: ({ row }) => (
+ <HStack className="py-1">
+ <Hyperlink to={`${path.to.kanban(row.original.id!)}?${params}`}>
+ <VStack spacing={0}>
+ {row.original.name}
+ <div className="text-muted-foreground text-xs">
+ {row.original.readableIdWithRevision}
+ </div>
+ </VStack>
+ </Hyperlink>
+ </HStack>
+ ),
+ meta: {
+ filter: {
+ type: "static",
+ options: items?.map((item) => ({
+ value: item.id,
+ label: item.readableIdWithRevision,
+ })),
+ },
+ icon: <LuPackage />,
},
- icon: <LuPackage />,
},
- },
- {
- id: "links",
- header: "",
- cell: ({ row }) => (
- <VStack>
- <HStack>
- <Tooltip>
- <TooltipTrigger>
- <a
- href={path.to.file.kanbanLabelsPdf([row.original.id!])}
- target="_blank"
- rel="noreferrer"
- >
- <Badge
- variant="outline"
- className="flex flex-row items-center gap-1"
- >
- <LuTag />
- Create
- </Badge>
- </a>
- </TooltipTrigger>
- <TooltipContent>
- Label to create a{" "}
- {row.original.replenishmentSystem === "Make"
- ? "Job"
- : "Order"}{" "}
- for this kanban
- </TooltipContent>
- </Tooltip>
-
- <Tooltip>
- <TooltipTrigger>
- <a
- href={path.to.file.kanbanLabelsPdf([row.original.id!])}
- target="_blank"
- rel="noreferrer"
- >
- <Badge
- variant="outline"
- className="flex flex-row items-center gap-1"
- >
- <LuTag />
- Start
- </Badge>
- </a>
- </TooltipTrigger>
- <TooltipContent>
- Label to start the next operation for this kanban
- </TooltipContent>
- </Tooltip>
+ {
+ id: "links",
+ header: "",
+ cell: ({ row }) => (
+ <>
+ {kanbanOutput === "label" && (
+ <HStack>
+ <Tooltip>
+ <TooltipTrigger>
+ <a
+ href={path.to.file.kanbanLabelsPdf([row.original.id!])}
+ target="_blank"
+ rel="noreferrer"
+ >
+ <Badge
+ variant="outline"
+ className="flex flex-row items-center gap-1"
+ >
+ <LuTag />
+ Create
+ </Badge>
+ </a>
+ </TooltipTrigger>
+ <TooltipContent>
+ Label to create a{" "}
+ {row.original.replenishmentSystem === "Make"
+ ? "Job"
+ : "Order"}{" "}
+ for this kanban
+ </TooltipContent>
+ </Tooltip>
+ {row.original.replenishmentSystem === "Make" && (
+ <>
+ <Tooltip>
+ <TooltipTrigger>
+ <a
+ href={path.to.file.kanbanLabelsPdf([
+ row.original.id!,
+ ])}
+ target="_blank"
+ rel="noreferrer"
+ >
+ <Badge
+ variant="outline"
+ className="flex flex-row items-center gap-1"
+ >
+ <LuTag />
+ Start
+ </Badge>
+ </a>
+ </TooltipTrigger>
+ <TooltipContent>
+ Label to start the next operation for this kanban
+ </TooltipContent>
+ </Tooltip>
- <Tooltip>
- <TooltipTrigger>
- <a
- href={path.to.file.kanbanLabelsPdf([row.original.id!])}
- target="_blank"
- rel="noreferrer"
- >
- <Badge
- variant="outline"
- className="flex flex-row items-center gap-1"
- >
- <LuTag />
- Complete
- </Badge>
- </a>
- </TooltipTrigger>
- <TooltipContent>
- Label to complete the current operation for this kanban
- </TooltipContent>
- </Tooltip>
- </HStack>
- {row.original.replenishmentSystem === "Make" && (
- <>
+ <Tooltip>
+ <TooltipTrigger>
+ <a
+ href={path.to.file.kanbanLabelsPdf([
+ row.original.id!,
+ ])}
+ target="_blank"
+ rel="noreferrer"
+ >
+ <Badge
+ variant="outline"
+ className="flex flex-row items-center gap-1"
+ >
+ <LuTag />
+ Complete
+ </Badge>
+ </a>
+ </TooltipTrigger>
+ <TooltipContent>
+ Label to complete the current operation for this
+ kanban
+ </TooltipContent>
+ </Tooltip>
+ </>
+ )}
+ </HStack>
+ )}
+ {kanbanOutput === "qrcode" && (
<HStack>
<HoverCard>
<Tooltip>
@@ -215,70 +227,75 @@ const KanbansTable = memo(({ data, count, locationId }: KanbansTableProps) => {
/>
</HoverCardContent>
</HoverCard>
+ {row.original.replenishmentSystem === "Make" && (
+ <>
+ <HoverCard>
+ <Tooltip>
+ <TooltipTrigger>
+ <HoverCardTrigger>
+ <Badge
+ variant="outline"
+ className="flex flex-row items-center gap-1 cursor-pointer"
+ >
+ <LuQrCode />
+ Start
+ </Badge>
+ </HoverCardTrigger>
+ </TooltipTrigger>
+ <TooltipContent>
+ QR Code to start the next operation for this kanban
+ </TooltipContent>
+ </Tooltip>
+ <HoverCardContent
+ align="center"
+ className="size-[236px] overflow-hidden z-[100] bg-white p-4"
+ >
+ <iframe
+ seamless
+ title={"Kanban QR Code"}
+ width="198"
+ height="198"
+ src={path.to.file.kanbanQrCode(row.original.id!)}
+ />
+ </HoverCardContent>
+ </HoverCard>
- <HoverCard>
- <Tooltip>
- <TooltipTrigger>
- <HoverCardTrigger>
- <Badge
- variant="outline"
- className="flex flex-row items-center gap-1 cursor-pointer"
- >
- <LuQrCode />
- Start
- </Badge>
- </HoverCardTrigger>
- </TooltipTrigger>
- <TooltipContent>
- QR Code to start the next operation for this kanban
- </TooltipContent>
- </Tooltip>
- <HoverCardContent
- align="center"
- className="size-[236px] overflow-hidden z-[100] bg-white p-4"
- >
- <iframe
- seamless
- title={"Kanban QR Code"}
- width="198"
- height="198"
- src={path.to.file.kanbanQrCode(row.original.id!)}
- />
- </HoverCardContent>
- </HoverCard>
-
- <HoverCard>
- <Tooltip>
- <TooltipTrigger>
- <HoverCardTrigger>
- <Badge
- variant="outline"
- className="flex flex-row items-center gap-1 cursor-pointer"
- >
- <LuQrCode />
- Complete
- </Badge>
- </HoverCardTrigger>
- </TooltipTrigger>
- <TooltipContent>
- QR Code to complete the current operation for this
- kanban
- </TooltipContent>
- </Tooltip>
- <HoverCardContent
- align="center"
- className="size-[236px] overflow-hidden z-[100] bg-white p-4"
- >
- <iframe
- seamless
- title={"Kanban QR Code"}
- width="198"
- height="198"
- src={path.to.file.kanbanQrCode(row.original.id!)}
- />
- </HoverCardContent>
- </HoverCard>
+ <HoverCard>
+ <Tooltip>
+ <TooltipTrigger>
+ <HoverCardTrigger>
+ <Badge
+ variant="outline"
+ className="flex flex-row items-center gap-1 cursor-pointer"
+ >
+ <LuQrCode />
+ Complete
+ </Badge>
+ </HoverCardTrigger>
+ </TooltipTrigger>
+ <TooltipContent>
+ QR Code to complete the current operation for this
+ kanban
+ </TooltipContent>
+ </Tooltip>
+ <HoverCardContent
+ align="center"
+ className="size-[236px] overflow-hidden z-[100] bg-white p-4"
+ >
+ <iframe
+ seamless
+ title={"Kanban QR Code"}
+ width="198"
+ height="198"
+ src={path.to.file.kanbanQrCode(row.original.id!)}
+ />
+ </HoverCardContent>
+ </HoverCard>
+ </>
+ )}
</HStack>
+ )}
+ {kanbanOutput === "url" && (
<HStack>
<CopyBadge
text="Create"
@@ -289,265 +306,272 @@ const KanbansTable = memo(({ data, count, locationId }: KanbansTableProps) => {
: "Order"
} for this kanban`}
/>
+ {row.original.replenishmentSystem === "Make" && (
+ <>
+ <CopyBadge
+ text="Start"
+ url={path.to.api.kanban(row.original.id!)}
+ tooltip={`Copy link to start the next operation for this kanban`}
+ />
- <CopyBadge
- text="Start"
- url={path.to.api.kanban(row.original.id!)}
- tooltip={`Copy link to start the next operation for this kanban`}
- />
-
- <CopyBadge
- text="Complete"
- url={path.to.api.kanban(row.original.id!)}
- tooltip={`Copy link to complete the current operation for this kanban`}
- />
+ <CopyBadge
+ text="Complete"
+ url={path.to.api.kanban(row.original.id!)}
+ tooltip={`Copy link to complete the current operation for this kanban`}
+ />
+ </>
+ )}
</HStack>
- </>
- )}
- </VStack>
- ),
- },
- {
- accessorKey: "quantity",
- header: "Reorder Qty.",
- cell: ({ row }) => {
- const { quantity, purchaseUnitOfMeasureCode } = row.original;
- const baseQuantity = quantity || 0;
-
- return (
- <span>
- {baseQuantity}
- {purchaseUnitOfMeasureCode && ` ${purchaseUnitOfMeasureCode}`}
- </span>
- );
+ )}
+ </>
+ ),
},
- meta: {
- icon: <LuHash />,
+ {
+ accessorKey: "quantity",
+ header: "Reorder Qty.",
+ cell: ({ row }) => {
+ const { quantity, purchaseUnitOfMeasureCode } = row.original;
+ const baseQuantity = quantity || 0;
+
+ return (
+ <span>
+ {baseQuantity}
+ {purchaseUnitOfMeasureCode && ` ${purchaseUnitOfMeasureCode}`}
+ </span>
+ );
+ },
+ meta: {
+ icon: <LuHash />,
+ },
},
- },
- {
- accessorKey: "replenishmentSystem",
- header: "Replenishment",
- cell: ({ row }) => (
- <Enumerable value={row.original.replenishmentSystem} />
- ),
- meta: {
- filter: {
- type: "static",
- options: ["Buy", "Make"].map((type) => ({
- value: type,
- label: <Enumerable value={type} />,
- })),
+ {
+ accessorKey: "replenishmentSystem",
+ header: "Replenishment",
+ cell: ({ row }) => (
+ <Enumerable value={row.original.replenishmentSystem} />
+ ),
+ meta: {
+ filter: {
+ type: "static",
+ options: ["Buy", "Make"].map((type) => ({
+ value: type,
+ label: <Enumerable value={type} />,
+ })),
+ },
+ icon: <LuRefreshCw />,
},
- icon: <LuRefreshCw />,
},
- },
- {
- accessorKey: "supplierId",
- header: "Supplier",
- cell: ({ row }) => (
- <SupplierAvatar supplierId={row.original.supplierId} />
- ),
- meta: {
- icon: <LuContainer />,
- filter: {
- type: "static",
- options: suppliers.map((supplier) => ({
- value: supplier.id,
- label: supplier.name,
- })),
+ {
+ accessorKey: "supplierId",
+ header: "Supplier",
+ cell: ({ row }) => (
+ <SupplierAvatar supplierId={row.original.supplierId} />
+ ),
+ meta: {
+ icon: <LuContainer />,
+ filter: {
+ type: "static",
+ options: suppliers.map((supplier) => ({
+ value: supplier.id,
+ label: supplier.name,
+ })),
+ },
},
},
- },
- {
- accessorKey: "shelfName",
- header: "Shelf",
- cell: ({ row }) => row.original.shelfName || "",
- meta: {
- icon: <LuMapPin />,
+ {
+ accessorKey: "shelfName",
+ header: "Shelf",
+ cell: ({ row }) => row.original.shelfName || "",
+ meta: {
+ icon: <LuMapPin />,
+ },
},
- },
- {
- accessorKey: "autoRelease",
- header: "Release",
- cell: ({ row }) =>
- row.original.replenishmentSystem === "Make" ? (
- <Checkbox isChecked={row.original.autoRelease ?? false} />
- ) : null,
- meta: {
- icon: <LuCheck />,
- filter: {
- type: "static",
- options: [
- { value: "true", label: "Yes" },
- { value: "false", label: "No" },
- ],
+ {
+ accessorKey: "autoRelease",
+ header: "Release",
+ cell: ({ row }) =>
+ row.original.replenishmentSystem === "Make" ? (
+ <div className="flex w-full items-center justify-center">
+ <Checkbox isChecked={row.original.autoRelease ?? false} />
+ </div>
+ ) : null,
+ meta: {
+ icon: <LuCheck />,
+ filter: {
+ type: "static",
+ options: [
+ { value: "true", label: "Yes" },
+ { value: "false", label: "No" },
+ ],
+ },
},
},
- },
- {
- accessorKey: "autoStartJob",
- header: "Start",
- cell: ({ row }) =>
- row.original.replenishmentSystem === "Make" ? (
- <Checkbox isChecked={row.original.autoRelease ?? false} />
- ) : null,
- meta: {
- icon: <LuCheck />,
- filter: {
- type: "static",
- options: [
- { value: "true", label: "Yes" },
- { value: "false", label: "No" },
- ],
+ {
+ accessorKey: "autoStartJob",
+ header: "Start",
+ cell: ({ row }) =>
+ row.original.replenishmentSystem === "Make" ? (
+ <div className="flex w-full items-center justify-center">
+ <Checkbox isChecked={row.original.autoRelease ?? false} />
+ </div>
+ ) : null,
+ meta: {
+ icon: <LuCheck />,
+ filter: {
+ type: "static",
+ options: [
+ { value: "true", label: "Yes" },
+ { value: "false", label: "No" },
+ ],
+ },
},
},
- },
- {
- accessorKey: "createdBy",
- header: "Created By",
- cell: ({ row }) => (
- <EmployeeAvatar employeeId={row.original.createdBy} />
- ),
- meta: {
- filter: {
- type: "static",
- options: people.map((employee) => ({
- value: employee.id,
- label: <Enumerable value={employee.name} />,
- })),
+ {
+ accessorKey: "createdBy",
+ header: "Created By",
+ cell: ({ row }) => (
+ <EmployeeAvatar employeeId={row.original.createdBy} />
+ ),
+ meta: {
+ filter: {
+ type: "static",
+ options: people.map((employee) => ({
+ value: employee.id,
+ label: <Enumerable value={employee.name} />,
+ })),
+ },
+ icon: <LuUser />,
},
- icon: <LuUser />,
},
- },
- {
- accessorKey: "createdAt",
- header: "Created At",
- cell: ({ row }) =>
- row.original.createdAt
- ? new Date(row.original.createdAt).toLocaleDateString()
- : "",
- meta: {
- icon: <LuCalendar />,
+ {
+ accessorKey: "createdAt",
+ header: "Created At",
+ cell: ({ row }) =>
+ row.original.createdAt
+ ? new Date(row.original.createdAt).toLocaleDateString()
+ : "",
+ meta: {
+ icon: <LuCalendar />,
+ },
},
- },
- {
- accessorKey: "updatedBy",
- header: "Updated By",
- cell: ({ row }) => (
- <EmployeeAvatar employeeId={row.original.updatedBy} />
- ),
- meta: {
- filter: {
- type: "static",
- options: people.map((employee) => ({
- value: employee.id,
- label: <Enumerable value={employee.name} />,
- })),
+ {
+ accessorKey: "updatedBy",
+ header: "Updated By",
+ cell: ({ row }) => (
+ <EmployeeAvatar employeeId={row.original.updatedBy} />
+ ),
+ meta: {
+ filter: {
+ type: "static",
+ options: people.map((employee) => ({
+ value: employee.id,
+ label: <Enumerable value={employee.name} />,
+ })),
+ },
+ icon: <LuUser />,
},
- icon: <LuUser />,
},
- },
- {
- accessorKey: "updatedAt",
- header: "Updated At",
- cell: ({ row }) =>
- row.original.updatedAt
- ? new Date(row.original.updatedAt).toLocaleDateString()
- : "",
- meta: {
- icon: <LuCalendar />,
+ {
+ accessorKey: "updatedAt",
+ header: "Updated At",
+ cell: ({ row }) =>
+ row.original.updatedAt
+ ? new Date(row.original.updatedAt).toLocaleDateString()
+ : "",
+ meta: {
+ icon: <LuCalendar />,
+ },
},
+ ],
+ [items, kanbanOutput, params, people, suppliers]
+ );
+
+ const renderContextMenu = useCallback(
+ (row: Kanban) => {
+ const canUpdate = permissions.can("update", "inventory");
+ const canDelete = permissions.can("delete", "inventory");
+
+ return (
+ <>
+ {canUpdate && (
+ <MenuItem asChild>
+ <Link to={`${path.to.kanban(row.id!)}?${params}`}>
+ <LuPencil className="mr-2 h-4 w-4" />
+ Edit
+ </Link>
+ </MenuItem>
+ )}
+ {canDelete && (
+ <MenuItem destructive asChild>
+ <Link to={`${path.to.deleteKanban(row.id!)}?${params}`}>
+ <LuTrash className="mr-2 h-4 w-4" />
+ Delete
+ </Link>
+ </MenuItem>
+ )}
+ </>
+ );
},
- ],
- [items, params, people, suppliers]
- );
+ [params, permissions]
+ );
- const renderContextMenu = useCallback(
- (row: Kanban) => {
- const canUpdate = permissions.can("update", "inventory");
- const canDelete = permissions.can("delete", "inventory");
+ const renderActions = useCallback((selectedRows: typeof data) => {
+ const handlePrintLabels = () => {
+ const selectedIds = selectedRows
+ .map((row) => row.id)
+ .filter(Boolean) as string[];
+ if (selectedIds.length > 0) {
+ window.open(path.to.file.kanbanLabelsPdf(selectedIds), "_blank");
+ }
+ };
return (
- <>
- {canUpdate && (
- <MenuItem asChild>
- <Link to={`${path.to.kanban(row.id!)}?${params}`}>
- <LuPencil className="mr-2 h-4 w-4" />
- Edit
- </Link>
- </MenuItem>
- )}
- {canDelete && (
- <MenuItem destructive asChild>
- <Link to={`${path.to.deleteKanban(row.id!)}?${params}`}>
- <LuTrash className="mr-2 h-4 w-4" />
- Delete
- </Link>
- </MenuItem>
- )}
- </>
+ <DropdownMenuContent align="end" className="min-w-[200px]">
+ <DropdownMenuLabel>Actions</DropdownMenuLabel>
+ <DropdownMenuSeparator />
+ <DropdownMenuGroup>
+ <DropdownMenuItem onClick={handlePrintLabels}>
+ <LuPrinter className="mr-2 h-4 w-4" />
+ Print Labels ({selectedRows.length})
+ </DropdownMenuItem>
+ </DropdownMenuGroup>
+ </DropdownMenuContent>
);
- },
- [params, permissions]
- );
-
- const renderActions = useCallback((selectedRows: typeof data) => {
- const handlePrintLabels = () => {
- const selectedIds = selectedRows
- .map((row) => row.id)
- .filter(Boolean) as string[];
- if (selectedIds.length > 0) {
- window.open(path.to.file.kanbanLabelsPdf(selectedIds), "_blank");
- }
- };
+ }, []);
return (
- <DropdownMenuContent align="end" className="min-w-[200px]">
- <DropdownMenuLabel>Actions</DropdownMenuLabel>
- <DropdownMenuSeparator />
- <DropdownMenuGroup>
- <DropdownMenuItem onClick={handlePrintLabels}>
- <LuPrinter className="mr-2 h-4 w-4" />
- Print Labels ({selectedRows.length})
- </DropdownMenuItem>
- </DropdownMenuGroup>
- </DropdownMenuContent>
+ <Table<Kanban>
+ count={count}
+ columns={columns}
+ data={data}
+ defaultColumnVisibility={defaultColumnVisibility}
+ primaryAction={
+ <div className="flex items-center gap-2">
+ <Combobox
+ asButton
+ size="sm"
+ value={locationId}
+ options={locations}
+ onChange={(selected) => {
+ // hard refresh because initialValues update has no effect otherwise
+ window.location.href = getLocationPath(selected);
+ }}
+ />
+ {permissions.can("create", "inventory") && (
+ <New label="Kanban" to={path.to.newKanban} />
+ )}
+ </div>
+ }
+ renderActions={renderActions}
+ renderContextMenu={renderContextMenu}
+ title="Kanbans"
+ table="kanban"
+ withSavedView
+ withSelectableRows
+ />
);
- }, []);
-
- return (
- <Table<Kanban>
- count={count}
- columns={columns}
- data={data}
- defaultColumnVisibility={defaultColumnVisibility}
- primaryAction={
- <div className="flex items-center gap-2">
- <Combobox
- asButton
- size="sm"
- value={locationId}
- options={locations}
- onChange={(selected) => {
- // hard refresh because initialValues update has no effect otherwise
- window.location.href = getLocationPath(selected);
- }}
- />
- {permissions.can("create", "inventory") && (
- <New label="Kanban" to={path.to.newKanban} />
- )}
- </div>
- }
- renderActions={renderActions}
- renderContextMenu={renderContextMenu}
- title="Kanbans"
- table="kanban"
- withSavedView
- withSelectableRows
- />
- );
-});
+ }
+);
KanbansTable.displayName = "KanbansTable";
diff --git a/apps/erp/app/modules/settings/settings.models.ts b/apps/erp/app/modules/settings/settings.models.ts
index 8587ad372d..7223e3cf7a 100644
--- a/apps/erp/app/modules/settings/settings.models.ts
+++ b/apps/erp/app/modules/settings/settings.models.ts
@@ -17,6 +17,8 @@ export const modulesType = [
"Users",
] as const;
+export const kanbanOutputTypes = ["label", "qrcode", "url"] as const;
+
export const apiKeyValidator = z.object({
id: zfd.text(z.string().optional()),
name: z.string().min(1, { message: "Name is required" }),
@@ -76,6 +78,10 @@ export const digitalQuoteValidator = z.object({
digitalQuoteIncludesPurchaseOrders: zfd.checkbox(),
});
+export const kanbanOutputValidator = z.object({
+ kanbanOutput: z.enum(kanbanOutputTypes),
+});
+
export const materialIdsValidator = z.object({
materialGeneratedIds: zfd.checkbox(),
});
diff --git a/apps/erp/app/modules/settings/settings.service.ts b/apps/erp/app/modules/settings/settings.service.ts
index d107085968..f4bb32ba3c 100644
--- a/apps/erp/app/modules/settings/settings.service.ts
+++ b/apps/erp/app/modules/settings/settings.service.ts
@@ -11,6 +11,7 @@ import { sanitize } from "~/utils/supabase";
import type {
apiKeyValidator,
companyValidator,
+ kanbanOutputTypes,
sequenceValidator,
webhookValidator,
} from "./settings.models";
@@ -249,6 +250,17 @@ export async function getIntegrations(
return client.from("integrations").select("*").eq("companyId", companyId);
}
+export async function getKanbanOutputSetting(
+ client: SupabaseClient<Database>,
+ companyId: string
+) {
+ return client
+ .from("companySettings")
+ .select("kanbanOutput")
+ .eq("id", companyId)
+ .single();
+}
+
export async function getPlanById(client: SupabaseClient, planId: string) {
return client.from("plan").select("*").eq("id", planId).single();
}
@@ -411,6 +423,17 @@ export async function updateCompany(
return client.from("company").update(sanitize(company)).eq("id", companyId);
}
+export async function updateKanbanOutputSetting(
+ client: SupabaseClient<Database>,
+ companyId: string,
+ kanbanOutput: (typeof kanbanOutputTypes)[number]
+) {
+ return client
+ .from("companySettings")
+ .update(sanitize({ kanbanOutput }))
+ .eq("id", companyId);
+}
+
export async function updateMetricSettings(
client: SupabaseClient<Database>,
companyId: string,
diff --git a/apps/erp/app/modules/settings/ui/useSettingsSubmodules.tsx b/apps/erp/app/modules/settings/ui/useSettingsSubmodules.tsx
index 03f7faa993..38eb896ca0 100644
--- a/apps/erp/app/modules/settings/ui/useSettingsSubmodules.tsx
+++ b/apps/erp/app/modules/settings/ui/useSettingsSubmodules.tsx
@@ -1,5 +1,6 @@
import {
LuBarcode,
+ LuBox,
LuCreditCard,
LuCrown,
LuFactory,
@@ -54,6 +55,12 @@ const settingsRoutes: AuthenticatedRouteGroup<{
{
name: "Modules",
routes: [
+ {
+ name: "Inventory",
+ to: path.to.inventorySettings,
+ role: "employee",
+ icon: <LuBox />,
+ },
{
name: "Items",
to: path.to.itemsSettings,
diff --git a/apps/erp/app/routes/x+/inventory+/kanbans.tsx b/apps/erp/app/routes/x+/inventory+/kanbans.tsx
index bbbc95b424..ba6c7bb0de 100644
--- a/apps/erp/app/routes/x+/inventory+/kanbans.tsx
+++ b/apps/erp/app/routes/x+/inventory+/kanbans.tsx
@@ -8,6 +8,7 @@ import { json, redirect } from "@vercel/remix";
import { getKanbans } from "~/modules/inventory";
import KanbansTable from "~/modules/inventory/ui/Kanbans/KanbansTable";
import { getLocationsList } from "~/modules/resources";
+import { getKanbanOutputSetting } from "~/modules/settings";
import { getUserDefaults } from "~/modules/users/users.server";
import type { Handle } from "~/utils/handle";
import { path } from "~/utils/path";
@@ -63,13 +64,16 @@ export async function loader({ request }: LoaderFunctionArgs) {
locationId = locations.data?.[0].id as string;
}
- const kanbans = await getKanbans(client, locationId, companyId, {
- search,
- limit,
- offset,
- sorts,
- filters,
- });
+ const [kanbans, kanbanOutput] = await Promise.all([
+ getKanbans(client, locationId, companyId, {
+ search,
+ limit,
+ offset,
+ sorts,
+ filters,
+ }),
+ getKanbanOutputSetting(client, companyId),
+ ]);
if (kanbans.error) {
throw redirect(
@@ -81,16 +85,23 @@ export async function loader({ request }: LoaderFunctionArgs) {
return json({
count: kanbans.count ?? 0,
kanbans: kanbans.data ?? [],
+ kanbanOutput: kanbanOutput.data?.kanbanOutput ?? "qrcode",
locationId,
});
}
export default function KanbansRoute() {
- const { count, kanbans, locationId } = useLoaderData<typeof loader>();
+ const { count, kanbans, locationId, kanbanOutput } =
+ useLoaderData<typeof loader>();
return (
<VStack spacing={0} className="h-full">
- <KanbansTable data={kanbans} count={count} locationId={locationId} />
+ <KanbansTable
+ data={kanbans}
+ count={count}
+ locationId={locationId}
+ kanbanOutput={kanbanOutput}
+ />
<Outlet />
</VStack>
);
diff --git a/apps/erp/app/routes/x+/settings+/inventory.tsx b/apps/erp/app/routes/x+/settings+/inventory.tsx
new file mode 100644
index 0000000000..c4c4147dd0
--- /dev/null
+++ b/apps/erp/app/routes/x+/settings+/inventory.tsx
@@ -0,0 +1,158 @@
+import {
+ Card,
+ CardContent,
+ CardDescription,
+ CardFooter,
+ CardHeader,
+ CardTitle,
+ Heading,
+ ScrollArea,
+ toast,
+ VStack,
+} from "@carbon/react";
+import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
+import { json, redirect } from "@vercel/remix";
+
+import { error } from "@carbon/auth";
+import { requirePermissions } from "@carbon/auth/auth.server";
+import { flash } from "@carbon/auth/session.server";
+import { Hidden, Select, Submit, ValidatedForm, validator } from "@carbon/form";
+import { useFetcher, useLoaderData } from "@remix-run/react";
+import { useEffect } from "react";
+import {
+ getCompanySettings,
+ kanbanOutputTypes,
+ kanbanOutputValidator,
+ updateKanbanOutputSetting,
+} from "~/modules/settings";
+
+import type { Handle } from "~/utils/handle";
+import { path } from "~/utils/path";
+
+export const handle: Handle = {
+ breadcrumb: "Inventory",
+ to: path.to.inventorySettings,
+};
+
+export async function loader({ request }: LoaderFunctionArgs) {
+ const { client, companyId } = await requirePermissions(request, {
+ view: "settings",
+ });
+
+ const [companySettings] = await Promise.all([
+ getCompanySettings(client, companyId),
+ ]);
+ if (!companySettings.data)
+ throw redirect(
+ path.to.settings,
+ await flash(
+ request,
+ error(companySettings.error, "Failed to get company settings")
+ )
+ );
+ return json({ companySettings: companySettings.data });
+}
+
+export async function action({ request }: ActionFunctionArgs) {
+ const { client, companyId } = await requirePermissions(request, {
+ update: "settings",
+ });
+
+ const formData = await request.formData();
+ const intent = formData.get("intent");
+
+ switch (intent) {
+ case "kanbanOutput":
+ const kanbanOutputValidation = await validator(
+ kanbanOutputValidator
+ ).validate(formData);
+
+ if (kanbanOutputValidation.error) {
+ return json({ success: false, message: "Invalid form data" });
+ }
+
+ const kanbanOutputResult = await updateKanbanOutputSetting(
+ client,
+ companyId,
+ kanbanOutputValidation.data.kanbanOutput
+ );
+ if (kanbanOutputResult.error)
+ return json({
+ success: false,
+ message: kanbanOutputResult.error.message,
+ });
+
+ return json({ success: true, message: "Kanban output setting updated" });
+ }
+
+ return json({ success: false, message: "Invalid form data" });
+}
+
+const outputLabels: Record<(typeof kanbanOutputTypes)[number], string> = {
+ label: "Label",
+ qrcode: "QR Code",
+ url: "URL",
+};
+
+export default function InventorySettingsRoute() {
+ const { companySettings } = useLoaderData<typeof loader>();
+ const fetcher = useFetcher<typeof action>();
+
+ useEffect(() => {
+ if (fetcher.data?.success === true && fetcher?.data?.message) {
+ toast.success(fetcher.data.message);
+ }
+
+ if (fetcher.data?.success === false && fetcher?.data?.message) {
+ toast.error(fetcher.data.message);
+ }
+ }, [fetcher.data?.message, fetcher.data?.success]);
+
+ return (
+ <ScrollArea className="w-full h-[calc(100dvh-49px)]">
+ <VStack
+ spacing={4}
+ className="py-12 px-4 max-w-[60rem] h-full mx-auto gap-4"
+ >
+ <Heading size="h3">Inventory</Heading>
+ <Card>
+ <ValidatedForm
+ method="post"
+ validator={kanbanOutputValidator}
+ defaultValues={{
+ kanbanOutput: companySettings.kanbanOutput ?? "qrcode",
+ }}
+ fetcher={fetcher}
+ >
+ <CardHeader>
+ <CardTitle className="flex items-center gap-2">
+ Kanban Output
+ </CardTitle>
+ <CardDescription>
+ Style of kanban output to show in the Kanban table
+ </CardDescription>
+ </CardHeader>
+ <CardContent>
+ <Hidden name="intent" value="kanbanOutput" />
+ <div className="flex flex-col gap-8 max-w-[400px]">
+ <div className="flex flex-col gap-2">
+ <Select
+ name="kanbanOutput"
+ label="Output"
+ options={kanbanOutputTypes.map((type) => ({
+ value: type,
+ label: outputLabels[type],
+ }))}
+ />
+ </div>
+ </div>
+ </CardContent>
+ <CardFooter>
+ <Submit>Save</Submit>
+ </CardFooter>
+ </ValidatedForm>
+ </Card>
+ </VStack>
+ </ScrollArea>
+ );
+}
diff --git a/apps/erp/app/utils/path.ts b/apps/erp/app/utils/path.ts
index abc6343ced..1aff5ad0f6 100644
--- a/apps/erp/app/utils/path.ts
+++ b/apps/erp/app/utils/path.ts
@@ -702,6 +702,7 @@ export const path = {
inventoryItemAdjustment: (id: string) =>
generatePath(`${x}/inventory/quantities/${id}/adjustment`),
inventoryRoot: `${x}/inventory`,
+ inventorySettings: `${x}/settings/inventory`,
invoicing: `${x}/invoicing`,
issues: `${x}/quality/issues`,
issue: (id: string) => generatePath(`${x}/issue/${id}`),
diff --git a/packages/database/supabase/migrations/20251001021231_kanban-settings.sql b/packages/database/supabase/migrations/20251001021231_kanban-settings.sql
new file mode 100644
index 0000000000..30266cf288
--- /dev/null
+++ b/packages/database/supabase/migrations/20251001021231_kanban-settings.sql
@@ -0,0 +1,4 @@
+CREATE TYPE "kanbanOutput" AS ENUM ('label', 'qrcode', 'url');
+
+ALTER TABLE "companySettings" ADD COLUMN "kanbanOutput" "kanbanOutput" NOT NULL DEFAULT 'qrcode';
+