PluginProbe
MailerLite – WooCommerce integration / 3.1.20
MailerLite – WooCommerce integration v3.1.20
3.1.25 3.1.26 3.1.24 3.1.23 3.1.22 3.1.21 3.1.20 3.1.19 3.1.18 3.1.17 3.1.16 3.1.15 1.8.7 1.8.8 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 All 147 releases
woo-mailerlite / admin / assets / js / components / App.js

App.js in MailerLite – WooCommerce integration 3.1.20, at admin/assets/js/components/App.js

104 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import eventBus from './eventBus.js';
2 import Header from './Ui/Header.js'
3 import Alerts from './Ui/Alerts.js'
4 import Wizard from './Views/Wizard.js'
5 import Settings from './Views/Settings.js'
6 import Modals from './Modals/Modals.js'
7
8 const template = `
9 <div class="woo-ml-wizard">
10 <Header></Header>
11 <Alerts :alerts="alerts"></Alerts>
12 <Wizard v-if="currentStep < 2"></Wizard>
13 <Settings v-else :group="selectedGroup" :fields="selectedFields"></Settings>
14 </div>
15 <Modals></Modals>
16 `
17
18 const App = {
19 template,
20 components: {
21 Header,
22 Alerts,
23 Wizard,
24 Settings,
25 Modals,
26 },
27 data() {
28 return {
29 alerts: [],
30 currentStep: 0,
31 selectedGroup: null,
32 selectedFields: [],
33 startSync: false,
34 manualSync: false,
35 }
36 },
37 methods: {
38 async syncProcess() {
39 const response = await fetch(woo_mailerlite_admin_data.ajaxUrl, {
40 method: 'POST',
41 headers: {
42 'Content-Type': 'application/x-www-form-urlencoded',
43 },
44 body: new URLSearchParams({
45 action: 'woo_mailerlite_sync_handler',
46 nonce: woo_mailerlite_admin_data.woo_mailerlite_admin_nonce,
47 async: !this.manualSync
48 }),
49 });
50
51 if ([200, 203].includes(response.status)) {
52 eventBus.emit('sync-completed', true);
53 clearInterval(this.interval);
54 }
55 }
56 },
57 mounted() {
58 if (woo_mailerlite_admin_data.falseApi && woo_mailerlite_admin_data.currentStep > 0) {
59 window.location.reload()
60 }
61 if (woo_mailerlite_admin_data.asyncSync || this.startSync || ((parseInt(woo_mailerlite_admin_data.currentStep) === 2) && woo_mailerlite_admin_data.sync.syncInProgress)) {
62 this.syncProcess();
63 if (!woo_mailerlite_admin_data.asyncSync) {
64 this.interval = setInterval(() => {
65 woo_mailerlite_admin_data.sync.syncInProgress = true
66 this.syncProcess();
67 }, 8000);
68 }
69 }
70
71 eventBus.on('alert-event', (data) => {
72 this.alerts = data
73 window.scrollTo({ top: 0, behavior: 'smooth' });
74 });
75 eventBus.on('start-sync', (data) => {
76 this.manualSync = true;
77 this.syncProcess();
78 this.interval = setInterval(() => {
79 woo_mailerlite_admin_data.sync.syncInProgress = true
80 this.syncProcess();
81 }, 8000);
82 });
83
84 eventBus.on('wizard-step-event', (step) => {
85 if (this.currentStep > 0 && step === 0) {
86 this.currentStep = 0
87 return
88 }
89 this.alerts = []
90 this.currentStep = step
91 });
92 eventBus.on('group-saved', (data) => {
93 this.selectedGroup = data.group
94 this.selectedFields = data.fields
95 })
96 eventBus.emit('wizard-step-event', parseInt(woo_mailerlite_admin_data.currentStep))
97 },
98 beforeDestroy() {
99 clearInterval(this.interval);
100 }
101 }
102
103 export default App
104