diff --git a/src/App.jsx b/src/App.jsx index e13619d..24e8899 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -51,7 +51,10 @@ export function App() { } /> } /> - } /> + } + /> diff --git a/src/api/firebase.js b/src/api/firebase.js index b3a0553..98f16a1 100644 --- a/src/api/firebase.js +++ b/src/api/firebase.js @@ -6,6 +6,7 @@ import { doc, onSnapshot, updateDoc, + addDoc, } from 'firebase/firestore'; import { useEffect, useState } from 'react'; import { db } from './config'; @@ -165,9 +166,7 @@ export async function shareList(listPath, currentUserId, recipientEmail) { */ export async function addItem(listPath, { itemName, daysUntilNextPurchase }) { const listCollectionRef = collection(db, listPath, 'items'); - // TODO: Replace this call to console.log with the appropriate - // Firebase function, so this information is sent to your database! - return console.log(listCollectionRef, { + return addDoc(listCollectionRef, { dateCreated: new Date(), // NOTE: This is null because the item has just been created. // We'll use updateItem to put a Date here when the item is purchased! diff --git a/src/views/ManageList.jsx b/src/views/ManageList.jsx index e1c5fde..0ee509d 100644 --- a/src/views/ManageList.jsx +++ b/src/views/ManageList.jsx @@ -1,7 +1,56 @@ -export function ManageList() { +import { useState } from 'react'; +import { addItem } from '../api/firebase'; +export function ManageList({ listPath }) { + const [formData, setFormData] = useState({ + itemName: '', + daysUntilNextPurchase: '', + }); + + const handleSubmit = async (event) => { + try { + event.preventDefault(); + await addItem(listPath, formData); + alert(`${formData.itemName} was added to the list successfully`); + } catch (error) { + alert(`There was a problem adding ${formData.itemName} to the list`); + } + }; + + const handleChange = (event) => { + let { name, value } = event.target; + setFormData((prevFormData) => ({ ...prevFormData, [name]: value })); + }; + return ( -

- Hello from the /manage-list page! -

+
handleSubmit(event)}> +
+ + +
+
+ + +
+ +
); }