Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 8x 7x 8x 8x 8x 7x 1x 1x 2x | import { LineItemMap, ShopperCurrency as ShopperCurrencyType, StoreCurrency } from '@bigcommerce/checkout-sdk';
import classNames from 'classnames';
import React, { memo, useCallback, FunctionComponent, ReactNode } from 'react';
import { ShopperCurrency } from '../currency';
import { TranslatedString } from '../locale';
import { IconGiftCertificate } from '../ui/icon';
import { ModalTrigger } from '../ui/modal';
import getItemsCount from './getItemsCount';
import getLineItemsCount from './getLineItemsCount';
import OrderSummaryModal from './OrderSummaryModal';
import { OrderSummarySubtotalsProps } from './OrderSummarySubtotals';
export interface OrderSummaryDrawerProps {
lineItems: LineItemMap;
total: number;
headerLink: ReactNode;
storeCurrency: StoreCurrency;
shopperCurrency: ShopperCurrencyType;
additionalLineItems?: ReactNode;
}
const OrderSummaryDrawer: FunctionComponent<OrderSummaryDrawerProps & OrderSummarySubtotalsProps> = ({
additionalLineItems,
coupons,
discountAmount,
giftCertificates,
handlingAmount,
headerLink,
lineItems,
onRemovedCoupon,
onRemovedGiftCertificate,
shippingAmount,
shopperCurrency,
storeCreditAmount,
giftWrappingAmount,
storeCurrency,
subtotalAmount,
taxes,
total,
}) => {
const renderModal = useCallback(props => (
<OrderSummaryModal
{ ...props }
additionalLineItems={ additionalLineItems }
coupons={ coupons }
discountAmount={ discountAmount }
giftCertificates={ giftCertificates }
giftWrappingAmount={ giftWrappingAmount }
handlingAmount={ handlingAmount }
headerLink={ headerLink }
lineItems={ lineItems }
onRemovedCoupon={ onRemovedCoupon }
onRemovedGiftCertificate={ onRemovedGiftCertificate }
shippingAmount={ shippingAmount }
shopperCurrency={ shopperCurrency }
storeCreditAmount={ storeCreditAmount }
storeCurrency={ storeCurrency }
subtotalAmount={ subtotalAmount }
taxes={ taxes }
total={ total }
/>
), [
additionalLineItems,
coupons,
discountAmount,
giftCertificates,
handlingAmount,
headerLink,
lineItems,
onRemovedCoupon,
onRemovedGiftCertificate,
giftWrappingAmount,
shippingAmount,
shopperCurrency,
storeCreditAmount,
storeCurrency,
subtotalAmount,
taxes,
total,
]);
return <ModalTrigger modal={ renderModal }>
{ ({ onClick }) => <div
className="cartDrawer optimizedCheckout-orderSummary"
onClick={ onClick }
>
<figure
className={ classNames(
'cartDrawer-figure',
{ 'cartDrawer-figure--stack': getLineItemsCount(lineItems) > 1 }
) }
>
<div className="cartDrawer-imageWrapper">
{ getImage(lineItems) }
</div>
</figure>
<div className="cartDrawer-body">
<h3 className="cartDrawer-items optimizedCheckout-headingPrimary">
<TranslatedString
data={ { count: getItemsCount(lineItems) } }
id="cart.item_count_text"
/>
</h3>
<a>
<TranslatedString id="cart.show_details_action" />
</a>
</div>
<div className="cartDrawer-actions">
<h3 className="cartDrawer-total optimizedCheckout-headingPrimary">
<ShopperCurrency amount={ total } />
</h3>
</div>
</div> }
</ModalTrigger>;
};
function getImage(lineItems: LineItemMap): ReactNode {
const productWithImage = lineItems.physicalItems[0] || lineItems.digitalItems[0];
if (productWithImage && productWithImage.imageUrl) {
return <img
alt={ productWithImage.name }
data-test="cart-item-image"
src={ productWithImage.imageUrl }
/>;
}
Eif (lineItems.giftCertificates.length) {
return <IconGiftCertificate />;
}
}
export default memo(OrderSummaryDrawer);
|