// @flow import React from "react"; import { translate } from "react-i18next"; import { InputField, Select } from "../../../components/forms/index"; import { SubmitButton } from "../../../components/buttons/index"; import type { Repository } from "../../types/Repositories"; import * as validator from "./repositoryValidation"; import type { RepositoryType } from "../../types/RepositoryTypes"; import Textarea from "../../../components/forms/Textarea"; type Props = { submitForm: Repository => void, repository?: Repository, repositoryTypes: RepositoryType[], loading?: boolean, t: string => string }; type State = { repository: Repository, nameValidationError: boolean, contactValidationError: boolean }; class RepositoryForm extends React.Component { constructor(props: Props) { super(props); this.state = { repository: { name: "", namespace: "", type: "", contact: "", description: "", _links: {} }, nameValidationError: false, contactValidationError: false, descriptionValidationError: false }; } componentDidMount() { const { repository } = this.props; if (repository) { this.setState({ repository: { ...repository } }); } } isFalsy(value) { if (!value) { return true; } return false; } isValid = () => { const repository = this.state.repository; return !( this.state.nameValidationError || this.state.contactValidationError || this.isFalsy(repository.name) ); }; 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; return (
{this.renderCreateOnlyFields()}