From 5a5587c2a1c4954416e4d956045cdec05bd65509 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Thu, 16 Apr 2026 22:03:24 -0400 Subject: [PATCH] refactor(automation): use Modal for RuleFormModal --- .../components/automation/RuleEditor.tsx | 50 ++++++++----------- 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/src/renderer/components/automation/RuleEditor.tsx b/src/renderer/components/automation/RuleEditor.tsx index 0b36748d..f14caece 100644 --- a/src/renderer/components/automation/RuleEditor.tsx +++ b/src/renderer/components/automation/RuleEditor.tsx @@ -1,9 +1,8 @@ import { useCallback, useEffect, useState } from "react" -import { motion } from "framer-motion" -import { Gear, Lightning, X } from "@phosphor-icons/react" +import { Gear, Lightning } from "@phosphor-icons/react" import type { AutomationAction, AutomationRuleRecord, AutomationTrigger, DepartmentId } from "@shared/types" -import { ActionButton, Select, useFocusTrap } from "../ui" -import { ACCENT, LINE, triggerConfig, actionConfig, departmentOptions, safeJsonStringify } from "./automation-config" +import { ActionButton, Modal, Select } from "../ui" +import { triggerConfig, actionConfig, departmentOptions, safeJsonStringify } from "./automation-config" interface RuleFormState { name: string; description: string; trigger: AutomationTrigger; conditionsJson: string; action: AutomationAction; actionConfigJson: string; sourceDepartment: string; targetDepartment: string; priority: number } const defaultRuleForm: RuleFormState = { name: "", description: "", trigger: "task_status_changed", conditionsJson: "{}", action: "assign_task", actionConfigJson: "{}", sourceDepartment: "", targetDepartment: "", priority: 50 } @@ -20,34 +19,25 @@ export function RuleFormModal({ open, editingRule, companyId, onClose, onSaved } setSaving(true); setError(null) try { const result = await window.agentCompany.saveAutomationRule({ id: editingRule?.id ?? null, companyId, name: form.name.trim(), description: form.description.trim(), trigger: form.trigger, conditionsJson: form.conditionsJson, action: form.action, actionConfigJson: form.actionConfigJson, sourceDepartment: (form.sourceDepartment || null) as DepartmentId | null, targetDepartment: (form.targetDepartment || null) as DepartmentId | null, priority: form.priority, status: editingRule?.status ?? "active" }); if (!result.ok) { setError(result.error.message); return }; onSaved(); onClose() } catch (err) { setError(err instanceof Error ? err.message : "Failed to save rule") } finally { setSaving(false) } }, [form, editingRule, companyId, onSaved, onClose]) - const trapRef = useFocusTrap(open) - useEffect(() => { if (!open) return; const onKey = (e: KeyboardEvent) => { if (e.key === "Escape") onClose() }; document.addEventListener("keydown", onKey); return () => document.removeEventListener("keydown", onKey) }, [open, onClose]) - if (!open) return null const triggerOptions = Object.entries(triggerConfig).map(([key, c]) => ({ value: key, label: c.label })); const actionOptions = Object.entries(actionConfig).map(([key, c]) => ({ value: key, label: c.label })) const selectedTriggerInfo = triggerConfig[form.trigger]; const selectedActionInfo = actionConfig[form.action] return ( - - e.stopPropagation()}> -
-

{isEditing ? "Edit Automation Rule" : "New Automation Rule"}

- -
-
- {error ?
{error}
: null} -
updateField("name", e.target.value)} placeholder="e.g., Auto-assign blocked tasks" className="focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 w-full rounded-lg border bg-card px-3.5 py-2.5 text-[14px] text-foreground placeholder:text-muted-foreground" style={{ borderColor: LINE }} />
-