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
|
|
|
Subtotal,
|
|
|
|
TotalsFees,
|
|
|
|
TotalsCoupon,
|
|
|
|
TotalsDiscount,
|
2020-03-12 09:41:35 +00:00
|
|
|
TotalsFooterItem,
|
2020-12-09 07:29:34 +00:00
|
|
|
TotalsShipping,
|
|
|
|
TotalsTaxes,
|
2020-03-30 13:04:27 +00:00
|
|
|
} from '@woocommerce/base-components/cart-checkout';
|
2020-04-02 17:10:36 +00:00
|
|
|
import { useShippingDataContext } from '@woocommerce/base-context';
|
2020-03-12 09:41:35 +00:00
|
|
|
import { getCurrencyFromPriceResponse } from '@woocommerce/base-utils';
|
|
|
|
import {
|
|
|
|
COUPONS_ENABLED,
|
|
|
|
DISPLAY_CART_PRICES_INCLUDING_TAX,
|
|
|
|
} from '@woocommerce/block-settings';
|
|
|
|
import { useStoreCartCoupons } from '@woocommerce/base-hooks';
|
|
|
|
|
|
|
|
const CheckoutSidebar = ( {
|
|
|
|
cartCoupons = [],
|
2020-03-13 15:49:33 +00:00
|
|
|
cartItems = [],
|
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 );
|
|
|
|
|
|
|
|
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 } />
|
|
|
|
<TotalsFees currency={ totalsCurrency } values={ cartTotals } />
|
|
|
|
<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 }
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default CheckoutSidebar;
|