/**
* Upcoming Runs — the next scheduled run for each active workflow.
*/
import { useState, useEffect, useCallback } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { apiGet } from '../../../utils/api';
import { toast } from '../../common/Toast';
import Card from '../../common/Card';
import Loader from '../../common/Loader';
import { formatDateTime } from '../../../utils/datetime';
// Stored as UTC; rendered in the site timezone and format (Settings → General).
const formatDate = ( value ) => formatDateTime( value );
const UpcomingRuns = ( { onNavigate } ) => {
const [ loading, setLoading ] = useState( true );
const [ items, setItems ] = useState( [] );
const load = useCallback( async () => {
setLoading( true );
try {
const res = await apiGet( '/workflow-automation/upcoming' );
setItems( res?.upcoming || [] );
} catch ( e ) {
toast( e?.message || __( 'Failed to load upcoming runs.', 'ai-marketing-expert' ), 'error' );
} finally {
setLoading( false );
}
}, [] );
useEffect( () => {
load();
}, [ load ] );
if ( loading ) {
return
{ __( 'No scheduled runs. Activate a workflow with a schedule to see it here.', 'ai-marketing-expert' ) }
| { __( 'Workflow', 'ai-marketing-expert' ) } | { __( 'Schedule', 'ai-marketing-expert' ) } | { __( 'Next run', 'ai-marketing-expert' ) } |
|---|---|---|
| { it.schedule_type } | { formatDate( it.next_run_at ) } |