Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (TextInput.isEmpty(formValues.key)) errors.key.missing = true;
// validate name
// A localized string is considered empty when no translation is given at all
if (LocalizedTextInput.isEmpty(formValues.name)) errors.name.missing = true;
// 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;
key: {},
name: {},
slug: {},
description: {},
inventory: {},
price: {},
};
// validate key
// Input elements usually provide a way to check whether it's value is empty
// This is useful to determine whether a required value was not filled out.
if (TextInput.isEmpty(formValues.key)) errors.key.missing = true;
// validate name
// A localized string is considered empty when no translation is given at all
if (LocalizedTextInput.isEmpty(formValues.name)) errors.name.missing = true;
// 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)