1 | import React from "react";
|
---|
2 | import axios from "../../custom-axios/axios";
|
---|
3 | import { useNavigate } from 'react-router-dom'
|
---|
4 | import { MapContainer, TileLayer, Marker, Popup } from 'react-leaflet'
|
---|
5 | import 'leaflet/dist/leaflet.css';
|
---|
6 | import markerIconPng from "leaflet/dist/images/marker-icon.png"
|
---|
7 | import {Icon} from 'leaflet'
|
---|
8 | import '../UtilComponents/App.css'
|
---|
9 |
|
---|
10 | const Requests = (props) => {
|
---|
11 | const navigate = useNavigate();
|
---|
12 |
|
---|
13 | const toConfirmedRequest = async (driverId, requestId) => {
|
---|
14 | const response = await axios.post(`/request/confirm/${driverId}/${requestId}`)
|
---|
15 | navigate('/confirmed-request', {state: {confirmedRequest: response.data}})
|
---|
16 | };
|
---|
17 |
|
---|
18 | return(
|
---|
19 | <div className={"container mm-4 mt-5"} style={{width: "85%", margin: 'auto'}}>
|
---|
20 | <h2 style={{textAlign: 'center', color: "darkcyan"}}>Requests</h2>
|
---|
21 | <hr></hr>
|
---|
22 | <div className={"row table-responsive"}>
|
---|
23 | <div className={"row"} style={{margin: 'auto'}}>
|
---|
24 | <table className={"table table-hover"} >
|
---|
25 | <thead>
|
---|
26 | <tr>
|
---|
27 | <th scope={"col"}>City</th>
|
---|
28 | <th scope={"col"}>Street</th>
|
---|
29 | <th scope={"col"}>Number</th>
|
---|
30 | <th scope={"col"}>Passenger</th>
|
---|
31 | <th scope={"col"}></th>
|
---|
32 | </tr>
|
---|
33 | </thead>
|
---|
34 | <tbody>
|
---|
35 | {props.requests.map((term) => {
|
---|
36 | return(
|
---|
37 | <tr style={ term.chosenDriver != null ? { backgroundColor:'lightgreen'} : {}}>
|
---|
38 | <td>{term.cityAddress}</td>
|
---|
39 | <td>{term.streetAddress}</td>
|
---|
40 | <td>{term.numberAddress}</td>
|
---|
41 | <td>{term.passenger.name} {term.passenger.surname}</td>
|
---|
42 | <td className={"text-right"}>
|
---|
43 | <a title={"Confirm"} id="submit" className={"myButton btn btn-primary"}
|
---|
44 | style={{backgroundColor: "darkcyan", borderColor: "black", color: 'white'}}
|
---|
45 | onClick={() => toConfirmedRequest(localStorage.getItem("driverId"), term.id)}>Confirm</a>
|
---|
46 | </td>
|
---|
47 | </tr>
|
---|
48 | )
|
---|
49 | })}
|
---|
50 | </tbody>
|
---|
51 | </table>
|
---|
52 | </div>
|
---|
53 | </div>
|
---|
54 | <MapContainer className="border border-info rounded-2" center={[41.9943, 21.4309]} zoom={13} scrollWheelZoom={true} style={{width: 'calc(750px - 50vw)', minWidth:'80%', maxWidth: '100%', margin: 'auto', position: 'relative', zIndex: 0, marginBottom: "50px"}}>
|
---|
55 | <TileLayer
|
---|
56 | attribution='© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
---|
57 | url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
|
---|
58 | />
|
---|
59 | {props.requests.map((term) => {
|
---|
60 | return(
|
---|
61 | <Marker position={[term.latitude, term.longitude]} icon={new Icon({iconUrl: markerIconPng, iconSize: [25, 41], iconAnchor: [12, 41]})}>
|
---|
62 | <Popup position={[term.latitude, term.longitude]}>
|
---|
63 | <p>{term.passenger.name} {term.passenger.surname}</p>
|
---|
64 | <p>{term.cityAddress}, {term.streetAddress}, {term.numberAddress}</p>
|
---|
65 | <a title={"Confirm"} id="submit" className={"myButton btn btn-primary"}
|
---|
66 | style={{backgroundColor: "darkcyan", borderColor: "black", color: 'white'}}
|
---|
67 | onClick={() => toConfirmedRequest(localStorage.getItem("driverId"), term.id)}>Confirm</a>
|
---|
68 | </Popup>
|
---|
69 | </Marker>
|
---|
70 | )
|
---|
71 | })}
|
---|
72 | </MapContainer>
|
---|
73 | </div>
|
---|
74 | )
|
---|
75 | }
|
---|
76 |
|
---|
77 | export default Requests; |
---|