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 {
- +
- +