@adv-ui/common-exma-consents-ui-consent
Advanced tools
Comparing version 1.6.0 to 1.7.0
# CHANGELOG | ||
# 1.7.0 (2022-10-13) | ||
### Features | ||
* **components/ui/consent:** add onClose prop for users that have consents ([8d0a392](https://github.mpi-internal.com/scmspain/frontend-common--uilib-exma-consents/commit/8d0a3926186f59e31f2f435f84f443ed65429eeb)) | ||
# 1.6.0 (2022-10-10) | ||
@@ -64,3 +73,2 @@ | ||
* **components/ui/consent:** add provider ([1f9c0ee](https://github.mpi-internal.com/scmspain/frontend-common--uilib-exma-consents/commit/1f9c0ee7fd565855580dcf40871a41bdce06f3ac)) | ||
* **components/ui/consent:** add themes ([158c6cc](https://github.mpi-internal.com/scmspain/frontend-common--uilib-exma-consents/commit/158c6ccb07c216b9ccc71e79218950fb76127e63)) | ||
* **components/ui/consent:** change accordion to controlled component ([a5310e3](https://github.mpi-internal.com/scmspain/frontend-common--uilib-exma-consents/commit/a5310e3f076e2e1c2e1414589cdfc0bcdd0ef7ce)) | ||
@@ -82,5 +90,5 @@ * **components/ui/consent:** change buttons behavior ([1762319](https://github.mpi-internal.com/scmspain/frontend-common--uilib-exma-consents/commit/17623196e24554332b0cf5f248efa782dd5740ad)) | ||
* **components/ui/consent:** simplify function. the repository now handles errors ([9e5345b](https://github.mpi-internal.com/scmspain/frontend-common--uilib-exma-consents/commit/9e5345b91be274d776511fb5ffacd84275258511)) | ||
* **Root:** delete Segment package ([6f3887f](https://github.mpi-internal.com/scmspain/frontend-common--uilib-exma-consents/commit/6f3887f99c4f59c44821ef926c352f7baca33c3d)) | ||
* **Root:** add themes ([027d5b3](https://github.mpi-internal.com/scmspain/frontend-common--uilib-exma-consents/commit/027d5b3c6c8654d2cc7fb990adc49129ae3a5a7a)) | ||
@@ -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 AtomImage from"@s-ui/react-atom-image";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";export default function ConsentModal(param1){var logo=param1.logo,privacyPolicyUrl=param1.privacyPolicyUrl,onSave=param1.onSave;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;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);setShowModal(!userConsent||latestConsentVersionResponse.version!==userConsent.version);case 9:case"end":return _ctx.stop()}},_callee)}));asyncEffect()},[domain]);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 handleCloseModal=function(){setShowModal(false)};var handleConsentsToggle=function(name,value){var _obj;setConsentsState(_extends({},consentsState,(_obj={},_obj[name]=value,_obj)))};var handleSubmit=function(consentsAccepted){console.log(">>> Consents state",consentsAccepted||consentsState);typeof onSave==="function"&&onSave();saveUserConsent();handleCloseModal()};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(AtomImage,{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,privacyPolicyUrl:PropTypes.string.isRequired,onSave:PropTypes.func} | ||
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 AtomImage from"@s-ui/react-atom-image";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]);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(AtomImage,{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} |
@@ -1,1 +0,1 @@ | ||
import{jsx as _jsx}from"react/jsx-runtime";import PropTypes from"prop-types";import ConsentModal from"./components/Modal/index.js";import ConsentProvider from"./context/ConsentProvider.js";export default function UiConsent(param){var userEmail=param.userEmail,userId=param.userId,site=param.site,environment=param.environment,logo=param.logo,privacyPolicyUrl=param.privacyPolicyUrl,onSave=param.onSave;return _jsx(ConsentProvider,{environment:environment,userEmail:userEmail,userId:userId,site:site,children:_jsx(ConsentModal,{onSave:onSave,logo:logo,privacyPolicyUrl:privacyPolicyUrl})})};UiConsent.displayName="UiConsent";UiConsent.propTypes={site:PropTypes.string.isRequired,userEmail:PropTypes.string.isRequired,userId:PropTypes.string.isRequired,environment:PropTypes.string.isRequired,logo:PropTypes.string.isRequired,privacyPolicyUrl:PropTypes.string.isRequired,onSave:PropTypes.func} | ||
import{jsx as _jsx}from"react/jsx-runtime";import PropTypes from"prop-types";import ConsentModal from"./components/Modal/index.js";import ConsentProvider from"./context/ConsentProvider.js";export default function UiConsent(param){var environment=param.environment,logo=param.logo,onClose=param.onClose,onSave=param.onSave,privacyPolicyUrl=param.privacyPolicyUrl,site=param.site,userEmail=param.userEmail,userId=param.userId;return _jsx(ConsentProvider,{environment:environment,userEmail:userEmail,userId:userId,site:site,children:_jsx(ConsentModal,{logo:logo,onClose:onClose,onSave:onSave,privacyPolicyUrl:privacyPolicyUrl})})};UiConsent.displayName="UiConsent";UiConsent.propTypes={environment:PropTypes.string.isRequired,logo:PropTypes.string.isRequired,onClose:PropTypes.func,onSave:PropTypes.func,privacyPolicyUrl:PropTypes.string.isRequired,site:PropTypes.string.isRequired,userEmail:PropTypes.string.isRequired,userId:PropTypes.string.isRequired} |
{ | ||
"name": "@adv-ui/common-exma-consents-ui-consent", | ||
"version": "1.6.0", | ||
"version": "1.7.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
23993