import React, { useState } from 'react'; import PropTypes from 'prop-types'; import { TextInput, Grid, GridItem, FormGroup } from '@patternfly/react-core'; import { translate as __ } from 'foremanReact/common/I18n'; import { SelectField } from '../form/SelectField'; import { repeatTypes } from '../../JobWizardConstants'; import { RepeatCron } from './RepeatCron'; import { RepeatHour } from './RepeatHour'; import { RepeatMonth } from './RepeatMonth'; import { RepeatDaily } from './RepeatDaily'; import { RepeatWeek } from './RepeatWeek'; export const RepeatOn = ({ repeatType, setRepeatType, repeatAmount, setRepeatAmount, repeatData, setRepeatData, setValid, }) => { const [repeatValidated, setRepeatValidated] = useState('default'); const handleRepeatInputChange = newValue => { setRepeatValidated(!newValue || newValue >= 1 ? 'default' : 'error'); setRepeatAmount(newValue); }; const getRepeatComponent = () => { switch (repeatType) { case repeatTypes.cronline: return ( ); case repeatTypes.monthly: return ( ); case repeatTypes.weekly: return ( ); case repeatTypes.daily: return ( ); case repeatTypes.hourly: return ( ); case repeatTypes.noRepeat: default: return null; } }; return ( { setRepeatType(newValue); if (newValue === repeatTypes.noRepeat) { setRepeatValidated('default'); } }} value={repeatType} /> handleRepeatInputChange(newValue)} placeholder={__('Repeat N times')} /> {getRepeatComponent()} ); }; RepeatOn.propTypes = { repeatType: PropTypes.oneOf(Object.values(repeatTypes)).isRequired, setRepeatType: PropTypes.func.isRequired, repeatAmount: PropTypes.oneOfType([PropTypes.string, PropTypes.number]) .isRequired, setRepeatAmount: PropTypes.func.isRequired, repeatData: PropTypes.object.isRequired, setRepeatData: PropTypes.func.isRequired, setValid: PropTypes.func.isRequired, };