feat(client): add common links to formValidators regex (#41094)
* feat(client): add repl join link to formValidators regex * add fCCRegex to validators
This commit is contained in:
@ -14,7 +14,8 @@ import { Field } from 'react-final-form';
|
|||||||
import {
|
import {
|
||||||
editorValidator,
|
editorValidator,
|
||||||
localhostValidator,
|
localhostValidator,
|
||||||
composeValidators
|
composeValidators,
|
||||||
|
fCCValidator
|
||||||
} from './FormValidators';
|
} from './FormValidators';
|
||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
@ -52,6 +53,7 @@ function FormFields(props) {
|
|||||||
}
|
}
|
||||||
const validationWarning = composeValidators(
|
const validationWarning = composeValidators(
|
||||||
name === 'githubLink' || isEditorLinkAllowed ? null : editorValidator,
|
name === 'githubLink' || isEditorLinkAllowed ? null : editorValidator,
|
||||||
|
fCCValidator,
|
||||||
localhostValidator
|
localhostValidator
|
||||||
)(value);
|
)(value);
|
||||||
const message = error || validationError || validationWarning;
|
const message = error || validationError || validationWarning;
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
// Matches editor links for: Repl.it, Glitch, CodeSandbox, GitHub
|
// 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:/;
|
const localhostRegex = /localhost:/;
|
||||||
|
|
||||||
export const editorValidator = value =>
|
export const editorValidator = value =>
|
||||||
editorRegex.test(value) ? 'Remember to submit the Live App URL.' : null;
|
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 =>
|
export const localhostValidator = value =>
|
||||||
localhostRegex.test(value)
|
localhostRegex.test(value)
|
||||||
? 'Remember to submit a publicly visible app URL.'
|
? 'Remember to submit a publicly visible app URL.'
|
||||||
|
@ -2,7 +2,8 @@ import normalizeUrl from 'normalize-url';
|
|||||||
import {
|
import {
|
||||||
localhostValidator,
|
localhostValidator,
|
||||||
editorValidator,
|
editorValidator,
|
||||||
composeValidators
|
composeValidators,
|
||||||
|
fCCValidator
|
||||||
} from './FormValidators';
|
} from './FormValidators';
|
||||||
|
|
||||||
export { default as BlockSaveButton } from './BlockSaveButton.js';
|
export { default as BlockSaveButton } from './BlockSaveButton.js';
|
||||||
@ -20,6 +21,7 @@ export function formatUrlValues(values, options) {
|
|||||||
const urlValues = Object.keys(values).reduce((result, key) => {
|
const urlValues = Object.keys(values).reduce((result, key) => {
|
||||||
let value = values[key];
|
let value = values[key];
|
||||||
const nullOrWarning = composeValidators(
|
const nullOrWarning = composeValidators(
|
||||||
|
fCCValidator,
|
||||||
localhostValidator,
|
localhostValidator,
|
||||||
key === 'githubLink' || isEditorLinkAllowed ? null : editorValidator
|
key === 'githubLink' || isEditorLinkAllowed ? null : editorValidator
|
||||||
)(value);
|
)(value);
|
||||||
|
Reference in New Issue
Block a user