2020-03-12 09:41:35 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import {
|
2020-06-05 15:03:48 +00:00
|
|
|
OrderSummary,
|
2020-12-09 07:29:34 +00:00
|
|
|
TotalsCoupon,
|
|
|
|
TotalsDiscount,
|
2020-03-12 09:41:35 +00:00
|
|
|
TotalsFooterItem,
|
2021-02-03 11:35:17 +00:00
|
|
|
TotalsShipping,
|
2020-03-30 13:04:27 +00:00
|
|
|
} from '@woocommerce/base-components/cart-checkout';
|
2021-01-20 20:35:53 +00:00
|
|
|
import {
|
|
|
|
Subtotal,
|
|
|
|
TotalsFees,
|
|
|
|
TotalsTaxes,
|
|
|
|
ExperimentalOrderMeta,
|
|
|
|
} from '@woocommerce/blocks-checkout';
|
2021-02-04 15:30:28 +00:00
|
|
|
import { getCurrencyFromPriceResponse } from '@woocommerce/price-format';
|
2020-04-02 17:10:36 +00:00
|
|
|
import { useShippingDataContext } from '@woocommerce/base-context';
|
2020-03-12 09:41:35 +00:00
|
|
|
import {
|
|
|
|
COUPONS_ENABLED,
|
|
|
|
DISPLAY_CART_PRICES_INCLUDING_TAX,
|
|
|
|
} from '@woocommerce/block-settings';
|
2021-04-08 12:31:12 +00:00
|
|
|
import {
|
|
|
|
useStoreCartCoupons,
|
|
|
|
useStoreCart,
|
|
|
|
} from '@woocommerce/base-context/hooks';
|
2020-03-12 09:41:35 +00:00
|
|
|
|
|
|
|
const CheckoutSidebar = ( {
|
|
|
|
cartCoupons = [],
|
2020-03-13 15:49:33 +00:00
|
|
|
cartItems = [],
|
2021-01-13 16:57:42 +00:00
|
|
|
cartFees = [],
|
2020-03-12 09:41:35 +00:00
|
|
|
cartTotals = {},
|
|
|
|
} ) => {
|
|
|
|
const {
|
|
|
|
applyCoupon,
|
|
|
|
removeCoupon,
|
|
|
|
isApplyingCoupon,
|
|
|
|
isRemovingCoupon,
|
|
|
|
} = useStoreCartCoupons();
|
2020-04-02 17:10:36 +00:00
|
|
|
|
|
|
|
const { needsShipping } = useShippingDataContext();
|
2020-03-12 09:41:35 +00:00
|
|
|
const totalsCurrency = getCurrencyFromPriceResponse( cartTotals );
|
|
|
|
|
2021-04-08 12:31:12 +00:00
|
|
|
// Prepare props to pass to the ExperimentalOrderMeta slot fill.
|
|
|
|
// We need to pluck out receiveCart.
|
|
|
|
// eslint-disable-next-line no-unused-vars
|
|
|
|
const { extensions, receiveCart, ...cart } = useStoreCart();
|
|
|
|
const slotFillProps = {
|
|
|
|
extensions,
|
|
|
|
cart,
|
|
|
|
};
|
|
|
|
|
2020-03-12 09:41:35 +00:00
|
|
|
return (
|
|
|
|
<>
|
2020-03-13 15:49:33 +00:00
|
|
|
<OrderSummary cartItems={ cartItems } />
|
2020-12-09 07:29:34 +00:00
|
|
|
<Subtotal currency={ totalsCurrency } values={ cartTotals } />
|
2021-01-13 16:57:42 +00:00
|
|
|
<TotalsFees currency={ totalsCurrency } cartFees={ cartFees } />
|
2020-12-09 07:29:34 +00:00
|
|
|
<TotalsDiscount
|
2020-03-12 09:41:35 +00:00
|
|
|
cartCoupons={ cartCoupons }
|
|
|
|
currency={ totalsCurrency }
|
|
|
|
isRemovingCoupon={ isRemovingCoupon }
|
|
|
|
removeCoupon={ removeCoupon }
|
|
|
|
values={ cartTotals }
|
|
|
|
/>
|
2020-04-02 17:10:36 +00:00
|
|
|
{ needsShipping && (
|
2020-12-09 07:29:34 +00:00
|
|
|
<TotalsShipping
|
2020-04-02 17:10:36 +00:00
|
|
|
showCalculator={ false }
|
2020-11-17 11:58:38 +00:00
|
|
|
showRateSelector={ false }
|
2020-04-02 17:10:36 +00:00
|
|
|
values={ cartTotals }
|
2020-11-17 11:58:38 +00:00
|
|
|
currency={ totalsCurrency }
|
2020-04-02 17:10:36 +00:00
|
|
|
/>
|
|
|
|
) }
|
2020-03-12 09:41:35 +00:00
|
|
|
{ ! DISPLAY_CART_PRICES_INCLUDING_TAX && (
|
2020-12-09 07:29:34 +00:00
|
|
|
<TotalsTaxes
|
2020-03-12 09:41:35 +00:00
|
|
|
currency={ totalsCurrency }
|
|
|
|
values={ cartTotals }
|
|
|
|
/>
|
|
|
|
) }
|
|
|
|
{ COUPONS_ENABLED && (
|
2020-12-09 07:29:34 +00:00
|
|
|
<TotalsCoupon
|
2020-03-12 09:41:35 +00:00
|
|
|
onSubmit={ applyCoupon }
|
|
|
|
initialOpen={ false }
|
|
|
|
isLoading={ isApplyingCoupon }
|
|
|
|
/>
|
|
|
|
) }
|
|
|
|
<TotalsFooterItem
|
|
|
|
currency={ totalsCurrency }
|
|
|
|
values={ cartTotals }
|
|
|
|
/>
|
2021-04-08 12:31:12 +00:00
|
|
|
<ExperimentalOrderMeta.Slot { ...slotFillProps } />
|
2020-03-12 09:41:35 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default CheckoutSidebar;
|