@shopgate/engage
Version:
Shopgate's ENGAGE library.
27 lines • 4.08 kB
JavaScript
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);}import{SHOP_SETTING_REGISTRATION_MODE_EXTENDED,SHOP_SETTING_REGISTRATION_MODE_SIMPLE}from'@shopgate/engage/core';import{generateFormConstraints}from'@shopgate/engage/account/helper/form';/**
* Helper to generate base constraints
* @param {Object} params Options for the helper
* @param {string} params.registrationMode Current active registration mode
* @returns {Object}
*/export var generateBaseConstraints=function generateBaseConstraints(_ref){var _ref$registrationMode=_ref.registrationMode,registrationMode=_ref$registrationMode===void 0?SHOP_SETTING_REGISTRATION_MODE_EXTENDED:_ref$registrationMode;return _extends({},registrationMode===SHOP_SETTING_REGISTRATION_MODE_SIMPLE?{firstName:{presence:{message:'validation.required',allowEmpty:false}},lastName:{presence:{message:'validation.required',allowEmpty:false}}}:null,{emailAddress:{presence:{message:'validation.required',allowEmpty:false},email:{message:'validation.email'}},password:{presence:{message:'validation.required',allowEmpty:false}},passwordConfirm:{presence:{message:'validation.required',allowEmpty:false},equality:{attribute:'password',message:'validation.passwordMismatch',comparator:function comparator(v1,v2){return JSON.stringify(v1)===JSON.stringify(v2);}}}});};/**
* Helper to generate address constraints
* @param {Object} params Options for the helper
* @param {string} params.registrationMode Current active registration mode
* @returns {Object}
*/var generateAddressConstraints=function generateAddressConstraints(_ref2){var _ref2$registrationMod=_ref2.registrationMode,registrationMode=_ref2$registrationMod===void 0?SHOP_SETTING_REGISTRATION_MODE_EXTENDED:_ref2$registrationMod;return _extends({},registrationMode===SHOP_SETTING_REGISTRATION_MODE_EXTENDED?{firstName:{presence:{message:'validation.required',allowEmpty:false}},lastName:{presence:{message:'validation.required',allowEmpty:false}},address1:{presence:{message:'validation.required',allowEmpty:false}},city:{presence:{message:'validation.required',allowEmpty:false}},country:{presence:{message:'validation.required',allowEmpty:false}},postalCode:{presence:{message:'validation.required',allowEmpty:false}},mobile:{presence:{message:'validation.required',allowEmpty:false},format:{pattern:'^[+0-9]+',message:'validation.mobileNumber'}}}:null);};/**
* Helper to generate billing form constraints
* @param {Object} params Options for the helper
* @param {string} [params.registrationMode] Current active registration mode
* @returns {Object}
*/export var generateBillingConstraints=function generateBillingConstraints(_ref3){var _ref3$registrationMod=_ref3.registrationMode,registrationMode=_ref3$registrationMod===void 0?SHOP_SETTING_REGISTRATION_MODE_EXTENDED:_ref3$registrationMod;return generateAddressConstraints({registrationMode:registrationMode});};/**
* Helper to generate shipping form constraints
* @param {Object} params Options for the helper
* @param {string} [params.registrationMode] Current active registration mode
* @returns {Object}
*/export var generateShippingConstraints=function generateShippingConstraints(_ref4){var _ref4$registrationMod=_ref4.registrationMode,registrationMode=_ref4$registrationMod===void 0?SHOP_SETTING_REGISTRATION_MODE_EXTENDED:_ref4$registrationMod;return registrationMode===SHOP_SETTING_REGISTRATION_MODE_EXTENDED// Only at "extended" mode there will be constraints for the shipping form since "simple" has no
// shipping form.
?generateAddressConstraints({registrationMode:registrationMode}):{};};/**
* Generates constraints for the "extra" form.
* @param {Object} customerAttributes Customer attributes.
* @returns {Object}
*/export var generateExtraConstraints=function generateExtraConstraints(customerAttributes){return _extends({},generateFormConstraints(customerAttributes));};