From 6ae1d3740cdaceb718c47400426a23c702e76f8e Mon Sep 17 00:00:00 2001 From: Martin Quarda Date: Tue, 15 Oct 2024 07:22:48 +0200 Subject: [PATCH] fix --- frontend/src/scripts/index.js | 38 ++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/frontend/src/scripts/index.js b/frontend/src/scripts/index.js index c9bd1ae..e6439bd 100644 --- a/frontend/src/scripts/index.js +++ b/frontend/src/scripts/index.js @@ -203,24 +203,26 @@ class Main extends Component { })); }; selectDeliveryCallback(point){ - fetch(addr_prefix + '/api/cart/select_delivery?delivery='+point.name).then(resp => resp.json()).then(json => { - if(json.status == "failed"){ - this.setState({ - status_text: json.reason, - status: "failed", - }) - }else{ - this.setState({ - cart: [ - ...this.state.cart.filter(product => !product.name.startsWith("Doprava na ")), - {"name": "Doprava na " + point.name, "id": 2, "price": delivery_cost, "locked": true, "quantity": 1} - ], - delivery: point.name, - status_text: json.reason, - status: "success", - }) - } - }); + if(point){ + fetch(addr_prefix + '/api/cart/select_delivery?delivery='+point.name).then(resp => resp.json()).then(json => { + if(json.status == "failed"){ + this.setState({ + status_text: json.reason, + status: "failed", + }) + }else{ + this.setState({ + cart: [ + ...this.state.cart.filter(product => !product.name.startsWith("Doprava na ")), + {"name": "Doprava na " + point.name, "id": 2, "price": delivery_cost, "locked": true, "quantity": 1} + ], + delivery: point.name, + status_text: json.reason, + status: "success", + }) + } + }); + } } selectDelivery = () => { Packeta.Widget.pick("8599115769fd895b", this.selectDeliveryCallback.bind(this))