diff --git a/assets/css/src/components/_welcomeWizard.scss b/assets/css/src/components/_welcomeWizard.scss index 0073630d96..4a5d3cf856 100644 --- a/assets/css/src/components/_welcomeWizard.scss +++ b/assets/css/src/components/_welcomeWizard.scss @@ -34,6 +34,12 @@ } } +.mailpoet_welcome_wizard_step_revenue_tracking { + input[type="submit"] { + margin-top: 40px; + } +} + .mailpoet_welcome_wizard_step { flex-grow: 1; padding: 60px 60px 40px 40px; diff --git a/assets/js/src/wizard/revenue_tracking_permission.jsx b/assets/js/src/wizard/revenue_tracking_permission.jsx index 0d4c15ee0a..652412505e 100644 --- a/assets/js/src/wizard/revenue_tracking_permission.jsx +++ b/assets/js/src/wizard/revenue_tracking_permission.jsx @@ -1,12 +1,46 @@ -import React from 'react'; +import React, { useState } from 'react'; +import MailPoet from 'mailpoet'; +import RevenueTrackingPermissionStep from './steps/revenue_tracking_permission_step.jsx'; function RevenueTrackingPermission() { + const [loading, setLoading] = useState(false); + + const handleApiError = (response) => { + setLoading(false); + let errorMessage = MailPoet.I18n.t('unknownError'); + if (response && response.errors && response.errors.length > 0) { + errorMessage = response.errors.map(error => error.message); + } + MailPoet.Notice.error(errorMessage, { scroll: true }); + }; + + const updateSettings = (data) => { + return MailPoet.Ajax.post({ + api_version: window.mailpoet_api_version, + endpoint: 'settings', + action: 'set', + data, + }).fail(handleApiError); + }; + + const finishWizard = () => { + window.location = window.finish_wizard_url; + }; + + const submit = (allowed) => { + setLoading(true); + const settings = { + accept_cookie_revenue_tracking: allowed ? 1 : 0, + }; + updateSettings(settings).then(finishWizard); + }; + return (
- MailPoet logo + MailPoet logo
-

This is the page

+
); } diff --git a/assets/js/src/wizard/steps/revenue_tracking_permission_step.jsx b/assets/js/src/wizard/steps/revenue_tracking_permission_step.jsx index e69de29bb2..b6c6374515 100644 --- a/assets/js/src/wizard/steps/revenue_tracking_permission_step.jsx +++ b/assets/js/src/wizard/steps/revenue_tracking_permission_step.jsx @@ -0,0 +1,64 @@ +import React, { useState } from 'react'; +import MailPoet from 'mailpoet'; +import PropTypes from 'prop-types'; + +function RevenueTrackingPermissionStep({ submitForm, loading }) { + const [allowed, setAllowed] = useState('true'); + + const submit = (event) => { + event.preventDefault(); + if (allowed === undefined) return false; + submitForm(allowed === 'true'); + return false; + }; + + return ( +
+

{MailPoet.I18n.t('revenueTrackingInfo1')}

+

{MailPoet.I18n.t('revenueTrackingInfo2')}

+
+ + + +
+
+ ); +} + +RevenueTrackingPermissionStep.propTypes = { + submitForm: PropTypes.func.isRequired, + loading: PropTypes.bool.isRequired, +}; + +export default RevenueTrackingPermissionStep; diff --git a/assets/js/src/wizard/wizard.jsx b/assets/js/src/wizard/wizard.jsx index fbe3ad8395..1030400c3a 100644 --- a/assets/js/src/wizard/wizard.jsx +++ b/assets/js/src/wizard/wizard.jsx @@ -17,10 +17,10 @@ if (container) { ReactDOM.render((
- } /> + } />
), container); diff --git a/lib/Config/Changelog.php b/lib/Config/Changelog.php index ebf3e8e3f0..f5485cff92 100644 --- a/lib/Config/Changelog.php +++ b/lib/Config/Changelog.php @@ -114,7 +114,7 @@ class Changelog { private function checkRevenueTrackingPermissionPage() { if ( !in_array($_GET['page'], ['mailpoet-revenue-tracking-permission', 'mailpoet-welcome-wizard', 'mailpoet-migration']) - && ($this->settings->get('woocommerce.accept_cookie_revenue_tracking ') !== null) + && ($this->settings->get('accept_cookie_revenue_tracking') === null) && $this->settings->get('tracking.enabled') && $this->wooCommerceHelper->isWooCommerceActive() && $this->wp->currentUserCan('administrator') diff --git a/views/revenue_tracking_permission.html b/views/revenue_tracking_permission.html index 7a7eae2ffd..ab7f61a131 100644 --- a/views/revenue_tracking_permission.html +++ b/views/revenue_tracking_permission.html @@ -12,6 +12,11 @@ <% block translations %> <%= localize({ - + 'revenueTrackingInfo1': 'MailPoet can use browser cookies for more precise WooCommerce tracking.', + 'revenueTrackingInfo2': 'This is practical for abandoned cart emails and when a customer uses several email addresses.', + 'revenueTrackingAllow': 'Allow MailPoet cookies. My visitors are made aware that cookies are used on my website', + 'revenueTrackingDontAllow': 'Don’t allow MailPoet cookies and rely on basic revenue tracking', + 'revenueTrackingSubmit': _x('Save', 'Submit button caption'), + 'unknownError': __('Unknown error') }) %> <% endblock %>