diff --git a/src/App.jsx b/src/App.jsx index 4325b02..ec2b0be 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -9,6 +9,7 @@ import LandingPage from './pages/LandingPage'; import SponsorPage from './pages/SponsorPage'; import Login from './pages/Login'; import Dashboard from './pages/HackerDashboard'; +import CheckIn from './pages/CheckIn'; const router = createBrowserRouter( createRoutesFromElements( @@ -17,6 +18,7 @@ const router = createBrowserRouter( } /> } /> } /> + } /> ) ); diff --git a/src/pages/CheckIn.jsx b/src/pages/CheckIn.jsx new file mode 100644 index 0000000..e1d7c89 --- /dev/null +++ b/src/pages/CheckIn.jsx @@ -0,0 +1,84 @@ +import React, { useState } from "react"; +import { query, collection, getDocs, where, updateDoc, doc } from 'firebase/firestore'; +import { db } from '../firebase/firebase-config'; + +const CheckIn = () => { + const [email, setEmail] = useState(""); + const [application, setApplication] = useState({}); + + const handleSubmit = async (event) => { + event.preventDefault(); + setApplication({ status: "Checking in" }); + // Call the fetchApplications function when the form is submitted + fetchApplications(); + } + + const updateApplicationStatus = async (docId, newStatus) => { + const applicationRef = doc(db, "applications", docId); + + try { + // Update the status in Firestore + await updateDoc(applicationRef, { status: newStatus }); + + // Update the status in the application state + setApplication({ status: newStatus }); + } catch (error) { + console.log(error); + alert("An error has occurred updating the application status"); + } + } + + const fetchApplications = async () => { + try { + const q = query(collection(db, "applications"), where("email", "==", email)); + const querySnapshot = await getDocs(q); + + // Check if there are any documents + if (!querySnapshot.empty) { + const applicationDoc = querySnapshot.docs[0]; + const status = applicationDoc.data().status; + + if (status === "Confirmed") { + // If the status is "confirmed," update it to "Checked In" + await updateApplicationStatus(applicationDoc.id, "Checked In"); + } else { + setApplication({ status: "You are not confirmed. Please speak to one of the BostonHacks Organizers" }); + } + } else { + // If there isn't any application, display a message + setApplication({ status: "No application found" }); + } + } catch (error) { + console.log(error); + alert("An error has occurred fetching user data"); + } + } + + return ( +
+

+ BostonHacks 2023 Check-In +

+ +
+ + setEmail(e.target.value)} + className="border p-2 w-full rounded-md focus:outline-none focus:ring focus:border-blue-300" + /> + +
+ + {/* Display application status */} +
+

Status: {application.status}

+
+
+ ) +} + +export default CheckIn;