feat(client): add github to validation list (#40894)

This commit is contained in:
Shaun Hamilton
2021-02-04 06:44:35 +00:00
committed by GitHub
parent 30c923b73d
commit ea1c132868
3 changed files with 7 additions and 7 deletions

View File

@ -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)}
</FormGroup>
</Col>
);

View File

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

View File

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