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

Added useCart hook #92

Merged
merged 1 commit into from
Oct 11, 2024
Merged

Added useCart hook #92

merged 1 commit into from
Oct 11, 2024

Conversation

yurii-ve
Copy link
Collaborator

Introduce useCart hook which combines all other cart-related hooks. This is going to simplify reusing of this functionality in other places - cart page for example.

  • renamed existing API hook useCart to useCartData
  • created useCart hook which returns cart data, cart totals, checkout, removeItem and updateItemQuantity


export const useCart = () => {
const ecomAPI = useEcomAPI();
const { data: cartData } = useCartData();
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe it would be better to rename values returned from hooks to not rename it during assignment?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

can't do that, because it's a SWR object returned from the hook

import { useCartTotals, useCartData, useUpdateCartItemQuantity, useRemoveItemFromCart } from '~/api/api-hooks';
import { useEcomAPI } from '~/api/ecom-api-context-provider';

export const useCart = () => {
Copy link
Collaborator

@VladyslavG VladyslavG Oct 11, 2024

Choose a reason for hiding this comment

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

return type? or is it too verbose for such return data ?

@yurii-ve yurii-ve merged commit 8af097d into development Oct 11, 2024
1 check passed
@yurii-ve yurii-ve deleted the yuriiv/use-cart-hook branch October 11, 2024 11:32
yurii-ve added a commit that referenced this pull request Nov 1, 2024
* Remove app board (#70)

* Update error handling (#72)

* Remove app board (#70) (#71)

* Update error handling

* Create CartItemView component, update ProductCard board (#74)

* Create CartItemView component

* Update product card board

* Updated UI kit components board

* Resolve comments

* Resolve comments 2

* Update codux config to use .env file (#76)

* Handle trackQuantity property for out of stock indication (#80)

* Keep entire selected choice object in route state (#81)

* Keep entire selected choice object in route state

* Remove console.log

* Add return types, update comment

* Update helper name and added comment

* Use selected choice media (#82)

* fix: out of stock indication for products with variants (#83)

* refactor: improve fix regarding navigation from error boundary (#84)

* refactor: improve fix regarding navigation from error boundary

* remove console.log

* Fix missing SKU issue (#85)

* Remove redundant instruction (#86)

* Change background-color to background, use color variables (#87)

* Remove absolute positioning from the intro board (#88)

* Remove absolute positioning from the intro board

* Fix tabs

* Remove redundant style

* Split Cart component into functional (Cart) and view parts (CartView) (#90)

* Update cart related boards (#91)

* Added useCart hook (#92)

* Remove cart loading state (#93)

* Update drawer component (#94)

* feat: hide non-visible variants to disallow selection (#89)

* feat: hide non-visible variatns to disallow selection

* rename

* some refactoring

* refactor

* rename

* refactor non visible choices, add out of stock choices

* review comments

* fix review comments

* Use quantity state (#95)

* Export addToCart from the useCart hook (#96)

* refactor: improve select types (#97)

* refactor: improve select types

* fix logic

* fix comment

* feat: products filtering and sorting (#98)

* added sorting and filters

* improve responsive views

* prettify files

* Sync latest changes from the ReClaim template (#102)

* Add lib folder, user session

* Update dependencies

* Update codux config

* Fix

* Define DEMO_STORE_WIX_CLIENT_ID in the src

* Add getStaticRoutes

* Prettier

* Prettier

* Add faker

* Update package-lock

* Put canonical links back

* Fix duplicate import

* Remove redundant code

---------

Co-authored-by: olehrakwix <[email protected]>
yurii-ve added a commit that referenced this pull request Nov 11, 2024
* Remove app board (#70)

* Update error handling (#72)

* Remove app board (#70) (#71)

* Update error handling

* Create CartItemView component, update ProductCard board (#74)

* Create CartItemView component

* Update product card board

* Updated UI kit components board

* Resolve comments

* Resolve comments 2

* Update codux config to use .env file (#76)

* Handle trackQuantity property for out of stock indication (#80)

* Keep entire selected choice object in route state (#81)

* Keep entire selected choice object in route state

* Remove console.log

* Add return types, update comment

* Update helper name and added comment

* Use selected choice media (#82)

* fix: out of stock indication for products with variants (#83)

* refactor: improve fix regarding navigation from error boundary (#84)

* refactor: improve fix regarding navigation from error boundary

* remove console.log

* Fix missing SKU issue (#85)

* Remove redundant instruction (#86)

* Change background-color to background, use color variables (#87)

* Remove absolute positioning from the intro board (#88)

* Remove absolute positioning from the intro board

* Fix tabs

* Remove redundant style

* Split Cart component into functional (Cart) and view parts (CartView) (#90)

* Update cart related boards (#91)

* Added useCart hook (#92)

* Remove cart loading state (#93)

* Update drawer component (#94)

* feat: hide non-visible variants to disallow selection (#89)

* feat: hide non-visible variatns to disallow selection

* rename

* some refactoring

* refactor

* rename

* refactor non visible choices, add out of stock choices

* review comments

* fix review comments

* Use quantity state (#95)

* Export addToCart from the useCart hook (#96)

* refactor: improve select types (#97)

* refactor: improve select types

* fix logic

* fix comment

* feat: products filtering and sorting (#98)

* added sorting and filters

* improve responsive views

* prettify files

* Sync latest changes from the ReClaim template (#102)

* Add lib folder, user session

* Update dependencies

* Update codux config

* Fix

* Define DEMO_STORE_WIX_CLIENT_ID in the src

* Add getStaticRoutes

* Prettier

* Prettier

* Add faker

* Update package-lock

* Put canonical links back

* Fix duplicate import

* chore(deps): upgrade to latest (#104)

* refactor: replace css reset (#107)

* Fix (#111)

* Use component wrapper instead of memory router (#112)

* Update/fix meta tags (#105)

* Update meta tags

* Change var name

* Change title

* Remove favicon links

* Remove canonical links

* Fix lint

* Simplify non-essential routes

* FIx

* Fix

* Update package-lock

* Remove redundant util

---------

Co-authored-by: olehrakwix <[email protected]>
Co-authored-by: Pilar Buchen <[email protected]>
Co-authored-by: Ido Rosenthal <[email protected]>
yurii-ve added a commit that referenced this pull request Jan 15, 2025
* Remove app board (#70)

* Update error handling (#72)

* Remove app board (#70) (#71)

* Update error handling

* Create CartItemView component, update ProductCard board (#74)

* Create CartItemView component

* Update product card board

* Updated UI kit components board

* Resolve comments

* Resolve comments 2

* Update codux config to use .env file (#76)

* Handle trackQuantity property for out of stock indication (#80)

* Keep entire selected choice object in route state (#81)

* Keep entire selected choice object in route state

* Remove console.log

* Add return types, update comment

* Update helper name and added comment

* Use selected choice media (#82)

* fix: out of stock indication for products with variants (#83)

* refactor: improve fix regarding navigation from error boundary (#84)

* refactor: improve fix regarding navigation from error boundary

* remove console.log

* Fix missing SKU issue (#85)

* Remove redundant instruction (#86)

* Change background-color to background, use color variables (#87)

* Remove absolute positioning from the intro board (#88)

* Remove absolute positioning from the intro board

* Fix tabs

* Remove redundant style

* Split Cart component into functional (Cart) and view parts (CartView) (#90)

* Update cart related boards (#91)

* Added useCart hook (#92)

* Remove cart loading state (#93)

* Update drawer component (#94)

* feat: hide non-visible variants to disallow selection (#89)

* feat: hide non-visible variatns to disallow selection

* rename

* some refactoring

* refactor

* rename

* refactor non visible choices, add out of stock choices

* review comments

* fix review comments

* Use quantity state (#95)

* Export addToCart from the useCart hook (#96)

* refactor: improve select types (#97)

* refactor: improve select types

* fix logic

* fix comment

* feat: products filtering and sorting (#98)

* added sorting and filters

* improve responsive views

* prettify files

* Sync latest changes from the ReClaim template (#102)

* Add lib folder, user session

* Update dependencies

* Update codux config

* Fix

* Define DEMO_STORE_WIX_CLIENT_ID in the src

* Add getStaticRoutes

* Prettier

* Prettier

* Add faker

* Update package-lock

* Put canonical links back

* Fix duplicate import

* chore(deps): upgrade to latest (#104)

* refactor: replace css reset (#107)

* Fix (#111)

* Use component wrapper instead of memory router (#112)

* Update/fix meta tags (#105)

* Update meta tags

* Change var name

* Change title

* Remove favicon links

* Remove canonical links

* Fix lint

* Simplify non-essential routes

* FIx

* Fix

* fix: regenerate lock file fixes run dev (#116)

* fix: position page layout correctly (#117)

* refactor: replace import with use (#118)

* remove import

* run install

---------

Co-authored-by: Yurii Venher <[email protected]>
Co-authored-by: olehrakwix <[email protected]>
Co-authored-by: Pilar Buchen <[email protected]>
Co-authored-by: Ido Rosenthal <[email protected]>
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.

3 participants