source: RebuMKReact/src/Components/Requests/madeRequest.js@ 364f27d

Last change on this file since 364f27d was 364f27d, checked in by MetodiMladenovski <meto.18@…>, 14 months ago

added projects and db scripts

  • Property mode set to 100644
File size: 5.1 KB
RevLine 
[364f27d]1import React from "react";
2import { useLocation, useNavigate } from 'react-router-dom'
3import CenteredContainer from "../UtilComponents/CenteredContainer";
4import axios from "../../custom-axios/axios";
5import { MapContainer, TileLayer, Marker, Popup } from 'react-leaflet'
6import 'leaflet/dist/leaflet.css';
7import markerIconPng from "leaflet/dist/images/marker-icon.png"
8import {Icon} from 'leaflet'
9import '../UtilComponents/App.css'
10
11const MadeRequest = (props) => {
12 const location = useLocation()
13 const navigate = useNavigate()
14 const [formData, updateFormData] = React.useState({
15 status : location.state.madeRequest.status,
16 cityAddress : location.state.madeRequest.cityAddress,
17 numberAddress : location.state.madeRequest.numberAddress,
18 streetAddress : location.state.madeRequest.streetAddress,
19 latitude: location.state.madeRequest.latitude,
20 longitude : location.state.madeRequest.longitude,
21 confirmedByDriver: "",
22 })
23
24 const updateMadeRequest = async () => {
25 const requestId = location.state.madeRequest.id
26 const response = await axios.get(`/request/${requestId}`)
27 updateFormData({
28 status : response.data.status,
29 cityAddress : response.data.cityAddress,
30 numberAddress : response.data.numberAddress,
31 streetAddress : response.data.streetAddress,
32 latitude: response.data.latitude,
33 longitude : response.data.longitude,
34 confirmedByDriver: response.data.confirmedByDriver
35 })
36 }
37
38 const joinDriveForPassenger = async () => {
39 const requestId = location.state.madeRequest.id
40 const response = await axios.get(`/drive/request/${requestId}`)
41 .catch(function (error) {
42 if (error.response) {
43 alert("Wait for the driver to pick you up and start the drive. Then you can join.");
44 }
45 });
46 localStorage.removeItem("madeRequestId")
47 const startLatitude = formData.latitude;
48 const startLongitude = formData.longitude;
49 navigate("/started-drive", {state: {startedDrive: response.data, startLatitude: startLatitude, startLongitude: startLongitude}})
50 }
51
52 let messageAfterConfirmation1 = ""
53 let messageAfterConfirmation2 = ""
54 let joinDrive = ""
55
56 if(formData.status === "CONFIRMED"){
57 messageAfterConfirmation1 = <p style={{color: "darkgreen", fontStyle: "bold"}}>Your request has been confirmed,
58 please wait for the driver on the provided address.</p>
59 messageAfterConfirmation2 = <p style={{color: "darkred", fontStyle: "bold"}}>After your driver picks you up and starts the drive,
60 you should start the drive too.</p>
61 joinDrive = <a title={"Start Drive"} className={"myButton btn btn-danger"}
62 style={{backgroundColor: "cyan", borderColor: "black", color: "black", width: '90%'}}
63 onClick={() => joinDriveForPassenger()} >
64 Join Drive
65 </a>
66 }
67
68 let confirmedByDriver = ""
69 if(formData.confirmedByDriver){
70 confirmedByDriver = <h6 className="card-text">
71 Confirmed by Driver: {formData.confirmedByDriver.name} {formData.confirmedByDriver.surname}</h6>
72 }
73
74 return (
75 <CenteredContainer>
76 <div className="card text-center">
77 <div className="card-header" style={{color : "darkcyan"}}>
78 {formData.status}
79 </div>
80 <div className="card-body">
81 <h6 className="card-title" style={{color : "darkcyan"}}>You have created your request, please wait until some driver confirms it</h6>
82 <h5 className="card-title">{formData.cityAddress}, {formData.streetAddress}, {formData.numberAddress}</h5>
83 {confirmedByDriver}
84 </div>
85 <br></br>
86 {messageAfterConfirmation1}
87 {messageAfterConfirmation2}
88 <p style={{textAlign: 'center'}}>
89 <a style={{backgroundColor: "darkcyan", color: 'white', borderColor: 'black', width: '90%'}} className="myButton btn btn-primary"
90 onClick={() => updateMadeRequest()}>Refresh</a>
91 </p>
92 <p style={{textAlign: 'center'}}>
93 {joinDrive}
94 </p>
95 </div>
96 <MapContainer className="border border-info rounded-2" center={[formData.latitude, formData.longitude]} zoom={16} scrollWheelZoom={true} style={{width: '100%', marginTop: '50px', position: 'relative', zIndex: 0}}>
97 <TileLayer
98 attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
99 url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
100 />
101 <Marker position={[formData.latitude, formData.longitude]} icon={new Icon({iconUrl: markerIconPng, iconSize: [25, 41], iconAnchor: [12, 41]})}>
102 <Popup position={[formData.latitude, formData.longitude]}>
103 <p>Pick up location. Wait here.</p>
104 </Popup>
105 </Marker>
106 </MapContainer>
107 </CenteredContainer>
108 )
109}
110
111export default MadeRequest;
Note: See TracBrowser for help on using the repository browser.