@shopgate/engage
Version:
Shopgate's ENGAGE library.
83 lines (82 loc) • 3.03 kB
JavaScript
import React, { useMemo } from 'react';
import classNames from 'classnames';
import { QuantityLabel, I18n, Price } from '@shopgate/engage/components';
import { getTranslatedLineItemStatus } from '@shopgate/engage/orders';
import { CartItemProductPriceCaption } from "./CartItemProductPriceCaption";
import { createCartItemPrices } from "../../cart.helpers";
import { useCartItem, useCartItemProduct } from "./CartItem.hooks";
import { quantityLabel, label, container, labelValue, fulfillmentLabel } from "./CartItemProductOrderDetails.style";
/**
* @returns {JSX.Element}
*/
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
const CartItemProductOrderDetails = () => {
const {
location,
cartItem,
cartIsDirectShipOnly
} = useCartItem();
const {
product,
currency
} = useCartItemProduct();
const hasUnitWithDecimals = product.unit && product.hasCatchWeight || false;
const unitPrice = useMemo(() => {
const result = createCartItemPrices(cartItem).price;
return result.slice(-1)[0].price;
}, [cartItem]);
return /*#__PURE__*/_jsxs("ul", {
className: container,
children: [!cartIsDirectShipOnly && location?.name ? /*#__PURE__*/_jsxs("li", {
children: [/*#__PURE__*/_jsx(I18n.Text, {
string: "cart.location",
className: label
}), /*#__PURE__*/_jsx("span", {
className: labelValue,
children: location?.name
}), /*#__PURE__*/_jsx(CartItemProductPriceCaption, {
className: fulfillmentLabel
})]
}) : null, /*#__PURE__*/_jsxs("li", {
children: [/*#__PURE__*/_jsx(I18n.Text, {
string: "cart.status",
className: label
}), /*#__PURE__*/_jsx("span", {
className: labelValue,
children: getTranslatedLineItemStatus(cartItem?.status, cartItem?.subStatus)
})]
}), /*#__PURE__*/_jsxs("li", {
children: [/*#__PURE__*/_jsx(I18n.Text, {
string: "cart.fulfilled_quantity",
className: label
}), /*#__PURE__*/_jsx(QuantityLabel, {
className: classNames(quantityLabel, labelValue),
value: cartItem.quantity,
unit: hasUnitWithDecimals ? product.unit : null,
maxDecimals: hasUnitWithDecimals ? 2 : 0
})]
}), /*#__PURE__*/_jsxs("li", {
children: [/*#__PURE__*/_jsx(I18n.Text, {
string: "cart.ordered_quantity",
className: label
}), /*#__PURE__*/_jsx(QuantityLabel, {
className: classNames(quantityLabel, labelValue),
value: cartItem.orderedQuantity,
unit: hasUnitWithDecimals ? product.unit : null,
maxDecimals: hasUnitWithDecimals ? 2 : 0
})]
}), /*#__PURE__*/_jsxs("li", {
children: [/*#__PURE__*/_jsx(I18n.Text, {
string: "cart.price",
className: label
}), /*#__PURE__*/_jsx(Price, {
className: labelValue,
currency: currency,
taxDisclaimer: true,
unitPrice: unitPrice,
allowFree: true
})]
})]
});
};
export default CartItemProductOrderDetails;