diff --git a/components/gmail/settings/automation/automation-domain-context.tsx b/components/gmail/settings/automation/automation-domain-context.tsx new file mode 100644 index 0000000..561e6b0 --- /dev/null +++ b/components/gmail/settings/automation/automation-domain-context.tsx @@ -0,0 +1,25 @@ +'use client' + +import { createContext, useContext, useMemo } from 'react' +import type { AutomationDomain } from '@/lib/mail-automation/domains' +import { inferDomainsFromTriggers } from '@/lib/mail-automation/domains' +import type { TriggerOrGroup } from '@/lib/mail-automation/types' + +const AutomationDomainContext = createContext(['mail']) + +export function AutomationDomainProvider({ + triggers, + children, +}: { + triggers: TriggerOrGroup + children: React.ReactNode +}) { + const domains = useMemo(() => inferDomainsFromTriggers(triggers), [triggers]) + return ( + {children} + ) +} + +export function useAutomationDomains(): AutomationDomain[] { + return useContext(AutomationDomainContext) +} diff --git a/components/gmail/settings/automation/rule-simulator-panel.tsx b/components/gmail/settings/automation/rule-simulator-panel.tsx index db83478..3667a1e 100644 --- a/components/gmail/settings/automation/rule-simulator-panel.tsx +++ b/components/gmail/settings/automation/rule-simulator-panel.tsx @@ -1,13 +1,20 @@ 'use client' -import { useState } from 'react' +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_MESSAGE, workflowToApiPayload } from '@/lib/mail-automation/defaults' +import { + 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 @@ -17,8 +24,15 @@ interface RuleSimulatorPanelProps { 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 [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({ @@ -38,25 +52,94 @@ export function RuleSimulatorPanel({ state, ruleId }: RuleSimulatorPanelProps) { return (
-

Tester avec un message exemple

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

+ 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 })} /> +
+
+
+ +