From 7b379914e44583b9b097ed286b669ad244b176a1 Mon Sep 17 00:00:00 2001 From: omagdy7 Date: Thu, 21 Dec 2023 01:26:51 +0200 Subject: Added Firestore support for both the driver app and the rider mobile app --- driver/src/App.tsx | 173 ++++++++++++++++++++++++++++++++- driver/src/components/ui/button.tsx | 56 +++++++++++ driver/src/components/ui/dialog.tsx | 120 +++++++++++++++++++++++ driver/src/components/ui/input.tsx | 25 +++++ driver/src/components/ui/label.tsx | 24 +++++ driver/src/firebase/firebase_config.ts | 2 + driver/src/index.css | 74 ++++++++++++++ driver/src/lib/utils.ts | 6 ++ driver/src/main.tsx | 24 ++++- 9 files changed, 498 insertions(+), 6 deletions(-) create mode 100644 driver/src/components/ui/button.tsx create mode 100644 driver/src/components/ui/dialog.tsx create mode 100644 driver/src/components/ui/input.tsx create mode 100644 driver/src/components/ui/label.tsx create mode 100644 driver/src/lib/utils.ts (limited to 'driver/src') diff --git a/driver/src/App.tsx b/driver/src/App.tsx index 4970091..233b96d 100644 --- a/driver/src/App.tsx +++ b/driver/src/App.tsx @@ -1,11 +1,176 @@ -import Login from "./pages/Login" -import SignUp from "./pages/SignUp" +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() + const [carModel, setCarModel] = useState() + const [carColor, setCarColor] = useState() + const [plateNumber, setPlateNumber] = useState() + const [status, _setStatus] = useState('Pending') + const [orderTime, _setOrderTime] = useState(new Date()) + const [fromLocation, setFromLocation] = useState() + const [toLocation, setToLocation] = useState() + + const [_rideOrder, _setRideOrder] = useState({ + 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 ( - // - +
+ + + + + + + Ride details + + Please enter details about your ride and click submit for the ride to appear to other students! + + +
+
+ + setDriverName(e.target.value)} + /> +
+
+ + setCarModel(e.target.value)} + /> +
+
+ + setToLocation(e.target.value)} + /> +
+
+ + setFromLocation(e.target.value)} + /> +
+
+ + setCarColor(e.target.value)} + /> +
+
+ + setPlateNumber(e.target.value)} + /> +
+
+ + + +
+
+
) } +// interface RideOrder { +// driverName: string +// carModel: string +// carColor: string +// plateNumber: string +// status: string +// orderTime: Date +// fromLocation: string +// toLocation: string +// } + export default App diff --git a/driver/src/components/ui/button.tsx b/driver/src/components/ui/button.tsx new file mode 100644 index 0000000..0ba4277 --- /dev/null +++ b/driver/src/components/ui/button.tsx @@ -0,0 +1,56 @@ +import * as React from "react" +import { Slot } from "@radix-ui/react-slot" +import { cva, type VariantProps } from "class-variance-authority" + +import { cn } from "@/lib/utils" + +const buttonVariants = cva( + "inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50", + { + variants: { + variant: { + default: "bg-primary text-primary-foreground hover:bg-primary/90", + destructive: + "bg-destructive text-destructive-foreground hover:bg-destructive/90", + outline: + "border border-input bg-background hover:bg-accent hover:text-accent-foreground", + secondary: + "bg-secondary text-secondary-foreground hover:bg-secondary/80", + ghost: "hover:bg-accent hover:text-accent-foreground", + link: "text-primary underline-offset-4 hover:underline", + }, + size: { + default: "h-10 px-4 py-2", + sm: "h-9 rounded-md px-3", + lg: "h-11 rounded-md px-8", + icon: "h-10 w-10", + }, + }, + defaultVariants: { + variant: "default", + size: "default", + }, + } +) + +export interface ButtonProps + extends React.ButtonHTMLAttributes, + VariantProps { + asChild?: boolean +} + +const Button = React.forwardRef( + ({ className, variant, size, asChild = false, ...props }, ref) => { + const Comp = asChild ? Slot : "button" + return ( + + ) + } +) +Button.displayName = "Button" + +export { Button, buttonVariants } diff --git a/driver/src/components/ui/dialog.tsx b/driver/src/components/ui/dialog.tsx new file mode 100644 index 0000000..bcaf970 --- /dev/null +++ b/driver/src/components/ui/dialog.tsx @@ -0,0 +1,120 @@ +import * as React from "react" +import * as DialogPrimitive from "@radix-ui/react-dialog" +import { X } from "lucide-react" + +import { cn } from "@/lib/utils" + +const Dialog = DialogPrimitive.Root + +const DialogTrigger = DialogPrimitive.Trigger + +const DialogPortal = DialogPrimitive.Portal + +const DialogClose = DialogPrimitive.Close + +const DialogOverlay = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +DialogOverlay.displayName = DialogPrimitive.Overlay.displayName + +const DialogContent = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, children, ...props }, ref) => ( + + + + {children} + + + Close + + + +)) +DialogContent.displayName = DialogPrimitive.Content.displayName + +const DialogHeader = ({ + className, + ...props +}: React.HTMLAttributes) => ( +
+) +DialogHeader.displayName = "DialogHeader" + +const DialogFooter = ({ + className, + ...props +}: React.HTMLAttributes) => ( +
+) +DialogFooter.displayName = "DialogFooter" + +const DialogTitle = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +DialogTitle.displayName = DialogPrimitive.Title.displayName + +const DialogDescription = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +DialogDescription.displayName = DialogPrimitive.Description.displayName + +export { + Dialog, + DialogPortal, + DialogOverlay, + DialogClose, + DialogTrigger, + DialogContent, + DialogHeader, + DialogFooter, + DialogTitle, + DialogDescription, +} diff --git a/driver/src/components/ui/input.tsx b/driver/src/components/ui/input.tsx new file mode 100644 index 0000000..677d05f --- /dev/null +++ b/driver/src/components/ui/input.tsx @@ -0,0 +1,25 @@ +import * as React from "react" + +import { cn } from "@/lib/utils" + +export interface InputProps + extends React.InputHTMLAttributes {} + +const Input = React.forwardRef( + ({ className, type, ...props }, ref) => { + return ( + + ) + } +) +Input.displayName = "Input" + +export { Input } diff --git a/driver/src/components/ui/label.tsx b/driver/src/components/ui/label.tsx new file mode 100644 index 0000000..683faa7 --- /dev/null +++ b/driver/src/components/ui/label.tsx @@ -0,0 +1,24 @@ +import * as React from "react" +import * as LabelPrimitive from "@radix-ui/react-label" +import { cva, type VariantProps } from "class-variance-authority" + +import { cn } from "@/lib/utils" + +const labelVariants = cva( + "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70" +) + +const Label = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef & + VariantProps +>(({ className, ...props }, ref) => ( + +)) +Label.displayName = LabelPrimitive.Root.displayName + +export { Label } diff --git a/driver/src/firebase/firebase_config.ts b/driver/src/firebase/firebase_config.ts index 43a458c..ca0a3e6 100644 --- a/driver/src/firebase/firebase_config.ts +++ b/driver/src/firebase/firebase_config.ts @@ -1,6 +1,7 @@ // Import the functions you need from the SDKs you need import { initializeApp } from "firebase/app"; import { getAuth } from "firebase/auth"; +import { getFirestore } from "firebase/firestore"; // Your web app's Firebase configuration // For Firebase JS SDK v7.20.0 and later, measurementId is optional @@ -17,3 +18,4 @@ const firebaseConfig = { // Initialize Firebase const app = initializeApp(firebaseConfig); export const auth = getAuth(app) +export const db = getFirestore(app) diff --git a/driver/src/index.css b/driver/src/index.css index b5c61c9..cd4a6b1 100644 --- a/driver/src/index.css +++ b/driver/src/index.css @@ -1,3 +1,77 @@ @tailwind base; @tailwind components; @tailwind utilities; + +@layer base { + :light { + --background: 0 0% 100%; + --foreground: 222.2 84% 4.9%; + + --card: 0 0% 100%; + --card-foreground: 222.2 84% 4.9%; + + --popover: 0 0% 100%; + --popover-foreground: 222.2 84% 4.9%; + + --primary: 222.2 47.4% 11.2%; + --primary-foreground: 210 40% 98%; + + --secondary: 210 40% 96.1%; + --secondary-foreground: 222.2 47.4% 11.2%; + + --muted: 210 40% 96.1%; + --muted-foreground: 215.4 16.3% 46.9%; + + --accent: 210 40% 96.1%; + --accent-foreground: 222.2 47.4% 11.2%; + + --destructive: 0 84.2% 60.2%; + --destructive-foreground: 210 40% 98%; + + --border: 214.3 31.8% 91.4%; + --input: 214.3 31.8% 91.4%; + --ring: 222.2 84% 4.9%; + + --radius: 0.5rem; + } + + :root { + --background: 222.2 84% 4.9%; + --foreground: 210 40% 98%; + + --card: 222.2 84% 4.9%; + --card-foreground: 210 40% 98%; + + --popover: 222.2 84% 4.9%; + --popover-foreground: 210 40% 98%; + + --primary: 210 40% 98%; + --primary-foreground: 222.2 47.4% 11.2%; + + --secondary: 217.2 32.6% 17.5%; + --secondary-foreground: 210 40% 98%; + + --muted: 217.2 32.6% 17.5%; + --muted-foreground: 215 20.2% 65.1%; + + --accent: 217.2 32.6% 17.5%; + --accent-foreground: 210 40% 98%; + + --destructive: 0 62.8% 30.6%; + --destructive-foreground: 210 40% 98%; + + --border: 217.2 32.6% 17.5%; + --input: 217.2 32.6% 17.5%; + --ring: 212.7 26.8% 83.9%; + } +} + +@layer base { + * { + @apply border-border; + } + + body { + @apply text-foreground; + } +} diff --git a/driver/src/lib/utils.ts b/driver/src/lib/utils.ts new file mode 100644 index 0000000..ec79801 --- /dev/null +++ b/driver/src/lib/utils.ts @@ -0,0 +1,6 @@ +import { type ClassValue, clsx } from "clsx" +import { twMerge } from "tailwind-merge" + +export function cn(...inputs: ClassValue[]) { + return twMerge(clsx(inputs)) +} diff --git a/driver/src/main.tsx b/driver/src/main.tsx index 3d7150d..300ddc1 100644 --- a/driver/src/main.tsx +++ b/driver/src/main.tsx @@ -1,10 +1,30 @@ import React from 'react' +import { createBrowserRouter, RouterProvider } from 'react-router-dom' import ReactDOM from 'react-dom/client' import App from './App.tsx' import './index.css' +import Login from './pages/Login.tsx' +import SignUp from './pages/SignUp.tsx' + + + +const router = createBrowserRouter([ + { + path: "/", + element: + }, + { + path: "/signup", + element: + }, + { + path: "/login", + element: + }, +]) ReactDOM.createRoot(document.getElementById('root')!).render( - - , + + ) -- cgit v1.2.3