Skip to content

Commit c4b4b7c

Browse files
committed
fix: mailerlite change state issue fixed
1 parent e10c407 commit c4b4b7c

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

frontend-dev/src/components/AllIntegrations/MailerLite/MailerLiteCommonFunc.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import { create } from 'mutative'
77
export const handleInput = (e, mailerLiteConf, setMailerLiteConf, loading, setLoading) => {
88
const { name, value } = e.target
99

10-
setMailerLiteConf(prev =>
11-
create(prev, draftConf => {
12-
draftConf[name] = value
10+
const updatedConf = create(mailerLiteConf, draftConf => {
11+
draftConf[name] = value
12+
})
1313

14-
if (name === 'action' && value !== '') {
15-
mailerliteRefreshFields(draftConf, setMailerLiteConf, loading, setLoading)
16-
}
17-
})
18-
)
14+
setMailerLiteConf(updatedConf)
15+
16+
if (name === 'action' && value !== '') {
17+
mailerliteRefreshFields(updatedConf, setMailerLiteConf, loading, setLoading)
18+
}
1919
}
2020

2121
export const generateMappedField = mailerLiteConf => {

frontend-dev/src/components/AllIntegrations/MailerLite/MailerLiteIntegLayout.jsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import MailerLiteFieldMap from './MailerLiteFieldMap'
55
import MailerLiteActions from './MailerLiteActions'
66
import { mailerliteRefreshFields } from './MailerLiteCommonFunc'
77
import { useState } from 'react'
8+
import Note from '../../Utilities/Note'
89

910
export default function MailerLiteIntegLayout({
1011
formFields,
@@ -102,6 +103,8 @@ export default function MailerLiteIntegLayout({
102103
</>
103104
)}
104105

106+
{mailerLiteConf?.action && mailerLiteConf?.action !== 'add_subscriber' && <Note note={note} />}
107+
105108
{mailerLiteConf?.action && mailerLiteConf?.action === 'add_subscriber' && (
106109
<>
107110
<div className="mt-4">
@@ -120,3 +123,7 @@ export default function MailerLiteIntegLayout({
120123
</>
121124
)
122125
}
126+
127+
const note = `
128+
<p>${__('This action requires a MailerLite New account. It isn’t supported with Classic accounts.', 'bit-integrations')}</p>
129+
`

includes/Actions/MailerLite/RecordApiHelper.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,14 @@ class RecordApiHelper
2525

2626
private $_actions;
2727

28+
private $_isMailerLiteV2;
29+
2830
public function __construct($auth_token, $integrationDetails, $integId, $actions, $version)
2931
{
3032
$this->_integrationDetails = $integrationDetails;
3133
$this->_integrationID = $integId;
34+
$this->_isMailerLiteV2 = (bool) ('v2' === $version);
35+
3236
if ('v2' === $version) {
3337
$this->_baseUrl = 'https://connect.mailerlite.com/api/';
3438
$this->_defaultHeader = [
@@ -94,10 +98,9 @@ public function addSubscriber($auth_token, $groupIds, $type, $finalData)
9498

9599
$email = $finalData['email'];
96100
$splitGroupIds = !empty($groupIds) ? explode(',', $groupIds) : [];
97-
$isMailerLiteV2 = $this->_baseUrl === 'https://connect.mailerlite.com/api/';
98101
$apiEndpoint = $this->_baseUrl . 'subscribers';
99102

100-
$requestParams = self::prepareRequestParams($finalData, $type, $isMailerLiteV2);
103+
$requestParams = self::prepareRequestParams($finalData, $type, $this->_isMailerLiteV2);
101104

102105
$isExist = $this->existSubscriber($auth_token, $email);
103106
$response = null;
@@ -110,10 +113,10 @@ public function addSubscriber($auth_token, $groupIds, $type, $finalData)
110113
];
111114
}
112115

113-
self::handleDoubleOptIn($this, $auth_token, $requestParams, $isMailerLiteV2);
116+
self::handleDoubleOptIn($this, $auth_token, $requestParams, $this->_isMailerLiteV2);
114117

115118
if (!empty($splitGroupIds)) {
116-
return self::sendToGroups($this, $splitGroupIds, $requestParams, $isMailerLiteV2);
119+
return self::sendToGroups($this, $splitGroupIds, $requestParams, $this->_isMailerLiteV2);
117120
}
118121

119122
if ($isExist) {
@@ -128,6 +131,14 @@ public function addSubscriber($auth_token, $groupIds, $type, $finalData)
128131

129132
public function deleteSubscriber($auth_token, $finalData)
130133
{
134+
if (!$this->_isMailerLiteV2) {
135+
return [
136+
'success' => false,
137+
'message' => __('This action is not supported for Classic accounts.', 'bit-integrations'),
138+
'code' => 400
139+
];
140+
}
141+
131142
if (empty($finalData['email'])) {
132143
return [
133144
'success' => false,
@@ -136,7 +147,6 @@ public function deleteSubscriber($auth_token, $finalData)
136147
];
137148
}
138149

139-
// $isMailerLiteV2 = $this->_baseUrl === 'https://connect.mailerlite.com/api/';
140150
$subscriberId = $this->existSubscriber($auth_token, $finalData['email']);
141151

142152
if (empty($subscriberId)) {

0 commit comments

Comments
 (0)