From b2ec1a3ef48c49a774a7baa906bbd4691bf1d351 Mon Sep 17 00:00:00 2001 From: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> Date: Fri, 19 Feb 2021 11:43:54 +0000 Subject: [PATCH] feat(client): add common links to formValidators regex (#41094) * feat(client): add repl join link to formValidators regex * add fCCRegex to validators --- client/src/components/formHelpers/FormFields.js | 4 +++- client/src/components/formHelpers/FormValidators.js | 6 +++++- client/src/components/formHelpers/index.js | 4 +++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/client/src/components/formHelpers/FormFields.js b/client/src/components/formHelpers/FormFields.js index 83d1d20357..72367f814f 100644 --- a/client/src/components/formHelpers/FormFields.js +++ b/client/src/components/formHelpers/FormFields.js @@ -14,7 +14,8 @@ import { Field } from 'react-final-form'; import { editorValidator, localhostValidator, - composeValidators + composeValidators, + fCCValidator } from './FormValidators'; const propTypes = { @@ -52,6 +53,7 @@ function FormFields(props) { } const validationWarning = composeValidators( name === 'githubLink' || isEditorLinkAllowed ? null : editorValidator, + fCCValidator, localhostValidator )(value); const message = error || validationError || validationWarning; diff --git a/client/src/components/formHelpers/FormValidators.js b/client/src/components/formHelpers/FormValidators.js index d8ce3911da..58176cbb1b 100644 --- a/client/src/components/formHelpers/FormValidators.js +++ b/client/src/components/formHelpers/FormValidators.js @@ -1,10 +1,14 @@ // Matches editor links for: Repl.it, Glitch, CodeSandbox, GitHub -const editorRegex = /repl\.it\/@|glitch\.com\/edit\/#!|codesandbox\.io\/s\/|github\.com/; +const editorRegex = /repl\.it\/(@|join\/)|glitch\.com\/edit\/#!|codesandbox\.io\/s\/|github\.com/; +const fCCRegex = /codepen\.io\/freecodecamp|freecodecamp\.rocks|github\.com\/freecodecamp/i; const localhostRegex = /localhost:/; export const editorValidator = value => editorRegex.test(value) ? 'Remember to submit the Live App URL.' : null; +export const fCCValidator = value => + fCCRegex.test(value) ? 'Remember to submit your own work.' : null; + export const localhostValidator = value => localhostRegex.test(value) ? 'Remember to submit a publicly visible app URL.' diff --git a/client/src/components/formHelpers/index.js b/client/src/components/formHelpers/index.js index e12593a309..1a70ea1caf 100644 --- a/client/src/components/formHelpers/index.js +++ b/client/src/components/formHelpers/index.js @@ -2,7 +2,8 @@ import normalizeUrl from 'normalize-url'; import { localhostValidator, editorValidator, - composeValidators + composeValidators, + fCCValidator } from './FormValidators'; export { default as BlockSaveButton } from './BlockSaveButton.js'; @@ -20,6 +21,7 @@ export function formatUrlValues(values, options) { const urlValues = Object.keys(values).reduce((result, key) => { let value = values[key]; const nullOrWarning = composeValidators( + fCCValidator, localhostValidator, key === 'githubLink' || isEditorLinkAllowed ? null : editorValidator )(value);