UNPKG

@shopgate/engage

Version:
5 lines 2.9 kB
function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}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 React,{useState,useCallback,useMemo}from'react';import PropTypes from'prop-types';import{hasNewServices}from'@shopgate/engage/core/helpers';import{Dialog,TextField}from'@shopgate/engage/components';import{i18n}from'@shopgate/engage/core';import{themeName}from'@shopgate/pwa-common/helpers/config';import{css}from'glamor';var isIos=themeName.includes('ios');var styles={root:css({display:'flex',flexDirection:'column'}),input:css({textAlign:'left',fontSize:'1rem'}).toString()};/** * @param {Object} props Props * @returns {Object} */var ListsModal=function ListsModal(_ref){var type=_ref.type,onConfirm=_ref.onConfirm,onDismiss=_ref.onDismiss;var _useState=useState(''),_useState2=_slicedToArray(_useState,2),input=_useState2[0],setInput=_useState2[1];var _useState3=useState(null),_useState4=_slicedToArray(_useState3,2),error=_useState4[0],setError=_useState4[1];var onConfirmWrapped=useCallback(function(){if(input.length===0){setError(i18n.text('favorites.errors.invalid_name'));return;}onConfirm(input);},[input,onConfirm]);var onChange=useCallback(function(value){setInput(value);},[]);// Favorites list name was restricted to 25 characters on PWA6 in CCP-2535 var textFieldMaxLength=useMemo(function(){return!hasNewServices()?'25':undefined;},[]);return React.createElement(Dialog,{onConfirm:onConfirmWrapped,onDismiss:onDismiss,modal:{title:i18n.text("favorites.".concat(type,"_modal.title")),dismiss:i18n.text("favorites.".concat(type,"_modal.dismiss")),confirm:i18n.text("favorites.".concat(type,"_modal.confirm"))}},React.createElement("div",{className:styles.root},React.createElement("span",null,i18n.text("favorites.".concat(type,"_modal.message"))),React.createElement(TextField,_extends({name:"name"},isIos?{placeholder:i18n.text("favorites.".concat(type,"_modal.label"))}:{label:i18n.text("favorites.".concat(type,"_modal.label"))},{maxLength:textFieldMaxLength,onChange:onChange,value:input,errorText:error||undefined,className:styles.input}))));};export default ListsModal;