-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add addItem function import #19
Conversation
Visit the preview URL for this PR (updated for commit 5810e7b): https://tcl-55-smart-shopping-list--pr19-tf-jf-add-item-sdt6nmdt.web.app (expires Sun, 23 Apr 2023 00:19:56 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: 607d14028385ebfcc7c9ec69a7bb14d95ed54078 |
Forgot to make sure the user enters an item name! Added it in the latest push. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noted a couple of small fixes that need to be changed before we merge but other than those, this looks awesome. This was a hefty user story!
I love that you all used a useEffect
with setTimeout
for the messages that was a great idea.
Using type=submit
and onSubmit
is making the using the Enter
button work perfectly and the items are being added to the passed down listId when you check firebase. So all here is working as it should!
Just a heads up that I think my cache and localStorage still had my testing of a new listID from our user story so you'll actually see that list in firebase now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks all!
src/api/firebase.js
Outdated
@@ -64,6 +62,7 @@ export async function addItem(listId, { itemName, daysUntilNextPurchase }) { | |||
name: itemName, | |||
totalPurchases: 0, | |||
}); | |||
return data; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Data in this case is a promise. How can you tell whether it was fulfilled or rejected?
src/views/AddItem.jsx
Outdated
setItemName(''); | ||
setTimeframe('Soon'); | ||
} else { | ||
setMessage('Error adding item'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were you all able to trigger this error message? I've tried a bunch of bad inputs, and I couldn't get the error.
result
here is also a promise, so the null check doesn't reall work if the promise was rejected by Firebase
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love the use effect and timeout to clear the message! I left two comments, one optional, another one I think should be implemented. But overall, great job!
src/views/AddItem.jsx
Outdated
Soon: 7, | ||
'Kind of Soon': 14, | ||
'Not Soon': 30, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This threw me off for a second. Is it possible to have them be consistent, maybe change 'Not Soon' to notSoon, kindOfSoon etc. And then update where this is being used in the form? I understand the default for one word keys is a string with no quotes (ex Soon). I tried adding quotes, but my linting is changing it back to this form as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good idea @Yaosaur. Alternatively, what about swapping the keys and values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I refactored it out completely. It seemed like a good idea when we were writing our code but wasn't needed at all. 😅
src/views/AddItem.jsx
Outdated
<label htmlFor="timeframe" style={{ gridColumn: 'span 2' }}> | ||
How soon will you buy this again? | ||
</label> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we replace with legend element for accessibility as per the wireframe requirement? See here: https://www.w3.org/WAI/tutorials/forms/grouping/#associating-related-controls-with-wai-aria
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, great suggestion!
Currently after you submit the form the radio buttons remain unchecked even though you set the timeframe after the result is returned. You can submit a new item in this state anyway, which appears as though you added an item with no buy again date even though you have Recording.2023-04-15.161116.mp4This is being caused by line 34 of AddItem.jsx and I don't think that you need it. |
Description
This code changes the
AddItem
view and thefirebase.js
api so that the user can add items to their shopping list. We followed acceptance criteria and wireframe and used a text input with a label for the name of the item and a group of radio buttons inside a fieldset so the user can select how often they would like to be reminded to buy the item they are adding. The firebase api is now using theaddDoc
function from thefirebase/firestore
library. We chose to use React'suseState
feature for storing the user's item name and timeframe between purchase so that we could easily send those as variables to the firebase function. The message showing that the item was successfully added appears temporarily as to not disrupt the UI if the user wants to add another item on the same visit to this page.Related Issue
Acceptance Criteria
UI-related tasks:
Add Item
view displays a form that allows them to enter the name of the item and select how soon they anticipate needing to buy it again. There should be 3 choices for this:label
element associated with itEnter
keyData-related tasks:
console.log
in theaddItem
function insrc/api/firebase.js
is replaced with a function that adds the new document to the Firestore database. That function will be imported from thefirebase/firestore
module.nextPurchasedDate
Type of Changes
Updates
Before
After
Testing Steps / QA Criteria
git pull
git checkout tf-jf-add-item
npm start
View the add-item page at
https://localhost:3000/add-item
and confirm items get added on thehttps://localhost:3000/list
page.