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 addItem function import #19

Merged
merged 13 commits into from
Apr 16, 2023
Merged

Add addItem function import #19

merged 13 commits into from
Apr 16, 2023

Conversation

jeremiahfallin
Copy link
Collaborator

@jeremiahfallin jeremiahfallin commented Apr 11, 2023

Description

This code changes the AddItem view and the firebase.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 the addDoc function from the firebase/firestore library. We chose to use React's useState 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:

  • 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
✨ New feature

Updates

Before

image

After

image

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 the https://localhost:3000/list page.

@github-actions
Copy link

github-actions bot commented Apr 11, 2023

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

@jeremiahfallin jeremiahfallin marked this pull request as ready for review April 11, 2023 03:59
@jeremiahfallin
Copy link
Collaborator Author

Forgot to make sure the user enters an item name! Added it in the latest push.

Copy link
Collaborator

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

src/views/AddItem.jsx Show resolved Hide resolved
src/views/AddItem.jsx Outdated Show resolved Hide resolved
Copy link
Collaborator

@katherineyuneman katherineyuneman left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks all!

@@ -64,6 +62,7 @@ export async function addItem(listId, { itemName, daysUntilNextPurchase }) {
name: itemName,
totalPurchases: 0,
});
return data;
Copy link
Collaborator

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?

setItemName('');
setTimeframe('Soon');
} else {
setMessage('Error adding item');
Copy link
Collaborator

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

src/views/AddItem.jsx Outdated Show resolved Hide resolved
src/api/firebase.js Outdated Show resolved Hide resolved
Copy link
Collaborator

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

Comment on lines 5 to 7
Soon: 7,
'Kind of Soon': 14,
'Not Soon': 30,
Copy link
Collaborator

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.

Copy link
Collaborator

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?

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 refactored it out completely. It seemed like a good idea when we were writing our code but wasn't needed at all. 😅

Comment on lines 74 to 76
<label htmlFor="timeframe" style={{ gridColumn: 'span 2' }}>
How soon will you buy this again?
</label>
Copy link
Collaborator

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done, great suggestion!

@lyleschemmerling
Copy link
Collaborator

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

This is being caused by line 34 of AddItem.jsx and I don't think that you need it.

src/views/AddItem.jsx Outdated Show resolved Hide resolved
@mentalcaries mentalcaries merged commit 8d78606 into main Apr 16, 2023
2 checks passed
@mentalcaries mentalcaries deleted the tf-jf-add-item branch April 16, 2023 13:52
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.

None yet

6 participants