@shopgate/engage
Version:
Shopgate's ENGAGE library.
8 lines • 1.82 kB
JavaScript
function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance");}function _iterableToArrayLimit(arr,i){var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[Symbol.iterator](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"]!=null)_i["return"]();}finally{if(_d)throw _e;}}return _arr;}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr;}import*as React from'react';import{FulfillmentSheet}from"../FulfillmentSheet";import connect from"./CartChangeFulfillmentMethod.connector";import{STAGE_FULFILLMENT_METHOD}from"../../constants";/**
* @param {Object} props The component props.
* @returns {JSX.Element}
*/function CartChangeFulfillmentMethod(props){var cartItem=props.cartItem,fetchProductLocations=props.fetchProductLocations,registerAction=props.registerAction;var _React$useState=React.useState(false),_React$useState2=_slicedToArray(_React$useState,2),opened=_React$useState2[0],setOpened=_React$useState2[1];/**
* Register cart item action
*/React.useEffect(function(){if(!registerAction||!cartItem){return;}registerAction('changeFulfillment',function(){fetchProductLocations(cartItem.product.id);setOpened(true);});},[cartItem,fetchProductLocations,registerAction]);/**
* Handles closing of the sheet.
*/function handleClose(){setOpened(false);}if(!opened){return null;}return React.createElement(FulfillmentSheet,{open:true,productId:cartItem.product.id,stage:STAGE_FULFILLMENT_METHOD,meta:{cartItem:cartItem},onClose:handleClose,updatePreferredLocation:true});}export default connect(CartChangeFulfillmentMethod);