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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
import RideDialog from "@/components/RideDialog"
import { Avatar } from "@/components/ui/avatar"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import { CardTitle, CardHeader, CardContent, Card } from "@/components/ui/card"
import { auth, db } from "@/firebase/firebase_config"
import { fetchUserDetails } from "@/utils/fetchUserDetails"
import { Toaster } from "@/components/ui/toaster"
import { useEffect, useState } from "react"
import { Navigate } from "react-router-dom"
import { fetchRideRequests } from "@/utils/fetchRideRequests"
interface IDriver {
uid: string,
name: string,
phoneNumber: string,
plateNumber: string,
carBrand: string,
carModel: string,
carColor: string,
}
interface IPassengerRequest {
passengerName: string,
phoneNumber: string,
status: string,
pickUp: string,
dropOff: string,
}
interface ITrip {
pickUp: string,
dropOff: string,
}
function PassengerRequestCard({ passengerName, pickUp, dropOff, status, phoneNumber }: IPassengerRequest) {
return (
<li className="py-2">
<p>
<strong>Passenger:</strong> {passengerName}
</p>
<p>
<strong>Phone number:</strong> {phoneNumber}
</p>
<p>
<strong>Status:</strong> {status}
</p>
<p>
<strong>Pickup:</strong> {pickUp}
</p>
<p>
<strong>Dropoff:</strong> {dropOff}
</p>
<div className="flex justify-between mt-2">
<Button className="text-green-500 border-green-500" variant="outline">
Accept
</Button>
<Button className="border-red-500 text-red-500" variant="outline">
Reject
</Button>
</div>
</li>
)
}
export default function Home() {
const [driverData, setDriverData] = useState<IDriver | null | undefined>()
const [rideRequests, setRideRequests] = useState<any[] | undefined>([])
const [currentTrip, setCurrentTrip] = useState<ITrip>()
useEffect(() => {
const user = auth.currentUser;
async function fetchData() {
const data: IDriver | null | undefined = await fetchUserDetails(user?.uid);
const rideReqs = await fetchRideRequests()
console.log("RideRequests:", rideReqs)
setDriverData(data)
setRideRequests(rideReqs)
console.log("Length: ", rideRequests?.length)
}
fetchData()
}, [auth.currentUser, db]);
return (
!auth.currentUser ? <Navigate to="/login" /> :
(
<main className="flex flex-col gap-6 p-6 bg-gray-900 text-white min-h-screen">
<header className="flex justify-between items-center">
<div className="flex items-center gap-4">
<h1 className="text-3xl font-bold">Driver Dashboard</h1>
<Avatar alt="Driver Avatar" className="w-10 h-10" src="/placeholder.svg?height=40&width=40" />
<h2 className="text-xl font-bold">{driverData?.name}</h2>
<Badge className="bg-white text-black" variant="secondary">
Active Driver
</Badge>
</div>
<div className="flex gap-4 items-center">
<Button className="text-black bg-white" variant="outline">
Log Out
</Button>
</div>
</header>
<section className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
<Card className="bg-slate-950 text-white">
<CardHeader className="bg-slate-800">
<CardTitle className="text-lg font-semibold">Vehicle Details</CardTitle>
</CardHeader>
<CardContent className="mt-5">
<ul className="space-y-2">
<li>
<strong>Brand:</strong> {driverData?.carBrand}
</li>
<li>
<strong>Model:</strong> {driverData?.carModel}
</li>
<li>
<strong>License Plate:</strong> {driverData?.plateNumber}
</li>
</ul>
</CardContent>
</Card>
<Card className="bg-slate-950 text-white">
<CardHeader className="bg-slate-800">
<CardTitle className="text-lg font-semibold">Current Trip</CardTitle>
</CardHeader>
<CardContent className="mt-5">
<p>
<strong>Pickup:</strong> {currentTrip?.pickUp}
</p>
<p>
<strong>Dropoff:</strong> {currentTrip?.dropOff}
</p>
<Button className="w-full mt-4 border-blue-500 text-white" variant="outline">
Start Trip
</Button>
<Button className="w-full mt-4 border-green-500 text-white" variant="outline">
Finish Trip
</Button>
<Button className="w-full mt-4 border-red-500 text-white" variant="outline">
Cancel Trip
</Button>
</CardContent>
</Card>
<Card className="bg-slate-950 text-white shadow-2xl transform transition hover:scale-105">
<CardHeader className="bg-slate-800">
<CardTitle className="text-lg font-semibold">Passenger Requests</CardTitle>
</CardHeader>
<CardContent className="mt-3">
<ul className="divide-y divide-gray-600">
{rideRequests?.map((rideReq) => {
return (
< PassengerRequestCard
passengerName={rideReq?.name}
pickUp={rideReq?.pickUp}
dropOff={rideReq?.dropOff}
phoneNumber={rideReq?.phoneNumber}
status={rideReq?.status}
/>
)
})}
</ul>
</CardContent>
</Card>
</section>
<div className="flex justify-end items-center mt-6">
<RideDialog
name={driverData?.name}
model={driverData?.carModel}
brand={driverData?.carBrand}
plateNumber={driverData?.plateNumber}
phoneNumber={driverData?.phoneNumber}
color={driverData?.carColor}
/>
</div>
<footer className="mt-auto">
</footer>
<Toaster />
</main>
)
)
}
|