Sha256: 8c4833382ff21acdc5e10d145894a44dc6c6871878a751d6da01c5321214d4d3
Contents?: true
Size: 1.04 KB
Versions: 12
Compression:
Stored size: 1.04 KB
Contents
import * as Yup from 'yup'; export const redirectToResult = history => () => history.push({ pathname: '/template_syncs/result' }); const repoFormat = formatAry => value => { if (value === undefined) { return true; } const valid = formatAry .map(item => value.startsWith(item)) .reduce((memo, item) => item || memo, false); return value && valid; }; export const syncFormSchema = (syncType, settingsObj, validationData) => { const schema = (settingsObj[syncType].asMutable() || []).reduce( (memo, setting) => { if (setting.name === 'repo') { return { ...memo, repo: Yup.string() .test( 'repo-format', `Invalid repo format, must start with one of: ${validationData.repo.join( ', ' )}`, repoFormat(validationData.repo) ) .required("can't be blank"), }; } return memo; }, {} ); return Yup.object().shape({ [syncType]: Yup.object().shape(schema), }); };
Version data entries
12 entries across 12 versions & 1 rubygems