[364f27d] | 1 | import './App.css';
|
---|
| 2 | import React, {Component} from "react";
|
---|
| 3 | import {Routes, BrowserRouter as Router, Route} from "react-router-dom";
|
---|
| 4 | import RebuMKService from "../../repository/rebuRepository";
|
---|
| 5 | import Home from "../Home/home";
|
---|
| 6 | import Login from '../Login/login';
|
---|
| 7 | import Header from "../Header/header";
|
---|
| 8 | import Register from "../Register/register";
|
---|
| 9 | import RegisterDriver from "../Register/registerDriver";
|
---|
| 10 | import RegisterPassenger from "../Register/registerPassenger";
|
---|
| 11 | import Requests from "../Requests/requests";
|
---|
| 12 | import ConfirmedRequest from '../Requests/confirmedRequest';
|
---|
| 13 | import StartedDrive from '../Drive/startedDrive';
|
---|
| 14 | import GradeDrive from '../Drive/gradeDrive'
|
---|
| 15 | import PayDrive from '../Drive/pay-drive'
|
---|
| 16 | import MakeRequest from '../Requests/makeRequest';
|
---|
| 17 | import MadeRequest from '../Requests/madeRequest';
|
---|
| 18 | import Drivers from '../Drivers/drivers'
|
---|
| 19 | import UnapprovedDrivers from '../Drivers/unapprovedDrivers';
|
---|
| 20 | import Car from '../Cars/car'
|
---|
| 21 | import AddCar from '../Cars/addCar'
|
---|
| 22 | import Payments from '../Payments/payments'
|
---|
| 23 | import AdminReport from '../Reports/adminReport'
|
---|
| 24 | import DriverReport from '../Reports/driverReport'
|
---|
| 25 | import PassengerReport from '../Reports/passengerReport'
|
---|
| 26 | import Footer from '../Footer/footer'
|
---|
| 27 | import DriverProfile from '../Drivers/driverProfile'
|
---|
| 28 | import TipDriver from '../Drive/tipDriver';
|
---|
| 29 |
|
---|
| 30 |
|
---|
| 31 | class App extends Component {
|
---|
| 32 |
|
---|
| 33 | constructor(props) {
|
---|
| 34 | super(props);
|
---|
| 35 | this.state = {
|
---|
| 36 | allCreatedRequests: [],
|
---|
| 37 | allApprovedDrivers: [],
|
---|
| 38 | allUnApprovedDrivers: [],
|
---|
| 39 | payments: [],
|
---|
| 40 | adminReport: [],
|
---|
| 41 | passengerReport: [],
|
---|
| 42 | driverReport: [],
|
---|
| 43 | loggedDriver: null
|
---|
| 44 | }
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | render() {
|
---|
| 48 | return (
|
---|
| 49 | <Router>
|
---|
| 50 | <Header/>
|
---|
| 51 | <main>
|
---|
| 52 | <div className={"container"}>
|
---|
| 53 | <Routes>
|
---|
| 54 | <Route path={"/"} element={<Home />}/>
|
---|
| 55 | <Route path={"/home"} element={<Home />}/>
|
---|
| 56 | <Route path={"/login"} element={<Login onLogin={this.fetchData} onLoadRequests={this.loadRequests}/>}/>
|
---|
| 57 | <Route path={"/register"} element={<Register />}/>
|
---|
| 58 | <Route path={"/registerPassenger"} element={<RegisterPassenger onRegisterPassenger={this.registerPassenger}/>}/>
|
---|
| 59 | <Route path={"/registerDriver"} element={<RegisterDriver onRegisterDriver={this.registerDriver}/>}/>
|
---|
| 60 | <Route path={"/registerDriver"} element={<RegisterDriver onRegisterDriver={this.registerDriver}/>}/>
|
---|
| 61 | <Route path={"/requests"} element={<Requests requests={this.state.allCreatedRequests} />}/>
|
---|
| 62 | <Route path={"/confirmed-request"} element={<ConfirmedRequest onRefreshPassengersMadeRequest={this.refreshPassengersMadeRequest}/>}/>
|
---|
| 63 | <Route path={"/started-drive"} element={<StartedDrive />}/>
|
---|
| 64 | <Route path={"/grade-drive"} element={<GradeDrive />}/>
|
---|
| 65 | <Route path={"/pay-drive"} element={<PayDrive />}/>
|
---|
| 66 | <Route path={"/tip-driver"} element={<TipDriver onTipDriver={this.tipDriver}/>}/>
|
---|
| 67 | <Route path={"/make-request"} element={<MakeRequest />}/>
|
---|
| 68 | <Route path={"/made-request"} element={<MadeRequest />}/>
|
---|
| 69 | <Route path={"/drivers"} element={<Drivers drivers={this.state.allApprovedDrivers} />}/>
|
---|
| 70 | <Route path={"/unapproved-drivers"} element={<UnapprovedDrivers drivers={this.state.allUnApprovedDrivers} onApproveDriver={this.approveDriver} onDenyDriver={this.denyDriver}/>}/>
|
---|
| 71 | <Route path={"/driver/profile"} element={<DriverProfile driver={this.loggedDriver} onChangeProfilePicture={this.changeProfilePicture}/>}/>
|
---|
| 72 | <Route path={"/car"} element={<Car />}/>
|
---|
| 73 | <Route path={"/add-car"} element={<AddCar onAddCar={this.addCar} />}/>
|
---|
| 74 | <Route path={"/payments"} element={<Payments payments={this.state.payments} />}/>
|
---|
| 75 | <Route path={"/report/admin"} element={<AdminReport report={this.state.adminReport} onDownloadReport={this.downloadAdminReport}/>}/>
|
---|
| 76 | <Route path={"/report/driver"} element={<DriverReport report={this.state.driverReport} onDownloadReport={this.downloadDriverReport}/>}/>
|
---|
| 77 | <Route path={"/report/passenger"} element={<PassengerReport report={this.state.passengerReport} onDownloadReport={this.downloadPassengerReport}/>}/>
|
---|
| 78 | </Routes>
|
---|
| 79 | </div>
|
---|
| 80 | </main>
|
---|
| 81 | <Footer/>
|
---|
| 82 | </Router>
|
---|
| 83 | )
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | tipDriver = (paymentId, driverTipSum) => {
|
---|
| 87 | RebuMKService.tipDriver(paymentId, driverTipSum).
|
---|
| 88 | then(() => {
|
---|
| 89 | this.fetchData()
|
---|
| 90 | });
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | changeProfilePicture = (driverId, profilePicture) => {
|
---|
| 94 | RebuMKService.changeProfilePicture(driverId, profilePicture)
|
---|
| 95 | .then((resp) => {
|
---|
| 96 | this.loggedDriver=resp.data
|
---|
| 97 | })
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | getLoggedDriver = (driverId) => {
|
---|
| 101 | RebuMKService.getDriverById(driverId)
|
---|
| 102 | .then((resp) => {
|
---|
| 103 | this.loggedDriver=resp.data
|
---|
| 104 | })
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | downloadPassengerReport = (passengerId) => {
|
---|
| 108 | RebuMKService.downloadPassengerReport(passengerId)
|
---|
| 109 | .then((resp) => {
|
---|
| 110 | const url = window.URL.createObjectURL(new Blob([resp.data]));
|
---|
| 111 | const link = document.createElement("a");
|
---|
| 112 | link.href = url;
|
---|
| 113 | link.setAttribute("download", passengerId + ".pdf");
|
---|
| 114 | document.body.appendChild(link);
|
---|
| 115 | link.click();
|
---|
| 116 | })
|
---|
| 117 | }
|
---|
| 118 | downloadDriverReport = (driverId) => {
|
---|
| 119 | RebuMKService.downloadDriverReport(driverId)
|
---|
| 120 | .then((resp) => {
|
---|
| 121 | const url = window.URL.createObjectURL(new Blob([resp.data]));
|
---|
| 122 | const link = document.createElement("a");
|
---|
| 123 | link.href = url;
|
---|
| 124 | link.setAttribute("download", driverId + ".pdf");
|
---|
| 125 | document.body.appendChild(link);
|
---|
| 126 | link.click();
|
---|
| 127 | })
|
---|
| 128 | }
|
---|
| 129 | downloadAdminReport = () => {
|
---|
| 130 | RebuMKService.downloadAdminReport()
|
---|
| 131 | .then((resp) => {
|
---|
| 132 | const url = window.URL.createObjectURL(new Blob([resp.data]));
|
---|
| 133 | const link = document.createElement("a");
|
---|
| 134 | link.href = url;
|
---|
| 135 | link.setAttribute("download", "admin.pdf");
|
---|
| 136 | document.body.appendChild(link);
|
---|
| 137 | link.click();
|
---|
| 138 | })
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 |
|
---|
| 142 | loadAdminReport = () => {
|
---|
| 143 | RebuMKService.getAdminReport()
|
---|
| 144 | .then((data) => {
|
---|
| 145 | this.setState({
|
---|
| 146 | adminReport: data.data
|
---|
| 147 | })
|
---|
| 148 | })
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 | loadDriverReport = (driverId) => {
|
---|
| 152 | RebuMKService.getDriverReport(driverId)
|
---|
| 153 | .then((data) => {
|
---|
| 154 | this.setState({
|
---|
| 155 | driverReport: data.data
|
---|
| 156 | })
|
---|
| 157 | })
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | loadPassengerReport = (passengerId) => {
|
---|
| 161 | RebuMKService.getPassengerReport(passengerId)
|
---|
| 162 | .then((data) => {
|
---|
| 163 | this.setState({
|
---|
| 164 | passengerReport: data.data
|
---|
| 165 | })
|
---|
| 166 | })
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 | approveDriver = (driverId) => {
|
---|
| 170 | RebuMKService.approveDriver(driverId)
|
---|
| 171 | .then(() => {
|
---|
| 172 | this.fetchData()
|
---|
| 173 | })
|
---|
| 174 | }
|
---|
| 175 | denyDriver = (driverId) => {
|
---|
| 176 | RebuMKService.denyDriver(driverId)
|
---|
| 177 | .then(() => {
|
---|
| 178 | this.fetchData()
|
---|
| 179 | })
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | addCar = (driverId, licensePlate, make, model, year) => {
|
---|
| 183 | RebuMKService.addCarForDriver(driverId, licensePlate, make, model, year)
|
---|
| 184 | .then(() => {
|
---|
| 185 | this.fetchData()
|
---|
| 186 | })
|
---|
| 187 | }
|
---|
| 188 |
|
---|
| 189 | refreshPassengersMadeRequest = () => {
|
---|
| 190 | <MadeRequest />
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 | loadRequests = (driverId) => {
|
---|
| 194 | RebuMKService.getAllCreatedRequests(driverId)
|
---|
| 195 | .then((data) => {
|
---|
| 196 | this.setState({
|
---|
| 197 | allCreatedRequests: data.data
|
---|
| 198 | })
|
---|
| 199 | })
|
---|
| 200 | }
|
---|
| 201 |
|
---|
| 202 | loadPayments = () => {
|
---|
| 203 | RebuMKService.getAllPayments()
|
---|
| 204 | .then((data) => {
|
---|
| 205 | this.setState({
|
---|
| 206 | payments: data.data
|
---|
| 207 | })
|
---|
| 208 | })
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | loadApprovedDrivers = () => {
|
---|
| 212 | RebuMKService.getAllDrivers()
|
---|
| 213 | .then((data) => {
|
---|
| 214 | this.setState({
|
---|
| 215 | allApprovedDrivers: data.data
|
---|
| 216 | })
|
---|
| 217 | })
|
---|
| 218 | }
|
---|
| 219 |
|
---|
| 220 | loadUnApprovedDrivers = () => {
|
---|
| 221 | RebuMKService.getUnapprovedDrivers()
|
---|
| 222 | .then((data) => {
|
---|
| 223 | this.setState({
|
---|
| 224 | allUnApprovedDrivers: data.data
|
---|
| 225 | })
|
---|
| 226 | })
|
---|
| 227 | }
|
---|
| 228 |
|
---|
| 229 | registerDriver = (firstName, surname, email, password, pricePerKm) => {
|
---|
| 230 | RebuMKService.registerDriver(firstName, surname, email, password, pricePerKm)
|
---|
| 231 | .then(() => {
|
---|
| 232 | this.fetchData()
|
---|
| 233 | })
|
---|
| 234 | }
|
---|
| 235 | registerPassenger = (firstName, surname, email, password) => {
|
---|
| 236 | RebuMKService.registerPassenger(firstName, surname, email, password)
|
---|
| 237 | .then(() => {
|
---|
| 238 | this.fetchData();
|
---|
| 239 | })
|
---|
| 240 | }
|
---|
| 241 |
|
---|
| 242 | componentDidMount() {
|
---|
| 243 | document.body.style.backgroundColor = "#f1faee"
|
---|
| 244 | this.fetchData();
|
---|
| 245 | }
|
---|
| 246 |
|
---|
| 247 | fetchData = () => {
|
---|
| 248 | if(localStorage.getItem("driverId")){
|
---|
| 249 | const driverId = localStorage.getItem("driverId");
|
---|
| 250 | this.loadRequests(driverId);
|
---|
| 251 | this.loadDriverReport(driverId);
|
---|
| 252 | this.getLoggedDriver(driverId);
|
---|
| 253 | } else if(localStorage.getItem("passengerId")){
|
---|
| 254 | this.loadApprovedDrivers()
|
---|
| 255 | this.loadPassengerReport(localStorage.getItem("passengerId"))
|
---|
| 256 | } else if(localStorage.getItem("adminId")){
|
---|
| 257 | this.loadUnApprovedDrivers()
|
---|
| 258 | this.loadPayments()
|
---|
| 259 | this.loadAdminReport()
|
---|
| 260 | }
|
---|
| 261 | }
|
---|
| 262 | }
|
---|
| 263 |
|
---|
| 264 | export default App; |
---|