mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-09-24 23:01:18 +08:00
fix(client): allow endpoint on projects (#49656)
* fix(client): allow endpoint on projects * refactor: structure form.tsx code similarly Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
co-authored by
Oliver Eyton-Williams
parent
6c0f2d0998
commit
3dab4261fb
@@ -59,13 +59,19 @@ function FormFields(props: FormFieldsProps): JSX.Element {
|
||||
validationError = (err as { message?: string })?.message;
|
||||
}
|
||||
}
|
||||
const validationWarning = composeValidators(
|
||||
name === 'githubLink' || isEditorLinkAllowed ? null : editorValidator,
|
||||
fCCValidator,
|
||||
httpValidator,
|
||||
isLocalLinkAllowed ? null : localhostValidator,
|
||||
pathValidator
|
||||
)(value);
|
||||
|
||||
const validators = [fCCValidator, httpValidator];
|
||||
const isSolutionLink = name !== 'githubLink';
|
||||
if (isSolutionLink && !isEditorLinkAllowed) {
|
||||
validators.push(editorValidator);
|
||||
if (isLocalLinkAllowed) {
|
||||
validators.push(pathValidator);
|
||||
}
|
||||
}
|
||||
if (!isLocalLinkAllowed) {
|
||||
validators.push(localhostValidator);
|
||||
}
|
||||
const validationWarning = composeValidators(...validators)(value);
|
||||
const message: string = (error ||
|
||||
validationError ||
|
||||
validationWarning) as string;
|
||||
|
||||
@@ -42,13 +42,19 @@ function formatUrlValues(
|
||||
invalidValues: []
|
||||
};
|
||||
const urlValues = Object.keys(values).reduce((result, key: string) => {
|
||||
// NOTE: pathValidator is not used here, because it is only used as a
|
||||
// suggestion - should not prevent form submission
|
||||
const validators = [fCCValidator, httpValidator];
|
||||
const isSolutionLink = key !== 'githubLink';
|
||||
if (isSolutionLink && !isEditorLinkAllowed) {
|
||||
validators.push(editorValidator);
|
||||
}
|
||||
if (!isLocalLinkAllowed) {
|
||||
validators.push(localhostValidator);
|
||||
}
|
||||
|
||||
let value: string = values[key];
|
||||
const nullOrWarning: JSX.Element | null = composeValidators(
|
||||
fCCValidator,
|
||||
httpValidator,
|
||||
isLocalLinkAllowed ? null : localhostValidator,
|
||||
key === 'githubLink' || isEditorLinkAllowed ? null : editorValidator
|
||||
)(value);
|
||||
const nullOrWarning = composeValidators(...validators)(value);
|
||||
if (nullOrWarning) {
|
||||
validatedValues.invalidValues.push(nullOrWarning);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user