import gql from 'graphql-tag' import { Query, Mutation } from 'react-apollo' import { ProjectSelector } from './ProjectForm' const CREATE_PROJECT_VERSION = gql` mutation CREATE_PROJECT_VERSION($name: String!, $date: String!, $project: ID!, $changes: [String]!) { createProjectVersion(name: $name, date: $date, project: $project, changes: $changes) { id } } ` const ProjectVersionFields = props => (
{props.title && {props.title}}
) const ProjectVersionState = { id: null, name: '', date: '', change: '', changes: [], project: null, } class ProjectVersionForm extends React.Component { state = { ...ProjectVersionState, ...this.props.projectVersion } toState = event => { this.setState({ [event.target.name]: event.target.value }) } addChange = event => { event.preventDefault() const newChanges = this.state.changes newChanges.push(this.state.change) this.setState({ changes: newChanges, change: '' }) } render() { return ( {(createProjectVersion, { data, error, loading }) => (
{ event.preventDefault() const { data } = await createProjectVersion() this.state.id = data.createProjectVersion.id }}> {this.state.changes.map((change, index) =>

{change}

)} {this.props.project || } )}
) } } export default ProjectVersionForm export { ProjectVersionFields, ProjectVersionState }