import React, { useState } from "react"; import { useNavigate, useLocation} from "react-router-dom"; import CenteredContainer from "../UtilComponents/CenteredContainer"; import axios from "../../custom-axios/axios"; 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 MakeRequest = () => { const location = useLocation(); // eslint-disable-next-line react-hooks/rules-of-hooks const navigate = useNavigate(); // eslint-disable-next-line react-hooks/rules-of-hooks const [formData, updateFormData] = React.useState({ cityAddress : "", streetAddress : "", numberAddress : "" }) const [latitude, setLatitude] = useState(null) const [longitude, setLongitude] = useState(null) const [position, setPosition] = useState(null) const handleChange = (e) => { updateFormData({ ...formData, [e.target.name]: e.target.value.trim() }) } const onFormSubmit = async (e) => { e.preventDefault(); const cityAddress = formData.cityAddress; const streetAddress = formData.streetAddress; const numberAddress = formData.numberAddress; const passengerId = localStorage.getItem("passengerId"); let chosenDriverId = null if(location.state){ chosenDriverId = location.state.driverId } if(!(latitude && longitude)){ alert("You must pick a location on the map") } const response = await axios.post(`/request/make/${passengerId}`, { "cityAddress" : cityAddress, "streetAddress" : streetAddress, "numberAddress" : numberAddress, "latitude" : latitude, "longitude" : longitude, "chosenDriverId" : chosenDriverId }) localStorage.setItem("madeRequestId", response.data.id) navigate("/made-request", {state: {madeRequest: response.data}}) } let showChosenDriver if(location.state){ showChosenDriver =
You picked the driver with name {location.state.driverName}.
Add your address to complete the request.