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

Add new item to the shopping list #17

Merged
merged 16 commits into from
Apr 15, 2023
Merged

Conversation

ToobaJamal
Copy link
Collaborator

@ToobaJamal ToobaJamal commented Apr 9, 2023

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

  • The 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:
  • “Soon”, corresponding to 7 days
  • “Kind of soon”, corresponding to 14 days
  • “Not soon”, corresponding to 30 days
  • The input that accepts the name of the item has a semantic label element associated with it
  • The user can submit this form with both the mouse and the Enter key
  • When the user submits the form, they see a message indicating that the item either was or was not saved to the database.

Data-related tasks:

  • The console.log in the addItem function in src/api/firebase.js is replaced with a function that adds the new document to the Firestore database. That function will be imported from the firebase/firestore module.
  • The user’s soon/not soon/kind of soon choice is used to calculate nextPurchasedDate

Type of Changes

Type
🐛 Bug fix
✨ New feature
🔨 Refactoring
💯 Add tests
🔗 Update dependencies
📜 Docs

Updates

Before

task4_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.

This commit serves the purpose of creating a draft PR

Co-authored-by: shahx95 <[email protected]>
@github-actions
Copy link

github-actions bot commented Apr 9, 2023

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

@ToobaJamal ToobaJamal changed the title Add task comment Add new item Apr 10, 2023
src/views/AddItem.jsx Outdated Show resolved Hide resolved
src/views/AddItem.jsx Outdated Show resolved Hide resolved

function handleSubmit(event) {
event.preventDefault();
if (formData.itemName !== '' && formData.daysUntilNextPurchase !== '') {
Copy link
Collaborator

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.

Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator

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! 😊

@shahx95
Copy link
Collaborator

shahx95 commented Apr 12, 2023

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.

@shahx95
Copy link
Collaborator

shahx95 commented Apr 12, 2023

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

@ToobaJamal ToobaJamal changed the title Add new item Add new item to the shopping list Apr 12, 2023
@ToobaJamal ToobaJamal marked this pull request as ready for review April 12, 2023 15:43
Copy link
Collaborator

@labrocadabro labrocadabro left a 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.

  1. 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.

  2. 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.

  3. 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

Copy link
Collaborator

@shagunZ shagunZ left a 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!!

@ToobaJamal
Copy link
Collaborator Author

Looks good! I do have a few comments, but nothing that would prevent merging.

  1. 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.
  2. 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.
  3. 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

Thank you for adding these points, Laura. These are helpful :)

@shahx95
Copy link
Collaborator

shahx95 commented Apr 14, 2023

@labrocadabro thanks for the feedback.

  1. 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.
  2. 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.

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),
Copy link
Member

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

@@ -1,3 +1,104 @@
import React from 'react';
Copy link
Member

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.

Suggested change
import React from 'react';
import React, { useState } from 'react';

Comment on lines 5 to 10
const [formData, setFormData] = React.useState({
itemName: '',
daysUntilNextPurchase: '',
});
const [submissionStatus, setSubmissionStatus] = React.useState('');
const [showMessage, setShowMessage] = React.useState(false);
Copy link
Member

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.

Suggested change
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);

Copy link
Collaborator Author

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 :)

Comment on lines +12 to +21
function handleChange(event) {
const { name, value } = event.target;

setFormData((prevFormData) => {
return {
...prevFormData,
[name]: value,
};
});
}
Copy link
Member

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!

Copy link
Member

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.

Copy link
Member

@paramsiddharth paramsiddharth left a 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!

@RajGM
Copy link
Collaborator

RajGM commented Apr 14, 2023

@shahx95 absorbs office hour insight and PR feedback very quickly.
Great work @shahx95 and @ToobaJamal

Copy link
Collaborator

@RajGM RajGM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@labrocadabro
Copy link
Collaborator

@labrocadabro thanks for the feedback.

  1. 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.
  2. 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.

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.

@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.

Copy link
Member

@paramsiddharth paramsiddharth left a 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!

Copy link
Member

@paramsiddharth paramsiddharth left a 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!

@paramsiddharth paramsiddharth merged commit f9ef46d into main Apr 15, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4. As a user, I want to add a new item to my shopping list so I can start recording purchases
6 participants