feat(client): add common links to formValidators regex (#41094)

* feat(client): add repl join link to formValidators regex

* add fCCRegex to validators
pull/41189/head
Shaun Hamilton 2021-02-19 11:43:54 +00:00 committed by GitHub
parent 9312060870
commit b2ec1a3ef4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 3 deletions

View File

@ -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;

View File

@ -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.'

View File

@ -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);