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

Allow Adding to Wishlist from the Product List Page #2

Merged
merged 37 commits into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
e4852a8
All of my branch squashed
alexvuong Aug 9, 2021
5af18a7
refactor add/remove wishlist on PLP
alexvuong Aug 10, 2021
757af3b
lint
alexvuong Aug 11, 2021
0c748f0
use destructing form for confirming modal
alexvuong Aug 11, 2021
4eed67a
Merge branch 'develop' into feature-add-to-wishlist-plp-new
alexvuong Aug 11, 2021
91f7e79
remove rebundant code
alexvuong Aug 11, 2021
fda4202
Merge branch 'develop' into feature-add-to-wishlist-plp-new
alexvuong Aug 16, 2021
ef5e45b
test commit
alexvuong Aug 16, 2021
be3ec24
PR feedback and design feedback
alexvuong Aug 17, 2021
30bdf56
refactor wishlist to be aware of quantity
alexvuong Aug 18, 2021
68c276a
extract messages
alexvuong Aug 18, 2021
0ecae2c
Merge branch 'develop' into feature-add-to-wishlist-plp-new
alexvuong Aug 18, 2021
c6d1fbd
import noop properly
alexvuong Aug 18, 2021
04ae26b
refactor PLP wishlist
alexvuong Aug 18, 2021
a673154
remove unused method
alexvuong Aug 18, 2021
f37ae03
fix quantity for requests
alexvuong Aug 19, 2021
62cd1a7
PR feedback and add more tests
alexvuong Aug 20, 2021
6437fb3
add more unit test
alexvuong Aug 20, 2021
8b77e30
translations
alexvuong Aug 20, 2021
b5b79b7
PR feedback
adamraya Aug 21, 2021
f9a020c
lint
alexvuong Aug 21, 2021
920b6af
rollback some changes
alexvuong Aug 23, 2021
d046f95
add more tests
alexvuong Aug 23, 2021
cb2d449
Merge branch 'develop' into feature-add-to-wishlist-plp-new
alexvuong Aug 23, 2021
46aad23
fix test
alexvuong Aug 23, 2021
9f86f1f
rollback a test
alexvuong Aug 23, 2021
95d8454
compiled messages
alexvuong Aug 23, 2021
d301f8d
Merge branch 'develop' into feature-add-to-wishlist-plp-new
alexvuong Aug 23, 2021
b77330a
resolve some merged conflict
alexvuong Aug 23, 2021
576e3dc
linting
alexvuong Aug 24, 2021
bd66566
fix proptype
alexvuong Aug 24, 2021
2eb88ed
fix stale loading state when click heart icon so fast
alexvuong Aug 24, 2021
3dd7c08
Merge branch 'develop' into feature-add-to-wishlist-plp-new
alexvuong Aug 24, 2021
4ffa0b0
resolve merge conflict
alexvuong Aug 24, 2021
33fea95
fix tests
alexvuong Aug 24, 2021
bf9afe0
bump tests
alexvuong Aug 24, 2021
f9fb084
fix failing tests
alexvuong Aug 24, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default function useCustomerProductLists() {
},

get loaded() {
return customerProductLists?.data?.length
return !!customerProductLists?.data?.length
},

getProductListPerType(type) {
Expand Down
19 changes: 9 additions & 10 deletions packages/pwa/app/commerce-api/hooks/useShopper.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,16 @@ const useShopper = () => {
useEffect(() => {
// Fetch product details for new items in product-lists
const hasCustomerProductLists = customerProductLists?.loaded
if (hasCustomerProductLists) {
customerProductLists.data.forEach((list) => {
let ids = list.customerProductListItems?.map((item) => item.productId)
if (list?._productItemsDetail) {
ids = ids.filter((id) => !list?._productItemsDetail[id])
}
if (!hasCustomerProductLists) return
customerProductLists.data.forEach((list) => {
let ids = list.customerProductListItems?.map((item) => item.productId)
if (list?._productItemsDetail) {
ids = ids.filter((id) => !list?._productItemsDetail[id])
}

customerProductLists.getProductsInList(ids?.toString(), list.id)
})
}
}, [customerProductLists])
customerProductLists.getProductsInList(ids?.toString(), list.id)
})
}, [customerProductLists.data])

return {customer, basket}
}
Expand Down
15 changes: 10 additions & 5 deletions packages/pwa/app/components/confirmation-modal/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,23 @@ const ConfirmationModal = ({
}) => {
const {formatMessage} = useIntl()

const handleConfirmClicked = () => {
const handleConfirmClick = () => {
onPrimaryAction()
props.onClose()
}

const handleCancelClicked = () => {
const handleAlternateActionClick = () => {
onAlternateAction()
props.onClose()
}

return (
<AlertDialog isOpen={props.isOpen} isCentered onClose={handleCancelClicked} {...props}>
<AlertDialog
isOpen={props.isOpen}
isCentered
onClose={handleAlternateActionClick}
{...props}
>
<AlertDialogOverlay />
<AlertDialogContent>
<AlertDialogHeader>{formatMessage(dialogTitle)}</AlertDialogHeader>
Expand All @@ -49,10 +54,10 @@ const ConfirmationModal = ({
</AlertDialogBody>

<AlertDialogFooter>
<Button variant="ghost" mr={3} onClick={handleCancelClicked}>
<Button variant="ghost" mr={3} onClick={handleAlternateActionClick}>
{formatMessage(alternateActionLabel)}
</Button>
<Button variant="solid" onClick={handleConfirmClicked}>
<Button variant="solid" onClick={handleConfirmClick}>
{formatMessage(primaryActionLabel)}
</Button>
</AlertDialogFooter>
Expand Down
9 changes: 9 additions & 0 deletions packages/pwa/app/components/product-item/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ import CartItemVariantPrice from '../cart-item-variant/item-price'
import LoadingSpinner from '../loading-spinner'
import {noop} from '../../utils/utils'

/**
* Component representing a product item usually in a list with details about the product - name, variant, pricing, etc.
* @param {Object} product Product to be represented in the list item.
* @param {node} primaryAction Child component representing the most prominent action to be performed by the user.
* @param {node} secondaryActions Child component representing the other actions relevant to the product to be performed by the user.
* @param {func} onItemQuantityChange callback function to be invoked whenever item quantity changes.
* @param {boolean} showLoading Renders a loading spinner with overlay if set to true.
* @returns A JSX element representing product item in a list (eg: wishlist, cart, etc).
*/
const ProductItem = ({
product,
primaryAction,
Expand Down
51 changes: 48 additions & 3 deletions packages/pwa/app/components/product-tile/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import React from 'react'
import PropTypes from 'prop-types'
import {WishlistIcon, WishlistSolidIcon} from '../icons'

// Components
import {
Expand All @@ -14,16 +15,20 @@ import {
Skeleton as ChakraSkeleton,
Text,
Stack,
useMultiStyleConfig
useMultiStyleConfig,
IconButton
} from '@chakra-ui/react'

// Hooks
import {useIntl} from 'react-intl'

// Other
import {productUrlBuilder} from '../../utils/url'
import {isServer} from '../../utils/utils'
import {isServer, noop} from '../../utils/utils'
import Link from '../link'
import withRegistration from '../../hoc/with-registration'

const IconButtonWithRegistration = withRegistration(IconButton)

// Component Skeleton
export const Skeleton = () => {
Expand Down Expand Up @@ -56,6 +61,10 @@ const ProductTile = (props) => {
productSearchItem,
// eslint-disable-next-line react/prop-types
staticContext,
// onWishlistItemToggled = noop,
onAddToWishlistClick = noop,
onRemoveWishlistClick = noop,
isInWishlist,
...rest
} = props
const {currency, image, price, productName} = productSearchItem
Expand All @@ -76,6 +85,30 @@ const ProductTile = (props) => {
<AspectRatio {...styles.image} ratio={1} display={isServer ? 'none' : 'block'}>
<Image alt={image.alt} src={image.disBaseLink} ignoreFallback={true} />
</AspectRatio>
{isInWishlist ? (
<IconButton
aria-label={intl.formatMessage({
defaultMessage: 'Wishlist'
})}
icon={<WishlistSolidIcon />}
variant="unstyled"
{...styles.iconButton}
onClick={(e) => {
e.preventDefault()
onRemoveWishlistClick()
}}
/>
) : (
<IconButtonWithRegistration
aria-label={intl.formatMessage({
defaultMessage: 'Wishlist'
})}
icon={<WishlistIcon />}
variant="unstyled"
{...styles.iconButton}
onClick={onAddToWishlistClick}
/>
)}
</Box>

{/* Title */}
Expand All @@ -98,7 +131,19 @@ ProductTile.propTypes = {
* The product search hit that will be represented in this
* component.
*/
productSearchItem: PropTypes.object.isRequired
productSearchItem: PropTypes.object.isRequired,
/**
* Types of lists the product/variant is added to. (eg: wishlist)
*/
isInWishlist: PropTypes.bool,
/**
* Callback function to be invoked when the user add item to wishlist
*/
onAddToWishlistClick: PropTypes.func,
/**
* Callback function to be invoked when the user removes item to wishlist
*/
onRemoveWishlistClick: PropTypes.func
}

export default ProductTile
3 changes: 2 additions & 1 deletion packages/pwa/app/hoc/with-registration/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const withRegistration = (Component) => {
const {formatMessage} = useIntl()
const showToast = useToast()

const handleClick = () => {
const handleClick = (e) => {
e.preventDefault()
if (customer?.authType !== 'registered') {
// Do not show auth modal if users is already on the login page
if (isLoginPage) {
Expand Down
7 changes: 4 additions & 3 deletions packages/pwa/app/pages/account/wishlist/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ const AccountWishlist = () => {
const wishlist = customerProductLists.getProductListPerType(
customerProductListTypes.WISHLIST
)

setWishlist(wishlist)
if (wishlist?._productItemsDetail) {
setWishlist(wishlist)
}
}
}, [customerProductLists])
}, [customerProductLists.data])

if (!wishlist) {
return (
Expand Down
Loading