Skip to content

Commit

Permalink
Use useShoppingCart in PrePurchaseNotices to get product slugs (#49965)
Browse files Browse the repository at this point in the history
  • Loading branch information
sirbrillig committed Feb 12, 2021
1 parent 2ccfbe0 commit cfdb935
Showing 1 changed file with 3 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import React from 'react';
import { useSelector } from 'react-redux';
import { useLineItems } from '@automattic/composite-checkout';
import { useShoppingCart } from '@automattic/shopping-cart';

/**
* Internal dependencies
Expand Down Expand Up @@ -39,13 +39,8 @@ const PrePurchaseNotices = () => {
const selectedSite = useSelector( getSelectedSite );
const siteId = selectedSite?.ID;

// We used to directly reference the cart itself here (passed in as a prop),
// but for some reason, cart items take ~20 seconds to populate in some cases,
// whereas line items are immediately available on page load.
const [ lineItems ] = useLineItems();
const cartItemSlugs = lineItems
.map( ( item ) => item.wpcom_meta?.product_slug )
.filter( ( item ) => item );
const { responseCart } = useShoppingCart();
const cartItemSlugs = responseCart.products.map( ( item ) => item.product_slug );

const currentSitePlan = useSelector( ( state ) => {
if ( ! siteId ) {
Expand Down

0 comments on commit cfdb935

Please sign in to comment.