'use client' import { useMemo, useState } from 'react' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { Play } from 'lucide-react' import { useSimulateMailRule } from '@/lib/api/hooks/use-mail-automation-queries' import type { RuleEditorState, RuleSimulationResult } from '@/lib/mail-automation/types' import { DEFAULT_SIMULATION_CALENDAR_EVENT, DEFAULT_SIMULATION_CONTACT, DEFAULT_SIMULATION_DRIVE_FILE, DEFAULT_SIMULATION_MESSAGE, workflowToApiPayload, } from '@/lib/mail-automation/defaults' import { inferDomainsFromTriggers } from '@/lib/mail-automation/domains' import { AUTOMATION_DOMAIN_LABELS } from '@/lib/mail-automation/domains' interface RuleSimulatorPanelProps { state: RuleEditorState ruleId?: string } export function RuleSimulatorPanel({ state, ruleId }: RuleSimulatorPanelProps) { const simulate = useSimulateMailRule() const [message, setMessage] = useState(DEFAULT_SIMULATION_MESSAGE) const [driveFile, setDriveFile] = useState(DEFAULT_SIMULATION_DRIVE_FILE) const [contact, setContact] = useState(DEFAULT_SIMULATION_CONTACT) const [calendarEvent, setCalendarEvent] = useState(DEFAULT_SIMULATION_CALENDAR_EVENT) const [result, setResult] = useState(null) const domains = useMemo( () => inferDomainsFromTriggers(state.workflow.triggers), [state.workflow.triggers] ) async function runSimulation() { const payload = workflowToApiPayload(state) const res = await simulate.mutateAsync({ message, ...(ruleId ? { rule_id: ruleId } : { rule: { conditions: payload.conditions, actions: payload.actions, workflow: payload.workflow, }, }), }) setResult(res) } return (

Tester avec un événement exemple {domains.length > 0 ? ( ({domains.map((d) => AUTOMATION_DOMAIN_LABELS[d]).join(', ')}) ) : null}

{domains.includes('mail') ? (

Mail

setMessage({ ...message, from: e.target.value })} />
setMessage({ ...message, subject: e.target.value })} />