// @ts-nocheck /** * External dependencies */ import PropTypes from 'prop-types'; import { __ } from '@wordpress/i18n'; import { SubtotalsItem, TotalsFeesItem, TotalsCouponCodeInput, TotalsDiscountItem, TotalsFooterItem, TotalsShippingItem, TotalsTaxesItem, } from '@woocommerce/base-components/cart-checkout'; import { COUPONS_ENABLED, DISPLAY_CART_PRICES_INCLUDING_TAX, } from '@woocommerce/block-settings'; import { getCurrencyFromPriceResponse } from '@woocommerce/base-utils'; import { CartExpressPayment } from '@woocommerce/base-components/payment-methods'; import { useStoreCartCoupons, useStoreCart, useStoreNotices, } from '@woocommerce/base-hooks'; import classnames from 'classnames'; import { Sidebar, SidebarLayout, Main, } from '@woocommerce/base-components/sidebar-layout'; import Title from '@woocommerce/base-components/title'; import { getSetting } from '@woocommerce/settings'; import { useEffect } from '@wordpress/element'; import { decodeEntities } from '@wordpress/html-entities'; /** * Internal dependencies */ import CheckoutButton from '../checkout-button'; import CartLineItemsTitle from './cart-line-items-title'; import CartLineItemsTable from './cart-line-items-table'; import './style.scss'; /** * Component that renders the Cart block when user has something in cart aka "full". * * @param {Object} props Incoming props for the component. * @param {Object} props.attributes Incoming attributes for block. */ const Cart = ( { attributes } ) => { const { isShippingCalculatorEnabled, isShippingCostHidden, hasDarkControls, } = attributes; const { cartItems, cartTotals, cartIsLoading, cartItemsCount, cartItemErrors, cartNeedsPayment, cartNeedsShipping, } = useStoreCart(); const { applyCoupon, removeCoupon, isApplyingCoupon, isRemovingCoupon, appliedCoupons, } = useStoreCartCoupons(); const { addErrorNotice } = useStoreNotices(); // Ensures any cart errors listed in the API response get shown. useEffect( () => { cartItemErrors.forEach( ( error ) => { addErrorNotice( decodeEntities( error.message ), { isDismissible: true, id: error.code, } ); } ); }, [ addErrorNotice, cartItemErrors ] ); const totalsCurrency = getCurrencyFromPriceResponse( cartTotals ); const cartClassName = classnames( 'wc-block-cart', { 'wc-block-cart--is-loading': cartIsLoading, 'has-dark-controls': hasDarkControls, } ); return (
{ __( 'Cart totals', 'woo-gutenberg-products-block' ) } { cartNeedsShipping && ( ) } { ! DISPLAY_CART_PRICES_INCLUDING_TAX && ( ) } { COUPONS_ENABLED && ( ) }
{ cartNeedsPayment && }
); }; Cart.propTypes = { attributes: PropTypes.object.isRequired, }; export default Cart;