import React from 'react'; import PropTypes from 'prop-types'; import { Button } from 'patternfly-react'; import $ from 'jquery'; import CommonForm from 'foremanReact/components/common/forms/CommonForm'; import { translate as __ } from 'foremanReact/common/I18n'; import ScmTypeSelector from './components/ScmTypeSelector'; import FormTextInput from './components/FormTextInput'; class SyncGitRepo extends React.Component { validateParameters() { let result = true; let msg = ''; if (this.props.path === '' && this.props.scmType === 'directory') { result = false; if (msg === '') { msg += __('Directory path cannot be blank'); } } if (this.props.scmType === 'git') { if (this.props.gitUrl === '') { result = false; if (msg === '') { msg += __('Git URL cannot be blank'); } } } if (this.props.scmType !== 'git' && this.props.scmType !== 'directory') { result = false; if (msg === '') { msg += __('SCM Type cannot be blank'); } } return { validateResult: result, validateMsg: msg, }; } componentDidMount() { const { data: { mode, scmType, path, gitCommit, gitUrl }, initSyncGitRepo, loadScmType, loadPath, loadGitCommit, loadGitUrl, handleGitRepoSync, } = this.props; if (mode === 'editInstance') { loadScmType(scmType); loadPath(path); loadGitCommit(gitCommit); loadGitUrl(gitUrl); handleGitRepoSync( this.props.scmType, this.props.path, this.props.gitCommit ); } initSyncGitRepo(scmType, path, gitCommit, gitUrl); } render() { const { data: { scmTypes, appDefinitions }, scmType, path, gitCommit, gitUrl, loadScmType, loadPath, loadGitCommit, loadGitUrl, handleGitRepoSync, } = this.props; const urlValidator = /^(ftp|http|https):\/\/[^ "]+$/; const { validateResult, validateMsg } = this.validateParameters(); /* eslint-disable jquery/no-attr */ if (validateResult === false) { $('input[type="submit"][name="commit"]').attr('disabled', true); } else { $('input[type="submit"][name="commit"]').attr('disabled', false); } /* eslint-enable jquery/no-attr */ return (