Delete cookie after forms is saved
[MAILPOET-2740]
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { select, dispatch } from '@wordpress/data';
|
import { select, dispatch } from '@wordpress/data';
|
||||||
import MailPoet from 'mailpoet';
|
import MailPoet from 'mailpoet';
|
||||||
import { merge } from 'lodash';
|
import { merge } from 'lodash';
|
||||||
|
import Cookies from 'js-cookie';
|
||||||
import { createBlock, unregisterBlockType } from '@wordpress/blocks';
|
import { createBlock, unregisterBlockType } from '@wordpress/blocks';
|
||||||
import { blocksToFormBodyFactory } from './blocks_to_form_body.jsx';
|
import { blocksToFormBodyFactory } from './blocks_to_form_body.jsx';
|
||||||
import formatCustomFieldBlockName from '../blocks/format_custom_field_block_name.jsx';
|
import formatCustomFieldBlockName from '../blocks/format_custom_field_block_name.jsx';
|
||||||
@@ -59,6 +60,7 @@ export default {
|
|||||||
data: requestData,
|
data: requestData,
|
||||||
}).done(() => {
|
}).done(() => {
|
||||||
dispatch('mailpoet-form-editor').saveFormDone();
|
dispatch('mailpoet-form-editor').saveFormDone();
|
||||||
|
Cookies.remove('popup_form_dismissed', { path: '/' });
|
||||||
}).fail((response) => {
|
}).fail((response) => {
|
||||||
dispatch('mailpoet-form-editor').saveFormFailed(formatApiErrorMessage(response));
|
dispatch('mailpoet-form-editor').saveFormFailed(formatApiErrorMessage(response));
|
||||||
});
|
});
|
||||||
|
@@ -1,30 +1,8 @@
|
|||||||
import MailPoet from 'mailpoet';
|
import MailPoet from 'mailpoet';
|
||||||
import jQuery from 'jquery';
|
import jQuery from 'jquery';
|
||||||
|
import Cookies from 'js-cookie';
|
||||||
import 'parsleyjs';
|
import 'parsleyjs';
|
||||||
|
|
||||||
function setCookie(name, value, days) {
|
|
||||||
let expires = '';
|
|
||||||
if (days) {
|
|
||||||
const date = new Date();
|
|
||||||
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
|
||||||
expires = `; expires=${date.toUTCString()}`;
|
|
||||||
}
|
|
||||||
document.cookie = `${name}=${value}${expires}; path=/`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getCookie(name) {
|
|
||||||
const nameEQ = `${name}=`;
|
|
||||||
const cookieParts = document.cookie.split(';');
|
|
||||||
for (let i = 0; i < cookieParts.length; i += 1) {
|
|
||||||
let cookiePart = cookieParts[i];
|
|
||||||
while (cookiePart.charAt(0) === ' ') cookiePart = cookiePart.substring(1, cookiePart.length);
|
|
||||||
if (cookiePart.indexOf(nameEQ) === 0) {
|
|
||||||
return cookiePart.substring(nameEQ.length, cookiePart.length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
jQuery(($) => {
|
jQuery(($) => {
|
||||||
window.reCaptchaCallback = function reCaptchaCallback() {
|
window.reCaptchaCallback = function reCaptchaCallback() {
|
||||||
$('.mailpoet_recaptcha').each((index, element) => {
|
$('.mailpoet_recaptcha').each((index, element) => {
|
||||||
@@ -90,7 +68,7 @@ jQuery(($) => {
|
|||||||
const closeForm = (formDiv) => {
|
const closeForm = (formDiv) => {
|
||||||
formDiv.removeClass('active');
|
formDiv.removeClass('active');
|
||||||
formDiv.prev('.mailpoet_form_popup_overlay').removeClass('active');
|
formDiv.prev('.mailpoet_form_popup_overlay').removeClass('active');
|
||||||
setCookie('popup_form_dismissed', '1', 365);
|
Cookies.set('popup_form_dismissed', '1', { expires: 365, path: '/' });
|
||||||
};
|
};
|
||||||
$('.mailpoet_form_close_icon').click((event) => {
|
$('.mailpoet_form_close_icon').click((event) => {
|
||||||
const closeIcon = $(event.target);
|
const closeIcon = $(event.target);
|
||||||
@@ -99,14 +77,14 @@ jQuery(($) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$('div.mailpoet_form_fixed_bar').each((index, element) => {
|
$('div.mailpoet_form_fixed_bar').each((index, element) => {
|
||||||
const cookieValue = getCookie('popup_form_dismissed');
|
const cookieValue = Cookies.get('popup_form_dismissed');
|
||||||
if (cookieValue === '1') return;
|
if (cookieValue === '1') return;
|
||||||
const formDiv = $(element);
|
const formDiv = $(element);
|
||||||
showForm(formDiv);
|
showForm(formDiv);
|
||||||
});
|
});
|
||||||
|
|
||||||
$('div.mailpoet_form_popup').each((index, element) => {
|
$('div.mailpoet_form_popup').each((index, element) => {
|
||||||
const cookieValue = getCookie('popup_form_dismissed');
|
const cookieValue = Cookies.get('popup_form_dismissed');
|
||||||
if (cookieValue === '1') return;
|
if (cookieValue === '1') return;
|
||||||
|
|
||||||
const formDiv = $(element);
|
const formDiv = $(element);
|
||||||
|
5
package-lock.json
generated
5
package-lock.json
generated
@@ -10804,6 +10804,11 @@
|
|||||||
"integrity": "sha512-M7kLczedRMYX4L8Mdh4MzyAMM9O5osx+4FcOQuTvr3A9F2D9S5JXheN0ewNbrvK2UatkTRhL5ejGmGSjNMiZuw==",
|
"integrity": "sha512-M7kLczedRMYX4L8Mdh4MzyAMM9O5osx+4FcOQuTvr3A9F2D9S5JXheN0ewNbrvK2UatkTRhL5ejGmGSjNMiZuw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"js-cookie": {
|
||||||
|
"version": "2.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/js-cookie/-/js-cookie-2.2.1.tgz",
|
||||||
|
"integrity": "sha512-HvdH2LzI/EAZcUwA8+0nKNtWHqS+ZmijLA30RwZA0bo7ToCckjK5MkGhjED9KoRcXO6BaGI3I9UIzSA1FKFPOQ=="
|
||||||
|
},
|
||||||
"js-tokens": {
|
"js-tokens": {
|
||||||
"version": "3.0.2",
|
"version": "3.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz",
|
||||||
|
@@ -52,6 +52,7 @@
|
|||||||
"html2canvas": "^1.0.0-alpha.12",
|
"html2canvas": "^1.0.0-alpha.12",
|
||||||
"interact.js": "~1.2.8",
|
"interact.js": "~1.2.8",
|
||||||
"jquery": "^3.4.1",
|
"jquery": "^3.4.1",
|
||||||
|
"js-cookie": "^2.2.1",
|
||||||
"lodash": "^4.17.15",
|
"lodash": "^4.17.15",
|
||||||
"moment": "^2.22.1",
|
"moment": "^2.22.1",
|
||||||
"mousetrap": "^1.6.3",
|
"mousetrap": "^1.6.3",
|
||||||
|
Reference in New Issue
Block a user