-
Notifications
You must be signed in to change notification settings - Fork 202
Add wishlist item to the cart #158
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
Conversation
| parameters: { | ||
| ids: ids.join(',') | ||
| ids: ids.join(','), | ||
| allImages: true |
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.
need this for the swatch images.
|
Some regression that I found on the add to cart modal |
|
I also notice a pattern for the modal components. We tend to keep the component in the same place we create the hook. Eg. the login modal and add to cart modal. We might want to do the same for the This will not require a change on this PR, but it can potentially create another refactor for the |
| import {findImageGroupBy} from '../utils/image-groups-utils' | ||
|
|
||
| export const AddToCartModalContext = React.createContext() | ||
| export const useAddToCartModalContext = () => useContext(AddToCartModalContext) |
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.
Should we declare this context inside the index.js under the context folder? How should we decide which context will stay in its own file or inside the context file?
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.
Should we declare this context inside the index.js under the context folder?
I'd say no, because i think the AddToCartModalContext itself doesn't work alone, it's not made to be shared with other modules or features. I view it as a part of the "Add to cart modal" module. This file encapsulate everything to make add to cart modal work in the app.
How should we decide which context will stay in its own file or inside the context file?
So i think this question comes down to recognizing the separation of concerns. A mental model for myself is like OO programming's principle Encapsulation, I view the module (e.g. this use-add-to-cart-modal.js file) as a "class" and everything related to this module should be encapsulated in the file. I think this pattern helps developers avoiding "Spagetti code" (generally because of bad separation of concerns)
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 noticed develop branch has a bunch of changes made to context.js (the update category context and the new currency context). Seems like we already established a pattern there, i guess i'll follow the pattern and maybe we can chat a bit more in tech discussion session.
TL;DR i'm moving this to context.js
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 couldn't do this because there is a circular dependency between the context, hook and the component... I really don't want to separate the component from the hook and contexts because the component itself doesn't work, it is meant to work only with the hook.
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.
Would you mind adding a comment to explain that so it won't confuse other developers?
…alesforceCommerceCloud/pwa-kit into W-9284634_add-wishlist-to-cart
alexvuong
left a comment
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
commit 915bf3e Author: Kevin He <[email protected]> Date: Wed Oct 13 09:29:43 2021 -0700 Add wishlist item to the cart (#158) * fix variant id * include ProductViewModal in wishlist item * refactor addtocartmodal to global * refactor AddToCartModal * remove modal from wishlist action * fix missing swatch images * add changelog * fix tests * close modal when path change * add AddToCartModalProvider * remove useMemo * fix lint * optimize modal rerenders * fix test * remove unused import commit 19cc8d4 Author: vcua-mobify <[email protected]> Date: Tue Oct 12 13:37:08 2021 -0700 Add a cache-control header to the PDP (#172) * Add a cache-control header to the PDP Co-authored-by: Ben Chypak <[email protected]> commit 2810522 Author: svc-scm <[email protected]> Date: Tue Oct 12 05:57:59 2021 -0700 Updated/Added CODEOWNERS with ECCN commit a2372d9 Author: Ben Chypak <[email protected]> Date: Fri Oct 8 16:47:20 2021 -0700 Invert equality comparison (#174) commit a329fa8 Author: Kevin He <[email protected]> Date: Fri Oct 8 13:53:46 2021 -0700 always enable the fav icon in product tiles (#173) commit 62d55bb Author: vcua-mobify <[email protected]> Date: Thu Oct 7 17:56:55 2021 -0700 Update localization cli and readme (#160) * Update localization cli and readme * Fix heading hierarchy * Update packages/pwa/app/translations/README.md Applying suggested change to the readme Co-authored-by: Vincent Marta <[email protected]> * Update packages/pwa/app/translations/README.md Applying suggested change to the readme Co-authored-by: Vincent Marta <[email protected]> * Clean up references to old CLI and update README * Update README.md * Update readme to remove references to locale.config.js * Update packages/pwa/app/translations/README.md Co-authored-by: Vincent Marta <[email protected]> * Update packages/pwa/app/translations/README.md Co-authored-by: Vincent Marta <[email protected]> * Update packages/pwa/app/translations/README.md Co-authored-by: Vincent Marta <[email protected]> Co-authored-by: Vincent Marta <[email protected]> commit b0db12a Author: John Boxall <[email protected]> Date: Thu Oct 7 11:32:56 2021 -0700 Remove the `X-Powered-By` HTTP response header


Description
This PR allows adding wishlist items to the cart.
This PR was suppose to be a small change but turns out needing to refactor a few components include
AddToCartModalandProductView. The reason is theAddToCartModalwas embedded inProductViewas a local component. This works okay until we need to haveProductViewin a modal. In the below screen, you will see a situation where we need to display theAddToCartModalafter successfully adding item to the cart from theProductViewmodal.Because the component hierarchy looks like this:
This is limiting the ability to display the two modals separately. We need to support the situation where
AddToCartModalis rendered on the page whileProductViewModalis not.The implementation becomes really messy after i'm trying to add a new
AddToCartModalin the wishlist components.So, I decided to move
AddToCartModalto top level as a global component, as this modal is shown on multiple pages like pdp, cart and wishlist. All place share the same modal. To achieve that, i also need to create a context to store the modal open/close state.Types of Changes
Changes
How to Test-Drive This PR
npm startChecklists
General
Accessibility Compliance
You must check off all items in one of the follow two lists:
or...
Localization