-
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 new item to the shopping list #17
Conversation
This commit serves the purpose of creating a draft PR Co-authored-by: shahx95 <[email protected]>
Visit the preview URL for this PR (updated for commit f9a150c): https://tcl-60-smart-shopping-list--pr17-sa-tj-add-item-shopp-8m7wl1bq.web.app (expires Sat, 22 Apr 2023 07:50:27 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: 93ba99965233232f14cf05d9d95de4adc510bd3b |
src/views/AddItem.jsx
Outdated
|
||
function handleSubmit(event) { | ||
event.preventDefault(); | ||
if (formData.itemName !== '' && formData.daysUntilNextPurchase !== '') { |
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.
Instead of using if (formData.itemName !== '' && formData.daysUntilNextPurchase !== '')
, we could simplify the condition by utilizing truthiness, like so: if (formData.itemName && formData.daysUntilNextPurchase)
. This approach considers any non-empty string input as valid for our purposes.
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.
After the data enters the if statement but before it is sent to the database, we can format it to all lowercase. This will ensure consistency in the data and prevent any potential issues like duplicates arising from case sensitivity.
It is not explicitly mentioned in the scope of this problem, however. What do you think?
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 think we have another issue for this.
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.
Ah ok. That's cool! 😊
…-collab-lab/tcl-60-smart-shopping-list into sa-tj-add-item-shopping-list
As per your previous suggestion, I implemented the form clearance feature after submission. I also added retrieval of data from local storage. Kindly review the changes made accordingly. |
If everything looks good, one of us can go ahead and remove all the console logs before we go ahead with the review and submission. @ToobaJamal |
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.
Looks good! I do have a few comments, but nothing that would prevent merging.
-
If you move the confirmation message below the submit button, then you won't need to worry about the button shifting anymore. I think that's the more common position anyway.
-
I'm not a fan of error messages that automatically disappear. If the user misses it, they won't have any idea why their submission didn't go through & might even think that it did. This can lead to frustration.
-
For accessibility purposes, you might want to look into
aria-live
for the text that appears and disappears: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Live_Regions
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.
Everything looks good to me!!
Thank you for adding these points, Laura. These are helpful :) |
@labrocadabro thanks for the feedback.
I am also not entirely convinced by the current placement and user experience of the error message as it is currently. As mentioned by @ToobaJamal, we could potentially address this during the styling phase, so we may consider it a minor issue for now and revisit it later. @paramsiddharth, I would appreciate your opinion on this matter as well. |
try { | ||
const convertedFormData = { | ||
itemName: formData.itemName, | ||
daysUntilNextPurchase: Number(formData.daysUntilNextPurchase), |
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.
Is it better to use Number(str)
than parseInt(str)
? There's no right answer, so I'll let you discover and decide on your own! 😃 Here's something you might want to check out: https://stackoverflow.com/questions/4090518/what-is-the-difference-between-parseint-and-number
src/views/AddItem.jsx
Outdated
@@ -1,3 +1,104 @@ | |||
import React from 'react'; |
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.
A part of the suggestion for my next comment.
import React from 'react'; | |
import React, { useState } from 'react'; |
src/views/AddItem.jsx
Outdated
const [formData, setFormData] = React.useState({ | ||
itemName: '', | ||
daysUntilNextPurchase: '', | ||
}); | ||
const [submissionStatus, setSubmissionStatus] = React.useState(''); | ||
const [showMessage, setShowMessage] = React.useState(false); |
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.
If we're using the useState
hook so many times, wouldn't it be a better idea to just import it instead of writing React.useState
everytime? :) Think about it, it is always encouraged to do this in production code. If you're using a property more than 3 times and it is possible to import it selectively, the key is to do that.
const [formData, setFormData] = React.useState({ | |
itemName: '', | |
daysUntilNextPurchase: '', | |
}); | |
const [submissionStatus, setSubmissionStatus] = React.useState(''); | |
const [showMessage, setShowMessage] = React.useState(false); | |
const [formData, setFormData] = useState({ | |
itemName: '', | |
daysUntilNextPurchase: '', | |
}); | |
const [submissionStatus, setSubmissionStatus] = useState(''); | |
const [showMessage, setShowMessage] = useState(false); |
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 have made the requested changes :)
function handleChange(event) { | ||
const { name, value } = event.target; | ||
|
||
setFormData((prevFormData) => { | ||
return { | ||
...prevFormData, | ||
[name]: value, | ||
}; | ||
}); | ||
} |
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 admire how you two wrote a generic function that would work for any field. 🌷 Impressive!
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.
Edit: This one is just an appreciation comment. :) No change is needed.
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.
A few changes are needed, and then you'll be good to go! :) Excellent and quality work on the PR, Shah and Tooba!
@shahx95 absorbs office hour insight and PR feedback very quickly. |
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
@shahx95 This is why I asked on slack if we should be addressing UI/UX concerns as we go. I'm unclear on whether such issues are scope creep, or if they're supposed to be addressed but are up to the discretion of the authors and therefore difficult to put in the acceptance criteria. Would appreciate it if @paramsiddharth, @RajGM, or @iamkrati22 could weigh in. |
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.
Excellent work, Tooba and Shah! <3 Looks good to me!
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.
Excellent job, Tooba and Shah! <3 I'm impressed. Let's merge it now!
Co-authored-by: shahx95 [email protected]
Description
This change allows users to add new items and an estimate of when they need to buy the items to the shopping list. The token is accessed from localStorage and passed to the addItem function so the users can add items to their shopping list when they submit the addItem form.
Related Issue
Closes #4
Acceptance Criteria
Data-related tasks:
Type of Changes
Updates
Before
After
task4_after.mp4
Testing Steps / QA Criteria
If the user enters both the item name and the estimate of when they need to buy the item, Item has been added to the list will be displayed on the browser. If any of the input fields are missing, the user will see the Please enter valid inputs message on the screen.