/** * TestRunModal — collects a sample event payload before manually running * an event-triggered workflow. Real runs get this data from the trigger; * manual runs would otherwise execute with an empty event and fail steps * that read from it (e.g. subscriber email). */ import { useState } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; const TestRunModal = ( { trigger, workflowName, onRun, onCancel } ) => { const fields = trigger?.payload_fields || []; const [ values, setValues ] = useState( {} ); const submit = () => { const event = {}; fields.forEach( ( f ) => { const v = ( values[ f.key ] || '' ).trim(); if ( v !== '' ) { event[ f.key ] = v; } } ); onRun( event ); }; return (
{ __( 'This workflow normally runs when its trigger event fires and receives data from that event. Enter sample values below so the test run behaves like a real one — steps that rely on missing values may fail or be skipped.', 'ai-marketing-expert' ) } { trigger?.label ? ` (${ __( 'Trigger:', 'ai-marketing-expert' ) } ${ trigger.label })` : '' }
{ fields.map( ( f ) => ({ __( 'This trigger has no sample fields; the workflow will run with an empty event payload.', 'ai-marketing-expert' ) }
) }