diff --git a/apps/web/app/(app)/[emailAccountId]/assistant/RuleForm.tsx b/apps/web/app/(app)/[emailAccountId]/assistant/RuleForm.tsx index df6496d438..8232efc3e2 100644 --- a/apps/web/app/(app)/[emailAccountId]/assistant/RuleForm.tsx +++ b/apps/web/app/(app)/[emailAccountId]/assistant/RuleForm.tsx @@ -64,9 +64,7 @@ import { DropdownMenuRadioItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; -import { LearnedPatterns } from "@/app/(app)/[emailAccountId]/assistant/group/LearnedPatterns"; -import { Tooltip } from "@/components/Tooltip"; -import { createGroupAction } from "@/utils/actions/group"; +import { LearnedPatternsDialog } from "@/app/(app)/[emailAccountId]/assistant/group/LearnedPatterns"; import { NEEDS_REPLY_LABEL_NAME } from "@/utils/reply-tracker/consts"; import { Badge } from "@/components/Badge"; import { useAccount } from "@/providers/EmailAccountProvider"; @@ -300,11 +298,6 @@ export function RuleForm({ ]; }, [digestEnabled]); - const [learnedPatternGroupId, setLearnedPatternGroupId] = useState( - rule.groupId, - ); - const [showLearnedPatterns, setShowLearnedPatterns] = useState(false); - const [isNameEditMode, setIsNameEditMode] = useState(alwaysEditMode); const [isConditionsEditMode, setIsConditionsEditMode] = useState(alwaysEditMode); @@ -401,40 +394,6 @@ export function RuleForm({ )} - {!!rule.id && ( - - { - if (!rule.id) return; - - setShowLearnedPatterns((b) => !b); - if (learnedPatternGroupId) return; - - const result = await createGroupAction(emailAccountId, { - ruleId: rule.id, - }); - - if (result?.serverError) { - toastError({ description: result.serverError }); - } else if (!result?.data?.groupId) { - toastError({ - description: - "There was an error setting up learned patterns.", - }); - } else { - setLearnedPatternGroupId(result.data.groupId); - setShowLearnedPatterns(true); - } - }} - > - - - - )} - {!alwaysEditMode && ( )} - {showLearnedPatterns && learnedPatternGroupId && ( - - - - )} - Actions {!alwaysEditMode && ( @@ -896,6 +849,15 @@ export function RuleForm({ /> + {!!rule.id && ( + + + + )} + {rule.id && ( (groupId); + + const { execute, isExecuting } = useAction( + createGroupAction.bind(null, emailAccountId), + { + onSuccess: (data) => { + if (data.data?.groupId) { + setLearnedPatternGroupId(data.data.groupId); + } else { + toastError({ + description: "There was an error setting up learned patterns.", + }); + } + }, + onError: (error) => { + toastError({ + description: error.error.serverError || "Unknown error", + }); + }, + }, + ); return ( - - - - - Learned Patterns - - - - - - - - - - - + + + { + if (!ruleId) return; + + if (groupId) return; + + execute({ ruleId }); + }} + > + View learned patterns + + + + + + Learned Patterns + + Learned patterns are patterns that the AI has learned from your + email history. When a learned pattern is matched other rules + conditions are skipped and this rule is automatically selected. + + + + {isExecuting ? ( + + ) : ( + learnedPatternGroupId && + )} + + ); } diff --git a/apps/web/utils/actions/group.validation.ts b/apps/web/utils/actions/group.validation.ts index 0f1b3dcbef..db882a6293 100644 --- a/apps/web/utils/actions/group.validation.ts +++ b/apps/web/utils/actions/group.validation.ts @@ -2,7 +2,7 @@ import { z } from "zod"; import { GroupItemType } from "@prisma/client"; export const createGroupBody = z.object({ - ruleId: z.string(), + ruleId: z.string().min(1, "Rule ID is required"), }); export type CreateGroupBody = z.infer; diff --git a/version.txt b/version.txt index 3b816664cd..7e96cbf1f7 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -v1.9.10 \ No newline at end of file +v1.9.11 \ No newline at end of file