From d39d7d947bcba2573eebe27e4109541723d9b108 Mon Sep 17 00:00:00 2001 From: Pranai-1 Date: Tue, 11 Jun 2024 12:29:03 +0530 Subject: [PATCH 1/2] finished location updates --- src/pages/scales/report/Booth.jsx | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/pages/scales/report/Booth.jsx b/src/pages/scales/report/Booth.jsx index a1cc2500e..6c6278e1b 100644 --- a/src/pages/scales/report/Booth.jsx +++ b/src/pages/scales/report/Booth.jsx @@ -47,6 +47,7 @@ const[latitude,setLatitude]=useState("") const[longitude,setLongitude]=useState("") const[locationLoading,setLocationLoading]=useState(0) const[valid,setValid]=useState(0) +const[err,setErr]=useState(false) const workspaceId=searchParams.get("workspace_id") const scaleType=searchParams.get("scale_type") @@ -83,11 +84,19 @@ function degreesToRadians(degrees) { setBoothErr(true) return }else{ + try{ const response=await axios.get(`https://100035.pythonanywhere.com/addons/register/?shop_number=${boothInput}`) + const arr = response.data.data; + + + const lat = arr[arr.length - 1]?.shop_lat ? Number(arr[arr.length - 1].shop_lat) : 0; + const lng = arr[arr.length - 1]?.shop_long ? Number(arr[arr.length - 1].shop_long) : 0; + + + + const distance=calculateDistance(latitude,longitude,lat,lng) - const distance=calculateDistance(latitude,longitude,latitude,longitude) - if(distance<=3){ if(scaleType=="nps"){ window.location.href=`https://100035.pythonanywhere.com/nps/api/v5/nps-create-scale/?user=True&scale_type=nps&workspace_id=${workspaceId}&username=Paolo&scale_id=${scaleId}&channel_name=${channelName}&instance_id=${boothInput}` @@ -100,7 +109,13 @@ function degreesToRadians(degrees) { setValid(-1) setSubmitted(false) } + } + catch(error){ + console.log(error) + setErr(true) } + } + } @@ -117,8 +132,8 @@ function degreesToRadians(degrees) { if (Array.isArray(detailedReport) && detailedReport.length > 0) { - setLatitude(detailedReport[detailedReport.length - 1].lat+"") - setLongitude(detailedReport[detailedReport.length - 1].long+"") + setLatitude(detailedReport[detailedReport.length - 1].lat) + setLongitude(detailedReport[detailedReport.length - 1].long) setLocationLoading(1) } else { From 59b4d6b8833e509b09266867cad1904d71830acc Mon Sep 17 00:00:00 2001 From: Pranai-1 Date: Tue, 11 Jun 2024 14:34:21 +0530 Subject: [PATCH 2/2] finished location updates --- src/pages/scales/report/Booth.jsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/pages/scales/report/Booth.jsx b/src/pages/scales/report/Booth.jsx index 6c6278e1b..f36c28eba 100644 --- a/src/pages/scales/report/Booth.jsx +++ b/src/pages/scales/report/Booth.jsx @@ -126,7 +126,8 @@ function degreesToRadians(degrees) { },[]) async function fetchLocation(){ - const response=await axios.get("https://www.qrcodereviews.uxlivinglab.online/api/v6/qrcode-data/22-71b0c608-ee3d-4b89-b4e4-19f76a6e50ec") + try{ + const response=await axios.get("https://www.qrcodereviews.uxlivinglab.online/api/v6/qrcode-data/22-71b0c608-ee3d-4b89-b4e4-19f76a6e50ec") const detailedReport = response.data.response.detailed_report; if (Array.isArray(detailedReport) && detailedReport.length > 0) { @@ -140,6 +141,12 @@ function degreesToRadians(degrees) { console.log("detailed_report is either not an array or is empty"); setLocationLoading(-1) } + + }catch(error){ + console.log(error) + setErr(true) + } + } @@ -153,6 +160,7 @@ function degreesToRadians(degrees) { setBoothInput(e.target.value); setBoothErr(false) setValid(0) + setErr(false) } } disabled={submitted==true} @@ -205,6 +213,7 @@ function degreesToRadians(degrees) { {valid==-1 &&

Please check the details and try again

} + {err &&

Something went wrong contact Admin!..

} )