diff --git a/src/pages/nearle/orders/createorder1.js b/src/pages/nearle/orders/createorder1.js index dac3f9e..be3295a 100644 --- a/src/pages/nearle/orders/createorder1.js +++ b/src/pages/nearle/orders/createorder1.js @@ -63,6 +63,8 @@ import CardContent from 'themes/overrides/CardContent'; import { PhoneAndroid } from '@mui/icons-material'; import { SearchOutlined, CloseOutlined } from '@ant-design/icons'; import PhoneInput from 'react-phone-number-input/input'; +import MyLocationIcon from '@mui/icons-material/MyLocation'; +import HighlightOffIcon from '@mui/icons-material/HighlightOff'; function loadScript(src, position, id) { if (!position) { @@ -113,130 +115,130 @@ const Createorder1 = () => { const [tenanatLocoId, setTenanatLocoId] = useState(localStorage.getItem('locationid')); const [isLocation, setIsLocation] = useState(false); - // ====================================================== || address (pick)|| ====================================================== - useEffect(() => { - if (address) { - try { - Geocode.fromAddress(address).then( - (response) => { - if (response.status == 'OK') { - const { lat, lng } = response.results[0].geometry.location; - console.log({ lat, lng }); - setLatlong({ - lat, - lng - }); - console.log(response); - if (response.results[0].address_components) { - let place = response.results[0]; - let cityA, zipcodeA, stateA, suburbA; - for (let i = 0; i < place.address_components.length; i++) { - for (let j = 0; j < place.address_components[i].types.length; j++) { - switch (place.address_components[i].types[j]) { - case 'locality': - cityA = place.address_components[i].long_name; - break; - case 'administrative_area_level_1': - stateA = place.address_components[i].long_name; - break; - case 'postal_code': - zipcodeA = place.address_components[i].long_name; - break; - case 'sublocality': - suburbA = place.address_components[i].long_name; - break; - } - } - } - setCity(cityA || ''); - setState(stateA || ''); - setZipcode(zipcodeA || ''); - setSuburb(suburbA || ''); - console.log({ lat, lng, cityA, stateA, zipcodeA, suburbA }); - setPickCust({ - ...pickCust, - city: cityA, - state: stateA, - postcode: zipcodeA, - suburb: suburbA, - latitude: lat, - longitude: lng - }); - setStartPoint({ latitude: lat, longitude: lng }); - } - } - }, - (error) => { - console.log(error); - } - ); - } catch (err) { - console.log(err); - } - } - }, [address]); - // ====================================================== || address 1 (drop)|| ====================================================== - useEffect(() => { - if (address) { - try { - Geocode.fromAddress(address1).then( - (response) => { - if (response.status == 'OK') { - const { lat, lng } = response.results[0].geometry.location; + // // // ====================================================== || address (pick)|| ====================================================== + // useEffect(() => { + // if (address) { + // try { + // Geocode.fromAddress(address).then( + // (response) => { + // if (response.status == 'OK') { + // const { lat, lng } = response.results[0].geometry.location; + // console.log({ lat, lng }); + // setLatlong({ + // lat, + // lng + // }); + // console.log(response); + // if (response.results[0].address_components) { + // let place = response.results[0]; + // let cityA, zipcodeA, stateA, suburbA; + // for (let i = 0; i < place.address_components.length; i++) { + // for (let j = 0; j < place.address_components[i].types.length; j++) { + // switch (place.address_components[i].types[j]) { + // case 'locality': + // cityA = place.address_components[i].long_name; + // break; + // case 'administrative_area_level_1': + // stateA = place.address_components[i].long_name; + // break; + // case 'postal_code': + // zipcodeA = place.address_components[i].long_name; + // break; + // case 'sublocality': + // suburbA = place.address_components[i].long_name; + // break; + // } + // } + // } + // setCity(cityA || ''); + // setState(stateA || ''); + // setZipcode(zipcodeA || ''); + // setSuburb(suburbA || ''); + // console.log({ lat, lng, cityA, stateA, zipcodeA, suburbA }); + // setPickCust({ + // ...pickCust + // // city: cityA, + // // state: stateA, + // // postcode: zipcodeA, + // // suburb: suburbA + // // latitude: lat, + // // longitude: lng + // }); + // // setStartPoint({ latitude: lat, longitude: lng }); + // } + // } + // }, + // (error) => { + // console.log(error); + // } + // ); + // } catch (err) { + // console.log(err); + // } + // } + // }, [address]); + // // // ====================================================== || address 1 (drop)|| ====================================================== + // useEffect(() => { + // if (address) { + // try { + // Geocode.fromAddress(address1).then( + // (response) => { + // if (response.status == 'OK') { + // const { lat, lng } = response.results[0].geometry.location; - setLatlong1({ - lat, - lng - }); - console.log(response); - if (response.results[0].address_components) { - let place = response.results[0]; - let cityB, zipcodeB, stateB, suburbB; - for (let i = 0; i < place.address_components.length; i++) { - for (let j = 0; j < place.address_components[i].types.length; j++) { - switch (place.address_components[i].types[j]) { - case 'locality': - cityB = place.address_components[i].long_name; - break; - case 'administrative_area_level_1': - stateB = place.address_components[i].long_name; - break; - case 'postal_code': - zipcodeB = place.address_components[i].long_name; - break; - case 'sublocality': - suburbB = place.address_components[i].long_name; - break; - } - } - } - setCity(cityB || ''); - setState(stateB || ''); - setZipcode(zipcodeB || ''); - setSuburb(suburbB || ''); - console.log({ lat, lng, cityB, stateB, zipcodeB, suburbB }); - setDropCust({ - ...dropCust, - city: cityB, - state: stateB, - postcode: zipcodeB, - suburb: suburbB, - latitude: lat, - longitude: lng - }); - setEndPoint({ latitude: lat, longitude: lng }); - } - } - }, - (error) => { - console.log(error); - } - ); - } catch (err) { - console.log(err); - } - } - }, [address1]); + // setLatlong1({ + // lat, + // lng + // }); + // console.log(response); + // if (response.results[0].address_components) { + // let place = response.results[0]; + // let cityB, zipcodeB, stateB, suburbB; + // for (let i = 0; i < place.address_components.length; i++) { + // for (let j = 0; j < place.address_components[i].types.length; j++) { + // switch (place.address_components[i].types[j]) { + // case 'locality': + // cityB = place.address_components[i].long_name; + // break; + // case 'administrative_area_level_1': + // stateB = place.address_components[i].long_name; + // break; + // case 'postal_code': + // zipcodeB = place.address_components[i].long_name; + // break; + // case 'sublocality': + // suburbB = place.address_components[i].long_name; + // break; + // } + // } + // } + // setCity(cityB || ''); + // setState(stateB || ''); + // setZipcode(zipcodeB || ''); + // setSuburb(suburbB || ''); + // console.log({ lat, lng, cityB, stateB, zipcodeB, suburbB }); + // setDropCust({ + // ...dropCust + // // city: cityB, + // // state: stateB, + // // postcode: zipcodeB, + // // suburb: suburbB + // // latitude: lat, + // // longitude: lng + // }); + // // setEndPoint({ latitude: lat, longitude: lng }); + // } + // } + // }, + // (error) => { + // console.log(error); + // } + // ); + // } catch (err) { + // console.log(err); + // } + // } + // }, [address1]); if (typeof window !== 'undefined' && !loaded.current) { if (!document.querySelector('#google-maps')) { @@ -246,93 +248,92 @@ const Createorder1 = () => { 'google-maps' ); } - loaded.current = true; } - const fetch = React.useMemo( - () => - debounce((request, callback) => { - autocompleteService.current.getPlacePredictions(request, callback); - }, 400), - [] - ); - const fetch1 = React.useMemo( - () => - debounce((request, callback) => { - autocompleteService.current.getPlacePredictions(request, callback); - }, 400), - [] - ); + // const fetch = React.useMemo( + // () => + // debounce((request, callback) => { + // autocompleteService.current.getPlacePredictions(request, callback); + // }, 400), + // [] + // ); + // const fetch1 = React.useMemo( + // () => + // debounce((request, callback) => { + // autocompleteService.current.getPlacePredictions(request, callback); + // }, 400), + // [] + // ); // ====================================================== || options (pick)|| ====================================================== - React.useEffect(() => { - let active = true; - if (!autocompleteService.current && window.google) { - autocompleteService.current = new window.google.maps.places.AutocompleteService(); - } - if (!autocompleteService.current) { - return undefined; - } - if (inputValue === '') { - setOptions(value ? [value] : []); - return undefined; - } - fetch({ input: inputValue }, (results) => { - if (active) { - let newOptions = []; + // React.useEffect(() => { + // let active = true; + // if (!autocompleteService.current && window.google) { + // autocompleteService.current = new window.google.maps.places.AutocompleteService(); + // } + // if (!autocompleteService.current) { + // return undefined; + // } + // if (inputValue === '') { + // setOptions(value ? [value] : []); + // return undefined; + // } + // fetch({ input: inputValue }, (results) => { + // if (active) { + // let newOptions = []; - if (value) { - newOptions = [value]; - } + // if (value) { + // newOptions = [value]; + // } - if (results) { - newOptions = [...newOptions, ...results]; - } + // if (results) { + // newOptions = [...newOptions, ...results]; + // } - setOptions(newOptions); - } - }); + // setOptions(newOptions); + // } + // }); - return () => { - active = false; - }; - }, [value, inputValue, fetch]); + // return () => { + // active = false; + // }; + // }, [value, inputValue, fetch]); - // ====================================================== || options1 (drop)|| ====================================================== - React.useEffect(() => { - let active = true; - if (!autocompleteService.current && window.google) { - autocompleteService.current = new window.google.maps.places.AutocompleteService(); - } - if (!autocompleteService.current) { - return undefined; - } - if (inputValue1 === '') { - setOptions1(value1 ? [value1] : []); - return undefined; - } - fetch1({ input: inputValue1 }, (results) => { - if (active) { - let newOptions = []; + // // ====================================================== || options1 (drop)|| ====================================================== + // React.useEffect(() => { + // let active = true; + // if (!autocompleteService.current && window.google) { + // autocompleteService.current = new window.google.maps.places.AutocompleteService(); + // } + // if (!autocompleteService.current) { + // return undefined; + // } + // if (inputValue1 === '') { + // setOptions1(value1 ? [value1] : []); + // return undefined; + // } + // fetch1({ input: inputValue1 }, (results) => { + // if (active) { + // let newOptions = []; - if (value1) { - newOptions = [value1]; - } + // if (value1) { + // newOptions = [value1]; + // } - if (results) { - newOptions = [...newOptions, ...results]; - } + // if (results) { + // newOptions = [...newOptions, ...results]; + // } - setOptions1(newOptions); - } - }); + // setOptions1(newOptions); + // } + // }); - return () => { - active = false; - }; - }, [value1, inputValue1, fetch1]); + // return () => { + // active = false; + // }; + // }, [value1, inputValue1, fetch1]); const appId = localStorage.getItem('applocationid'); const navigate = useNavigate(); @@ -461,8 +462,8 @@ const Createorder1 = () => { } setShowDistance(true); if (roundedDistance > appLocaRadius) { - opentoast('Service not available at this location', 'error', 2000); setShowDistance(true); + setOpen4(true); } }; @@ -772,106 +773,108 @@ const Createorder1 = () => { let arr = {}; arr = { orders: { - orderheaderid: 0, - tenantid: tenant.tenantid, applocationid: tenant.applolcationid, - locationid: +tenanatLocoId, //main or branch - moduleid: +tenant.moduleid, + cancellled: '', categoryid: +tenant.categoryid, - subcategoryid: +subCatId, configid: +localStorage.getItem('configid'), - orderid: '', // - orderdate: dayjs().format('YYYY-MM-DD HH:mm:ss'), + customerid: +pickCust.customerid || 0, + deliveryaddress: dropCust.address || '', + deliverycharge: +totalCharge.toFixed(2) || 0, + deliverycity: dropCust.city || '', + deliverycontactno: dropCust.contactno || '', + deliverycustomer: dropCust.firstname || '', + deliveryid: dropCust.customerid || 0, + deliverylandmark: dropCust.landmark || '', + deliverylat: dropCust.latitude.toString(), + deliverylocation: dropCust.suburb || '', + deliverylocationid: dropCust.deliverylocationid || 0, + deliverylong: dropCust.longitude.toString(), deliverytime: `${dayjs(startdate).format('YYYY-MM-DD')} ${dayjs(selectedtime.$d).format('HH:mm:ss')}`, deliverytype: pickCust.customerid !== 0 || dropCust.customerid !== 0 ? 'B' : 'C', + delivered: '', + itemcount: 1, + kms: distance || 0, + locationid: +tenanatLocoId, //main or branch + moduleid: +tenant.moduleid, + orderamount: +totalCharge.toFixed(2) || 0, + ordercharges: 0.0, + orderdate: dayjs().format('YYYY-MM-DD HH:mm:ss'), + orderheaderid: 0, + orderid: '', // + ordernotes: otherinstructions, orderstatus: 'created', + ordervalue: +totalCharge.toFixed(2) || 0, + partnerid: tenant.partnerid, + paymentstatus: 1, + paymenttype: 42, pending: '', + pickupaddress: pickCust.address || '', + pickupcity: pickCust.city || '', + pickupcontactno: pickCust.contactno || '', + pickupcustomer: pickCust.firstname || '', + pickuplandmark: pickCust.landmark || '', + pickuplat: pickCust.latitude.toString(), + pickuplocation: pickCust.suburb || '', + pickuplocationid: pickCust.deliverylocationid || 0, + pickuplong: pickCust.longitude.toString(), + pickupaddress: pickCust.address || '', processing: '', ready: '', - delivered: '', - cancellled: '', - customerid: +pickCust.customerid || 0, - pickupcustomer: pickCust.firstname || '', - pickupcontactno: pickCust.contactno || '', - pickuplandmark: pickCust.landmark || '', - pickuplocation: pickCust.suburb || '', - pickupcity: pickCust.city || '', - pickuplocationid: pickCust.deliverylocationid || 0, - pickupaddress: pickCust.address || '', - pickuplat: pickCust.latitude.toString(), - pickuplong: pickCust.longitude.toString(), - deliveryid: dropCust.customerid || 0, - deliverycustomer: dropCust.firstname || '', - deliverycontactno: dropCust.contactno || '', - deliverylocationid: dropCust.deliverylocationid || 0, - deliverylat: dropCust.latitude.toString(), - deliverylong: dropCust.longitude.toString(), - deliveryaddress: dropCust.address || '', - deliverylandmark: dropCust.landmark || '', - deliverylocation: dropCust.suburb || '', - deliverycity: dropCust.city || '', - orderamount: +totalCharge.toFixed(2) || 0, - taxamount: 0.0, - ordercharges: 0.0, - ordervalue: +totalCharge.toFixed(2) || 0, - itemcount: 1, - paymenttype: 42, - paymentstatus: 1, - deliverycharge: +totalCharge.toFixed(2) || 0, - ordernotes: otherinstructions, - kms: distance || 0, - smsdelivery: 1, remarks: '', - tenantuserid: parseInt(localStorage.getItem('userid')), - partnerid: tenant.partnerid + smsdelivery: 1, + subcategoryid: +subCatId, + taxamount: 0.0, + tenantid: tenant.tenantid, + tenantuserid: parseInt(localStorage.getItem('userid')) }, + pickup: { - customerid: pickCust.customerid || 0, - configid: parseInt(localStorage.getItem('configid')), - firstname: pickCust.firstname || '', + address: pickCust.address || '', applocationid: pickCust.applocationid, - profileimage: '', - dialcode: '+91', + city: pickCust.city || '', + configid: parseInt(localStorage.getItem('configid')), contactno: pickCust.contactno || '', + customertoken: '', + customerid: pickCust.customerid || 0, devicetype: '', deviceid: '', - customertoken: '', - address: pickCust.address || '', - suburb: pickCust.suburb || '', - city: pickCust.city || '', - state: pickCust.state || '', - postcode: pickCust.postcode || '', - landmark: pickCust.landmark || '', + dialcode: '+91', doorno: pickCust.doorno || '', + email: pickCust.email || '', + firstname: pickCust.firstname || '', + landmark: pickCust.landmark || '', latitude: pickCust.latitude.toString() || '', longitude: pickCust.longitude.toString() || '', - tenantid: tenant.tenantid, - email: pickCust.email || '', - primaryaddress: 1 + postcode: pickCust.postcode || '', + primaryaddress: 1, + profileimage: '', + state: pickCust.state || '', + suburb: pickCust.suburb || '', + tenantid: tenant.tenantid }, drop: { - customerid: dropCust.customerid || 0, - configid: parseInt(localStorage.getItem('configid')), - firstname: dropCust.firstname || '', + address: dropCust.address || '', applocationid: dropCust.applocationid, - profileimage: '', - dialcode: '+91', + city: dropCust.city || '', + configid: parseInt(localStorage.getItem('configid')), contactno: dropCust.contactno || '', + customertoken: '', + customerid: dropCust.customerid || 0, devicetype: '', deviceid: '', - customertoken: '', - address: dropCust.address || '', - suburb: dropCust.suburb || '', - city: dropCust.city || '', - state: dropCust.state || '', - postcode: dropCust.postcode || '', - landmark: dropCust.landmark || '', + dialcode: '+91', doorno: dropCust.doorno || '', + email: dropCust.email || '', + firstname: dropCust.firstname || '', + landmark: dropCust.landmark || '', latitude: dropCust.latitude.toString(), longitude: dropCust.longitude.toString(), - tenantid: tenant.tenantid, - email: dropCust.email || '', - primaryaddress: 1 + postcode: dropCust.postcode || '', + primaryaddress: 1, + profileimage: '', + state: dropCust.state || '', + suburb: dropCust.suburb || '', + tenantid: tenant.tenantid } }; console.log('createsubmitobj2', arr); @@ -1058,144 +1061,173 @@ const Createorder1 = () => { // ============================================= || Google Maps Autocomplete(pick) || ============================================= useEffect(() => { // Initialize Google Maps Autocomplete - const autocompleteInput = document.getElementById('addressAuto1'); - const autocomplete = new window.google.maps.places.Autocomplete(autocompleteInput, { - // types: ['(cities)'], // You can adjust the types parameter based on your requirements - strictBounds: true, - bounds: new window.google.maps.Circle({ - // center: new window.google.maps.LatLng(11.0050707, 76.9509083), - // radius: 100000 - center: new window.google.maps.LatLng(appLocaLat, appLocaLng), - radius: appLocaRadius * 1000 - }).getBounds() - }); - let arr = []; - // Event listener for autocomplete place changed - autocomplete.addListener('place_changed', () => { - const place = autocomplete.getPlace(); - setInputValue2(`${place.name}, ${place.formatted_address}`); - console.log('new place', place); // Do something with the selected place - console.log('new place lat lng', { lat: place.geometry.location.lat(), lng: place.geometry.location.lng() }); // Do something with the selected place - setValue(place); - setAddress(`${place.name} ${place.formatted_address}`); - setPickCust({ ...pickCust, address: `${place.name} ${place.formatted_address}` }); - const address = { - street_number: '', - route: '', - locality: '', - sublocality_level_1: '', - administrative_area_level_3: '', - administrative_area_level_1: '', - country: '', - postal_code: '' - }; - place.address_components.forEach((component) => { - component.types.forEach((type) => { - switch (type) { - case 'street_number': - address.street_number = component.long_name; - break; - case 'route': - address.route = component.long_name; - break; - case 'locality': - address.locality = component.long_name; - break; - case 'sublocality_level_1': - address.sublocality_level_1 = component.long_name; - break; - case 'administrative_area_level_3': - address.administrative_area_level_3 = component.long_name; - break; - case 'administrative_area_level_1': - address.administrative_area_level_1 = component.long_name; - break; - case 'country': - address.country = component.long_name; - break; - case 'postal_code': - address.postal_code = component.long_name; - break; - // Add more cases as needed for other types - } - }); + if (inputValue2) { + const autocompleteInput = document.getElementById('addressAuto1'); + const autocomplete = new window.google.maps.places.Autocomplete(autocompleteInput, { + // types: ['(cities)'], // You can adjust the types parameter based on your requirements + strictBounds: true, + bounds: new window.google.maps.Circle({ + // center: new window.google.maps.LatLng(11.0050707, 76.9509083), + // radius: 100000 + center: new window.google.maps.LatLng(appLocaLat, appLocaLng), + radius: appLocaRadius * 1000 + }).getBounds() }); + let arr = []; + // Event listener for autocomplete place changed + autocomplete.addListener('place_changed', () => { + const place = autocomplete.getPlace(); + setInputValue2(`${place.name}, ${place.formatted_address}`); + console.log('new place', place); // Do something with the selected place + console.log(' pick (new place) lat lng', { lat: place.geometry.location.lat(), lng: place.geometry.location.lng() }); // Do something with the selected place + // to trigger getDistance + setStartPoint({ latitude: place.geometry.location.lat(), longitude: place.geometry.location.lng() }); + setValue(place); + setAddress(`${place.name} ${place.formatted_address}`); + setPickCust({ ...pickCust, address: `${place.name} ${place.formatted_address}` }); + const address = { + address: `${place.name} ${place.formatted_address}`, + street_number: '', + route: '', + locality: '', + sublocality_level_1: '', + administrative_area_level_3: '', + administrative_area_level_1: '', + country: '', + postal_code: '' + }; + place.address_components.forEach((component) => { + component.types.forEach((type) => { + switch (type) { + case 'street_number': + address.street_number = component.long_name; + break; + case 'route': + address.route = component.long_name; + break; + case 'locality': + address.locality = component.long_name; + break; + case 'sublocality_level_1': + address.sublocality_level_1 = component.long_name; + break; + case 'administrative_area_level_3': + address.administrative_area_level_3 = component.long_name; + break; + case 'administrative_area_level_1': + address.administrative_area_level_1 = component.long_name; + break; + case 'country': + address.country = component.long_name; + break; + case 'postal_code': + address.postal_code = component.long_name; + break; + // Add more cases as needed for other types + } + }); + }); - // Use address object as per your requirements - console.log('Address:', address); - }); - }, [address, inputValue2, pickCust]); + // Use address object as per your requirements + setPickCust({ + ...pickCust, + address: address.address, + doorno: `${address.street_number} ${address.route}`, + suburb: address.sublocality_level_1, + city: address.locality, + postcode: address.postal_code, + latitude: place.geometry.location.lat(), + longitude: place.geometry.location.lng() + }); + console.log('Pick Address:', address); + }); + } + }, [inputValue2]); // ============================================= || Google Maps Autocomplete(Drop) || ============================================= useEffect(() => { - // Initialize Google Maps Autocomplete - const autocompleteInput = document.getElementById('addressAuto2'); - const autocomplete = new window.google.maps.places.Autocomplete(autocompleteInput, { - // types: ['(cities)'], // You can adjust the types parameter based on your requirements - strictBounds: true, - bounds: new window.google.maps.Circle({ - // center: new window.google.maps.LatLng(11.0050707, 76.9509083), - center: new window.google.maps.LatLng(appLocaLat, appLocaLng), - radius: appLocaRadius * 1000 //km to m - // radius: 100000 //km to m - }).getBounds() - }); - let arr = []; - // Event listener for autocomplete place changed - autocomplete.addListener('place_changed', () => { - const place = autocomplete.getPlace(); - setInputValue3(`${place.name}, ${place.formatted_address}`); - console.log('new place', place); // Do something with the selected place - console.log('new place lat lng', { lat: place.geometry.location.lat(), lng: place.geometry.location.lng() }); // Do something with the selected place - setValue1(place); - setAddress1(`${place.name} ${place.formatted_address}`); - setDropCust({ ...pickCust, address: `${place.name} ${place.formatted_address}` }); - const address = { - street_number: '', - route: '', - locality: '', - sublocality_level_1: '', - administrative_area_level_3: '', - administrative_area_level_1: '', - country: '', - postal_code: '' - }; - place.address_components.forEach((component) => { - component.types.forEach((type) => { - switch (type) { - case 'street_number': - address.street_number = component.long_name; - break; - case 'route': - address.route = component.long_name; - break; - case 'locality': - address.locality = component.long_name; - break; - case 'sublocality_level_1': - address.sublocality_level_1 = component.long_name; - break; - case 'administrative_area_level_3': - address.administrative_area_level_3 = component.long_name; - break; - case 'administrative_area_level_1': - address.administrative_area_level_1 = component.long_name; - break; - case 'country': - address.country = component.long_name; - break; - case 'postal_code': - address.postal_code = component.long_name; - break; - // Add more cases as needed for other types - } - }); + if (inputValue3) { + // Initialize Google Maps Autocomplete + const autocompleteInput = document.getElementById('addressAuto2'); + const autocomplete = new window.google.maps.places.Autocomplete(autocompleteInput, { + // types: ['(cities)'], // You can adjust the types parameter based on your requirements + strictBounds: true, + bounds: new window.google.maps.Circle({ + // center: new window.google.maps.LatLng(11.0050707, 76.9509083), + center: new window.google.maps.LatLng(appLocaLat, appLocaLng), + radius: appLocaRadius * 1000 //km to m + // radius: 100000 //km to m + }).getBounds() }); + let arr = []; + // Event listener for autocomplete place changed + autocomplete.addListener('place_changed', () => { + const place = autocomplete.getPlace(); + setInputValue3(`${place.name}, ${place.formatted_address}`); + console.log('new place', place); // Do something with the selected place + console.log('drop (new place) lat lng', { lat: place.geometry.location.lat(), lng: place.geometry.location.lng() }); // Do something with the selected place + setEndPoint({ latitude: place.geometry.location.lat(), longitude: place.geometry.location.lng() }); + setValue1(place); + setAddress1(`${place.name} ${place.formatted_address}`); + setDropCust({ ...dropCust, address: `${place.name} ${place.formatted_address}` }); + const address = { + address: `${place.name} ${place.formatted_address}`, + street_number: '', + route: '', + locality: '', + sublocality_level_1: '', + administrative_area_level_3: '', + administrative_area_level_1: '', + country: '', + postal_code: '' + }; + place.address_components.forEach((component) => { + component.types.forEach((type) => { + switch (type) { + case 'street_number': + address.street_number = component.long_name; + break; + case 'route': + address.route = component.long_name; + break; + case 'locality': + address.locality = component.long_name; + break; + case 'sublocality_level_1': + address.sublocality_level_1 = component.long_name; + break; + case 'administrative_area_level_3': + address.administrative_area_level_3 = component.long_name; + break; + case 'administrative_area_level_1': + address.administrative_area_level_1 = component.long_name; + break; + case 'country': + address.country = component.long_name; + break; + case 'postal_code': + address.postal_code = component.long_name; + break; + // Add more cases as needed for other types + } + }); + }); - // Use address object as per your requirements - console.log('Address:', address); - }); - }, [address, inputValue3, dropCust]); + // Use address object as per your requirements + setDropCust({ + ...dropCust, + address: address.address, + doorno: `${address.street_number} ${address.route}`, + suburb: address.sublocality_level_1, + city: address.locality, + postcode: address.postal_code, + latitude: place.geometry.location.lat(), + longitude: place.geometry.location.lng() + }); + console.log('Drop Address:', address); + }); + } + }, [inputValue3]); // ============================================= || gettenantlocations (branches) || ============================================= const gettenantlocations = async () => { @@ -1240,7 +1272,21 @@ const Createorder1 = () => { > Create Order {tenantLocations.length == 1 ? ( - + + + + ) + }} + /> ) : ( { ) }} variant="outlined" - label="Door No" + label="Door No / Street" value={pickCust.doorno} onChange={(e) => { setPickCust({ ...pickCust, doorno: e.target.value }); @@ -1922,7 +1968,7 @@ const Createorder1 = () => { @@ -2123,7 +2169,7 @@ const Createorder1 = () => { label={dayjs(val).format('hh:mm A')} onClick={() => { if (distance > appLocaRadius) { - opentoast('Service not available at this location', 'error', 2000); + setOpen4(true); } else if (showDistance) { console.log('selectedtime', val); setSelectedtime(val); @@ -2233,9 +2279,19 @@ const Createorder1 = () => {