feat(client): add common links to formValidators regex (#41094)
* feat(client): add repl join link to formValidators regex * add fCCRegex to validatorspull/41189/head
parent
9312060870
commit
b2ec1a3ef4
|
@ -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;
|
||||
|
|
|
@ -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.'
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue