Working Form Submission component

This commit is contained in:
Ray 2023-12-29 08:59:14 +00:00 committed by GitHub
parent 564d517052
commit db2cd2980b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 4 deletions

View File

@ -1,7 +1,8 @@
// Import required components and modules from Firebase and Firebase Config // Import required components and modules from Firebase and Firebase Config
import firebaseConfig from "./config/Config.js" import { firebaseConfig } from "./config/Config.js"
import { getApp, initializeApp } from "firebase/app" import { getApp, initializeApp } from "firebase/app"
import { useState, useEffect } from "react" import { useState, useEffect } from "react"
import { getApps } from "firebase/app";
import { import {
getFirestore, getFirestore,
collection, collection,
@ -11,9 +12,10 @@ import {
addDoc addDoc
} from "firebase/firestore"; } from "firebase/firestore";
// import components from React.js if (!getApps().length) {
initializeApp(firebaseConfig);
}
import { useContext } from "react";
// Import required compenets from Bootstrap and React-Boostrap // Import required compenets from Bootstrap and React-Boostrap
import Form from 'react-bootstrap/Form'; import Form from 'react-bootstrap/Form';
@ -26,16 +28,26 @@ import './App.css'
import { FSContext } from ".//contexts/FSContext.js" import { FSContext } from ".//contexts/FSContext.js"
// declare variables // declare variables
export function MyForm(props) { export function MyForm(props) {
const db = useContext(FSContext)
const [submitter, setSubmitter] = useState(''); const [submitter, setSubmitter] = useState('');
const [date, setDate] = useState(''); const [date, setDate] = useState('');
const [context, setContext] = useState(''); const [context, setContext] = useState('');
const [selectedOptions, setSelectedOptions] = useState([]); const [selectedOptions, setSelectedOptions] = useState([]);
const [incidents, setIncidents] = useState([]); // Declare incidents as an empty array const [incidents, setIncidents] = useState([]); // Declare incidents as an empty array
// 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. // Create a function to handle the checkbox changes and update the state accordingly.
const handleCheckboxChange = (event) => { const handleCheckboxChange = (event) => {
const { value, checked } = event.target; const { value, checked } = event.target;