import React from "react"; import { useLocation, useNavigate } from 'react-router-dom' import CenteredContainer from "../UtilComponents/CenteredContainer"; import axios from "../../custom-axios/axios"; import { MapContainer, TileLayer, Marker, Popup } 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 MadeRequest = (props) => { const location = useLocation() const navigate = useNavigate() const [formData, updateFormData] = React.useState({ status : location.state.madeRequest.status, cityAddress : location.state.madeRequest.cityAddress, numberAddress : location.state.madeRequest.numberAddress, streetAddress : location.state.madeRequest.streetAddress, latitude: location.state.madeRequest.latitude, longitude : location.state.madeRequest.longitude, confirmedByDriver: "", }) const updateMadeRequest = async () => { const requestId = location.state.madeRequest.id const response = await axios.get(`/request/${requestId}`) updateFormData({ status : response.data.status, cityAddress : response.data.cityAddress, numberAddress : response.data.numberAddress, streetAddress : response.data.streetAddress, latitude: response.data.latitude, longitude : response.data.longitude, confirmedByDriver: response.data.confirmedByDriver }) } const joinDriveForPassenger = async () => { const requestId = location.state.madeRequest.id const response = await axios.get(`/drive/request/${requestId}`) .catch(function (error) { if (error.response) { alert("Wait for the driver to pick you up and start the drive. Then you can join."); } }); localStorage.removeItem("madeRequestId") const startLatitude = formData.latitude; const startLongitude = formData.longitude; navigate("/started-drive", {state: {startedDrive: response.data, startLatitude: startLatitude, startLongitude: startLongitude}}) } let messageAfterConfirmation1 = "" let messageAfterConfirmation2 = "" let joinDrive = "" if(formData.status === "CONFIRMED"){ messageAfterConfirmation1 =

Your request has been confirmed, please wait for the driver on the provided address.

messageAfterConfirmation2 =

After your driver picks you up and starts the drive, you should start the drive too.

joinDrive = joinDriveForPassenger()} > Join Drive } let confirmedByDriver = "" if(formData.confirmedByDriver){ confirmedByDriver =
Confirmed by Driver: {formData.confirmedByDriver.name} {formData.confirmedByDriver.surname}
} return (
{formData.status}
You have created your request, please wait until some driver confirms it
{formData.cityAddress}, {formData.streetAddress}, {formData.numberAddress}
{confirmedByDriver}


{messageAfterConfirmation1} {messageAfterConfirmation2}

updateMadeRequest()}>Refresh

{joinDrive}

Pick up location. Wait here.

) } export default MadeRequest;