// Import required components and modules from Firebase and Firebase Config import { firebaseConfig } from "./config/Config.js" import { getApp, initializeApp } from "firebase/app" import { useState, useEffect } from "react" import { getApps } from "firebase/app"; import { getFirestore, collection, getDocs, addDoc } from "firebase/firestore"; // Import required compenets from Bootstrap and React-Boostrap import Form from 'react-bootstrap/Form'; import Button from 'react-bootstrap/Button'; import 'bootstrap/dist/css/bootstrap.min.css'; import Col from 'react-bootstrap/Col'; import './App.css' if (!getApps().length) { initializeApp(firebaseConfig); } // declare variables export function MyForm(props) { const [submitter, setSubmitter] = useState(''); const [date, setDate] = useState(''); const [context, setContext] = useState(''); // Fetch incidents from Firestore when the component mounts useEffect(() => { const incidentsRef = collection(db, "incidents"); getDocs(incidentsRef).then((snapshot) => { const incidentsArray = snapshot.docs.map((doc) => ({ id: doc.id, ...doc.data() })); setIncidents(incidentsArray); }); }, []); // Ensure Firebase is initialized before using it if (!getApp().length) { initializeApp(firebaseConfig); } const db = getFirestore(getApp()); // Create a function to handle the checkbox changes and update the state accordingly. const handleCheckboxChange = (event) => { const { value, checked } = event.target; if (checked) { setSelectedOptions([...selectedOptions, value]); } else { setSelectedOptions(selectedOptions.filter((option) => option !== value)); } }; // Create a function to handle the form submission and add data to Firebase. // Once user presses submit, a popup will appearstating the data was sent. // When user acknowledges popup and closes it, the page will reload, // clearing the form and adding the new data to the database. const submitHandler = async (event) => { event.preventDefault() const unbasedData = { submitter, date, context} const col = collection(db, `unbasedtakes`) const ref = await addDoc(col, unbasedData) console.log(ref) alert("Form submitted successfully!"); window.location.reload(); } // Create form for user to imput data return (
Ray's Unbased Takes' Enter submitter name: setSubmitter(e.target.value)} /> Enter the date the shennanigans occurred (dd-mm-yyyy): setDate(e.target.value)} /> Enter context for this unbased take of Ray: setContext(e.target.value)} />

Existing incidents in the database:

{unbasedtakes.map((unbasee, index) => (

Incident ID:

{incident.id}

What date did this shennanigans occur?:

{incident.date}

Who submitted this:

{incident.submitter}

What caused Ray's moment?:

{incident.context}

What word's did Ray use this time?:

{incident.selectedOptions.join(', ')}

{index !== incidents.length - 1 &&
}
))}
// Create a form group to display the existing entries in the database. ); } export default MyForm;