import React, { Component } from 'react'; import { graphql, gql } from 'react-apollo'; import { ALL_ITEMS_QUERY, CREATE_LINK_MUTATION } from '../queries'; import ErrorMessage from './ErrorMessage'; class CreateLink extends Component { state = { description: '', title: '', image: '', price: 0, fullPrice: 0, loading: false, error: { message: 'shit!', }, }; componentWillReceiveProps(nextProps) { console.log(nextProps); } uploadFile = async e => { const files = e.currentTarget.files; const data = new FormData(); data.append('data', files[0]); // use the file endpoint const res = await fetch('https://api.graph.cool/file/v1/cj5xz8szs28930145gct82bdj', { method: 'POST', body: data, }); const file = await res.json(); console.log(file); this.setState({ image: file.id }); }; _createLink = async e => { e.preventDefault(); // pull the values from state const { description, title, image, price, fullPrice } = this.state; // create a mutation // TODO: handle any errors // turn loading on this.setState({ loading: true }); try { const res = await this.props.createLinkMutation({ // pass in those variables from state variables: { description, title, price: parseInt(price), fullPrice, imageId: image, }, }); } catch (error) { this.setState({ error }); console.log(error); } this.setState({ loading: false }); }; render() { return (