From 20552a34ff176b744b141847bd1d835a1e38436a Mon Sep 17 00:00:00 2001 From: R3D347HR4Y Date: Sun, 7 Jun 2026 15:51:47 +0200 Subject: [PATCH] feat(automation): multi-domain rules and webhook scope UI Extend automations to drive and contacts with context-aware triggers, conditions, and actions. Webhooks can filter event types and scopes per domain. --- .../automation/automation-domain-context.tsx | 25 ++ .../automation/rule-simulator-panel.tsx | 121 ++++++++-- .../automation/rule-workflow-editor.tsx | 4 + .../webhook-contacts-scope-editor.tsx | 86 +++++++ .../automation/webhook-event-scope-editor.tsx | 103 ++++++++ .../webhook-template-variables-panel.tsx | 40 ++- .../settings/automation/webhooks-panel.tsx | 228 ++++++++++++++---- .../automation/workflow-node-inspector.tsx | 129 ++++++++-- .../settings/automation/workflow-nodes.tsx | 7 +- .../automation/workflow-triggers-panel.tsx | 104 ++++++-- .../sections/automation-settings-section.tsx | 2 +- lib/api/hooks/use-mail-automation-queries.ts | 31 ++- lib/api/types.ts | 9 + lib/mail-automation/condition-helpers.ts | 76 ++++-- lib/mail-automation/defaults.ts | 39 ++- lib/mail-automation/domains.ts | 218 +++++++++++++++++ lib/mail-automation/node-definitions.ts | 66 ++--- lib/mail-automation/types.ts | 51 +++- .../use-automation-suggestions.ts | 16 ++ lib/mail-automation/webhook-config.ts | 81 +++++++ .../webhook-template-variables.ts | 130 +++++++++- 21 files changed, 1385 insertions(+), 181 deletions(-) create mode 100644 components/gmail/settings/automation/automation-domain-context.tsx create mode 100644 components/gmail/settings/automation/webhook-contacts-scope-editor.tsx create mode 100644 components/gmail/settings/automation/webhook-event-scope-editor.tsx create mode 100644 lib/mail-automation/domains.ts create mode 100644 lib/mail-automation/webhook-config.ts 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 })} /> +
+
+
+ +