2020-03-12 09:41:35 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import {
|
2020-06-05 15:03:48 +00:00
|
|
|
OrderSummary,
|
2020-03-12 09:41:35 +00:00
|
|
|
SubtotalsItem,
|
|
|
|
TotalsFeesItem,
|
|
|
|
TotalsCouponCodeInput,
|
|
|
|
TotalsDiscountItem,
|
|
|
|
TotalsFooterItem,
|
|
|
|
TotalsShippingItem,
|
|
|
|
TotalsTaxesItem,
|
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-03-12 09:41:35 +00:00
|
|
|
<SubtotalsItem currency={ totalsCurrency } values={ cartTotals } />
|
|
|
|
<TotalsFeesItem currency={ totalsCurrency } values={ cartTotals } />
|
|
|
|
<TotalsDiscountItem
|
|
|
|
cartCoupons={ cartCoupons }
|
|
|
|
currency={ totalsCurrency }
|
|
|
|
isRemovingCoupon={ isRemovingCoupon }
|
|
|
|
removeCoupon={ removeCoupon }
|
|
|
|
values={ cartTotals }
|
|
|
|
/>
|
2020-04-02 17:10:36 +00:00
|
|
|
{ needsShipping && (
|
|
|
|
<TotalsShippingItem
|
|
|
|
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 && (
|
|
|
|
<TotalsTaxesItem
|
|
|
|
currency={ totalsCurrency }
|
|
|
|
values={ cartTotals }
|
|
|
|
/>
|
|
|
|
) }
|
|
|
|
{ COUPONS_ENABLED && (
|
|
|
|
<TotalsCouponCodeInput
|
|
|
|
onSubmit={ applyCoupon }
|
|
|
|
initialOpen={ false }
|
|
|
|
isLoading={ isApplyingCoupon }
|
|
|
|
/>
|
|
|
|
) }
|
|
|
|
<TotalsFooterItem
|
|
|
|
currency={ totalsCurrency }
|
|
|
|
values={ cartTotals }
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default CheckoutSidebar;
|