Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// validate slug
// A slug must match [a-zA-Z0-9_-]{2,256}
// The error object of the slug is
// {
// missing: Boolean,
// translations: { de: { hasForbiddenChars: Boolean }, ... },
// }
// The "missing" part is used to highlight all fields, while the
// "translations" part gets mapped to errors per translation.
if (LocalizedTextInput.isEmpty(formValues.slug)) {
errors.slug.missing = true;
} else {
const isValidSlug = value => /^[a-zA-Z0-9_-]{2,256}$/.test(value);
const translationErrors = Object.keys(
LocalizedTextInput.omitEmptyTranslations(formValues.slug)
).reduce((acc, language) => {
const value = isValidSlug(formValues.slug[language])
? {}
: { hasForbiddenChars: true };
return {
...acc,
[language]: value,
};
}, {});
errors.slug.translations = translationErrors;
}
// validate description
if (MultilineTextInput.isEmpty(formValues.description))
errors.description.missing = true;