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/add item quantity #46

Open
wants to merge 42 commits into
base: main
Choose a base branch
from
Open

Feat/add item quantity #46

wants to merge 42 commits into from

Conversation

RossaMania
Copy link
Collaborator

@RossaMania RossaMania commented Sep 27, 2024

For an example of how to fill this template out, see this Pull Request.

Description

This code adds "item quantity functionality"!

  • I add item quantity parameter to addItem function in firebase.ts. It's been updated to include an additional parameter, itemQuantity. This allows for specifying the quantity of the item being added to the list. I figure this would be as close as I would get to updating some sort of controller function.
  • I add item quantity parameter to addItem function in AddItemForm.tsx in the AddItemForm.tsx file on what would be the frontend. Add itemQuantity and setItemQuantity state var and state func with the useState hook. Console log item quanity of 1 upon successful addition. Set item quantity state to 1 upon success. Update return string interpolation in toast to show itemQuantity as well. When an item is added successfully, the default quantity should be “1” in the browser console log and in the toast notification. Upon completion, the state will still be set to “1”.
  • The quantity successfully shows up in the browser console and the toast! The itemQuantity shows up in the Firebase itself with the item! I add quantity input to AddItemForm.tsx with type "number". I wired the input up to handleItemQuantityChange func. I add and revise console logs for item quantity entered in that input to make sure the value is captured, and item quantity added to the list.
  • I add the item quantity property to ListItemModel in firebase.ts. I learned this must be the actual data model in Firebase! The itemQuantity property represents the quantity of the item. It is of type "number". Once the data model has that itemQuantity, I am able to render item.itemQuantity into the ListItem.tsx view!
  • This feature is getting pretty big already! I add item quantity input to AddItemForm.tsx and create ItemQuantityForm component. I add a quantity input field to the AddItemForm.tsx component with the type "number". I create a new component called ItemQuantityForm.tsx to handle the quantity input. The ItemQuantityForm component includes a form with an input field for the quantity. The quantity input field has a maximum value of 100, is initially set to “1”, can be edited and saved, and the saved quantity is passed to the parent component using a callback function. The edit is a piece of local state set with the useState hook. When edit is disabled, the input is grayed out. I also add console logs to track the quantity entered and the quantity saved.
  • I rendered the ItemQuantityForm component in the ItemList.tsx file!
  • I created a updateItemQuantity func in firebase.ts! This takes a quantity argument in addition to the item and listPath arguments! It's called in the ListItem.tsx!
  • "item" is passed as a prop to the ItemQuantityForm from the AddItemForm.tsx file and the ListItem.tsx file so the item.itemQuantity prop can display the quantity dynamically!
  • In ListItem.tsx, a check is set so if the quantity is set to "0", the deleteItemHandler function is called as if the user clicked the delete button and the user is prompted to confirm if he or she really wants to delete the item!

Related Issue

Acceptance Criteria

  • "number" is going to be the data type.
  • "1" should be the default quantity.
  • The quantity should be saved to the database.
  • Setting the quantity to "0" prompts the user to confirm that they want to delete the item from the list.

Type of Changes

Use one or more labels to help your team understand the nature of the change(s) you’re proposing. E.g., bug fix or enhancement are common ones.

Updates

Before

image

After

image

image

image

image

image

Testing Steps / QA Criteria

  • Plenty of console logs right now to look at that delicious data flow!

Change Quantity!

  • Navigate to the Manage List page.
  • Click that Edit button. Enter a number in "How Many" text field. Click Save.
  • Enter an item name, and select an option for when to buy.
  • Then click Submit.
  • On the /list page, you can click that Edit button, enter a new number, and then click Save!

1 Is The Default Number!

  • Navigate to the Manage List page.
  • Leave the "How Many" text field blank!
  • Enter an item name, and select an option for when to buy.
  • Then click Submit.
  • You should see a confirmation toast that only one of your item has been added!

Delete Item!

  • Navigate to the List page of a list with items that have quantities.
  • Click that Edit button. Enter "0" in "How Many" text field. Click Save.
  • The deleteItemHandler func will be called, and you can go through that flow like normal!
  • A dialogue will appear to confirm deletion
  • If user clicks "yes", a confirmation message is displayed.
  • If user clicks "cancel", they are returned to the windows page as normal.

… It's been updated to include an additional parameter, itemQuantity. This allows for specifying the quantity of the item being added to the list. The func now creates a new item document with the provided quantity, enhancing the functionality of adding items to the list.
…tsx in the `AddItemForm.tsx` file. Add itemQuantity and setItemQuantity state var and state func with the useState hook. Console log item quanity of 1 upon successful addition. Set item quantity state to 1 upon success. Update return string interpolation in toast to show itemQuantity as well.
…it to handleItemQuantityChange func. Add and revise console logs for item quantity entered, and item quantity added.
…s property represents the quantity of the item. It is of type "number". Render item.itemQuantity into ListItem.tsx view.
…ityForm component.

- Add a quantity input field to the AddItemForm.tsx component with the type "number".
- Create a new component called ItemQuantityForm.tsx to handle the quantity input.
- The ItemQuantityForm component includes a form with an input field for the quantity.
- The quantity input field has a maximum value of 100.
- The quantity input field is initially set to 1.
- The quantity input field can be edited and saved.
- The saved quantity is passed to the parent component using a callback function.
- Console logs are added to track the quantity entered and saved.
…tityForm component from "./forms/ItemQuantityForm". Replace the display of item quantity with the ItemQuantityForm component. Implement the editItemQuantity function to handle changes in item quantity.
…trieves the old item quantity from Firebase and logs it to the console. This function will be used to update the quantity of an item in the shopping list.
…tes object, and updateDoc method call to update the itemQuantity.
…gging of item quantity after successful update in try block.
- Modified `editItemQuantity` function in ListItem.tsx to accept the new quantity and pass it to the `updateItemQuantity` function.
- Updated `updateItemQuantity` function in firebase.ts to accept the new quantity as a parameter and update the item with this new quantity.
- Ensured that the new quantity is correctly passed and updated in firebase.
- In the ListItem component, the ItemQuantityForm component is updated to pass the item object as a prop.
- In the ItemQuantityForm component, the initial item quantity is set to the item's itemQuantity property.
- This change ensures that the ItemQuantityForm displays the correct initial quantity for each item.
…item quantity is null. This change initializes the item quantity state with the value from the item prop, allowing for proper rendering and editing of the quantity.
…ent. If quantity is 0, deleteItemHandler is called!
@RossaMania RossaMania added enhancement New feature or request new feature labels Sep 27, 2024
Copy link

github-actions bot commented Sep 27, 2024

Visit the preview URL for this PR (updated for commit 5427158):

https://tcl-77-smart-shopping-list--pr46-feat-add-item-quanti-g2sg65a4.web.app

(expires Thu, 10 Oct 2024 00:02:17 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: b77df24030dca7d8b6561cb24957d2273c5e9d72

@@ -83,6 +84,30 @@ export function ListItemCheckBox({ item, listPath }: Props) {
}
};

Copy link
Collaborator

@bbland1 bbland1 Sep 28, 2024

Choose a reason for hiding this comment

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

suggestion: i think we could move this logic for updating the item quantity into the ItemQuantityForm. reading through the code right now it feels like there is some duplication of logic, kind of adding logic to components to make another component work.

moving this to be handled by the ItemQuantityForm it could make it a bit more reusable because we could just place it into the location it is needed and not write logic within that component to get it to work. it would be like this check box and other forms the logic to do the updating and steps the form is doing is housed within the logic.

To get the item prop needed with these changes on the list view we could try moving the <ItemQuantityForm saveItemQuantity={editItemQuantity} item={item} /> x{" "} call into the List component with this logic

{filteredListItems.map((item) => (<ListItemCheckBox key={item.id} item={item} listPath={listPath} />))}

and I believe it would get the same result.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Great idea, that way the logic outside of firebase for quantity is all referable in one place.

Copy link
Collaborator

@alex-andria alex-andria left a comment

Choose a reason for hiding this comment

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

This is a cool feature Ross, I haven't seen a Smart Shopping List from TCL with a quantity feature so it's awesome to see you add this functionality and be so motivated to do so. I found a bug when adding a second item with a different quantity that needs to be addressed, and maybe some refactoring like Brianna suggested could help with reading this as well on a dev level. Great work with the amount of detail you added in your PR too!

src/components/ListItem.tsx Outdated Show resolved Hide resolved
@@ -83,6 +84,30 @@ export function ListItemCheckBox({ item, listPath }: Props) {
}
};

Copy link
Collaborator

Choose a reason for hiding this comment

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

Great idea, that way the logic outside of firebase for quantity is all referable in one place.

src/components/forms/AddItemForm.tsx Outdated Show resolved Hide resolved
src/components/forms/ItemQuantityForm.tsx Outdated Show resolved Hide resolved
src/components/forms/ItemQuantityForm.tsx Outdated Show resolved Hide resolved
…emQuantityForm in AddItemForm underneath Item name input.
…from a nullable type to using a logical operator. If there's an item, then show item.itemQuantity. Else, set to "1".
…rm component. Set "min" attribute in ItemQuantityForm attribute to 1.
…et default item quantity to 1 if it is less than 1.
…ntity is less than 1. Don't set quantity back to 1.
…ItemQuantity to prevent confusion, and to explicitly describe what func does. Re-write console logs to be more specific about what is happening in each file.
…ore descriptive. In ItemQuantityForm, set the edit state to true if itemQuality is less than 1, and just return. This way user is prompted to enter valid input.
…ding a new item's quantity. Update AddItemForm component to use addedQuantity instead of itemQuantity.

- Renamed the state variable 'itemQuantity' to 'addedQuantity' in the AddItemForm component to improve clarity and consistency.
- Updated the handleItemQuantityChange function to set the 'addedQuantity' state based on the input value.
- Updated the handleSubmit function to use the 'addedQuantity' state when adding the item to the list.
- Updated the error message in the AddItemForm component to display the correct 'addedQuantity' value when adding the item fails.
- Reset the 'addedQuantity' state to 1 after successfully adding the item to the list.
- Removed the ItemQuantityForm component and replaced it with a simple input element for item quantity.
…h. Update styles and dependencies.

- Update _variables.scss with new color variables
- Update vite.config.js to configure svgr plugin
- Add new views: About, UnauthenticatedHome, AuthenticatedHome
- Update index.tsx to import bootstrap and index.scss
- Update components/index.ts to import AuthenticatedNavBar and UnauthenticatedNavBar
- Update package.json to add bootstrap and react-bootstrap dependencies
- Update index.html to include bootstrap.min.css
- Update SingleList.tsx to import Button and update styles
- Update App.tsx to import About and update routes
- Add AuthenticatedNavBar.scss and AuthenticatedNavBar.tsx
- Add AuthenticatedHome.tsx and UnauthenticatedNavBar.tsx
- Update AddItemForm.tsx to import Button and Form from react-bootstrap
- Update Home.tsx to import AuthenticatedHome and UnauthenticatedHome
- Update FilterListInput.tsx to import Button, Form, and InputGroup from react-bootstrap
@RossaMania
Copy link
Collaborator Author

I was able to merge other pull requests into this pull request as well, and refactor as needed!
image
image
image

Still a bit of refactoring to do!

…r. Remove lablel, but keep aria label of checkbox.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants