@shopgate/engage
Version:
Shopgate's ENGAGE library.
58 lines (55 loc) • 1.62 kB
JavaScript
import React, { useCallback, useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import { FulfillmentSheet } from "../FulfillmentSheet";
import connect from "./CartChangeFulfillmentMethod.connector";
import { STAGE_FULFILLMENT_METHOD } from "../../constants";
/**
* @typedef {import('./CartChangeFulfillmentMethod.types').OwnProps} OwnProps
* @typedef {import('./CartChangeFulfillmentMethod.types').DispatchProps} DispatchProps
* @typedef {OwnProps & DispatchProps} Props
*/
/**
* Renders the CartChangeFulfillmentMethod component.
* @param {Props} props The component props.
* @returns {JSX.Element|null}
*/
import { jsx as _jsx } from "react/jsx-runtime";
const CartChangeFulfillmentMethod = ({
cartItem,
fetchProductLocations,
registerAction
}) => {
const [opened, setOpened] = useState(false);
useEffect(() => {
if (!registerAction || !cartItem) {
return;
}
registerAction('changeFulfillment', () => {
fetchProductLocations(cartItem.product.id);
setOpened(true);
});
}, [cartItem, fetchProductLocations, registerAction]);
/**
* Handles closing of the sheet.
*/
const handleClose = useCallback(() => {
setOpened(false);
}, []);
if (!opened) {
return null;
}
return /*#__PURE__*/_jsx(FulfillmentSheet, {
open: true,
productId: cartItem.product.id,
stage: STAGE_FULFILLMENT_METHOD,
meta: {
cartItem
},
onClose: handleClose,
updatePreferredLocation: true
});
};
CartChangeFulfillmentMethod.defaultProps = {
registerAction: null
};
export default connect(CartChangeFulfillmentMethod);