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
|
import { addDoc, collection } from "firebase/firestore"
import { db } from "./firebase/firebase_config"
import { Button } from "@/components/ui/button"
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import { useState } from "react"
interface RideOrder {
driverName: string
carModel: string
carColor: string
plateNumber: string
status: string
orderTime: Date
fromLocation: string
toLocation: string
}
function App() {
const [driverName, setDriverName] = useState<string>()
const [carModel, setCarModel] = useState<string>()
const [carColor, setCarColor] = useState<string>()
const [plateNumber, setPlateNumber] = useState<string>()
const [status, _setStatus] = useState<string>('Pending')
const [orderTime, _setOrderTime] = useState<Date>(new Date())
const [fromLocation, setFromLocation] = useState<string>()
const [toLocation, setToLocation] = useState<string>()
const [_rideOrder, _setRideOrder] = useState<RideOrder>({
driverName: "Mahmoud",
carModel: "Toyota Corolla",
carColor: "Red",
plateNumber: "ABC-123",
status: "Pending",
orderTime: new Date("2023-12-20"),
fromLocation: "Abdu-Basha",
toLocation: "5th Settlement",
})
const addRideOrderToFirestore = async () => {
try {
// Get a reference to the 'rideOrders' collection
const rideOrdersCollection = collection(db, 'Rides');
// Add a new document to the 'rideOrders' collection with the data from the RideOrder object
const newRideOrderRef = await addDoc(rideOrdersCollection, {
driverName: driverName,
carModel: carModel,
carColor: carColor,
plateNumber: plateNumber,
status: status,
orderTime: orderTime,
fromLocation: fromLocation,
toLocation: toLocation,
});
console.log('Ride order added with ID:', newRideOrderRef.id);
// 'newRideOrderRef.id' will give you the document ID of the added ride order
} catch (error) {
console.error('Error adding ride order:', error);
}
};
return (
<div className="bg-white h-screen w-screen flex items-center justify-center">
<Dialog>
<DialogTrigger asChild>
<Button className="rounded-xl" variant="outline">Add Ride</Button>
</DialogTrigger>
<DialogContent className="sm:max-w-[425px]">
<DialogHeader>
<DialogTitle>Ride details</DialogTitle>
<DialogDescription>
Please enter details about your ride and click submit for the ride to appear to other students!
</DialogDescription>
</DialogHeader>
<div className="grid gap-4 py-4">
<div className="grid grid-cols-4 items-center gap-4">
<Label htmlFor="name" className="text-right">
Name
</Label>
<Input
id="Name"
defaultValue=""
className="col-span-3"
onChange={(e) => setDriverName(e.target.value)}
/>
</div>
<div className="grid grid-cols-4 items-center gap-4">
<Label htmlFor="Car Model" className="text-right">
Car Model
</Label>
<Input
id="Car Model"
defaultValue=""
className="col-span-3"
onChange={(e) => setCarModel(e.target.value)}
/>
</div>
<div className="grid grid-cols-4 items-center gap-4">
<Label htmlFor="To Location" className="text-right">
To Location
</Label>
<Input
id="To Location"
defaultValue=""
className="col-span-3"
onChange={(e) => setToLocation(e.target.value)}
/>
</div>
<div className="grid grid-cols-4 items-center gap-4">
<Label htmlFor="From location" className="text-right">
From location
</Label>
<Input
id="From location"
defaultValue=""
className="col-span-3"
onChange={(e) => setFromLocation(e.target.value)}
/>
</div>
<div className="grid grid-cols-4 items-center gap-4">
<Label htmlFor="Car color" className="text-right">
Car color
</Label>
<Input
id="Car color"
defaultValue=""
className="col-span-3"
onChange={(e) => setCarColor(e.target.value)}
/>
</div>
<div className="grid grid-cols-4 items-center gap-4">
<Label htmlFor="Plate Number" className="text-right">
Plate Number
</Label>
<Input
id="Plate Number"
defaultValue=""
className="col-span-3"
onChange={(e) => setPlateNumber(e.target.value)}
/>
</div>
</div>
<DialogFooter>
<Button type="submit" onClick={addRideOrderToFirestore}>Add Ride</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</div>
)
}
// interface RideOrder {
// driverName: string
// carModel: string
// carColor: string
// plateNumber: string
// status: string
// orderTime: Date
// fromLocation: string
// toLocation: string
// }
export default App
|