source: RebuMKReact/src/Components/App/App.js

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

added projects and db scripts

  • Property mode set to 100644
File size: 9.4 KB
Line 
1import './App.css';
2import React, {Component} from "react";
3import {Routes, BrowserRouter as Router, Route} from "react-router-dom";
4import RebuMKService from "../../repository/rebuRepository";
5import Home from "../Home/home";
6import Login from '../Login/login';
7import Header from "../Header/header";
8import Register from "../Register/register";
9import RegisterDriver from "../Register/registerDriver";
10import RegisterPassenger from "../Register/registerPassenger";
11import Requests from "../Requests/requests";
12import ConfirmedRequest from '../Requests/confirmedRequest';
13import StartedDrive from '../Drive/startedDrive';
14import GradeDrive from '../Drive/gradeDrive'
15import PayDrive from '../Drive/pay-drive'
16import MakeRequest from '../Requests/makeRequest';
17import MadeRequest from '../Requests/madeRequest';
18import Drivers from '../Drivers/drivers'
19import UnapprovedDrivers from '../Drivers/unapprovedDrivers';
20import Car from '../Cars/car'
21import AddCar from '../Cars/addCar'
22import Payments from '../Payments/payments'
23import AdminReport from '../Reports/adminReport'
24import DriverReport from '../Reports/driverReport'
25import PassengerReport from '../Reports/passengerReport'
26import Footer from '../Footer/footer'
27import DriverProfile from '../Drivers/driverProfile'
28import TipDriver from '../Drive/tipDriver';
29
30
31class 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
264export default App;
Note: See TracBrowser for help on using the repository browser.