@adv-ui/common-exma-consents-ui-consent
Advanced tools
Comparing version 1.10.0 to 1.11.0
# CHANGELOG | ||
# 1.11.0 (2022-10-19) | ||
### Features | ||
* **components/ui/consent:** fix track when renders modal ([86f206f](https://github.mpi-internal.com/scmspain/frontend-common--uilib-exma-consents/commit/86f206fb4a4aa5f613589407c58422875a975dd6)) | ||
# 1.10.0 (2022-10-18) | ||
@@ -4,0 +13,0 @@ |
@@ -1,1 +0,1 @@ | ||
import _async_to_generator from"@swc/helpers/lib/_async_to_generator.js";import _extends from"@swc/helpers/lib/_extends.js";import regeneratorRuntime from"regenerator-runtime";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{Fragment,useEffect,useState}from"react";import PropTypes from"prop-types";import MoleculeAccordion,{moleculeAccordionBehavior as ACCORDION_BEHAVIOR}from"@s-ui/react-molecule-accordion";import MoleculeModal,{MODAL_SIZES,MoleculeModalWithoutAnimation}from"@s-ui/react-molecule-modal";import analytics from"@s-ui/segment-wrapper";import useConsent from"../../context/useConsent.js";import ConsentFooter from"../Footer/index.js";import ConsentPreference from"../Preference/index.js";import{CONSENTS,CUSTOM_CONSENTS,EVENTS,INITIAL_CONSENTS,LITERALS}from"../setting.js";var BASE_CLASS="common-exma-UiConsent";var noop=function(){};export default function ConsentModal(param1){var logo=param1.logo,_onClose=param1.onClose,onClose=_onClose===void 0?noop:_onClose,_onSave=param1.onSave,onSave=_onSave===void 0?noop:_onSave,privacyPolicyUrl=param1.privacyPolicyUrl;var domain=useConsent().domain;var ref=useState([]),consentShown=ref[0],setConsentShown=ref[1];var ref1=useState(INITIAL_CONSENTS),consentsState=ref1[0],setConsentsState=ref1[1];var ref2=useState(true),showCustomConsents=ref2[0],setShowCustomConsents=ref2[1];var ref3=useState(false),showModal=ref3[0],setShowModal=ref3[1];var ref4=useState([]),consentPreferences=ref4[0],setConsentPreferences=ref4[1];var ref5=useState({}),latestConsentVersion=ref5[0],setLatestConsentVersion=ref5[1];useEffect(function(){var asyncEffect=_async_to_generator(regeneratorRuntime.mark(function _callee(){var userConsent,latestConsentVersionResponse,mustShowModal;return regeneratorRuntime.wrap(function _callee$(_ctx){while(1)switch(_ctx.prev=_ctx.next){case 0:_ctx.next=2;return domain.getUserConsent();case 2:userConsent=_ctx.sent;_ctx.next=5;return domain.getConsentVersion();case 5:latestConsentVersionResponse=_ctx.sent;setLatestConsentVersion(latestConsentVersionResponse);setConsentPreferences(latestConsentVersionResponse.preferences);mustShowModal=!userConsent||latestConsentVersionResponse.version!==userConsent.version;if(mustShowModal){setShowModal(mustShowModal)}else{onClose()}case 10:case"end":return _ctx.stop()}},_callee)}));asyncEffect()},[domain,onClose]);useEffect(function(){if(showModal){analytics.track(EVENTS.CONSENTS_RENDERS.name,_extends({},EVENTS.CONSENTS_RENDERS.properties))}},[]);var getConsentsAcceptedString=function(){var consentsAccepted="consent1:"+consentsState.Own+",consent2:"+consentsState.ThirdParty;return consentsAccepted};var saveUserConsent=_async_to_generator(regeneratorRuntime.mark(function _callee(){return regeneratorRuntime.wrap(function _callee$(_ctx){while(1)switch(_ctx.prev=_ctx.next){case 0:_ctx.next=2;return domain.saveUserConsent({version:latestConsentVersion.version,preferences:consentsState});case 2:case"end":return _ctx.stop()}},_callee)}));var handleConsentsToggle=function(name,value){var _obj;setConsentsState(_extends({},consentsState,(_obj={},_obj[name]=value,_obj)))};var handleSubmit=function(consentsAccepted){onSave();saveUserConsent();setShowModal(false);onClose()};var handleAcceptPartialConsents=function(consentsAccepted){analytics.track(EVENTS.CONSENTS_PARTIAL_ACCEPTED.name,_extends({},EVENTS.CONSENTS_ACCEPTED.properties,{hit_information:getConsentsAcceptedString()}));handleSubmit(consentsAccepted)};var handleAcceptAllClick=function(){handleSubmit(INITIAL_CONSENTS);analytics.track(EVENTS.CONSENTS_ACCEPTED.name,_extends({},EVENTS.CONSENTS_ACCEPTED.properties))};var handleCustomConsentsClick=function(){setConsentsState(CUSTOM_CONSENTS);setConsentShown([].concat(CONSENTS));setShowCustomConsents(false)};return _jsxs(MoleculeModalWithoutAnimation,{size:MODAL_SIZES.MEDIUM,isOpen:showModal,closeOnOutsideClick:false,closeOnEscKeyDown:false,fitContent:true,isContentless:true,header:_jsx("div",{className:""+BASE_CLASS+"-header",children:_jsx("img",{src:logo,alt:"Logo",className:"common-exma-UiConsent-logo"})}),children:[_jsx(MoleculeModal.Content,{children:_jsxs("div",{className:""+BASE_CLASS+"-content",children:[_jsx("h1",{className:""+BASE_CLASS+"-title",children:LITERALS.BODY.TITLE}),_jsx("p",{className:""+BASE_CLASS+"-text",children:LITERALS.BODY.BEFORE_SPECIFICATIONS}),_jsx(MoleculeAccordion,{as:Fragment,className:""+BASE_CLASS+"-groups",behavior:ACCORDION_BEHAVIOR.MULTIPLE,autoHeight:true,values:consentShown,onChange:function(_,param){var values=param.values;setConsentShown([].concat(values));setConsentsState(CUSTOM_CONSENTS);setShowCustomConsents(false)},children:consentPreferences.map(function(preference){return _jsx(ConsentPreference,_extends({},preference,{name:preference.key,onClickToggle:handleConsentsToggle}))})}),_jsx("p",{className:""+BASE_CLASS+"-text",children:LITERALS.BODY.AFTER_SPECIFICATIONS}),_jsxs("a",{className:"sui-AtomButton sui-AtomButton--primary sui-AtomButton--link common-exma-UiConsent-link",href:privacyPolicyUrl,target:"_blank",children:[LITERALS.BODY.PRIVACY_POLICY,"."]})]})}),_jsx(MoleculeModal.Footer,{children:_jsx(ConsentFooter,{onSubmit:handleAcceptPartialConsents,onClickAccept:handleAcceptAllClick,onClickCustomConsents:handleCustomConsentsClick,showCustomConsentsButton:showCustomConsents})})]})};ConsentModal.displayName="ConsentModal";ConsentModal.propTypes={logo:PropTypes.string.isRequired,onClose:PropTypes.func,onSave:PropTypes.func,privacyPolicyUrl:PropTypes.string.isRequired} | ||
import _async_to_generator from"@swc/helpers/lib/_async_to_generator.js";import _extends from"@swc/helpers/lib/_extends.js";import regeneratorRuntime from"regenerator-runtime";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{Fragment,useEffect,useState}from"react";import PropTypes from"prop-types";import MoleculeAccordion,{moleculeAccordionBehavior as ACCORDION_BEHAVIOR}from"@s-ui/react-molecule-accordion";import MoleculeModal,{MODAL_SIZES,MoleculeModalWithoutAnimation}from"@s-ui/react-molecule-modal";import analytics from"@s-ui/segment-wrapper";import useConsent from"../../context/useConsent.js";import ConsentFooter from"../Footer/index.js";import ConsentPreference from"../Preference/index.js";import{CONSENTS,CUSTOM_CONSENTS,EVENTS,INITIAL_CONSENTS,LITERALS}from"../setting.js";var BASE_CLASS="common-exma-UiConsent";var noop=function(){};export default function ConsentModal(param1){var logo=param1.logo,_onClose=param1.onClose,onClose=_onClose===void 0?noop:_onClose,_onSave=param1.onSave,onSave=_onSave===void 0?noop:_onSave,privacyPolicyUrl=param1.privacyPolicyUrl;var domain=useConsent().domain;var ref=useState([]),consentShown=ref[0],setConsentShown=ref[1];var ref1=useState(INITIAL_CONSENTS),consentsState=ref1[0],setConsentsState=ref1[1];var ref2=useState(true),showCustomConsents=ref2[0],setShowCustomConsents=ref2[1];var ref3=useState(false),showModal=ref3[0],setShowModal=ref3[1];var ref4=useState([]),consentPreferences=ref4[0],setConsentPreferences=ref4[1];var ref5=useState({}),latestConsentVersion=ref5[0],setLatestConsentVersion=ref5[1];useEffect(function(){var asyncEffect=_async_to_generator(regeneratorRuntime.mark(function _callee(){var userConsent,latestConsentVersionResponse,mustShowModal;return regeneratorRuntime.wrap(function _callee$(_ctx){while(1)switch(_ctx.prev=_ctx.next){case 0:_ctx.next=2;return domain.getUserConsent();case 2:userConsent=_ctx.sent;_ctx.next=5;return domain.getConsentVersion();case 5:latestConsentVersionResponse=_ctx.sent;setLatestConsentVersion(latestConsentVersionResponse);setConsentPreferences(latestConsentVersionResponse.preferences);mustShowModal=!userConsent||latestConsentVersionResponse.version!==userConsent.version;if(mustShowModal){setShowModal(mustShowModal)}else{onClose()}case 10:case"end":return _ctx.stop()}},_callee)}));asyncEffect()},[domain,onClose]);useEffect(function(){if(showModal){analytics.track(EVENTS.CONSENTS_RENDERS.name,_extends({},EVENTS.CONSENTS_RENDERS.properties))}},[showModal]);var getConsentsAcceptedString=function(){var consentsAccepted="consent1:"+consentsState.Own+",consent2:"+consentsState.ThirdParty;return consentsAccepted};var saveUserConsent=_async_to_generator(regeneratorRuntime.mark(function _callee(){return regeneratorRuntime.wrap(function _callee$(_ctx){while(1)switch(_ctx.prev=_ctx.next){case 0:_ctx.next=2;return domain.saveUserConsent({version:latestConsentVersion.version,preferences:consentsState});case 2:case"end":return _ctx.stop()}},_callee)}));var handleConsentsToggle=function(name,value){var _obj;setConsentsState(_extends({},consentsState,(_obj={},_obj[name]=value,_obj)))};var handleSubmit=function(consentsAccepted){onSave();saveUserConsent();setShowModal(false);onClose()};var handleAcceptPartialConsents=function(consentsAccepted){analytics.track(EVENTS.CONSENTS_PARTIAL_ACCEPTED.name,_extends({},EVENTS.CONSENTS_ACCEPTED.properties,{hit_information:getConsentsAcceptedString()}));handleSubmit(consentsAccepted)};var handleAcceptAllClick=function(){handleSubmit(INITIAL_CONSENTS);analytics.track(EVENTS.CONSENTS_ACCEPTED.name,_extends({},EVENTS.CONSENTS_ACCEPTED.properties))};var handleCustomConsentsClick=function(){setConsentsState(CUSTOM_CONSENTS);setConsentShown([].concat(CONSENTS));setShowCustomConsents(false)};return _jsxs(MoleculeModalWithoutAnimation,{size:MODAL_SIZES.MEDIUM,isOpen:showModal,closeOnOutsideClick:false,closeOnEscKeyDown:false,fitContent:true,isContentless:true,header:_jsx("div",{className:""+BASE_CLASS+"-header",children:_jsx("img",{src:logo,alt:"Logo",className:"common-exma-UiConsent-logo"})}),children:[_jsx(MoleculeModal.Content,{children:_jsxs("div",{className:""+BASE_CLASS+"-content",children:[_jsx("h1",{className:""+BASE_CLASS+"-title",children:LITERALS.BODY.TITLE}),_jsx("p",{className:""+BASE_CLASS+"-text",children:LITERALS.BODY.BEFORE_SPECIFICATIONS}),_jsx(MoleculeAccordion,{as:Fragment,className:""+BASE_CLASS+"-groups",behavior:ACCORDION_BEHAVIOR.MULTIPLE,autoHeight:true,values:consentShown,onChange:function(_,param){var values=param.values;setConsentShown([].concat(values));setConsentsState(CUSTOM_CONSENTS);setShowCustomConsents(false)},children:consentPreferences.map(function(preference){return _jsx(ConsentPreference,_extends({},preference,{name:preference.key,onClickToggle:handleConsentsToggle}))})}),_jsx("p",{className:""+BASE_CLASS+"-text",children:LITERALS.BODY.AFTER_SPECIFICATIONS}),_jsxs("a",{className:"sui-AtomButton sui-AtomButton--primary sui-AtomButton--link common-exma-UiConsent-link",href:privacyPolicyUrl,target:"_blank",children:[LITERALS.BODY.PRIVACY_POLICY,"."]})]})}),_jsx(MoleculeModal.Footer,{children:_jsx(ConsentFooter,{onSubmit:handleAcceptPartialConsents,onClickAccept:handleAcceptAllClick,onClickCustomConsents:handleCustomConsentsClick,showCustomConsentsButton:showCustomConsents})})]})};ConsentModal.displayName="ConsentModal";ConsentModal.propTypes={logo:PropTypes.string.isRequired,onClose:PropTypes.func,onSave:PropTypes.func,privacyPolicyUrl:PropTypes.string.isRequired} |
{ | ||
"name": "@adv-ui/common-exma-consents-ui-consent", | ||
"version": "1.10.0", | ||
"version": "1.11.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25626