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.

refactor: human implementation of custom investigation types and actions

Brad Barbin76f2b7a5990c
diff --git a/apps/erp/app/modules/quality/quality.models.ts b/apps/erp/app/modules/quality/quality.models.ts
index a1113410b6..3aaa952ab9 100644
--- a/apps/erp/app/modules/quality/quality.models.ts
+++ b/apps/erp/app/modules/quality/quality.models.ts
@@ -9,24 +9,6 @@ export const gaugeCalibrationStatus = [
] as const;
export const gaugeRole = ["Master", "Standard"] as const;
-export const nonConformanceInvestigationType = [
- "Root Cause Analysis",
- "Inventory",
- "WIP",
- "Finished Goods",
- "Incoming Materials",
- "Process",
- "Documentation",
-] as const;
-
-export const nonConformanceRequiredAction = [
- "Corrective Action",
- "Preventive Action",
- "Containment Action",
- "Verification",
- "Customer Communication",
-] as const;
-
export const nonConformanceApprovalRequirement = ["MRB"] as const;
export const nonConformanceSource = ["Internal", "External"] as const;
@@ -137,8 +119,8 @@ export const issueValidator = z.object({
priority: z.enum(nonConformancePriority),
source: z.enum(nonConformanceSource),
name: z.string().min(1, { message: "Name is required" }),
- investigationTypes: z.array(z.string()).optional(),
- requiredActions: z.array(z.string()).optional(),
+ investigationTypeIds: z.array(z.string()).optional(),
+ requiredActionIds: z.array(z.string()).optional(),
approvalRequirements: z
.array(z.enum(nonConformanceApprovalRequirement))
.optional(),
@@ -156,6 +138,12 @@ export const nonConformanceReviewerValidator = z.object({
title: z.string().min(1, { message: "Title is required" }),
});
+export const investigationTypeValidator = z.object({
+ id: zfd.text(z.string().optional()),
+ name: z.string().min(1, { message: "Name is required" }),
+ active: zfd.checkbox(),
+});
+
export const issueTypeValidator = z.object({
id: zfd.text(z.string().optional()),
name: z.string().min(1, { message: "Name is required" }),
@@ -176,8 +164,8 @@ export const issueWorkflowValidator = z.object({
}),
priority: z.enum(nonConformancePriority),
source: z.enum(nonConformanceSource),
- investigationTypes: z.array(z.string()).optional(),
- requiredActions: z.array(z.string()).optional(),
+ investigationTypeIds: z.array(z.string()).optional(),
+ requiredActionIds: z.array(z.string()).optional(),
approvalRequirements: z
.array(z.enum(nonConformanceApprovalRequirement))
.optional(),
diff --git a/apps/erp/app/modules/quality/quality.service.ts b/apps/erp/app/modules/quality/quality.service.ts
index 9992ae78e2..740d7e44b3 100644
--- a/apps/erp/app/modules/quality/quality.service.ts
+++ b/apps/erp/app/modules/quality/quality.service.ts
@@ -11,6 +11,7 @@ import type {
gaugeCalibrationStatus,
gaugeTypeValidator,
gaugeValidator,
+ investigationTypeValidator,
issueTypeValidator,
issueValidator,
issueWorkflowValidator,
@@ -120,6 +121,16 @@ export async function deleteIssueAssociation(
}
}
+export async function deleteInvestigationType(
+ client: SupabaseClient<Database>,
+ investigationTypeId: string
+) {
+ return client
+ .from("nonConformanceInvestigationType")
+ .delete()
+ .eq("id", investigationTypeId);
+}
+
export async function deleteIssueType(
client: SupabaseClient<Database>,
nonConformanceTypeId: string
@@ -349,10 +360,9 @@ export async function getIssueInvestigationTasks(
) {
return client
.from("nonConformanceInvestigationTask")
- .select("*")
+ .select("*, ...nonConformanceInvestigationType(name)")
.eq("nonConformanceId", id)
- .eq("companyId", companyId)
- .order("investigationType", { ascending: true });
+ .eq("companyId", companyId);
}
export async function getIssueActionTasks(
@@ -362,10 +372,9 @@ export async function getIssueActionTasks(
) {
return client
.from("nonConformanceActionTask")
- .select("*")
+ .select("*, ...nonConformanceRequiredAction(name)")
.eq("nonConformanceId", id)
- .eq("companyId", companyId)
- .order("actionType", { ascending: true });
+ .eq("companyId", companyId);
}
export async function getIssueApprovalTasks(
@@ -666,30 +675,6 @@ export async function getIssueTypesList(
.order("name");
}
-export async function getInvestigationTypesList(
- client: SupabaseClient<Database>,
- companyId: string
-) {
- return client
- .from("nonConformanceInvestigationType")
- .select("id, name")
- .eq("companyId", companyId)
- .eq("active", true)
- .order("sortOrder");
-}
-
-export async function getRequiredActionsList(
- client: SupabaseClient<Database>,
- companyId: string
-) {
- return client
- .from("nonConformanceRequiredAction")
- .select("id, name")
- .eq("companyId", companyId)
- .eq("active", true)
- .order("sortOrder");
-}
-
export async function getInvestigationTypes(
client: SupabaseClient<Database>,
companyId: string,
@@ -706,12 +691,49 @@ export async function getInvestigationTypes(
if (args) {
query = setGenericQueryFilters(query, args, [
- { column: "sortOrder", ascending: true },
{ column: "name", ascending: true },
]);
+ } else {
+ query = query.order("name");
}
- return query;
+ const result = await query;
+ return result;
+}
+
+export async function getInvestigationType(
+ client: SupabaseClient<Database>,
+ investigationTypeId: string
+) {
+ return client
+ .from("nonConformanceInvestigationType")
+ .select("*")
+ .eq("id", investigationTypeId)
+ .single();
+}
+
+export async function getInvestigationTypesList(
+ client: SupabaseClient<Database>,
+ companyId: string
+) {
+ return client
+ .from("nonConformanceInvestigationType")
+ .select("id, name")
+ .eq("companyId", companyId)
+ .eq("active", true)
+ .order("name");
+}
+
+export async function getRequiredActionsList(
+ client: SupabaseClient<Database>,
+ companyId: string
+) {
+ return client
+ .from("nonConformanceRequiredAction")
+ .select("id, name")
+ .eq("companyId", companyId)
+ .eq("active", true)
+ .order("name");
}
export async function getRequiredActions(
@@ -730,7 +752,6 @@ export async function getRequiredActions(
if (args) {
query = setGenericQueryFilters(query, args, [
- { column: "sortOrder", ascending: true },
{ column: "name", ascending: true },
]);
}
@@ -738,17 +759,6 @@ export async function getRequiredActions(
return query;
}
-export async function getInvestigationType(
- client: SupabaseClient<Database>,
- investigationTypeId: string
-) {
- return client
- .from("nonConformanceInvestigationType")
- .select("*")
- .eq("id", investigationTypeId)
- .single();
-}
-
export async function getRequiredAction(
client: SupabaseClient<Database>,
requiredActionId: string
@@ -760,16 +770,6 @@ export async function getRequiredAction(
.single();
}
-export async function deleteInvestigationType(
- client: SupabaseClient<Database>,
- investigationTypeId: string
-) {
- return client
- .from("nonConformanceInvestigationType")
- .delete()
- .eq("id", investigationTypeId);
-}
-
export async function deleteRequiredAction(
client: SupabaseClient<Database>,
requiredActionId: string
@@ -993,12 +993,15 @@ export async function upsertIssue(
customFields?: Json;
})
) {
+ console.log({ nonConformance });
if ("createdBy" in nonConformance) {
- return client
+ const result = await client
.from("nonConformance")
.insert([nonConformance])
.select("id")
.single();
+
+ return result;
} else {
return client
.from("nonConformance")
@@ -1063,15 +1066,13 @@ export async function upsertIssueType(
export async function upsertInvestigationType(
client: SupabaseClient<Database>,
investigationType:
- | (Omit<z.infer<typeof issueTypeValidator>, "id"> & {
+ | (Omit<z.infer<typeof investigationTypeValidator>, "id"> & {
companyId: string;
- sortOrder?: number;
active?: boolean;
createdBy: string;
})
- | (Omit<z.infer<typeof issueTypeValidator>, "id"> & {
+ | (Omit<z.infer<typeof investigationTypeValidator>, "id"> & {
id: string;
- sortOrder?: number;
active?: boolean;
updatedBy: string;
})
@@ -1079,7 +1080,7 @@ export async function upsertInvestigationType(
if ("createdBy" in investigationType) {
return client
.from("nonConformanceInvestigationType")
- .insert([{ sortOrder: 1, active: true, ...investigationType }])
+ .insert([investigationType])
.select("id");
} else {
return client
diff --git a/apps/erp/app/modules/quality/types.ts b/apps/erp/app/modules/quality/types.ts
index ffffec572c..a775f25f16 100644
--- a/apps/erp/app/modules/quality/types.ts
+++ b/apps/erp/app/modules/quality/types.ts
@@ -4,6 +4,7 @@ import type {
getGaugeCalibrationRecords,
getGauges,
getGaugeTypes,
+ getInvestigationTypes,
getIssue,
getIssueActionTasks,
getIssueApprovalTasks,
@@ -47,6 +48,10 @@ export type IssueStatus = Database["public"]["Enums"]["nonConformanceStatus"];
export type Issue = NonNullable<Awaited<ReturnType<typeof getIssue>>["data"]>;
+export type InvestigationType = NonNullable<
+ Awaited<ReturnType<typeof getInvestigationTypes>>["data"]
+>[number];
+
export type IssueType = NonNullable<
Awaited<ReturnType<typeof getIssueTypes>>["data"]
>[number];
diff --git a/apps/erp/app/modules/quality/ui/InvestigationTypes/InvestigationTypeForm.tsx b/apps/erp/app/modules/quality/ui/InvestigationTypes/InvestigationTypeForm.tsx
new file mode 100644
index 0000000000..62ddd28822
--- /dev/null
+++ b/apps/erp/app/modules/quality/ui/InvestigationTypes/InvestigationTypeForm.tsx
@@ -0,0 +1,112 @@
+import { ValidatedForm } from "@carbon/form";
+import {
+ Button,
+ HStack,
+ ModalDrawer,
+ ModalDrawerBody,
+ ModalDrawerContent,
+ ModalDrawerFooter,
+ ModalDrawerHeader,
+ ModalDrawerProvider,
+ ModalDrawerTitle,
+ VStack,
+ toast,
+} from "@carbon/react";
+import { useFetcher } from "@remix-run/react";
+import type { PostgrestResponse } from "@supabase/supabase-js";
+import { useEffect } from "react";
+import type { z } from "zod";
+import { Boolean, CustomFormFields, Hidden, Input, Submit } from "~/components/Form";
+import { usePermissions } from "~/hooks";
+import { path } from "~/utils/path";
+import { investigationTypeValidator } from "../../quality.models";
+
+type InvestigationTypeFormProps = {
+ initialValues: z.infer<typeof investigationTypeValidator>;
+ type?: "modal" | "drawer";
+ open?: boolean;
+ onClose: () => void;
+};
+
+const InvestigationTypeForm = ({
+ initialValues,
+ open = true,
+ type = "drawer",
+ onClose,
+}: InvestigationTypeFormProps) => {
+ const permissions = usePermissions();
+ const fetcher = useFetcher<PostgrestResponse<{ id: string }>>();
+
+ useEffect(() => {
+ if (type !== "modal") return;
+
+ if (fetcher.state === "loading" && fetcher.data?.data) {
+ onClose?.();
+ toast.success(`Created investigation type`);
+ } else if (fetcher.state === "idle" && fetcher.data?.error) {
+ toast.error(
+ `Failed to create investigation type: ${fetcher.data.error.message}`
+ );
+ }
+ }, [fetcher.data, fetcher.state, onClose, type]);
+
+ const isEditing = initialValues.id !== undefined;
+ const isDisabled = isEditing
+ ? !permissions.can("update", "quality")
+ : !permissions.can("create", "quality");
+
+ return (
+ <ModalDrawerProvider type={type}>
+ <ModalDrawer
+ open={open}
+ onOpenChange={(open) => {
+ if (!open) onClose?.();
+ }}
+ >
+ <ModalDrawerContent>
+ <ValidatedForm
+ validator={investigationTypeValidator}
+ method="post"
+ action={
+ isEditing
+ ? path.to.investigationType(initialValues.id!)
+ : path.to.newInvestigationType
+ }
+ defaultValues={initialValues}
+ fetcher={fetcher}
+ className="flex flex-col h-full"
+ >
+ <ModalDrawerHeader>
+ <ModalDrawerTitle>
+ {isEditing ? "Edit" : "New"} Investigation Type
+ </ModalDrawerTitle>
+ </ModalDrawerHeader>
+ <ModalDrawerBody>
+ <Hidden name="id" />
+ <Hidden name="type" value={type} />
+ <VStack spacing={4}>
+ <Input name="name" label="Investigation Type" />
+ <Boolean
+ name="active"
+ label="Active"
+ description="Inactive types will not appear in selection lists"
+ />
+ <CustomFormFields table="nonConformanceInvestigationType" />
+ </VStack>
+ </ModalDrawerBody>
+ <ModalDrawerFooter>
+ <HStack>
+ <Submit isDisabled={isDisabled}>Save</Submit>
+ <Button size="md" variant="solid" onClick={() => onClose()}>
+ Cancel
+ </Button>
+ </HStack>
+ </ModalDrawerFooter>
+ </ValidatedForm>
+ </ModalDrawerContent>
+ </ModalDrawer>
+ </ModalDrawerProvider>
+ );
+};
+
+export default InvestigationTypeForm;
\ No newline at end of file
diff --git a/apps/erp/app/modules/quality/ui/InvestigationTypes/InvestigationTypesTable.tsx b/apps/erp/app/modules/quality/ui/InvestigationTypes/InvestigationTypesTable.tsx
new file mode 100644
index 0000000000..b506e4e1e2
--- /dev/null
+++ b/apps/erp/app/modules/quality/ui/InvestigationTypes/InvestigationTypesTable.tsx
@@ -0,0 +1,125 @@
+import { Checkbox, MenuIcon, MenuItem, useDisclosure } from "@carbon/react";
+import { useNavigate } from "@remix-run/react";
+import type { ColumnDef } from "@tanstack/react-table";
+import { memo, useCallback, useMemo, useState } from "react";
+import { flushSync } from "react-dom";
+import { LuFlaskConical, LuPencil, LuTrash } from "react-icons/lu";
+import { Hyperlink, New, Table } from "~/components";
+import { Enumerable } from "~/components/Enumerable";
+import { ConfirmDelete } from "~/components/Modals";
+import { usePermissions, useUrlParams } from "~/hooks";
+import { path } from "~/utils/path";
+import type { InvestigationType } from "../../types";
+
+type InvestigationTypesTableProps = {
+ data: InvestigationType[];
+ count: number;
+};
+
+const InvestigationTypesTable = memo(
+ ({ data, count }: InvestigationTypesTableProps) => {
+ const [params] = useUrlParams();
+ const navigate = useNavigate();
+ const permissions = usePermissions();
+ const deleteDisclosure = useDisclosure();
+ const [selectedInvestigationType, setSelectedInvestigationType] =
+ useState<InvestigationType | null>(null);
+
+ const columns = useMemo<ColumnDef<InvestigationType>[]>(() => {
+ const defaultColumns: ColumnDef<InvestigationType>[] = [
+ {
+ accessorKey: "name",
+ header: "Investigation Type",
+ cell: ({ row }) => (
+ <Hyperlink to={row.original.id}>
+ <Enumerable value={row.original.name} />
+ </Hyperlink>
+ ),
+ meta: {
+ icon: <LuFlaskConical />,
+ },
+ },
+ {
+ accessorKey: "active",
+ header: "Active",
+ cell: ({ row }) => <Checkbox checked={row.original.active} />,
+ },
+ ];
+ return defaultColumns;
+ }, []);
+
+ const renderContextMenu = useCallback(
+ (row: InvestigationType) => {
+ return (
+ <>
+ <MenuItem
+ onClick={() => {
+ navigate(
+ `${path.to.investigationType(row.id)}?${params.toString()}`
+ );
+ }}
+ >
+ <MenuIcon icon={<LuPencil />} />
+ Edit Type
+ </MenuItem>
+ <MenuItem
+ destructive
+ disabled={!permissions.can("delete", "quality")}
+ onClick={() => {
+ flushSync(() => {
+ setSelectedInvestigationType(row);
+ });
+ deleteDisclosure.onOpen();
+ }}
+ >
+ <MenuIcon icon={<LuTrash />} />
+ Delete Type
+ </MenuItem>
+ </>
+ );
+ },
+ [navigate, params, permissions, deleteDisclosure]
+ );
+
+ return (
+ <>
+ <Table<InvestigationType>
+ data={data}
+ columns={columns}
+ count={count}
+ primaryAction={
+ permissions.can("create", "quality") && (
+ <New
+ label="Investigation Type"
+ to={`${path.to.newInvestigationType}?${params.toString()}`}
+ />
+ )
+ }
+ renderContextMenu={renderContextMenu}
+ title="Investigation Types"
+ />
+ {deleteDisclosure.isOpen && selectedInvestigationType && (
+ <ConfirmDelete
+ action={path.to.deleteInvestigationType(
+ selectedInvestigationType.id
+ )}
+ isOpen
+ onCancel={() => {
+ setSelectedInvestigationType(null);
+ deleteDisclosure.onClose();
+ }}
+ onSubmit={() => {
+ setSelectedInvestigationType(null);
+ deleteDisclosure.onClose();
+ }}
+ name={selectedInvestigationType.name ?? "investigation type"}
+ text="Are you sure you want to delete this investigation type?"
+ />
+ )}
+ </>
+ );
+ }
+);
+
+InvestigationTypesTable.displayName = "InvestigationTypesTable";
+export default InvestigationTypesTable;
diff --git a/apps/erp/app/modules/quality/ui/InvestigationTypes/index.ts b/apps/erp/app/modules/quality/ui/InvestigationTypes/index.ts
new file mode 100644
index 0000000000..b8287cd262
--- /dev/null
+++ b/apps/erp/app/modules/quality/ui/InvestigationTypes/index.ts
@@ -0,0 +1,2 @@
+export { default as InvestigationTypeForm } from "./InvestigationTypeForm";
+export { default as InvestigationTypesTable } from "./InvestigationTypesTable";
\ No newline at end of file
diff --git a/apps/erp/app/modules/quality/ui/Issue/IssueForm.tsx b/apps/erp/app/modules/quality/ui/Issue/IssueForm.tsx
index fc266a575b..e4c67678da 100644
--- a/apps/erp/app/modules/quality/ui/Issue/IssueForm.tsx
+++ b/apps/erp/app/modules/quality/ui/Issue/IssueForm.tsx
@@ -60,14 +60,14 @@ const IssueForm = ({
const [workflow, setWorkflow] = useState<{
priority: string;
source: string;
- investigationTypes: string[];
- requiredActions: string[];
+ investigationTypeIds: string[];
+ requiredActionIds: string[];
approvalRequirements: string[];
}>({
priority: initialValues.priority,
source: initialValues.source,
- investigationTypes: initialValues.investigationTypes ?? [],
- requiredActions: initialValues.requiredActions ?? [],
+ investigationTypeIds: initialValues.investigationTypeIds ?? [],
+ requiredActionIds: initialValues.requiredActionIds ?? [],
approvalRequirements: initialValues.approvalRequirements ?? [],
});
@@ -78,12 +78,13 @@ const IssueForm = ({
const selectedWorkflow = nonConformanceWorkflows.find(
(w) => w.id === value.value
);
+ console.log(selectedWorkflow);
if (selectedWorkflow) {
setWorkflow({
priority: selectedWorkflow.priority,
source: selectedWorkflow.source,
- investigationTypes: selectedWorkflow.investigationTypes ?? [],
- requiredActions: selectedWorkflow.requiredActions ?? [],
+ investigationTypeIds: selectedWorkflow.investigationTypeIds ?? [],
+ requiredActionIds: selectedWorkflow.requiredActionIds ?? [],
approvalRequirements: selectedWorkflow.approvalRequirements ?? [],
});
}
@@ -156,32 +157,32 @@ const IssueForm = ({
<VStack spacing={4}>
<MultiSelect
- name="investigationTypes"
+ name="investigationTypeIds"
label="Investigation Types"
options={investigationTypes.map((type) => ({
label: type.name,
value: type.id,
}))}
- value={workflow.investigationTypes}
+ value={workflow.investigationTypeIds}
onChange={(value) => {
setWorkflow({
...workflow,
- investigationTypes: value.map((v) => v.value),
+ investigationTypeIds: value.map((v) => v.value),
});
}}
/>
<MultiSelect
- name="requiredActions"
+ name="requiredActionIds"
label="Required Actions"
options={requiredActions.map((action) => ({
label: action.name,
value: action.id,
}))}
- value={workflow.requiredActions}
+ value={workflow.requiredActionIds}
onChange={(value) => {
setWorkflow({
...workflow,
- requiredActions: value.map((v) => v.value),
+ requiredActionIds: value.map((v) => v.value),
});
}}
/>
diff --git a/apps/erp/app/modules/quality/ui/Issue/IssueProperties.tsx b/apps/erp/app/modules/quality/ui/Issue/IssueProperties.tsx
index 50bb3cb6d7..de6bb6e9a3 100644
--- a/apps/erp/app/modules/quality/ui/Issue/IssueProperties.tsx
+++ b/apps/erp/app/modules/quality/ui/Issue/IssueProperties.tsx
@@ -51,6 +51,8 @@ const IssueProperties = () => {
tags: { name: string }[];
}>(path.to.issue(id));
+ console.log(routeData);
+
const optimisticAssignment = useOptimisticAssignment({
id: id,
table: "nonConformance",
@@ -373,8 +375,12 @@ const IssueProperties = () => {
label="Investigation Types"
name="investigationTypeIds"
inline
+ value={routeData?.nonConformance?.investigationTypeIds ?? []}
onChange={(value) => {
- onUpdate("investigationTypeIds", value.map((v) => v.value).join(","));
+ onUpdate(
+ "investigationTypeIds",
+ value.map((v) => v.value).join(",")
+ );
}}
/>
</ValidatedForm>
@@ -397,6 +403,7 @@ const IssueProperties = () => {
label="Required Actions"
name="requiredActionIds"
inline
+ value={routeData?.nonConformance?.requiredActionIds ?? []}
onChange={(value) => {
onUpdate("requiredActionIds", value.map((v) => v.value).join(","));
}}
diff --git a/apps/erp/app/modules/quality/ui/Issue/IssueTask.tsx b/apps/erp/app/modules/quality/ui/Issue/IssueTask.tsx
index fffdf45e12..a3bb68d3ab 100644
--- a/apps/erp/app/modules/quality/ui/Issue/IssueTask.tsx
+++ b/apps/erp/app/modules/quality/ui/Issue/IssueTask.tsx
@@ -121,9 +121,9 @@ export function TaskItem({
const taskTitle =
type === "investigation"
- ? (task as IssueInvestigationTask).investigationType
+ ? (task as IssueInvestigationTask).name
: type === "action"
- ? (task as IssueActionTask).actionType
+ ? (task as IssueActionTask).name
: (task as IssueReviewer).title;
return (
diff --git a/apps/erp/app/modules/quality/ui/Issue/useIssueNavigation.tsx b/apps/erp/app/modules/quality/ui/Issue/useIssueNavigation.tsx
index af28661d36..6d169827b6 100644
--- a/apps/erp/app/modules/quality/ui/Issue/useIssueNavigation.tsx
+++ b/apps/erp/app/modules/quality/ui/Issue/useIssueNavigation.tsx
@@ -19,10 +19,10 @@ export function useIssueNavigation() {
throw new Error("Could not find source in routeData");
const hasInvestigations =
- (routeData.nonConformance.investigationTypes?.length ?? 0) > 0;
+ (routeData.nonConformance.investigationTypeIds?.length ?? 0) > 0;
const hasActions =
- (routeData.nonConformance.requiredActions?.length ?? 0) > 0;
+ (routeData.nonConformance.requiredActionIds?.length ?? 0) > 0;
const requiresManagementReview =
routeData.nonConformance.approvalRequirements?.includes("MRB");
diff --git a/apps/erp/app/modules/quality/ui/IssueWorkflows/IssueWorkflowForm.tsx b/apps/erp/app/modules/quality/ui/IssueWorkflows/IssueWorkflowForm.tsx
index c06caa400a..b588f2105b 100644
--- a/apps/erp/app/modules/quality/ui/IssueWorkflows/IssueWorkflowForm.tsx
+++ b/apps/erp/app/modules/quality/ui/IssueWorkflows/IssueWorkflowForm.tsx
@@ -16,24 +16,27 @@ import { useState } from "react";
import type { z } from "zod";
import { Hidden, Input, Submit } from "~/components/Form";
import { usePermissions, useUser } from "~/hooks";
+import type { ListItem } from "~/types";
import { getPrivateUrl, path } from "~/utils/path";
import {
issueWorkflowValidator,
nonConformanceApprovalRequirement,
- nonConformanceInvestigationType,
nonConformancePriority,
- nonConformanceRequiredAction,
nonConformanceSource,
} from "../../quality.models";
import { getPriorityIcon } from "../Issue/IssueIcons";
type IssueWorkflowFormProps = {
initialValues: z.infer<typeof issueWorkflowValidator>;
+ investigationTypes: ListItem[];
+ requiredActions: ListItem[];
onClose: () => void;
};
const IssueWorkflowForm = ({
initialValues,
+ investigationTypes,
+ requiredActions,
onClose,
}: IssueWorkflowFormProps) => {
const permissions = usePermissions();
@@ -172,20 +175,21 @@ const IssueWorkflowForm = ({
/>
</div>
<MultiSelect
- name="investigationTypes"
+ name="investigationTypeIds"
label="Investigation Types"
- options={nonConformanceInvestigationType.map((type) => ({
- label: type,
- value: type,
+ options={investigationTypes.map((type) => ({
+ label: type.name,
+ value: type.id,
}))}
+ value={initialValues.investigationTypeIds}
/>
<MultiSelect
- name="requiredActions"
+ name="requiredActionIds"
label="Required Actions"
- options={nonConformanceRequiredAction.map((action) => ({
- label: action,
- value: action,
+ options={requiredActions.map((action) => ({
+ label: action.name,
+ value: action.id,
}))}
/>
diff --git a/apps/erp/app/modules/quality/ui/useQualitySubmodules.tsx b/apps/erp/app/modules/quality/ui/useQualitySubmodules.tsx
index 51634c1649..1f1b494bc4 100644
--- a/apps/erp/app/modules/quality/ui/useQualitySubmodules.tsx
+++ b/apps/erp/app/modules/quality/ui/useQualitySubmodules.tsx
@@ -3,6 +3,7 @@ import {
LuDraftingCompass,
LuListChecks,
LuOctagonX,
+ LuSearch,
LuShapes,
LuShieldX,
LuWorkflow,
@@ -59,6 +60,11 @@ const qualityRoutes: AuthenticatedRouteGroup[] = [
to: path.to.gaugeTypes,
icon: <LuShapes />,
},
+ {
+ name: "Investigation Types",
+ to: path.to.investigationTypes,
+ icon: <LuSearch />,
+ },
{
name: "Issue Types",
to: path.to.issueTypes,
diff --git a/apps/erp/app/routes/x+/issue+/$id.actions.tsx b/apps/erp/app/routes/x+/issue+/$id.actions.tsx
index 1d730b9910..0c8fe0bc02 100644
--- a/apps/erp/app/routes/x+/issue+/$id.actions.tsx
+++ b/apps/erp/app/routes/x+/issue+/$id.actions.tsx
@@ -68,14 +68,16 @@ function ActionTasksList({
</HStack>
<CardContent>
<VStack spacing={3}>
- {tasks.map((task) => (
- <TaskItem
- key={task.id}
- task={task}
- type="action"
- isDisabled={isDisabled}
- />
- ))}
+ {tasks
+ .sort((a, b) => a.name?.localeCompare(b.name ?? "") ?? 0)
+ .map((task) => (
+ <TaskItem
+ key={task.id}
+ task={task}
+ type="action"
+ isDisabled={isDisabled}
+ />
+ ))}
</VStack>
</CardContent>
</Card>
diff --git a/apps/erp/app/routes/x+/issue+/$id.investigations.tsx b/apps/erp/app/routes/x+/issue+/$id.investigations.tsx
index ccb509b9e3..005a12a29c 100644
--- a/apps/erp/app/routes/x+/issue+/$id.investigations.tsx
+++ b/apps/erp/app/routes/x+/issue+/$id.investigations.tsx
@@ -30,6 +30,10 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
companyId
);
+ if (investigationTasks.error) {
+ console.error(investigationTasks.error);
+ }
+
return json({
investigationTasks: investigationTasks.data || [],
});
@@ -74,14 +78,16 @@ function InvestigationTasksList({
</HStack>
<CardContent>
<VStack spacing={3}>
- {tasks.map((task) => (
- <TaskItem
- key={task.id}
- task={task}
- type="investigation"
- isDisabled={isDisabled}
- />
- ))}
+ {tasks
+ .sort((a, b) => a.name?.localeCompare(b.name ?? "") ?? 0)
+ .map((task) => (
+ <TaskItem
+ key={task.id}
+ task={task}
+ type="investigation"
+ isDisabled={isDisabled}
+ />
+ ))}
</VStack>
</CardContent>
</Card>
diff --git a/apps/erp/app/routes/x+/issue+/new.tsx b/apps/erp/app/routes/x+/issue+/new.tsx
index c6ab7daa89..af8edd0833 100644
--- a/apps/erp/app/routes/x+/issue+/new.tsx
+++ b/apps/erp/app/routes/x+/issue+/new.tsx
@@ -34,12 +34,13 @@ export async function loader({ request }: LoaderFunctionArgs) {
view: "quality",
});
- const [workflows, types, investigationTypes, requiredActions] = await Promise.all([
- getIssueWorkflowsList(client, companyId),
- getIssueTypesList(client, companyId),
- getInvestigationTypesList(client, companyId),
- getRequiredActionsList(client, companyId),
- ]);
+ const [workflows, types, investigationTypes, requiredActions] =
+ await Promise.all([
+ getIssueWorkflowsList(client, companyId),
+ getIssueTypesList(client, companyId),
+ getInvestigationTypesList(client, companyId),
+ getRequiredActionsList(client, companyId),
+ ]);
return json({
workflows: workflows.data ?? [],
@@ -125,7 +126,8 @@ export async function action({ request }: ActionFunctionArgs) {
}
export default function IssueNewRoute() {
- const { workflows, types, investigationTypes, requiredActions } = useLoaderData<typeof loader>();
+ const { workflows, types, investigationTypes, requiredActions } =
+ useLoaderData<typeof loader>();
const { defaults } = useUser();
const [params] = useUrlParams();
@@ -144,7 +146,7 @@ export default function IssueNewRoute() {
nonConformanceId: undefined,
approvalRequirements: [],
customerId: customerId ?? "",
- investigationTypes: [],
+ investigationTypeIds: [],
itemId: "",
jobId: jobId ?? "",
locationId: defaults.locationId ?? "",
@@ -156,7 +158,7 @@ export default function IssueNewRoute() {
purchaseOrderId: purchaseOrderId ?? "",
purchaseOrderLineId: purchaseOrderLineId ?? "",
quantity: 1,
- requiredActions: [],
+ requiredActionIds: [],
salesOrderId: salesOrderId ?? "",
salesOrderLineId: salesOrderLineId ?? "",
shipmentId: shipmentId ?? "",
diff --git a/apps/erp/app/routes/x+/issue-workflow+/$id.tsx b/apps/erp/app/routes/x+/issue-workflow+/$id.tsx
index d60859e2c5..c6b415149d 100644
--- a/apps/erp/app/routes/x+/issue-workflow+/$id.tsx
+++ b/apps/erp/app/routes/x+/issue-workflow+/$id.tsx
@@ -8,7 +8,9 @@ import { useLoaderData, useNavigate, useParams } from "@remix-run/react";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
import { json, redirect } from "@vercel/remix";
import {
+ getInvestigationTypesList,
getIssueWorkflow,
+ getRequiredActionsList,
issueWorkflowValidator,
upsertIssueWorkflow,
} from "~/modules/quality";
@@ -23,7 +25,7 @@ export const handle: Handle = {
};
export async function loader({ request, params }: LoaderFunctionArgs) {
- const { client } = await requirePermissions(request, {
+ const { client, companyId } = await requirePermissions(request, {
view: "quality",
role: "employee",
bypassRls: true,
@@ -32,7 +34,11 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
const { id } = params;
if (!id) throw new Error("Could not find id");
- const [workflow] = await Promise.all([getIssueWorkflow(client, id)]);
+ const [workflow, investigationTypes, requiredActions] = await Promise.all([
+ getIssueWorkflow(client, id),
+ getInvestigationTypesList(client, companyId),
+ getRequiredActionsList(client, companyId),
+ ]);
if (workflow.error) {
throw redirect(
@@ -46,6 +52,8 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
return json({
workflow: workflow.data,
+ investigationTypes: investigationTypes.data ?? [],
+ requiredActions: requiredActions.data ?? [],
});
}
@@ -92,26 +100,32 @@ export default function IssueWorkflowRoute() {
const { id } = useParams();
if (!id) throw new Error("Could not find id");
- const loaderData = useLoaderData<typeof loader>();
+ const { workflow, investigationTypes, requiredActions } =
+ useLoaderData<typeof loader>();
const navigate = useNavigate();
const onClose = () => {
navigate(path.to.issueWorkflows);
};
const initialValues = {
- id: loaderData?.workflow?.id,
- name: loaderData?.workflow?.name,
- content: JSON.stringify(loaderData?.workflow?.content),
- priority: (loaderData?.workflow?.priority ?? "Medium") as "Medium",
- source: (loaderData?.workflow?.source ?? "Internal") as "Internal",
- investigationTypes: loaderData?.workflow?.investigationTypes ?? [],
- requiredActions: loaderData?.workflow?.requiredActions ?? [],
- approvalRequirements: loaderData?.workflow?.approvalRequirements ?? [],
+ id: workflow?.id,
+ name: workflow?.name,
+ content: JSON.stringify(workflow?.content),
+ priority: (workflow?.priority ?? "Medium") as "Medium",
+ source: (workflow?.source ?? "Internal") as "Internal",
+ investigationTypeIds: workflow?.investigationTypeIds ?? [],
+ requiredActionIds: workflow?.requiredActionIds ?? [],
+ approvalRequirements: workflow?.approvalRequirements ?? [],
};
return (
<ScrollArea className="w-full h-[calc(100dvh-49px)] bg-card">
- <IssueWorkflowForm initialValues={initialValues} onClose={onClose} />
+ <IssueWorkflowForm
+ initialValues={initialValues}
+ investigationTypes={investigationTypes}
+ requiredActions={requiredActions}
+ onClose={onClose}
+ />
</ScrollArea>
);
}
diff --git a/apps/erp/app/routes/x+/issue-workflow+/new.tsx b/apps/erp/app/routes/x+/issue-workflow+/new.tsx
index d9aebb14e6..0226cb96ba 100644
--- a/apps/erp/app/routes/x+/issue-workflow+/new.tsx
+++ b/apps/erp/app/routes/x+/issue-workflow+/new.tsx
@@ -3,20 +3,32 @@ import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
import { validationError, validator } from "@carbon/form";
import { ScrollArea } from "@carbon/react";
-import { useNavigate } from "@remix-run/react";
+import { useLoaderData, useNavigate } from "@remix-run/react";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
import { json, redirect } from "@vercel/remix";
import { issueWorkflowValidator } from "~/modules/quality/quality.models";
-import { upsertIssueWorkflow } from "~/modules/quality/quality.service";
+import {
+ getInvestigationTypesList,
+ getRequiredActionsList,
+ upsertIssueWorkflow,
+} from "~/modules/quality/quality.service";
import IssueWorkflowForm from "~/modules/quality/ui/IssueWorkflows/IssueWorkflowForm";
import { path } from "~/utils/path";
export async function loader({ request }: LoaderFunctionArgs) {
- await requirePermissions(request, {
+ const { client, companyId } = await requirePermissions(request, {
create: "quality",
});
- return null;
+ const [investigationTypes, requiredActions] = await Promise.all([
+ getInvestigationTypesList(client, companyId),
+ getRequiredActionsList(client, companyId),
+ ]);
+
+ return json({
+ investigationTypes: investigationTypes.data ?? [],
+ requiredActions: requiredActions.data ?? [],
+ });
}
export async function action({ request }: ActionFunctionArgs) {
@@ -56,14 +68,16 @@ export async function action({ request }: ActionFunctionArgs) {
}
export default function NewIssueWorkflowRoute() {
+ const { investigationTypes, requiredActions } =
+ useLoaderData<typeof loader>();
const navigate = useNavigate();
const initialValues = {
name: "",
content: "{}",
priority: "Medium" as const,
source: "Internal" as const,
- investigationTypes: [],
- requiredActions: [],
+ investigationTypeIds: [],
+ requiredActionIds: [],
approvalRequirements: [],
};
@@ -71,6 +85,8 @@ export default function NewIssueWorkflowRoute() {
<ScrollArea className="w-full h-[calc(100dvh-49px)] bg-card">
<IssueWorkflowForm
initialValues={initialValues}
+ investigationTypes={investigationTypes}
+ requiredActions={requiredActions}
onClose={() => navigate(-1)}
/>
</ScrollArea>
diff --git a/apps/erp/app/routes/x+/quality+/investigation-types.$id.tsx b/apps/erp/app/routes/x+/quality+/investigation-types.$id.tsx
new file mode 100644
index 0000000000..f1ed5c9026
--- /dev/null
+++ b/apps/erp/app/routes/x+/quality+/investigation-types.$id.tsx
@@ -0,0 +1,93 @@
+import { assertIsPost, error, success } from "@carbon/auth";
+import { requirePermissions } from "@carbon/auth/auth.server";
+import { flash } from "@carbon/auth/session.server";
+import { validator } from "@carbon/form";
+import { useLoaderData, useNavigate } from "@remix-run/react";
+
+import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
+import { json, redirect } from "@vercel/remix";
+import {
+ getInvestigationType,
+ investigationTypeValidator,
+ upsertInvestigationType,
+} from "~/modules/quality";
+import { InvestigationTypeForm } from "~/modules/quality/ui/InvestigationTypes";
+
+import { path } from "~/utils/path";
+
+export async function loader({ request, params }: LoaderFunctionArgs) {
+ const { id } = params;
+ if (!id) throw new Error("Investigation type ID is required");
+
+ const { client } = await requirePermissions(request, {
+ view: "quality",
+ role: "employee",
+ });
+
+ const result = await getInvestigationType(client, id);
+ if (!result.data) {
+ return redirect(
+ path.to.investigationTypes,
+ await flash(request, error(result.error, "Investigation type not found"))
+ );
+ }
+
+ return json({ investigationType: result.data });
+}
+
+export async function action({ request, params }: ActionFunctionArgs) {
+ assertIsPost(request);
+ const { id } = params;
+ if (!id) throw new Error("Investigation type ID is required");
+
+ const { client, userId } = await requirePermissions(request, {
+ update: "quality",
+ });
+
+ const formData = await request.formData();
+ const validation = await validator(investigationTypeValidator).validate(
+ formData
+ );
+
+ if (validation.error) {
+ return json({ success: false, message: "Invalid form data" });
+ }
+
+ const { name, active } = validation.data;
+
+ const updateResult = await upsertInvestigationType(client, {
+ id,
+ name,
+ active: active ?? true,
+ updatedBy: userId,
+ });
+
+ if (updateResult.error) {
+ return redirect(
+ path.to.investigationTypes,
+ await flash(
+ request,
+ error(updateResult.error, "Failed to update investigation type")
+ )
+ );
+ }
+
+ return redirect(
+ path.to.investigationTypes,
+ await flash(request, success("Investigation type updated successfully"))
+ );
+}
+
+export default function EditInvestigationTypeRoute() {
+ const { investigationType } = useLoaderData<typeof loader>();
+ const navigate = useNavigate();
+ const onClose = () => navigate(path.to.investigationTypes);
+
+ return (
+ <InvestigationTypeForm
+ type="modal"
+ initialValues={investigationType}
+ onClose={onClose}
+ />
+ );
+}
diff --git a/apps/erp/app/routes/x+/quality+/investigation-types.delete.$id.tsx b/apps/erp/app/routes/x+/quality+/investigation-types.delete.$id.tsx
new file mode 100644
index 0000000000..14ab3bc8ec
--- /dev/null
+++ b/apps/erp/app/routes/x+/quality+/investigation-types.delete.$id.tsx
@@ -0,0 +1,33 @@
+import { error, notFound, success } from "@carbon/auth";
+import { requirePermissions } from "@carbon/auth/auth.server";
+import { flash } from "@carbon/auth/session.server";
+import type { ActionFunctionArgs } from "@vercel/remix";
+import { redirect } from "@vercel/remix";
+import { deleteInvestigationType } from "~/modules/quality";
+import { path } from "~/utils/path";
+
+export async function action({ request, params }: ActionFunctionArgs) {
+ const { id } = params;
+ if (!id) throw notFound("Investigation type ID is required");
+
+ const { client } = await requirePermissions(request, {
+ delete: "quality",
+ });
+
+ const deleteResult = await deleteInvestigationType(client, id);
+
+ if (deleteResult.error) {
+ return redirect(
+ path.to.investigationTypes,
+ await flash(
+ request,
+ error(deleteResult.error, "Failed to delete investigation type")
+ )
+ );
+ }
+
+ return redirect(
+ path.to.investigationTypes,
+ await flash(request, success("Investigation type deleted successfully"))
+ );
+}
diff --git a/apps/erp/app/routes/x+/quality+/investigation-types.new.tsx b/apps/erp/app/routes/x+/quality+/investigation-types.new.tsx
new file mode 100644
index 0000000000..682cfd7bb9
--- /dev/null
+++ b/apps/erp/app/routes/x+/quality+/investigation-types.new.tsx
@@ -0,0 +1,71 @@
+import { assertIsPost, error, success } from "@carbon/auth";
+import { requirePermissions } from "@carbon/auth/auth.server";
+import { flash } from "@carbon/auth/session.server";
+import { validator } from "@carbon/form";
+import { useNavigate } from "@remix-run/react";
+import type { ActionFunctionArgs } from "@vercel/remix";
+import { json, redirect } from "@vercel/remix";
+import {
+ investigationTypeValidator,
+ upsertInvestigationType,
+} from "~/modules/quality";
+import { InvestigationTypeForm } from "~/modules/quality/ui/InvestigationTypes";
+import { path } from "~/utils/path";
+
+export async function action({ request }: ActionFunctionArgs) {
+ assertIsPost(request);
+ const { client, companyId, userId } = await requirePermissions(request, {
+ create: "quality",
+ });
+
+ const formData = await request.formData();
+ const validation = await validator(investigationTypeValidator).validate(
+ formData
+ );
+
+ if (validation.error) {
+ return json({ success: false, message: "Invalid form data" });
+ }
+
+ const { name, active } = validation.data;
+
+ const createResult = await upsertInvestigationType(client, {
+ name,
+ active: active ?? true,
+ companyId,
+ createdBy: userId,
+ });
+
+ if (createResult.error) {
+ return redirect(
+ path.to.investigationTypes,
+ await flash(
+ request,
+ error(createResult.error, "Failed to create investigation type")
+ )
+ );
+ }
+
+ const [newInvestigationType] = createResult.data ?? [];
+
+ return redirect(
+ path.to.investigationType(newInvestigationType.id),
+ await flash(request, success("Investigation type created successfully"))
+ );
+}
+
+export default function NewInvestigationTypeRoute() {
+ const navigate = useNavigate();
+ const onClose = () => navigate(path.to.investigationTypes);
+
+ return (
+ <InvestigationTypeForm
+ type="modal"
+ initialValues={{
+ name: "",
+ active: true,
+ }}
+ onClose={onClose}
+ />
+ );
+}
diff --git a/apps/erp/app/routes/x+/quality+/investigation-types.tsx b/apps/erp/app/routes/x+/quality+/investigation-types.tsx
new file mode 100644
index 0000000000..7997a33770
--- /dev/null
+++ b/apps/erp/app/routes/x+/quality+/investigation-types.tsx
@@ -0,0 +1,49 @@
+import { requirePermissions } from "@carbon/auth/auth.server";
+import { VStack } from "@carbon/react";
+import { Outlet, useLoaderData } from "@remix-run/react";
+import type { LoaderFunctionArgs } from "@vercel/remix";
+import { json } from "@vercel/remix";
+import { getInvestigationTypes } from "~/modules/quality";
+import InvestigationTypesTable from "~/modules/quality/ui/InvestigationTypes/InvestigationTypesTable";
+import type { Handle } from "~/utils/handle";
+import { path } from "~/utils/path";
+import { getGenericQueryFilters } from "~/utils/query";
+
+export const handle: Handle = {
+ breadcrumb: "Investigation Types",
+ to: path.to.investigationTypes,
+};
+
+export async function loader({ request }: LoaderFunctionArgs) {
+ const { client, companyId } = await requirePermissions(request, {
+ view: "quality",
+ role: "employee",
+ });
+
+ const url = new URL(request.url);
+ const searchParams = new URLSearchParams(url.search);
+ const search = searchParams.get("search");
+ const { limit, offset, sorts, filters } =
+ getGenericQueryFilters(searchParams);
+
+ return json(
+ await getInvestigationTypes(client, companyId, {
+ search,
+ limit,
+ offset,
+ sorts,
+ filters,
+ })
+ );
+}
+
+export default function InvestigationTypesRoute() {
+ const { data, count } = useLoaderData<typeof loader>();
+
+ return (
+ <VStack spacing={0} className="h-full">
+ <InvestigationTypesTable data={data ?? []} count={count ?? 0} />
+ <Outlet />
+ </VStack>
+ );
+}
\ No newline at end of file
diff --git a/apps/erp/app/utils/path.ts b/apps/erp/app/utils/path.ts
index 095f2e91ad..8ef7663d60 100644
--- a/apps/erp/app/utils/path.ts
+++ b/apps/erp/app/utils/path.ts
@@ -539,6 +539,8 @@ export const path = {
),
deleteIssueWorkflow: (id: string) =>
generatePath(`${x}/issue-workflow/delete/${id}`),
+ deleteInvestigationType: (id: string) =>
+ generatePath(`${x}/quality/investigation-types/delete/${id}`),
deleteIssueType: (id: string) =>
generatePath(`${x}/quality/issue-types/delete/${id}`),
deleteNoQuoteReason: (id: string) =>
@@ -693,6 +695,8 @@ export const path = {
issueReview: (id: string) => generatePath(`${x}/issue/${id}/review`),
issueWorkflow: (id: string) => generatePath(`${x}/issue-workflow/${id}`),
issueWorkflows: `${x}/quality/issue-workflows`,
+ investigationType: (id: string) => generatePath(`${x}/quality/investigation-types/${id}`),
+ investigationTypes: `${x}/quality/investigation-types`,
issueType: (id: string) => generatePath(`${x}/quality/issue-types/${id}`),
issueTypes: `${x}/quality/issue-types`,
items: `${x}/items`,
@@ -862,6 +866,7 @@ export const path = {
newIssue: `${x}/issue/new`,
newIssueAssociation: (id: string) =>
generatePath(`${x}/issue/${id}/association/new`),
+ newInvestigationType: `${x}/quality/investigation-types/new`,
newIssueType: `${x}/quality/issue-types/new`,
newIssueWorkflow: `${x}/issue-workflow/new`,
newNote: `${x}/shared/notes/new`,
diff --git a/llm/cache/issue-module.md b/llm/cache/issue-module.md
index 5ea2db6659..203534dc51 100644
--- a/llm/cache/issue-module.md
+++ b/llm/cache/issue-module.md
@@ -7,11 +7,13 @@ The Issue module is part of the quality management system in Carbon ERP. It hand
## Issue Status Flow
Issues have the following status progression:
+
1. **Registered** - Initial status when an issue is created
2. **In Progress** - Status when work begins on the issue
3. **Closed** - Final status when the issue is resolved
### Status Transitions
+
- **Start Button**: Visible when status is "Registered", changes status to "In Progress"
- **Complete Button**: Visible when status is "In Progress", changes status to "Closed"
- **Reopen Button**: Visible when status is "Closed", changes status back to "In Progress"
@@ -21,18 +23,21 @@ Issues have the following status progression:
Issues can have three types of tasks that are created automatically based on the issue configuration:
### 1. Investigation Tasks
-- Created based on `investigationTypes` array in the issue
+
+- Created based on `investigationTypeIds` array in the issue
- Each investigation type creates one task
- Stored in `nonConformanceInvestigationTask` table
- Examples: Root Cause Analysis, Material Analysis, Process Review
### 2. Action Tasks
-- Created based on `requiredActions` array in the issue
+
+- Created based on `requiredActionIds` array in the issue
- Each action type creates one task
- Stored in `nonConformanceActionTask` table
- Examples: Corrective Action, Preventive Action, Containment
### 3. Approval Tasks
+
- Created based on `approvalRequirements` array in the issue
- Each approval type creates one task
- Stored in `nonConformanceApprovalTask` table
@@ -41,12 +46,14 @@ Issues can have three types of tasks that are created automatically based on the
## Task Status
All tasks have the following statuses:
+
- **Pending** - Initial status (tasks do NOT auto-start)
- **In Progress** - When work is actively being done
- **Completed** - When the task is finished
- **Skipped** - When the task is not applicable
### Task Actions
+
- **Start**: Changes status from "Pending" to "In Progress"
- **Complete**: Changes status from "In Progress" to "Completed"
- **Skip**: Available only when status is "Pending", changes to "Skipped"
@@ -93,4 +100,4 @@ All tasks have the following statuses:
- Details: `/x/issue/{id}`
- Investigations: `/x/issue/{id}/investigations`
- Actions: `/x/issue/{id}/actions`
-- Review: `/x/issue/{id}/review`
\ No newline at end of file
+- Review: `/x/issue/{id}/review`
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index 486b22b0de..de065d760f 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -13897,9 +13897,7 @@ export type Database = {
description: string | null
dueDate: string | null
id: string
- investigationTypes:
- | Database["public"]["Enums"]["nonConformanceInvestigation"][]
- | null
+ investigationTypeIds: string[] | null
itemId: string | null
locationId: string
name: string
@@ -13909,9 +13907,7 @@ export type Database = {
openDate: string
priority: Database["public"]["Enums"]["nonConformancePriority"] | null
quantity: number
- requiredActions:
- | Database["public"]["Enums"]["nonConformanceAction"][]
- | null
+ requiredActionIds: string[] | null
source: Database["public"]["Enums"]["nonConformanceSource"]
status: Database["public"]["Enums"]["nonConformanceStatus"]
tags: string[] | null
@@ -13932,9 +13928,7 @@ export type Database = {
description?: string | null
dueDate?: string | null
id?: string
- investigationTypes?:
- | Database["public"]["Enums"]["nonConformanceInvestigation"][]
- | null
+ investigationTypeIds?: string[] | null
itemId?: string | null
locationId: string
name: string
@@ -13946,9 +13940,7 @@ export type Database = {
| Database["public"]["Enums"]["nonConformancePriority"]
| null
quantity?: number
- requiredActions?:
- | Database["public"]["Enums"]["nonConformanceAction"][]
- | null
+ requiredActionIds?: string[] | null
source: Database["public"]["Enums"]["nonConformanceSource"]
status?: Database["public"]["Enums"]["nonConformanceStatus"]
tags?: string[] | null
@@ -13969,9 +13961,7 @@ export type Database = {
description?: string | null
dueDate?: string | null
id?: string
- investigationTypes?:
- | Database["public"]["Enums"]["nonConformanceInvestigation"][]
- | null
+ investigationTypeIds?: string[] | null
itemId?: string | null
locationId?: string
name?: string
@@ -13983,9 +13973,7 @@ export type Database = {
| Database["public"]["Enums"]["nonConformancePriority"]
| null
quantity?: number
- requiredActions?:
- | Database["public"]["Enums"]["nonConformanceAction"][]
- | null
+ requiredActionIds?: string[] | null
source?: Database["public"]["Enums"]["nonConformanceSource"]
status?: Database["public"]["Enums"]["nonConformanceStatus"]
tags?: string[] | null
@@ -14186,7 +14174,7 @@ export type Database = {
}
nonConformanceActionTask: {
Row: {
- actionType: Database["public"]["Enums"]["nonConformanceAction"] | null
+ actionTypeId: string | null
assignee: string | null
companyId: string
completedDate: string | null
@@ -14203,9 +14191,7 @@ export type Database = {
updatedBy: string | null
}
Insert: {
- actionType?:
- | Database["public"]["Enums"]["nonConformanceAction"]
- | null
+ actionTypeId?: string | null
assignee?: string | null
companyId: string
completedDate?: string | null
@@ -14222,9 +14208,7 @@ export type Database = {
updatedBy?: string | null
}
Update: {
- actionType?:
- | Database["public"]["Enums"]["nonConformanceAction"]
- | null
+ actionTypeId?: string | null
assignee?: string | null
companyId?: string
completedDate?: string | null
@@ -14241,6 +14225,13 @@ export type Database = {
updatedBy?: string | null
}
Relationships: [
+ {
+ foreignKeyName: "nonConformanceActionTask_actionTypeId_fkey"
+ columns: ["actionTypeId"]
+ isOneToOne: false
+ referencedRelation: "nonConformanceRequiredAction"
+ referencedColumns: ["id"]
+ },
{
foreignKeyName: "nonConformanceActionTask_assignee_fkey"
columns: ["assignee"]
@@ -14753,9 +14744,7 @@ export type Database = {
createdBy: string
dueDate: string | null
id: string
- investigationType:
- | Database["public"]["Enums"]["nonConformanceInvestigation"]
- | null
+ investigationTypeId: string | null
nonConformanceId: string
notes: Json
sortOrder: number
@@ -14772,9 +14761,7 @@ export type Database = {
createdBy: string
dueDate?: string | null
id?: string
- investigationType?:
- | Database["public"]["Enums"]["nonConformanceInvestigation"]
- | null
+ investigationTypeId?: string | null
nonConformanceId: string
notes?: Json
sortOrder?: number
@@ -14791,9 +14778,7 @@ export type Database = {
createdBy?: string
dueDate?: string | null
id?: string
- investigationType?:
- | Database["public"]["Enums"]["nonConformanceInvestigation"]
- | null
+ investigationTypeId?: string | null
nonConformanceId?: string
notes?: Json
sortOrder?: number
@@ -14901,6 +14886,13 @@ export type Database = {
referencedRelation: "userDefaults"
referencedColumns: ["userId"]
},
+ {
+ foreignKeyName: "nonConformanceInvestigationTask_investigationTypeId_fkey"
+ columns: ["investigationTypeId"]
+ isOneToOne: false
+ referencedRelation: "nonConformanceInvestigationType"
+ referencedColumns: ["id"]
+ },
{
foreignKeyName: "nonConformanceInvestigationTask_nonConformanceId_fkey"
columns: ["nonConformanceId"]
@@ -14945,6 +14937,141 @@ export type Database = {
},
]
}
+ nonConformanceInvestigationType: {
+ Row: {
+ active: boolean
+ companyId: string
+ createdAt: string
+ createdBy: string
+ id: string
+ name: string
+ sortOrder: number
+ updatedAt: string | null
+ updatedBy: string | null
+ }
+ Insert: {
+ active?: boolean
+ companyId: string
+ createdAt?: string
+ createdBy: string
+ id?: string
+ name: string
+ sortOrder?: number
+ updatedAt?: string | null
+ updatedBy?: string | null
+ }
+ Update: {
+ active?: boolean
+ companyId?: string
+ createdAt?: string
+ createdBy?: string
+ id?: string
+ name?: string
+ sortOrder?: number
+ updatedAt?: string | null
+ updatedBy?: string | null
+ }
+ Relationships: [
+ {
+ foreignKeyName: "nonConformanceInvestigationType_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "companies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceInvestigationType_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "company"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceInvestigationType_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "customFieldTables"
+ referencedColumns: ["companyId"]
+ },
+ {
+ foreignKeyName: "nonConformanceInvestigationType_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "integrations"
+ referencedColumns: ["companyId"]
+ },
+ {
+ foreignKeyName: "nonConformanceInvestigationType_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceInvestigationType_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeesAcrossCompanies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceInvestigationType_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceInvestigationType_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceInvestigationType_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ {
+ foreignKeyName: "nonConformanceInvestigationType_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceInvestigationType_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeesAcrossCompanies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceInvestigationType_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceInvestigationType_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceInvestigationType_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ ]
+ }
nonConformanceJobOperation: {
Row: {
companyId: string
@@ -15485,6 +15612,141 @@ export type Database = {
},
]
}
+ nonConformanceRequiredAction: {
+ Row: {
+ active: boolean
+ companyId: string
+ createdAt: string
+ createdBy: string
+ id: string
+ name: string
+ sortOrder: number
+ updatedAt: string | null
+ updatedBy: string | null
+ }
+ Insert: {
+ active?: boolean
+ companyId: string
+ createdAt?: string
+ createdBy: string
+ id?: string
+ name: string
+ sortOrder?: number
+ updatedAt?: string | null
+ updatedBy?: string | null
+ }
+ Update: {
+ active?: boolean
+ companyId?: string
+ createdAt?: string
+ createdBy?: string
+ id?: string
+ name?: string
+ sortOrder?: number
+ updatedAt?: string | null
+ updatedBy?: string | null
+ }
+ Relationships: [
+ {
+ foreignKeyName: "nonConformanceRequiredAction_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "companies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceRequiredAction_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "company"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceRequiredAction_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "customFieldTables"
+ referencedColumns: ["companyId"]
+ },
+ {
+ foreignKeyName: "nonConformanceRequiredAction_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "integrations"
+ referencedColumns: ["companyId"]
+ },
+ {
+ foreignKeyName: "nonConformanceRequiredAction_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceRequiredAction_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeesAcrossCompanies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceRequiredAction_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceRequiredAction_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceRequiredAction_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ {
+ foreignKeyName: "nonConformanceRequiredAction_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceRequiredAction_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeesAcrossCompanies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceRequiredAction_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceRequiredAction_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceRequiredAction_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ ]
+ }
nonConformanceReviewer: {
Row: {
assignee: string | null
@@ -16485,14 +16747,10 @@ export type Database = {
createdBy: string
description: string | null
id: string
- investigationTypes:
- | Database["public"]["Enums"]["nonConformanceInvestigation"][]
- | null
+ investigationTypeIds: string[] | null
name: string
priority: Database["public"]["Enums"]["nonConformancePriority"]
- requiredActions:
- | Database["public"]["Enums"]["nonConformanceAction"][]
- | null
+ requiredActionIds: string[] | null
source: Database["public"]["Enums"]["nonConformanceSource"]
tags: string[] | null
updatedAt: string | null
@@ -16509,14 +16767,10 @@ export type Database = {
createdBy: string
description?: string | null
id?: string
- investigationTypes?:
- | Database["public"]["Enums"]["nonConformanceInvestigation"][]
- | null
+ investigationTypeIds?: string[] | null
name: string
priority?: Database["public"]["Enums"]["nonConformancePriority"]
- requiredActions?:
- | Database["public"]["Enums"]["nonConformanceAction"][]
- | null
+ requiredActionIds?: string[] | null
source?: Database["public"]["Enums"]["nonConformanceSource"]
tags?: string[] | null
updatedAt?: string | null
@@ -16533,14 +16787,10 @@ export type Database = {
createdBy?: string
description?: string | null
id?: string
- investigationTypes?:
- | Database["public"]["Enums"]["nonConformanceInvestigation"][]
- | null
+ investigationTypeIds?: string[] | null
name?: string
priority?: Database["public"]["Enums"]["nonConformancePriority"]
- requiredActions?:
- | Database["public"]["Enums"]["nonConformanceAction"][]
- | null
+ requiredActionIds?: string[] | null
source?: Database["public"]["Enums"]["nonConformanceSource"]
tags?: string[] | null
updatedAt?: string | null
@@ -39297,14 +39547,14 @@ export type Database = {
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["id"]
+ columns: ["supplierLocationId"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["supplierLocationId"]
+ columns: ["id"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
@@ -40665,14 +40915,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["supplierCountryCode"]
+ columns: ["customerCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["customerCountryCode"]
+ columns: ["supplierCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
@@ -41046,7 +41296,8 @@ export type Database = {
}
qualityActions: {
Row: {
- actionType: Database["public"]["Enums"]["nonConformanceAction"] | null
+ actionType: string | null
+ actionTypeId: string | null
assignee: string | null
companyId: string | null
completedDate: string | null
@@ -41108,6 +41359,13 @@ export type Database = {
referencedRelation: "tools"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "nonConformanceActionTask_actionTypeId_fkey"
+ columns: ["actionTypeId"]
+ isOneToOne: false
+ referencedRelation: "nonConformanceRequiredAction"
+ referencedColumns: ["id"]
+ },
{
foreignKeyName: "nonConformanceActionTask_assignee_fkey"
columns: ["assignee"]
diff --git a/packages/database/supabase/functions/create/index.ts b/packages/database/supabase/functions/create/index.ts
index db2f1d1266..570c1b4d41 100644
--- a/packages/database/supabase/functions/create/index.ts
+++ b/packages/database/supabase/functions/create/index.ts
@@ -198,17 +198,19 @@ serve(async (req: Request) => {
const approvalTasksToDelete: string[] = [];
const reviewersToDelete: string[] = [];
- Object.keys(currentInvestigationTasks).forEach((investigationTypeId) => {
- if (
- !(nonConformance.data?.investigationTypeIds ?? []).some(
- (d) => d === investigationTypeId
- )
- ) {
- investigationTasksToDelete.push(
- currentInvestigationTasks[investigationTypeId]
- );
+ Object.keys(currentInvestigationTasks).forEach(
+ (investigationTypeId) => {
+ if (
+ !(nonConformance.data?.investigationTypeIds ?? []).some(
+ (d) => d === investigationTypeId
+ )
+ ) {
+ investigationTasksToDelete.push(
+ currentInvestigationTasks[investigationTypeId]
+ );
+ }
}
- });
+ );
Object.keys(currentActionTasks).forEach((actionTypeId) => {
if (
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index 486b22b0de..de065d760f 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -13897,9 +13897,7 @@ export type Database = {
description: string | null
dueDate: string | null
id: string
- investigationTypes:
- | Database["public"]["Enums"]["nonConformanceInvestigation"][]
- | null
+ investigationTypeIds: string[] | null
itemId: string | null
locationId: string
name: string
@@ -13909,9 +13907,7 @@ export type Database = {
openDate: string
priority: Database["public"]["Enums"]["nonConformancePriority"] | null
quantity: number
- requiredActions:
- | Database["public"]["Enums"]["nonConformanceAction"][]
- | null
+ requiredActionIds: string[] | null
source: Database["public"]["Enums"]["nonConformanceSource"]
status: Database["public"]["Enums"]["nonConformanceStatus"]
tags: string[] | null
@@ -13932,9 +13928,7 @@ export type Database = {
description?: string | null
dueDate?: string | null
id?: string
- investigationTypes?:
- | Database["public"]["Enums"]["nonConformanceInvestigation"][]
- | null
+ investigationTypeIds?: string[] | null
itemId?: string | null
locationId: string
name: string
@@ -13946,9 +13940,7 @@ export type Database = {
| Database["public"]["Enums"]["nonConformancePriority"]
| null
quantity?: number
- requiredActions?:
- | Database["public"]["Enums"]["nonConformanceAction"][]
- | null
+ requiredActionIds?: string[] | null
source: Database["public"]["Enums"]["nonConformanceSource"]
status?: Database["public"]["Enums"]["nonConformanceStatus"]
tags?: string[] | null
@@ -13969,9 +13961,7 @@ export type Database = {
description?: string | null
dueDate?: string | null
id?: string
- investigationTypes?:
- | Database["public"]["Enums"]["nonConformanceInvestigation"][]
- | null
+ investigationTypeIds?: string[] | null
itemId?: string | null
locationId?: string
name?: string
@@ -13983,9 +13973,7 @@ export type Database = {
| Database["public"]["Enums"]["nonConformancePriority"]
| null
quantity?: number
- requiredActions?:
- | Database["public"]["Enums"]["nonConformanceAction"][]
- | null
+ requiredActionIds?: string[] | null
source?: Database["public"]["Enums"]["nonConformanceSource"]
status?: Database["public"]["Enums"]["nonConformanceStatus"]
tags?: string[] | null
@@ -14186,7 +14174,7 @@ export type Database = {
}
nonConformanceActionTask: {
Row: {
- actionType: Database["public"]["Enums"]["nonConformanceAction"] | null
+ actionTypeId: string | null
assignee: string | null
companyId: string
completedDate: string | null
@@ -14203,9 +14191,7 @@ export type Database = {
updatedBy: string | null
}
Insert: {
- actionType?:
- | Database["public"]["Enums"]["nonConformanceAction"]
- | null
+ actionTypeId?: string | null
assignee?: string | null
companyId: string
completedDate?: string | null
@@ -14222,9 +14208,7 @@ export type Database = {
updatedBy?: string | null
}
Update: {
- actionType?:
- | Database["public"]["Enums"]["nonConformanceAction"]
- | null
+ actionTypeId?: string | null
assignee?: string | null
companyId?: string
completedDate?: string | null
@@ -14241,6 +14225,13 @@ export type Database = {
updatedBy?: string | null
}
Relationships: [
+ {
+ foreignKeyName: "nonConformanceActionTask_actionTypeId_fkey"
+ columns: ["actionTypeId"]
+ isOneToOne: false
+ referencedRelation: "nonConformanceRequiredAction"
+ referencedColumns: ["id"]
+ },
{
foreignKeyName: "nonConformanceActionTask_assignee_fkey"
columns: ["assignee"]
@@ -14753,9 +14744,7 @@ export type Database = {
createdBy: string
dueDate: string | null
id: string
- investigationType:
- | Database["public"]["Enums"]["nonConformanceInvestigation"]
- | null
+ investigationTypeId: string | null
nonConformanceId: string
notes: Json
sortOrder: number
@@ -14772,9 +14761,7 @@ export type Database = {
createdBy: string
dueDate?: string | null
id?: string
- investigationType?:
- | Database["public"]["Enums"]["nonConformanceInvestigation"]
- | null
+ investigationTypeId?: string | null
nonConformanceId: string
notes?: Json
sortOrder?: number
@@ -14791,9 +14778,7 @@ export type Database = {
createdBy?: string
dueDate?: string | null
id?: string
- investigationType?:
- | Database["public"]["Enums"]["nonConformanceInvestigation"]
- | null
+ investigationTypeId?: string | null
nonConformanceId?: string
notes?: Json
sortOrder?: number
@@ -14901,6 +14886,13 @@ export type Database = {
referencedRelation: "userDefaults"
referencedColumns: ["userId"]
},
+ {
+ foreignKeyName: "nonConformanceInvestigationTask_investigationTypeId_fkey"
+ columns: ["investigationTypeId"]
+ isOneToOne: false
+ referencedRelation: "nonConformanceInvestigationType"
+ referencedColumns: ["id"]
+ },
{
foreignKeyName: "nonConformanceInvestigationTask_nonConformanceId_fkey"
columns: ["nonConformanceId"]
@@ -14945,6 +14937,141 @@ export type Database = {
},
]
}
+ nonConformanceInvestigationType: {
+ Row: {
+ active: boolean
+ companyId: string
+ createdAt: string
+ createdBy: string
+ id: string
+ name: string
+ sortOrder: number
+ updatedAt: string | null
+ updatedBy: string | null
+ }
+ Insert: {
+ active?: boolean
+ companyId: string
+ createdAt?: string
+ createdBy: string
+ id?: string
+ name: string
+ sortOrder?: number
+ updatedAt?: string | null
+ updatedBy?: string | null
+ }
+ Update: {
+ active?: boolean
+ companyId?: string
+ createdAt?: string
+ createdBy?: string
+ id?: string
+ name?: string
+ sortOrder?: number
+ updatedAt?: string | null
+ updatedBy?: string | null
+ }
+ Relationships: [
+ {
+ foreignKeyName: "nonConformanceInvestigationType_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "companies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceInvestigationType_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "company"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceInvestigationType_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "customFieldTables"
+ referencedColumns: ["companyId"]
+ },
+ {
+ foreignKeyName: "nonConformanceInvestigationType_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "integrations"
+ referencedColumns: ["companyId"]
+ },
+ {
+ foreignKeyName: "nonConformanceInvestigationType_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceInvestigationType_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeesAcrossCompanies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceInvestigationType_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceInvestigationType_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceInvestigationType_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ {
+ foreignKeyName: "nonConformanceInvestigationType_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceInvestigationType_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeesAcrossCompanies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceInvestigationType_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceInvestigationType_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceInvestigationType_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ ]
+ }
nonConformanceJobOperation: {
Row: {
companyId: string
@@ -15485,6 +15612,141 @@ export type Database = {
},
]
}
+ nonConformanceRequiredAction: {
+ Row: {
+ active: boolean
+ companyId: string
+ createdAt: string
+ createdBy: string
+ id: string
+ name: string
+ sortOrder: number
+ updatedAt: string | null
+ updatedBy: string | null
+ }
+ Insert: {
+ active?: boolean
+ companyId: string
+ createdAt?: string
+ createdBy: string
+ id?: string
+ name: string
+ sortOrder?: number
+ updatedAt?: string | null
+ updatedBy?: string | null
+ }
+ Update: {
+ active?: boolean
+ companyId?: string
+ createdAt?: string
+ createdBy?: string
+ id?: string
+ name?: string
+ sortOrder?: number
+ updatedAt?: string | null
+ updatedBy?: string | null
+ }
+ Relationships: [
+ {
+ foreignKeyName: "nonConformanceRequiredAction_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "companies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceRequiredAction_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "company"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceRequiredAction_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "customFieldTables"
+ referencedColumns: ["companyId"]
+ },
+ {
+ foreignKeyName: "nonConformanceRequiredAction_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "integrations"
+ referencedColumns: ["companyId"]
+ },
+ {
+ foreignKeyName: "nonConformanceRequiredAction_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceRequiredAction_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeesAcrossCompanies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceRequiredAction_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceRequiredAction_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceRequiredAction_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ {
+ foreignKeyName: "nonConformanceRequiredAction_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceRequiredAction_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeesAcrossCompanies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceRequiredAction_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceRequiredAction_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "nonConformanceRequiredAction_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ ]
+ }
nonConformanceReviewer: {
Row: {
assignee: string | null
@@ -16485,14 +16747,10 @@ export type Database = {
createdBy: string
description: string | null
id: string
- investigationTypes:
- | Database["public"]["Enums"]["nonConformanceInvestigation"][]
- | null
+ investigationTypeIds: string[] | null
name: string
priority: Database["public"]["Enums"]["nonConformancePriority"]
- requiredActions:
- | Database["public"]["Enums"]["nonConformanceAction"][]
- | null
+ requiredActionIds: string[] | null
source: Database["public"]["Enums"]["nonConformanceSource"]
tags: string[] | null
updatedAt: string | null
@@ -16509,14 +16767,10 @@ export type Database = {
createdBy: string
description?: string | null
id?: string
- investigationTypes?:
- | Database["public"]["Enums"]["nonConformanceInvestigation"][]
- | null
+ investigationTypeIds?: string[] | null
name: string
priority?: Database["public"]["Enums"]["nonConformancePriority"]
- requiredActions?:
- | Database["public"]["Enums"]["nonConformanceAction"][]
- | null
+ requiredActionIds?: string[] | null
source?: Database["public"]["Enums"]["nonConformanceSource"]
tags?: string[] | null
updatedAt?: string | null
@@ -16533,14 +16787,10 @@ export type Database = {
createdBy?: string
description?: string | null
id?: string
- investigationTypes?:
- | Database["public"]["Enums"]["nonConformanceInvestigation"][]
- | null
+ investigationTypeIds?: string[] | null
name?: string
priority?: Database["public"]["Enums"]["nonConformancePriority"]
- requiredActions?:
- | Database["public"]["Enums"]["nonConformanceAction"][]
- | null
+ requiredActionIds?: string[] | null
source?: Database["public"]["Enums"]["nonConformanceSource"]
tags?: string[] | null
updatedAt?: string | null
@@ -39297,14 +39547,14 @@ export type Database = {
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["id"]
+ columns: ["supplierLocationId"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["supplierLocationId"]
+ columns: ["id"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
@@ -40665,14 +40915,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["supplierCountryCode"]
+ columns: ["customerCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["customerCountryCode"]
+ columns: ["supplierCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
@@ -41046,7 +41296,8 @@ export type Database = {
}
qualityActions: {
Row: {
- actionType: Database["public"]["Enums"]["nonConformanceAction"] | null
+ actionType: string | null
+ actionTypeId: string | null
assignee: string | null
companyId: string | null
completedDate: string | null
@@ -41108,6 +41359,13 @@ export type Database = {
referencedRelation: "tools"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "nonConformanceActionTask_actionTypeId_fkey"
+ columns: ["actionTypeId"]
+ isOneToOne: false
+ referencedRelation: "nonConformanceRequiredAction"
+ referencedColumns: ["id"]
+ },
{
foreignKeyName: "nonConformanceActionTask_assignee_fkey"
columns: ["assignee"]
diff --git a/packages/database/supabase/migrations/20250806000000_custom-investigation-types-and-actions.sql b/packages/database/supabase/migrations/20250806000000_custom-investigation-types-and-actions.sql
index ac181ecc9b..2c789f1c49 100644
--- a/packages/database/supabase/migrations/20250806000000_custom-investigation-types-and-actions.sql
+++ b/packages/database/supabase/migrations/20250806000000_custom-investigation-types-and-actions.sql
@@ -1,10 +1,9 @@
-- Create custom investigation types table
CREATE TABLE "nonConformanceInvestigationType" (
- "id" TEXT NOT NULL DEFAULT xid(),
+ "id" TEXT NOT NULL DEFAULT id("nct"),
"companyId" TEXT NOT NULL,
"name" TEXT NOT NULL,
"active" BOOLEAN NOT NULL DEFAULT true,
- "sortOrder" INTEGER NOT NULL DEFAULT 1,
"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL,
"createdBy" TEXT NOT NULL,
"updatedAt" TIMESTAMP WITH TIME ZONE,
@@ -19,11 +18,10 @@ CREATE TABLE "nonConformanceInvestigationType" (
-- Create custom required actions table
CREATE TABLE "nonConformanceRequiredAction" (
- "id" TEXT NOT NULL DEFAULT xid(),
+ "id" TEXT NOT NULL DEFAULT id("nca"),
"companyId" TEXT NOT NULL,
"name" TEXT NOT NULL,
"active" BOOLEAN NOT NULL DEFAULT true,
- "sortOrder" INTEGER NOT NULL DEFAULT 1,
"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL,
"createdBy" TEXT NOT NULL,
"updatedAt" TIMESTAMP WITH TIME ZONE,
@@ -38,9 +36,7 @@ CREATE TABLE "nonConformanceRequiredAction" (
-- Create indexes
CREATE INDEX "nonConformanceInvestigationType_companyId_idx" ON "nonConformanceInvestigationType" ("companyId");
-CREATE INDEX "nonConformanceInvestigationType_sortOrder_idx" ON "nonConformanceInvestigationType" ("sortOrder");
CREATE INDEX "nonConformanceRequiredAction_companyId_idx" ON "nonConformanceRequiredAction" ("companyId");
-CREATE INDEX "nonConformanceRequiredAction_sortOrder_idx" ON "nonConformanceRequiredAction" ("sortOrder");
-- RLS policies for nonConformanceInvestigationType
CREATE POLICY "SELECT" ON "public"."nonConformanceInvestigationType"
@@ -129,37 +125,39 @@ ALTER TABLE "nonConformanceInvestigationType" ENABLE ROW LEVEL SECURITY;
ALTER TABLE "nonConformanceRequiredAction" ENABLE ROW LEVEL SECURITY;
-- Populate all existing companies with default investigation types
-INSERT INTO "nonConformanceInvestigationType" ("companyId", "name", "sortOrder", "createdBy")
+INSERT INTO "nonConformanceInvestigationType" ("companyId", "name", "createdBy")
SELECT
c."id" as "companyId",
inv_type.name,
- inv_type.sort_order,
'system' as "createdBy"
FROM "company" c
CROSS JOIN (
VALUES
- ('Root Cause Analysis', 1),
- ('Inventory', 2),
- ('WIP', 3),
- ('Finished Goods', 4),
- ('Incoming Materials', 5),
- ('Process', 6),
- ('Documentation', 7)
-) AS inv_type(name, sort_order);
+ ('Root Cause Analysis'),
+ ('Inventory'),
+ ('WIP'),
+ ('Finished Goods'),
+ ('Incoming Materials'),
+ ('Process'),
+ ('Documentation')
+) AS inv_type(name);
-- Populate all existing companies with default required actions
-INSERT INTO "nonConformanceRequiredAction" ("companyId", "name", "sortOrder", "createdBy")
+INSERT INTO "nonConformanceRequiredAction" ("companyId", "name", "createdBy")
SELECT
c."id" as "companyId",
action_type.name,
- action_type.sort_order,
'system' as "createdBy"
FROM "company" c
CROSS JOIN (
VALUES
- ('Corrective Action', 1),
- ('Preventive Action', 2),
- ('Containment Action', 3),
- ('Verification', 4),
- ('Customer Communication', 5)
-) AS action_type(name, sort_order);
\ No newline at end of file
+ ('Corrective Action'),
+ ('Preventive Action'),
+ ('Containment Action'),
+ ('Verification'),
+ ('Customer Communication')
+) AS action_type(name);
+
+-- Add investigation type IDs and required action IDs to workflow table
+ALTER TABLE "nonConformanceWorkflow" ADD COLUMN "investigationTypeIds" TEXT[];
+ALTER TABLE "nonConformanceWorkflow" ADD COLUMN "requiredActionIds" TEXT[];
\ No newline at end of file
diff --git a/packages/database/supabase/migrations/20250806000001_update-schema-custom-types.sql b/packages/database/supabase/migrations/20250806000001_update-schema-custom-types.sql
index c74cecd0e2..b2ff465272 100644
--- a/packages/database/supabase/migrations/20250806000001_update-schema-custom-types.sql
+++ b/packages/database/supabase/migrations/20250806000001_update-schema-custom-types.sql
@@ -3,6 +3,10 @@ ALTER TABLE "nonConformance"
ADD COLUMN "investigationTypeIds" TEXT[] DEFAULT ARRAY[]::TEXT[],
ADD COLUMN "requiredActionIds" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "nonConformanceWorkflow"
+ADD COLUMN "investigationTypeIds" TEXT[] DEFAULT ARRAY[]::TEXT[],
+ADD COLUMN "requiredActionIds" TEXT[] DEFAULT ARRAY[]::TEXT[];
+
-- Add new foreign key columns to task tables
ALTER TABLE "nonConformanceInvestigationTask"
ADD COLUMN "investigationTypeId" TEXT;
@@ -28,17 +32,17 @@ UPDATE "nonConformance"
SET "investigationTypeIds" = (
SELECT ARRAY_AGG(ict."id")
FROM UNNEST("investigationTypes") AS inv_type(name)
- JOIN "nonConformanceInvestigationType" ict ON ict."name" = inv_type.name AND ict."companyId" = "nonConformance"."companyId"
+ JOIN "nonConformanceInvestigationType" ict ON ict."name" = inv_type.name::text AND ict."companyId" = "nonConformance"."companyId"
)
WHERE "investigationTypes" IS NOT NULL AND ARRAY_LENGTH("investigationTypes", 1) > 0;
UPDATE "nonConformance"
SET "requiredActionIds" = (
SELECT ARRAY_AGG(rac."id")
- FROM UNNEST("requiredActions") AS req_action(name)
- JOIN "nonConformanceRequiredAction" rac ON rac."name" = req_action.name AND rac."companyId" = "nonConformance"."companyId"
+ FROM UNNEST("requiredActionTypes") AS req_action(name)
+ JOIN "nonConformanceRequiredAction" rac ON rac."name" = req_action.name::text AND rac."companyId" = "nonConformance"."companyId"
)
-WHERE "requiredActions" IS NOT NULL AND ARRAY_LENGTH("requiredActions", 1) > 0;
+WHERE "requiredActionTypes" IS NOT NULL AND ARRAY_LENGTH("requiredActionTypes", 1) > 0;
-- Migrate existing data from ENUM to foreign key in investigation task table
UPDATE "nonConformanceInvestigationTask"
@@ -52,6 +56,51 @@ WHERE ict."name" = "nonConformanceInvestigationTask"."investigationType"::text
UPDATE "nonConformanceActionTask"
SET "actionTypeId" = rac."id"
FROM "nonConformanceRequiredAction" rac
-WHERE rac."name" = "nonConformanceActionTask"."actionType"::text
+WHERE rac."name" = "nonConformanceActionTask"."requiredActionType"::text
AND rac."companyId" = "nonConformanceActionTask"."companyId"
- AND "nonConformanceActionTask"."actionType" IS NOT NULL;
\ No newline at end of file
+ AND "nonConformanceActionTask"."requiredActionType" IS NOT NULL;
+
+-- Migrate existing workflow data from ENUM arrays to foreign key arrays
+UPDATE "nonConformanceWorkflow"
+SET "investigationTypeIds" = (
+ SELECT ARRAY_AGG(ict."id")
+ FROM UNNEST("investigationTypes") AS inv_type(name)
+ JOIN "nonConformanceInvestigationType" ict ON ict."name" = inv_type.name::text AND ict."companyId" = "nonConformanceWorkflow"."companyId"
+)
+WHERE "investigationTypes" IS NOT NULL AND ARRAY_LENGTH("investigationTypes", 1) > 0;
+
+UPDATE "nonConformanceWorkflow"
+SET "requiredActionIds" = (
+ SELECT ARRAY_AGG(rac."id")
+ FROM UNNEST("requiredActions") AS req_action(name)
+ JOIN "nonConformanceRequiredAction" rac ON rac."name" = req_action.name::text AND rac."companyId" = "nonConformanceWorkflow"."companyId"
+)
+WHERE "requiredActions" IS NOT NULL AND ARRAY_LENGTH("requiredActions", 1) > 0;
+
+DROP VIEW IF EXISTS "qualityActions";
+
+ALTER TABLE "nonConformanceInvestigationTask" DROP COLUMN "investigationType";
+ALTER TABLE "nonConformanceActionTask" DROP COLUMN "requiredActionType";
+
+ALTER TABLE "nonConformance" DROP COLUMN "investigationTypes";
+ALTER TABLE "nonConformance" DROP COLUMN "requiredActionTypes";
+ALTER TABLE "nonConformanceWorkflow" DROP COLUMN "investigationTypes";
+ALTER TABLE "nonConformanceWorkflow" DROP COLUMN "requiredActions";
+
+DROP VIEW IF EXISTS "qualityActions";
+CREATE OR REPLACE VIEW "qualityActions" WITH(SECURITY_INVOKER=true) AS
+ SELECT
+ "nonConformanceActionTask".*,
+ "nonConformanceRequiredAction"."name" AS "actionType",
+ "nonConformance"."nonConformanceId" AS "readableNonConformanceId",
+ "nonConformance"."name" AS "nonConformanceName",
+ "nonConformance"."status" AS "nonConformanceStatus",
+ "nonConformance"."openDate" AS "nonConformanceOpenDate",
+ "nonConformance"."dueDate" AS "nonConformanceDueDate",
+ "nonConformance"."closeDate" AS "nonConformanceCloseDate",
+ "nonConformance"."itemId" AS "nonConformanceItemId",
+ "nonConformanceType"."name" AS "nonConformanceTypeName"
+ FROM "nonConformanceActionTask"
+ INNER JOIN "nonConformance" ON "nonConformanceActionTask"."nonConformanceId" = "nonConformance"."id"
+ LEFT JOIN "nonConformanceRequiredAction" ON "nonConformanceRequiredAction"."id" = "nonConformanceActionTask"."actionTypeId"
+ LEFT JOIN "nonConformanceType" ON "nonConformance"."nonConformanceTypeId" = "nonConformanceType"."id";
\ No newline at end of file
diff --git a/packages/form/src/components/MultiSelect.tsx b/packages/form/src/components/MultiSelect.tsx
index 89cf5296c0..0c92e2438f 100644
--- a/packages/form/src/components/MultiSelect.tsx
+++ b/packages/form/src/components/MultiSelect.tsx
@@ -40,15 +40,19 @@ const MultiSelectPreview = (
{value.length} selected
</Badge>
) : (
- value.sort().map((label: string) => (
- <Badge
- className="max-w-[160px] truncate border dark:border-none dark:shadow-button-base"
- key={label}
- variant="secondary"
- >
- {label}
- </Badge>
- ))
+ value.sort().map((val: string) => {
+ const option = options.find((opt) => opt.value === val);
+ const label = option ? option.label : val;
+ return (
+ <Badge
+ className="max-w-[160px] truncate border dark:border-none dark:shadow-button-base"
+ key={val}
+ variant="secondary"
+ >
+ {label}
+ </Badge>
+ );
+ })
)}
</div>
);
@@ -76,7 +80,7 @@ const MultiSelect = ({
return (
<FormControl isInvalid={!!error}>
{label && <FormLabel htmlFor={name}>{label}</FormLabel>}
- {value.filter(Boolean).map((selection, index) => (
+ {value?.filter(Boolean).map((selection, index) => (
<input
key={`${name}[${index}]`}
type="hidden"
@@ -87,7 +91,7 @@ const MultiSelect = ({
<MultiSelectBase
{...props}
- value={value.filter(Boolean)}
+ value={value?.filter(Boolean)}
inline={props.inline ? MultiSelectPreview : undefined}
onChange={(newValue) => {
setValue(newValue ?? []);