import React, { useState } from "react"; import { useNavigate, useLocation } from 'react-router-dom' import axios from "../../custom-axios/axios"; import CenteredContainer from "../UtilComponents/CenteredContainer"; import { MapContainer, TileLayer, Marker, Popup, useMapEvents } from 'react-leaflet' import 'leaflet/dist/leaflet.css'; import markerIconPng from "leaflet/dist/images/marker-icon.png"; import {Icon} from 'leaflet'; import '../UtilComponents/App.css'; const ConfirmedRequest = (props) => { const location = useLocation(); const navigate = useNavigate(); const [destinationLatitude, setLatitude] = useState(null) const [destinationLongitude, setLongitude] = useState(null) const [position, setPosition] = useState(null) const startDrive = async () => { const requestId = location.state.confirmedRequest.id; const driverId = localStorage.getItem("driverId"); if(!(destinationLatitude && destinationLongitude)){ alert("Must choose destination address for passenger on the map."); return; } const response = await axios.post(`/drive/start/${requestId}/${driverId}`, { "destinationLatitude" : destinationLatitude, "destinationLongitude" : destinationLongitude }) const startLatitude = location.state.confirmedRequest.latitude; const startLongitude = location.state.confirmedRequest.longitude; props.onRefreshPassengersMadeRequest(); navigate('/started-drive', {state: {startedDrive: response.data, startLatitude: startLatitude, startLongitude: startLongitude}}) } function LocationMarker() { const map = useMapEvents({ dblclick(){ map.locate() }, click(e) { setLatitude(e.latlng.lat) setLongitude(e.latlng.lng) setPosition(e.latlng) map.flyTo(e.latlng, map.getZoom()) }, locationfound(e) { setPosition(e.latlng) map.flyTo(e.latlng, map.getZoom()) } }) return position === null ? null : (

This is the passenger's

destination location.

) } return (
{location.state.confirmedRequest.status}
{location.state.confirmedRequest.cityAddress}, {location.state.confirmedRequest.streetAddress}, {location.state.confirmedRequest.numberAddress}

Passenger: {location.state.confirmedRequest.passenger.name} {location.state.confirmedRequest.passenger.surname}



Pick your passenger

{location.state.confirmedRequest.passenger.name} {location.state.confirmedRequest.passenger.surname} from here.

) } export default ConfirmedRequest;