Storing data in Firestore (Broken) (In Progress)
This commit is contained in:
parent
3f28772527
commit
d5ccae751e
48
src/App.js
48
src/App.js
|
@ -1,4 +1,4 @@
|
||||||
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 {
|
import {
|
||||||
|
@ -6,29 +6,44 @@ import {
|
||||||
collection,
|
collection,
|
||||||
getDoc,
|
getDoc,
|
||||||
doc,
|
doc,
|
||||||
getDocs
|
getDocs,
|
||||||
|
addDoc
|
||||||
} from "firebase/firestore";
|
} from "firebase/firestore";
|
||||||
import { getStorage } from "firebase/storage"
|
|
||||||
import Form from 'react-bootstrap/Form';
|
import Form from 'react-bootstrap/Form';
|
||||||
import Button from 'react-bootstrap/Button';
|
import Button from 'react-bootstrap/Button';
|
||||||
import 'bootstrap/dist/css/bootstrap.min.css';
|
import 'bootstrap/dist/css/bootstrap.min.css';
|
||||||
import Col from 'react-bootstrap/Col';
|
import Col from 'react-bootstrap/Col';
|
||||||
import './App.css'
|
import './App.css'
|
||||||
|
|
||||||
|
import { FSContext } from ".//contexts/FSContext.js"
|
||||||
|
|
||||||
|
import { useContext } from "react";
|
||||||
|
|
||||||
|
|
||||||
function MyForm() {
|
export function MyForm(props) {
|
||||||
|
const db = useContext(FSContext)
|
||||||
|
const [submitter, setSubmitter] = useState('');
|
||||||
|
const [date, setDate] = useState('');
|
||||||
|
const [context, setContext] = useState('');
|
||||||
const [selectedOptions, setSelectedOptions] = useState([]);
|
const [selectedOptions, setSelectedOptions] = useState([]);
|
||||||
|
|
||||||
const handleCheckboxChange = (event) => {
|
const handleCheckboxChange = (event) => {
|
||||||
const { value, checked } = event.target;
|
const { value, checked } = event.target;
|
||||||
if (checked) {
|
if (checked) {
|
||||||
setSelectedOptions([...selectedOptions, value]);
|
setSelectedOptions([selectedOptions, value]);
|
||||||
} else {
|
} else {
|
||||||
setSelectedOptions(selectedOptions.filter((option) => option !== value));
|
setSelectedOptions(selectedOptions.filter((option) => option !== value));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const submitHandler = async (event) => {
|
||||||
|
event.preventDefault()
|
||||||
|
const incident = {setSubmitter: submitter, setDate: date, setContext: context, setSelectedOptions: selectedOptions }
|
||||||
|
const col = collection(db, `incidents/`)
|
||||||
|
const ref = await addDoc(col, incident )
|
||||||
|
console.log( ref )
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form>
|
<Form>
|
||||||
<Form.Group>
|
<Form.Group>
|
||||||
|
@ -36,14 +51,25 @@ function MyForm() {
|
||||||
<Col sm={2}></Col>
|
<Col sm={2}></Col>
|
||||||
<Col sm={8}>
|
<Col sm={8}>
|
||||||
<Form.Label style={{ fontSize: '30px' }}>Enter submitter name:</Form.Label>
|
<Form.Label style={{ fontSize: '30px' }}>Enter submitter name:</Form.Label>
|
||||||
<Form.Control type="text"
|
<Form.Control
|
||||||
placeholder="Name" />
|
name="submitter"
|
||||||
|
type="text"
|
||||||
|
placeholder="Name" />
|
||||||
<Form.Label style={{ fontSize: '30px' }}>Enter the date the shennanigans occurred (dd-mm-yyyy):</Form.Label>
|
<Form.Label style={{ fontSize: '30px' }}>Enter the date the shennanigans occurred (dd-mm-yyyy):</Form.Label>
|
||||||
<Form.Control type="text" placeholder="Date" />
|
<Form.Control
|
||||||
|
name="date"
|
||||||
|
type="text"
|
||||||
|
placeholder="Date"
|
||||||
|
/>
|
||||||
<Form.Label style={{ fontSize: '30px' }}>Enter context for this tamper tantrum:</Form.Label>
|
<Form.Label style={{ fontSize: '30px' }}>Enter context for this tamper tantrum:</Form.Label>
|
||||||
<Form.Control type="text"
|
<Form.Control
|
||||||
placeholder="Enter context here" />
|
type="text"
|
||||||
<Form.Label style={{ fontSize: '30px' }}>Select the words used by Ray during his little tamper tantrum:</Form.Label>
|
name="context"
|
||||||
|
placeholder="Enter context here" />
|
||||||
|
<Form.Label
|
||||||
|
name="selectedoptions"
|
||||||
|
style={{ fontSize: '30px' }}>Select the words used by Ray during his little tamper tantrum:
|
||||||
|
</Form.Label>
|
||||||
<Form.Check
|
<Form.Check
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
label="poop"
|
label="poop"
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
import { createContext } from 'react';
|
||||||
|
|
||||||
|
export const FSContext = createContext()
|
Loading…
Reference in New Issue