import React, { Component } from 'react'; import { graphql, gql } from 'react-apollo'; import { ALL_ITEMS_QUERY, CREATE_ITEM_MUTATION } from '../queries'; import ErrorMessage from './ErrorMessage'; import { fileEndpoint } from '../config'; import Form from './styles/Form'; class CreateLink extends Component { state = { description: 'test', title: 'testing title', image: '', largeImage: '', price: 500, fullPrice: 0, loading: false, error: { message: '', }, }; componentWillReceiveProps(nextProps) { console.log(nextProps); } uploadFile = async e => { this.setState({ loading: true }); const files = e.currentTarget.files; const data = new FormData(); data.append('file', files[0]); data.append('upload_preset', 'sickfits'); // use the file endpoint const res = await fetch('https://api.cloudinary.com/v1_1/wesbos/image/upload', { method: 'POST', body: data, }); const file = await res.json(); console.log(file); this.setState({ image: file.secure_url, largeImage: file.eager[0].secure_url, loading: false }); }; createItem = async e => { e.preventDefault(); // pull the values from state const { description, title, price, image, largeImage } = this.state; // create a mutation // TODO: handle any errors // turn loading on this.setState({ loading: true }); try { console.log('About to call create item mutation'); const res = await this.props.createItemMutation({ // pass in those variables from state variables: { description, title, image, largeImage, price: parseInt(price), }, }); } catch (error) { this.setState({ error }); console.log(error); } this.setState({ loading: false }); }; render() { return (