-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
100 lines (80 loc) · 2.16 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import "./App.css";
import React, { useState, useEffect } from "react";
import RentalInformation from "./RentalInformation";
import ViewCars from "./ViewCars";
function App() {
const url = "http://localhost:8081/api/report";
const carInfourl = "http://localhost:8081/api/cars";
const [data, setData] = useState([]);
const[showRentalInfo, setShowRentalInfo] = useState(false);
const[showCarInfo, setShowCarInfo] = useState(false);
const[carData, setCarData] = useState([]);
const fetchInfo = async() => {
return await fetch(url)
.then((res) => res.json())
.then((d) => setData(d))
}
useEffect(() => {
fetchInfo();
}, []);
//when page loads first time, populates car info and
// stores in variable in carData (line 16)
const fetchCarInfo = async() => {
return await fetch(carInfourl)
.then((res) => res.json())
.then((d) => setCarData(d))
}
useEffect(() => {
fetchCarInfo();
}, []);
return (<>
<div className="navbar">
<a onClick = {() => {setShowRentalInfo(false); setShowCarInfo(true)}}> View Cars</a>
<a onClick = {() => {setShowRentalInfo(true); setShowCarInfo(false)}}>Rental Information</a>
</div>
{showCarInfo ?
<table>
<thead>
<th>Car ID</th>
<th>Make</th>
<th>Model</th>
<th>Color</th>
<th>Year </th>
<th>Mileage </th>
<th>Location ID </th>
<th>Availability</th>
</thead>
<tbody>
<ViewCars selectedCarData = {carData} />
</tbody>
</table>
:null }
{showRentalInfo ?
<table>
<thead>
<th>Make</th>
<th>Model</th>
<th>Color</th>
<th>Customer ID </th>
<th>Customer Name </th>
<th>Customer Email</th>
<th>Customer Phone Number</th>
<th>Rental ID</th>
<th>Date of Rental</th>
<th>Rental Fees</th>
<th>Receipt ID </th>
<th>Total Cost </th>
<th>Payment Method </th>
<th>Staff ID </th>
<th>Staff Name</th>
<th>Staff Email</th>
</thead>
<tbody>
<RentalInformation rentalData = {data} />
</tbody>
</table>
:null }
</>
);
}
export default App;