From ea1c1328681c239478d64824ffc734c5a5d25888 Mon Sep 17 00:00:00 2001 From: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> Date: Thu, 4 Feb 2021 06:44:35 +0000 Subject: [PATCH] feat(client): add github to validation list (#40894) --- client/src/components/formHelpers/FormFields.js | 6 +++--- client/src/components/formHelpers/FormValidators.js | 6 +++--- client/src/components/formHelpers/index.js | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/client/src/components/formHelpers/FormFields.js b/client/src/components/formHelpers/FormFields.js index db087217dd..c249b456e1 100644 --- a/client/src/components/formHelpers/FormFields.js +++ b/client/src/components/formHelpers/FormFields.js @@ -39,7 +39,7 @@ function FormFields(props) { types = {} } = options; - const nullOrWarning = (value, error, isURL) => { + const nullOrWarning = (value, error, isURL, name) => { let validationError; if (value && isURL) { try { @@ -49,7 +49,7 @@ function FormFields(props) { } } const validationWarning = composeValidators( - editorValidator, + name === 'githubLink' ? null : editorValidator, localhostValidator )(value); const message = error || validationError || validationWarning; @@ -90,7 +90,7 @@ function FormFields(props) { type={type} value={value} /> - {nullOrWarning(value, !pristine && error, isURL)} + {nullOrWarning(value, !pristine && error, isURL, name)} ); diff --git a/client/src/components/formHelpers/FormValidators.js b/client/src/components/formHelpers/FormValidators.js index 15fa624c50..d8ce3911da 100644 --- a/client/src/components/formHelpers/FormValidators.js +++ b/client/src/components/formHelpers/FormValidators.js @@ -1,5 +1,5 @@ -// Matches editor links for: Repl.it, Glitch, CodeSandbox -const editorRegex = /repl\.it\/@|glitch\.com\/edit\/#!|codesandbox\.io\/s\//; +// Matches editor links for: Repl.it, Glitch, CodeSandbox, GitHub +const editorRegex = /repl\.it\/@|glitch\.com\/edit\/#!|codesandbox\.io\/s\/|github\.com/; const localhostRegex = /localhost:/; export const editorValidator = value => @@ -11,4 +11,4 @@ export const localhostValidator = value => : null; export const composeValidators = (...validators) => value => - validators.reduce((error, validator) => error ?? validator(value), null); + validators.reduce((error, validator) => error ?? validator?.(value), null); diff --git a/client/src/components/formHelpers/index.js b/client/src/components/formHelpers/index.js index 0ea401c813..0d274a7612 100644 --- a/client/src/components/formHelpers/index.js +++ b/client/src/components/formHelpers/index.js @@ -20,7 +20,7 @@ export function formatUrlValues(values, options) { let value = values[key]; const nullOrWarning = composeValidators( localhostValidator, - editorValidator + key === 'githubLink' ? null : editorValidator )(value); if (nullOrWarning) { validatedValues.invalidValues.push(nullOrWarning);