import React, { Component } from 'react'; import { graphql, gql, compose } from 'react-apollo'; import { SINGLE_ITEM_QUERY, UPDATE_LINK_MUTATION } from '../queries'; import { singleItemEnhancer } from '../enhancers/enhancers'; class UpdateItem extends Component { state = { item: {}, }; componentDidMount() { console.log(this.props); } saveToState = e => { let { name, value, type } = e.target; if (type === 'number') { value = parseInt(value); } console.log('Saving to state'); const item = { ...this.state.item }; item[name] = value; this.setState({ item }); }; updateItem = async e => { e.preventDefault(); // pull the values from state const { description, title } = this.state; const { id } = this.props; // create a mutation // TODO: handle any errors. If you send an extra field it should break -how do we display those errors if they are currently only visible via the network tab? // turn loading on this.setState({ loading: true }); const res = await this.props.updateItem({ // pass in those variables from state variables: { ...this.props.findItem.items[0], ...this.state.item, }, }); console.log(res); this.setState({ loading: false }); }; render() { if (this.props.findItem.loading) { return
Loading...
; } const item = this.props.findItem.items[0]; return (