chore: added a validate function for storepath

This commit is contained in:
blam
2021-01-14 18:51:03 +01:00
parent 5224a49a26
commit 2249b22e3e
3 changed files with 28 additions and 9 deletions
+1
View File
@@ -40,6 +40,7 @@
"@rjsf/core": "^2.4.0",
"@rjsf/material-ui": "^2.4.0",
"classnames": "^2.2.6",
"git-url-parse": "^11.4.3",
"moment": "^2.26.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
@@ -39,6 +39,7 @@ import { rootRoute } from '../../routes';
import { JobStatusModal } from '../JobStatusModal';
import { MultistepJsonForm } from '../MultistepJsonForm';
import { useJobPolling } from '../hooks/useJobPolling';
import gitParse from 'git-url-parse';
const useTemplate = (
templateName: string,
@@ -183,6 +184,18 @@ export const TemplatePage = () => {
label: 'Choose owner and repo',
schema: OWNER_REPO_SCHEMA,
customFormats: REPO_FORMAT,
validate: (formData, errors) => {
const { storePath } = formData;
const parsedUrl = gitParse(storePath);
if (!parsedUrl.resource) {
errors.storePath.addError(
'There needs to be a hostname in the storePath',
);
}
return errors;
},
},
]}
/>