import {useState, useEffect} from '@wordpress/element'; import {__, sprintf} from '@wordpress/i18n'; import {DateTimePicker} from '@wordpress/components'; import ButtonGroup from '../components/ButtonGroup'; import DateRangePicker from '../components/DateRangePicker'; import {DayPicker} from 'react-day-picker'; import '../scss/_schedule.scss'; const SchedulePeriodField = ( {field, allMetaData, onDataChange} ) => { // Get the saved values. If empty, they are null or undefined. const startDate = allMetaData['start_date']; const endDate = allMetaData['end_date']; const startMode = startDate ? 'scheduled' : 'now'; const endMode = endDate ? 'scheduled' : 'no_end'; const timezoneLabel = window.adpressoData?.timezone || ''; const handleStartModeChange = ( newMode ) => { if ( newMode === 'now' ) { onDataChange( 'start_date', '' ); } else { onDataChange( 'start_date', new Date().toISOString() ); } }; const handleEndModeChange = ( newMode ) => { if ( newMode === 'no_end' ) { onDataChange( 'end_date', '' ); } else { // Initialise with startDate + 1 week, or today when empty const baseDate = startDate ? new Date( startDate ) : new Date(); baseDate.setDate( baseDate.getDate() + 7 ); onDataChange( 'end_date', baseDate.toISOString() ); } }; return (
{__( 'Warning: End date is before start date.', 'adpresso' )}
)}