Sha256: 0923645d1d9525d5ee683cb56d871fbfdbeb52d78c6f7305bf91e56d7bfced62
Contents?: true
Size: 1.72 KB
Versions: 24
Compression:
Stored size: 1.72 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.timeToPickup, advancedValues.concurrencyLevel, ].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
24 entries across 24 versions & 1 rubygems