diff --git a/web/src/components/NewRepoModalButton/ImportForm/ImportForm.tsx b/web/src/components/NewRepoModalButton/ImportForm/ImportForm.tsx new file mode 100644 index 000000000..a625ec0a9 --- /dev/null +++ b/web/src/components/NewRepoModalButton/ImportForm/ImportForm.tsx @@ -0,0 +1,191 @@ +import React, { useState } from 'react' +import { Intent } from '@blueprintjs/core' +import * as yup from 'yup' +import { Button, Container, Layout, FlexExpander, Formik, FormikForm, FormInput, Text } from '@harnessio/uicore' +import { Icon } from '@harnessio/icons' +import { FontVariation } from '@harnessio/design-system' +import { useStrings } from 'framework/strings' +import { REGEX_VALID_REPO_NAME } from 'utils/Utils' +import { ImportFormData, RepoVisibility, parseUrl } from 'utils/GitUtils' +import css from '../NewRepoModalButton.module.scss' + +interface ImportFormProps { + handleSubmit: (data: ImportFormData) => void + loading: boolean // eslint-disable-next-line @typescript-eslint/no-explicit-any + hideModal: any +} + +const ImportForm = (props: ImportFormProps) => { + const { handleSubmit, loading, hideModal } = props + const { getString } = useStrings() + const [auth, setAuth] = useState(false) + + // eslint-disable-next-line no-control-regex + const MATCH_REPOURL_REGEX = /^(https?:\/\/(?:www\.)?(github|gitlab)\.com\/([^/]+\/[^/]+))/ + + const formInitialValues: ImportFormData = { + repoUrl: '', + username: '', + password: '', + name: '', + description: '', + isPublic: RepoVisibility.PRIVATE + } + return ( + + {formik => { + return ( + + { + const target = event.target as HTMLInputElement + formik.setFieldValue('repoUrl', target.value) + if (target.value) { + const provider = parseUrl(target.value) + if (provider?.fullRepo) { + formik.setFieldValue('name', provider.repoName ? provider.repoName : provider?.fullRepo) + formik.validateField('repoUrl') + } + } + }} + /> + { + setAuth(!auth) + }} + /> + + {auth ? ( + <> + + + + ) : null} +
+ { + formik.validateField('repoUrl') + }} + /> + + +
+ + + + + + + + {getString('public')} + + {getString('createRepoModal.publicLabel')} + + + + + + ), + value: RepoVisibility.PUBLIC + }, + { + label: ( + + + + + + {getString('private')} + + {getString('createRepoModal.privateLabel')} + + + + + + ), + value: RepoVisibility.PRIVATE + } + ]} + /> + + + +