diff --git a/packages/peregrine/lib/talons/CartPage/PriceSummary/usePriceSummary.js b/packages/peregrine/lib/talons/CartPage/PriceSummary/usePriceSummary.js index bbaabfa047..a5df9d879f 100644 --- a/packages/peregrine/lib/talons/CartPage/PriceSummary/usePriceSummary.js +++ b/packages/peregrine/lib/talons/CartPage/PriceSummary/usePriceSummary.js @@ -1,5 +1,5 @@ -import { useEffect } from 'react'; -import { useLocation } from 'react-router-dom'; +import { useEffect, useCallback } from 'react'; +import { useHistory, useRouteMatch } from 'react-router-dom'; import { useLazyQuery } from '@apollo/react-hooks'; import { useCartContext } from '@magento/peregrine/lib/context/cart'; @@ -28,10 +28,10 @@ export const usePriceSummary = props => { } = props; const [{ cartId }] = useCartContext(); - - const location = useLocation(); + const history = useHistory(); // We don't want to display "Estimated" or the "Proceed" button in checkout. - const isCheckout = location.pathname === '/checkout'; + const match = useRouteMatch('/checkout'); + const isCheckout = !!match; const [fetchPriceSummary, { error, loading, data }] = useLazyQuery( getPriceSummary @@ -53,7 +53,12 @@ export const usePriceSummary = props => { } }, [error]); + const handleProceedToCheckout = useCallback(() => { + history.push('/checkout'); + }, [history]); + return { + handleProceedToCheckout, hasError: !!error, hasItems: data && !!data.cart.items.length, isCheckout, diff --git a/packages/venia-ui/lib/components/CartPage/PriceSummary/priceSummary.js b/packages/venia-ui/lib/components/CartPage/PriceSummary/priceSummary.js index 88540b9026..7a98c043c8 100644 --- a/packages/venia-ui/lib/components/CartPage/PriceSummary/priceSummary.js +++ b/packages/venia-ui/lib/components/CartPage/PriceSummary/priceSummary.js @@ -10,7 +10,6 @@ import GiftCardSummary from './giftCardSummary'; import ShippingSummary from './shippingSummary'; import TaxSummary from './taxSummary'; import { PriceSummaryFragment } from './priceSummaryFragments'; -import { Link } from '@magento/venia-drivers'; const GET_PRICE_SUMMARY = gql` query getPriceSummary($cartId: String!) { @@ -40,7 +39,14 @@ const PriceSummary = props => { } }); - const { hasError, hasItems, isCheckout, isLoading, flatData } = talonProps; + const { + handleProceedToCheckout, + hasError, + hasItems, + isCheckout, + isLoading, + flatData + } = talonProps; if (hasError) { return ( @@ -61,10 +67,12 @@ const PriceSummary = props => { const proceedToCheckoutButton = !isCheckout ? (