Skip to content

Commit ea1c132

Browse files
feat(client): add github to validation list (freeCodeCamp#40894)
1 parent 30c923b commit ea1c132

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

client/src/components/formHelpers/FormFields.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function FormFields(props) {
3939
types = {}
4040
} = options;
4141

42-
const nullOrWarning = (value, error, isURL) => {
42+
const nullOrWarning = (value, error, isURL, name) => {
4343
let validationError;
4444
if (value && isURL) {
4545
try {
@@ -49,7 +49,7 @@ function FormFields(props) {
4949
}
5050
}
5151
const validationWarning = composeValidators(
52-
editorValidator,
52+
name === 'githubLink' ? null : editorValidator,
5353
localhostValidator
5454
)(value);
5555
const message = error || validationError || validationWarning;
@@ -90,7 +90,7 @@ function FormFields(props) {
9090
type={type}
9191
value={value}
9292
/>
93-
{nullOrWarning(value, !pristine && error, isURL)}
93+
{nullOrWarning(value, !pristine && error, isURL, name)}
9494
</FormGroup>
9595
</Col>
9696
);

client/src/components/formHelpers/FormValidators.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Matches editor links for: Repl.it, Glitch, CodeSandbox
2-
const editorRegex = /repl\.it\/@|glitch\.com\/edit\/#!|codesandbox\.io\/s\//;
1+
// Matches editor links for: Repl.it, Glitch, CodeSandbox, GitHub
2+
const editorRegex = /repl\.it\/@|glitch\.com\/edit\/#!|codesandbox\.io\/s\/|github\.com/;
33
const localhostRegex = /localhost:/;
44

55
export const editorValidator = value =>
@@ -11,4 +11,4 @@ export const localhostValidator = value =>
1111
: null;
1212

1313
export const composeValidators = (...validators) => value =>
14-
validators.reduce((error, validator) => error ?? validator(value), null);
14+
validators.reduce((error, validator) => error ?? validator?.(value), null);

client/src/components/formHelpers/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function formatUrlValues(values, options) {
2020
let value = values[key];
2121
const nullOrWarning = composeValidators(
2222
localhostValidator,
23-
editorValidator
23+
key === 'githubLink' ? null : editorValidator
2424
)(value);
2525
if (nullOrWarning) {
2626
validatedValues.invalidValues.push(nullOrWarning);

0 commit comments

Comments
 (0)