// @flow import React from "react"; import { translate } from "react-i18next"; import { Subtitle, InputField, Select, SubmitButton, Textarea } from "@scm-manager/ui-components"; import { ExtensionPoint } from "@scm-manager/ui-extensions"; import type { Repository, RepositoryType } from "@scm-manager/ui-types"; import * as validator from "./repositoryValidation"; type Props = { submitForm: Repository => void, repository?: Repository, repositoryTypes: RepositoryType[], namespaceStrategy: string, loading?: boolean, t: string => string }; type State = { repository: Repository, namespaceValidationError: boolean, nameValidationError: boolean, contactValidationError: boolean }; const CUSTOM_NAMESPACE_STRATEGY = "CustomNamespaceStrategy"; class RepositoryForm extends React.Component { constructor(props: Props) { super(props); this.state = { repository: { name: "", namespace: "", type: "", contact: "", description: "", _links: {} }, namespaceValidationError: false, nameValidationError: false, contactValidationError: false }; } componentDidMount() { const { repository } = this.props; if (repository) { this.setState({ repository: { ...repository } }); } } isFalsy(value) { if (!value) { return true; } return false; } isValid = () => { const { namespaceStrategy } = this.props; const { repository } = this.state; return !( this.state.namespaceValidationError || this.state.nameValidationError || this.state.contactValidationError || this.isFalsy(repository.name) || (namespaceStrategy === CUSTOM_NAMESPACE_STRATEGY && this.isFalsy(repository.namespace)) ); }; submit = (event: Event) => { event.preventDefault(); if (this.isValid()) { this.props.submitForm(this.state.repository); } }; isCreateMode = () => { return !this.props.repository; }; render() { const { loading, t } = this.props; const repository = this.state.repository; let subtitle = null; if (this.props.repository) { // edit existing repo subtitle = ; } return ( <> {subtitle}
{this.renderCreateOnlyFields()}