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 RoutingMachine from "./routineMachine"; import '../UtilComponents/App.css' const StartedDrive = () => { const location = useLocation(); const navigate = useNavigate(); const distanceToTravel = getDistance([location.state.startLatitude, location.state.startLongitude], [location.state.startedDrive.destinationLatitude, location.state.startedDrive.destinationLongitude]) const finishDrive = () => { const driveId = location.state.startedDrive.id axios.post(`/drive/finish/${driveId}`, null, { params: { kmTravelled: distanceToTravel } }) navigate("/home"); } const gradeDrive = () => { const driveId = location.state.startedDrive.id navigate("/grade-drive", {state: {driveId: driveId}}) } const payDrive = async () => { const driverId = location.state.startedDrive.driver.id const requestId = location.state.startedDrive.request.id const driverResponse = await axios.get(`/driver/${driverId}`); const startedDriveResponse = await axios.get(`/drive/request/${requestId}`) const driverPricePerKm = driverResponse.data.pricePerKm const kmTravelled = distanceToTravel const totalSumToPay = driverPricePerKm * kmTravelled navigate("/pay-drive", {state: {driveId: startedDriveResponse.data.id, driverPricePerKm: driverPricePerKm, totalSumToPay: totalSumToPay, kmTravelled: kmTravelled}}) } let finishDriveButton = {finishDrive()}}> Finish Drive let gradeButton = {gradeDrive()}}> Grade Driver for Drive let payForDrive = {payDrive()}}> Pay Drive let grade =
Passenger's destination address
You started your drive here.