From cd0b07b3adb36fb5ec098f9e511ab45d774fee7b Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Tue, 30 Jan 2018 12:41:01 -0500 Subject: Move to Prisma Backend --- frontend/components/UpdateItem.js | 75 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 frontend/components/UpdateItem.js (limited to 'frontend/components/UpdateItem.js') diff --git a/frontend/components/UpdateItem.js b/frontend/components/UpdateItem.js new file mode 100644 index 0000000..27be90f --- /dev/null +++ b/frontend/components/UpdateItem.js @@ -0,0 +1,75 @@ +import React, { Component } from 'react'; +import { graphql, gql, compose } from 'react-apollo'; +import { SINGLE_ITEM_QUERY, UPDATE_LINK_MUTATION } from '../queries'; + +class UpdateLink extends Component { + state = { + ...this.props.findItem.Item, + }; + + saveToState = e => { + let { name, value, type } = e.target; + if (type === 'number') { + value = parseInt(value); + } + + this.setState({ [name]: value }); + }; + + _createLink = 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 + // turn loading on + this.setState({ loading: true }); + console.log(this.state); + const res = await this.props.updateItem({ + // pass in those variables from state + variables: { + ...this.state, + }, + }); + this.setState({ loading: false }); + }; + + render() { + return ( +
+

Edit {this.props.id}

+ {this.state.loading ? 'LOADING...' : 'Ready!'} +
+ + + + +