Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Allowing user to add items to shopping list #22

Merged
merged 21 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
c8bcd2f
adding a form layout to manage list
bbland1 Aug 19, 2024
7d01c41
update item label tag
bbland1 Aug 19, 2024
493db35
installed react-hot-toast and added toast for successful item add
bbland1 Aug 19, 2024
95bab87
modified addItem in firebase.js and WIP: parameters of call in Manage…
bbland1 Aug 20, 2024
6167526
cleaning up form tags and adding select possiblity
bbland1 Aug 21, 2024
7d39f08
adding the listPath prop to the ManageList component
bbland1 Aug 22, 2024
80d6b32
making form controlled with state, adding the listPath info and contr…
bbland1 Aug 22, 2024
4efe30b
replaced console.log in addItem (firebase.js) with addDoc and updated…
bbland1 Aug 22, 2024
da88150
chore: Add console logs and error logging in MAnageList.jsx.
RossaMania Aug 22, 2024
e980494
chore: Add console log for listpath in ManageList.jsx
RossaMania Aug 22, 2024
32403a6
Added console log for adding item to list success.
RossaMania Aug 22, 2024
d1157c4
change the when to buy options to a fieldset
bbland1 Aug 23, 2024
2a2a0e6
adding aria-label to form submit button
bbland1 Aug 23, 2024
71c983f
refactor: Improve form submission by adding strings to radio button s…
RossaMania Aug 23, 2024
ef5aded
feat: Improve ManageList component by setting daysUntilNextPurchase a…
RossaMania Aug 23, 2024
d13a6b7
remoiving debug console.logs and resetting state or keeping during fo…
bbland1 Aug 23, 2024
bdee02d
refactor: removed unneeded setState calls in toast error func
bbland1 Aug 23, 2024
02538e0
fix: remove the unneeded parseInt in firebase.js
bbland1 Aug 25, 2024
6a22d8d
refactor: add validation for no empty items, added constants for time…
bbland1 Aug 25, 2024
8e914c7
refactor: added valid trim input util, added validation of text and r…
bbland1 Aug 25, 2024
1792e84
Merge branch 'main' into bb-rc-add-items-to-list
bbland1 Aug 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"firebase": "^10.12.5",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-hot-toast": "^2.4.1",
bbland1 marked this conversation as resolved.
Show resolved Hide resolved
"react-router-dom": "^6.26.0"
},
"devDependencies": {
Expand Down
13 changes: 13 additions & 0 deletions src/api/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,19 @@ 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!

//This saves item to database.
await setDoc(listCollectionRef, {
bbland1 marked this conversation as resolved.
Show resolved Hide resolved
owner: userId,
});

// This updates user record.
const userDocumentRef = doc(db, 'users', userEmail);

updateDoc(userDocumentRef, {
sharedLists: arrayUnion(listCollectionRef),
});

return console.log(listCollectionRef, {
dateCreated: new Date(),
// NOTE: This is null because the item has just been created.
Expand Down
37 changes: 34 additions & 3 deletions src/views/ManageList.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,38 @@
import { addItem } from '../api/firebase';
import toast, { Toaster } from 'react-hot-toast';

export function ManageList() {
const notify = () => toast.success('Item added to list!');

const handleSubmit = (e) => {
e.preventDefault();
bbland1 marked this conversation as resolved.
Show resolved Hide resolved
addItem({ itemName: item });
console.log('hi');
notify();
};

return (
<p>
Hello from the <code>/manage-list</code> page!
</p>
<div>
<p>
Hello from the <code>/manage-list</code> page!
</p>
<form onSubmit={handleSubmit}>
bbland1 marked this conversation as resolved.
Show resolved Hide resolved
<label htmlFor="item">Item </label>
<input id="item" type="text" />
<br />
{/* radio inputs for how soon to buy. */}
<input type="radio" id="soon" name="when-to-buy" value="7" />
<label htmlFor="soon">Soon</label>
<br />
<input type="radio" id="kind-of-soon" name="when-to-buy" value="14" />
<label htmlFor="kind-of-soon">Kind of soon</label>
<br />
<input type="radio" id="not-soon" name="when-to-buy" value="30" />
<label htmlFor="not-soon">Not soon</label>
<br />
<button type="submit">Submit Item</button>
bbland1 marked this conversation as resolved.
Show resolved Hide resolved
</form>
<Toaster />
</div>
);
}