@shopgate/engage
Version:
Shopgate's ENGAGE library.
55 lines (54 loc) • 1.92 kB
JavaScript
import * as React from 'react';
import classNames from 'classnames';
import { Grid } from '@shopgate/engage/components';
import { i18n } from "../../../core";
import { Availability } from "../../../product";
import { DIRECT_SHIP_LABEL, DIRECT_SHIP } from "../../constants";
import { itemRow, itemColumn, itemRowDisabled } from "./FulfillmentSelectorItem.style";
import { useFulfillmentSelectorState } from "./FulfillmentSelector.hooks";
import { FulfillmentSelectorImpossibleError } from "./FulfillmentSelectorImpossibleError";
/**
* Renders the direct ship item label.
* @returns {JSX.Element}
*/
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
export const FulfillmentSelectorDirectShip = () => {
const {
productId,
selection,
isOrderable,
isDirectShipEnabled,
isReady
} = useFulfillmentSelectorState();
const rowClasses = React.useMemo(() => classNames(itemRow, {
[itemRowDisabled.toString()]: !isReady || !isDirectShipEnabled
}), [isDirectShipEnabled, isReady]);
const selected = selection === DIRECT_SHIP;
if (selected && !isOrderable) {
return /*#__PURE__*/_jsxs(_Fragment, {
children: [/*#__PURE__*/_jsx("div", {
children: i18n.text(DIRECT_SHIP_LABEL)
}), /*#__PURE__*/_jsx(FulfillmentSelectorImpossibleError, {})]
});
}
return /*#__PURE__*/_jsxs(Grid, {
className: rowClasses,
component: "div",
children: [/*#__PURE__*/_jsx(Grid.Item, {
className: itemColumn,
grow: 1,
shrink: 0,
component: "div",
children: i18n.text(DIRECT_SHIP_LABEL)
}), /*#__PURE__*/_jsx(Grid.Item, {
className: itemColumn,
grow: 1,
shrink: 0,
component: "div",
children: isReady && isDirectShipEnabled && isOrderable && /*#__PURE__*/_jsx(Availability, {
productId: productId,
fulfillmentSelection: DIRECT_SHIP
})
})]
});
};