diff --git a/apps/web/app/(app)/automation/RuleForm.tsx b/apps/web/app/(app)/automation/RuleForm.tsx index 4987ad64..f99ec569 100644 --- a/apps/web/app/(app)/automation/RuleForm.tsx +++ b/apps/web/app/(app)/automation/RuleForm.tsx @@ -28,7 +28,7 @@ import { SectionDescription, TypographyH3, } from "@/components/Typography"; -import { ActionType, type CategoryFilterType, RuleType } from "@prisma/client"; +import { ActionType, CategoryFilterType, RuleType } from "@prisma/client"; import { createRuleAction, updateRuleAction } from "@/utils/actions/rule"; import { type CreateRuleBody, @@ -163,8 +163,6 @@ export function RuleForm({ rule }: { rule: CreateRuleBody & { id?: string } }) { return unusedCondition; }, [conditions]); - console.log("errors", errors); - // biome-ignore lint/correctness/useExhaustiveDependencies: useEffect(() => { trigger("conditions"); @@ -314,7 +312,7 @@ export function RuleForm({ rule }: { rule: CreateRuleBody & { id?: string } }) { <>
- +
- +
@@ -682,9 +686,6 @@ function GroupsTab(props: { {...props.registerProps} // TODO: fix this // error={props.errors.groupId} - // error={ - // errors.conditions?.[index]?.type as FieldError | undefined - // } />
)} diff --git a/apps/web/utils/actions/rule.ts b/apps/web/utils/actions/rule.ts index f8773152..be7530d7 100644 --- a/apps/web/utils/actions/rule.ts +++ b/apps/web/utils/actions/rule.ts @@ -35,7 +35,6 @@ export const createRuleAction = withActionInstrumentation( const rule = await prisma.rule.create({ data: { name: body.name || "", - instructions: body.instructions || "", automate: body.automate ?? undefined, runOnThreads: body.runOnThreads ?? undefined, actions: body.actions @@ -58,6 +57,8 @@ export const createRuleAction = withActionInstrumentation( } : undefined, userId: session.user.id, + // conditions + instructions: conditions.instructions || null, from: conditions.from || null, to: conditions.to || null, subject: conditions.subject || null, @@ -119,10 +120,11 @@ export const updateRuleAction = withActionInstrumentation( prisma.rule.update({ where: { id: body.id, userId: session.user.id }, data: { - instructions: body.instructions || "", automate: body.automate ?? undefined, runOnThreads: body.runOnThreads ?? undefined, name: body.name || undefined, + // conditions + instructions: conditions.instructions || null, from: conditions.from || null, to: conditions.to || null, subject: conditions.subject || null, diff --git a/apps/web/utils/actions/validation.ts b/apps/web/utils/actions/validation.ts index c2ea43e0..1acd45cc 100644 --- a/apps/web/utils/actions/validation.ts +++ b/apps/web/utils/actions/validation.ts @@ -58,17 +58,14 @@ export const zodRuleType = z.enum([ ]); const zodAiCondition = z.object({ - type: z.literal(RuleType.AI), - instructions: z.string(), + instructions: z.string().nullish(), }); const zodGroupCondition = z.object({ - type: z.literal(RuleType.GROUP), - groupId: z.string(), + groupId: z.string().nullish(), }); const zodStaticCondition = z.object({ - type: z.literal(RuleType.STATIC), to: z.string().nullish(), from: z.string().nullish(), subject: z.string().nullish(), @@ -76,19 +73,19 @@ const zodStaticCondition = z.object({ }); const zodCategoryCondition = z.object({ - type: z.literal(RuleType.CATEGORY), categoryFilterType: z .enum([CategoryFilterType.INCLUDE, CategoryFilterType.EXCLUDE]) .nullish(), categoryFilters: z.array(z.string()).nullish(), }); -const zodCondition = z.union([ - zodAiCondition, - zodGroupCondition, - zodStaticCondition, - zodCategoryCondition, -]); +const zodCondition = z.object({ + type: zodRuleType, + ...zodAiCondition.shape, + ...zodGroupCondition.shape, + ...zodStaticCondition.shape, + ...zodCategoryCondition.shape, +}); export type ZodCondition = z.infer; export const createRuleBody = z.object({ diff --git a/apps/web/utils/condition.ts b/apps/web/utils/condition.ts index 6b58c3c1..ae2e2e23 100644 --- a/apps/web/utils/condition.ts +++ b/apps/web/utils/condition.ts @@ -114,7 +114,7 @@ const staticEmptyCondition = { const categoryEmptyCondition = { type: RuleType.CATEGORY, - categoryFilterType: CategoryFilterType.INCLUDE, + categoryFilterType: null, categoryFilters: null, };