1
|
|
|
import React from "react"; |
2
|
|
|
import cities from "../models/cities"; |
3
|
|
|
import { CityList, RegisterCityForm, Filterbar } from "../components"; |
4
|
|
|
import { useState, useEffect } from "react"; |
5
|
|
|
|
6
|
|
|
const Cities = () => { |
7
|
|
|
const [filterPhrase, setFilterPhrase] = useState(""); |
8
|
|
|
const [displayForm, setDisplayForm] = useState(false); |
9
|
|
|
const [cityData, setCityData] = useState({}); |
10
|
|
|
const [newCity, setNewCity] = useState({ |
11
|
|
|
name: "", |
12
|
|
|
fixedRate: 0, |
13
|
|
|
timeRate: 0, |
14
|
|
|
bonusParkingZoneRate: 0, |
15
|
|
|
parkingZoneRate: 0, |
16
|
|
|
noParkingZoneRate: 0, |
17
|
|
|
chargingZoneRate: 0, |
18
|
|
|
noParkingToValidParking: 0, |
19
|
|
|
}); |
20
|
|
|
|
21
|
|
|
useEffect(() => { |
22
|
|
|
fetchData(); |
23
|
|
|
}, []); |
24
|
|
|
|
25
|
|
|
async function fetchData() { |
26
|
|
|
const res = await cities.getCitiesOverview(); |
27
|
|
|
setCityData(res); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
const handleRegister = async () => { |
31
|
|
|
await cities.addCity(newCity); |
32
|
|
|
await fetchData(); |
33
|
|
|
handleForm(); |
34
|
|
|
}; |
35
|
|
|
|
36
|
|
|
const handleForm = () => { |
37
|
|
|
if (displayForm) { |
38
|
|
|
setDisplayForm(false); |
39
|
|
|
} else { |
40
|
|
|
setDisplayForm(true); |
41
|
|
|
} |
42
|
|
|
}; |
43
|
|
|
|
44
|
|
|
const overlay = () => { |
45
|
|
|
let state = { click: "auto", backdrop: "blur(0px)" }; |
46
|
|
|
if (displayForm) { |
47
|
|
|
state = { click: "none", backdrop: "blur(4px)" }; |
48
|
|
|
} |
49
|
|
|
return state; |
50
|
|
|
}; |
51
|
|
|
|
52
|
|
|
return ( |
53
|
|
|
<> |
54
|
|
|
{displayForm ? ( |
55
|
|
|
<div |
56
|
|
|
className="fixed top-1/2 left-1/2 z-10 |
57
|
|
|
transform -translate-x-1/2 -translate-y-1/2" |
58
|
|
|
> |
59
|
|
|
<RegisterCityForm |
60
|
|
|
handleForm={handleForm} |
61
|
|
|
handleRegister={handleRegister} |
62
|
|
|
setNewCity={setNewCity} |
63
|
|
|
newCity={newCity} |
64
|
|
|
/> |
65
|
|
|
</div> |
66
|
|
|
) : ( |
67
|
|
|
<div></div> |
68
|
|
|
)} |
69
|
|
|
<div |
70
|
|
|
style={{ |
71
|
|
|
pointerEvents: overlay().click, |
72
|
|
|
filter: overlay().backdrop, |
73
|
|
|
}} |
74
|
|
|
className="flex flex-col w-full px-11 min-h-screen" |
75
|
|
|
> |
76
|
|
|
<div className="text-4xl font-semibold p-3"> |
77
|
|
|
<h1>Cities</h1> |
78
|
|
|
</div> |
79
|
|
|
<div className="flex flex-row justify-between"> |
80
|
|
|
<div className="py-3"> |
81
|
|
|
<Filterbar |
82
|
|
|
filterPhrase={filterPhrase} |
83
|
|
|
setFilterPhrase={setFilterPhrase} |
84
|
|
|
placeholder={"Filter Cities"} |
85
|
|
|
/> |
86
|
|
|
</div> |
87
|
|
|
<div> |
88
|
|
|
<button |
89
|
|
|
onClick={handleForm} |
90
|
|
|
className="py-2 px-3 transition-colors bg-sidebarHover hover:bg-sidebarBlue text-white rounded-full" |
91
|
|
|
> |
92
|
|
|
Register City |
93
|
|
|
</button> |
94
|
|
|
</div> |
95
|
|
|
</div> |
96
|
|
|
<div className="mt-6"> |
97
|
|
|
<CityList filterPhrase={filterPhrase} cityData={cityData} /> |
98
|
|
|
</div> |
99
|
|
|
</div> |
100
|
|
|
</> |
101
|
|
|
); |
102
|
|
|
}; |
103
|
|
|
|
104
|
|
|
export default Cities; |
105
|
|
|
|