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" import { useToast } from "./ui/use-toast" function RideDialog({ name, brand, model, color, plateNumber, phoneNumber }: any) { const { toast } = useToast() const [status, _setStatus] = useState('Unreserved') const [orderTime, _setOrderTime] = useState(new Date()) const [pickUpLocation, setPickUpLocation] = useState() const [dropOffLocation, setDropOffLocation] = useState() const [isRideAdded, setIsRideAdded] = useState(false) const [cost, setCost] = useState('') const addRideOrderToFirestore = async () => { if (isRideAdded) { return; } 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: name, phoneNumber: phoneNumber, carModel: model, carBrand: brand, carColor: color, plateNumber: plateNumber, cost: parseInt(cost), status: status, orderTime: orderTime, fromLocation: pickUpLocation, toLocation: dropOffLocation, }); setIsRideAdded(true) 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 (
Ride details Please enter details about your ride and click submit for the ride to appear to other students!
setDropOffLocation(e.target.value)} />
setPickUpLocation(e.target.value)} />
setCost(e.target.value)} />
) } export default RideDialog;