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

[chore]: Order Summary fast follow #2278

Merged
merged 6 commits into from
Mar 26, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
@@ -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';

Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!) {
Expand Down Expand Up @@ -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 (
Expand All @@ -61,10 +67,12 @@ const PriceSummary = props => {

const proceedToCheckoutButton = !isCheckout ? (
<div className={classes.checkoutButton_container}>
<Button disabled={isUpdating} priority={'high'}>
<Link to={'/checkout'} className={classes.images}>
{'Proceed to Checkout'}
</Link>
<Button
disabled={isUpdating}
priority={'high'}
onClick={handleProceedToCheckout}
>
{'Proceed to Checkout'}
</Button>
</div>
) : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@

@media (max-width: 960px) {
.heading {
border: unset;
border-width: 0;
}
}
14 changes: 11 additions & 3 deletions packages/venia-ui/lib/components/CheckoutPage/checkoutPage.css
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,18 @@
margin-bottom: 1.5rem;
}

.summary_container {
.summaryContainer {
grid-column: 2 / span 1;
grid-row: 1 / span 1;
height: 0;
position: sticky;
top: 5.5rem;
}

.summaryContainerPreReview {
composes: summaryContainer;
}

.place_order_button {
composes: root_highPriority from '../Button/button.css';
grid-column: 1 / span 1;
Expand All @@ -92,19 +96,23 @@
gap: 1rem;
}

.summary_container {
.summaryContainer {
grid-column: 1 / span 1;
grid-row: unset;
height: auto;
}

.summaryContainerPreReview {
display: none;
}

.stepper_heading {
padding-bottom: 1rem;
}

.payment_information_heading {
composes: stepper_heading;
/* On mobile, order summary has a top border, so avoid doubling up. */
border-bottom: unset;
border-bottom-width: 0;
}
}
27 changes: 11 additions & 16 deletions packages/venia-ui/lib/components/CheckoutPage/checkoutPage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { Fragment } from 'react';
import { useWindowSize } from '@magento/peregrine';
import {
CHECKOUT_STEP,
useCheckoutPage
Expand Down Expand Up @@ -47,9 +46,6 @@ const CheckoutPage = props => {

const classes = mergeClasses(defaultClasses, propClasses);

const windowSize = useWindowSize();
const isMobile = windowSize.innerWidth <= 960;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Spoke with @jimbo we may actually wnat to use window size now considering upcoming UX changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted this to use the hook again :)


let content;
if (isLoading) {
return fullPageLoadingIndicator;
Expand Down Expand Up @@ -118,24 +114,21 @@ const CheckoutPage = props => {
) : null;

// If we're on mobile we should only render price summary in/after review.
const shouldRenderPriceSummary = !(
isMobile && checkoutStep < CHECKOUT_STEP.REVIEW
);
let orderSummaryClassName = classes.summaryContainer;
if (checkoutStep < CHECKOUT_STEP.REVIEW) {
orderSummaryClassName = classes.summaryContainerPreReview;
}

const orderSummary = shouldRenderPriceSummary ? (
<div className={classes.summary_container}>
<OrderSummary isUpdating={isUpdating} />
</div>
) : null;
const guestCheckoutHeaderText = isGuestCheckout
? 'Guest Checkout'
: 'Review and Place Order';

content = (
<Fragment>
{loginButton}
<div className={classes.heading_container}>
<h1 className={classes.heading}>
{isGuestCheckout
? 'Guest Checkout'
: 'Review and Place Order'}
{guestCheckoutHeaderText}
</h1>
</div>
<div className={classes.shipping_information_container}>
Expand All @@ -148,7 +141,9 @@ const CheckoutPage = props => {
{paymentInformationSection}
</div>
{itemsReview}
{orderSummary}
<div className={orderSummaryClassName}>
<OrderSummary isUpdating={isUpdating} />
</div>
{placeOrderButton}
</Fragment>
);
Expand Down