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:
Shaun Hamilton
2023-03-21 09:47:04 +01:00
committed by GitHub
co-authored by Oliver Eyton-Williams
parent 6c0f2d0998
commit 3dab4261fb
2 changed files with 25 additions and 13 deletions
@@ -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;
+12 -6
View File
@@ -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);
}