From f95dbb256d0621331c13e0a5ab86f419a9c6039a Mon Sep 17 00:00:00 2001 From: Drew Larson Date: Sun, 29 Jan 2017 19:13:57 -0600 Subject: [PATCH] Wire up button to trigger CPIC. --- .../js/bikes/components/BikeForm/index.jsx | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/bikeshop_project/assets/js/bikes/components/BikeForm/index.jsx b/bikeshop_project/assets/js/bikes/components/BikeForm/index.jsx index 5a62f58..cc29acb 100644 --- a/bikeshop_project/assets/js/bikes/components/BikeForm/index.jsx +++ b/bikeshop_project/assets/js/bikes/components/BikeForm/index.jsx @@ -32,6 +32,7 @@ class BikeForm extends React.Component { this.handleSizeChange = this.handleSizeChange.bind(this); this.handleSourceChange = this.handleSourceChange.bind(this); this.handleSave = this.handleSave.bind(this); + this.handleCpicCheck = this.handleCpicCheck.bind(this); } handleChange(event, value) { @@ -46,11 +47,32 @@ class BikeForm extends React.Component { this.setState({ bike: { ...this.state.bike, source: value } }); } + handleCpicCheck() { + const id = this.state.bike.id; + const serialNumber = this.state.bike.serial_number; + const data = JSON.stringify({ serial_number: serialNumber }); + const csrfToken = Cookies.get('csrftoken'); + + fetch(`/api/v1/bikes/${id}/check/`, { + credentials: 'same-origin', + method: 'PUT', + headers: { + 'Content-Type': 'application/json', + 'X-CSRFToken': csrfToken, + }, + body: data, + }).then((response) => { + if (response.status >= 400) { + throw new Error('Bad response from server'); + } + console.log(response.json()); + }); + } + handleSave() { const id = this.state.bike.id; const data = JSON.stringify(this.state.bike); const csrfToken = Cookies.get('csrftoken'); - const sessionId = Cookies.get('sessionid'); fetch(`/api/v1/bikes/${id}/`, { credentials: 'same-origin', @@ -167,7 +189,7 @@ class BikeForm extends React.Component {
- +
- +