Sha256: c4af72d51a975a41d964174e40c58b068cdcca9f0bf95a2a9acd1180a909553e
Contents?: true
Size: 1.71 KB
Versions: 20
Compression:
Stored size: 1.71 KB
Contents
import { useState, useEffect } from 'react'; import { useSelector } from 'react-redux'; import { selectTemplateInputs, selectAdvancedTemplateInputs, } from './JobWizardSelectors'; import { isPositiveNumber, isValidDate } from './steps/form/FormHelpers'; import './JobWizard.scss'; export const useValidation = ({ advancedValues, templateValues }) => { const [valid, setValid] = useState({}); const templateInputs = useSelector(selectTemplateInputs); const advancedTemplateInputs = useSelector(selectAdvancedTemplateInputs); useEffect(() => { setValid({ hostsAndInputs: true, advanced: true, schedule: true, }); const inputValidation = (inputs, values, setInvalid) => { inputs.forEach(({ name, required, value_type: valueType }) => { const value = values[name]; if (required && !value) { setInvalid(); } if (value && valueType === 'date') { if (!isValidDate(value) && !isValidDate(new Date(value))) { setInvalid(); } } }); }; inputValidation(templateInputs, templateValues, () => setValid(currValid => ({ ...currValid, hostsAndInputs: false })) ); inputValidation(advancedTemplateInputs, advancedValues.templateValues, () => setValid(currValid => ({ ...currValid, advanced: false })) ); [ advancedValues.timeoutToKill, advancedValues.concurrencyLevel, advancedValues.timeSpan, ].forEach(value => { if (value && !isPositiveNumber(value)) { setValid(currValid => ({ ...currValid, advanced: false })); } }); // eslint-disable-next-line react-hooks/exhaustive-deps }, [advancedValues, templateValues]); return [valid, setValid]; };
Version data entries
20 entries across 20 versions & 1 rubygems