Skip to content

Commit e4ad318

Browse files
authored
Merge pull request #51 from Bit-Apps-Pro/rishad-dev-tmp
Kit & Brevo action new features with new helper method added
2 parents a9fcd63 + b5d8f30 commit e4ad318

File tree

18 files changed

+620
-405
lines changed

18 files changed

+620
-405
lines changed

frontend-dev/src/Utils/StaticData/webhookIntegrations.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export const customFormIntegrations = [
2121
'Bricks',
2222
'Bricksforge',
2323
'Brizy',
24-
'GutenaForms'
24+
'GutenaForms',
25+
'PieForms',
2526
]
2627

2728
export const actionHookIntegrations = ['ActionHook']

frontend-dev/src/components/AllIntegrations/ConvertKit/ConvertKit.jsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ function ConvertKit({ formFields, setFlow, flow, allIntegURL }) {
2424
api_secret:
2525
process.env.NODE_ENV === 'development' ? 'm4iHyMa_gu65b16dJMnYJJzOlSFpj3wl1pB3k_IvOhc' : '',
2626
field_map: [{ formField: '', convertKitField: '' }],
27-
actions: {}
27+
actions: {},
28+
module: '',
2829
})
2930

3031
const nextPage = (val) => {
@@ -40,15 +41,24 @@ function ConvertKit({ formFields, setFlow, flow, allIntegURL }) {
4041
})
4142
return
4243
}
43-
if (!convertKitConf?.formId) {
44+
if (!convertKitConf?.module) {
45+
setSnackbar({ show: true, msg: __('Please select module to continue.', 'bit-integrations') })
46+
return
47+
}
48+
if (convertKitConf?.module === 'add_subscriber_to_a_form' && !convertKitConf?.formId) {
4449
setSnackbar({ show: true, msg: __('Please select form to continue.', 'bit-integrations') })
4550
return
4651
}
52+
if ((convertKitConf?.module === 'add_tags_to_a_subscriber' || convertKitConf?.module === 'remove_tags_to_a_subscriber') && !convertKitConf?.tagIds) {
53+
setSnackbar({ show: true, msg: __('Please select tag continue.', 'bit-integrations') })
54+
return
55+
}
4756
if (convertKitConf.name !== '' && convertKitConf.field_map.length > 0) {
4857
setstep(3)
4958
}
5059
}
5160
}
61+
5262
return (
5363
<div>
5464
<SnackMsg snack={snack} setSnackbar={setSnackbar} />
@@ -82,7 +92,7 @@ function ConvertKit({ formFields, setFlow, flow, allIntegURL }) {
8292
/>
8393
<button
8494
onClick={() => nextPage(3)}
85-
disabled={!convertKitConf?.formId || convertKitConf.field_map.length < 1}
95+
disabled={!checkMappedFields(convertKitConf)}
8696
className="btn f-right btcd-btn-lg purple sh-sm flx"
8797
type="button">
8898
{__('Next', 'bit-integrations')} &nbsp;

frontend-dev/src/components/AllIntegrations/ConvertKit/ConvertKitActions.jsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,19 @@ export default function ConvertKitActions({ convertKitConf, setConvertKitConf })
1818

1919
return (
2020
<div className="pos-rel d-flx w-8">
21-
<TableCheckBox
22-
checked={convertKitConf.actions?.update || false}
23-
onChange={(e) => actionHandler(e, 'update')}
24-
className="wdt-200 mt-4 mr-2"
25-
value="user_share"
26-
title={sprintf(__('Update %s', 'bit-integrations'), 'Kit(ConvertKit)')}
27-
subTitle={sprintf(
28-
__('Update Responses with %s existing email?', 'bit-integrations'),
29-
'Kit(ConvertKit)'
30-
)}
31-
/>
21+
{(!convertKitConf?.module || convertKitConf?.module === 'add_subscriber_to_a_form') &&
22+
<TableCheckBox
23+
checked={convertKitConf.actions?.update || false}
24+
onChange={(e) => actionHandler(e, 'update')}
25+
className="wdt-200 mt-4 mr-2"
26+
value="user_share"
27+
title={sprintf(__('Update %s', 'bit-integrations'), 'Kit(ConvertKit)')}
28+
subTitle={sprintf(
29+
__('Update Responses with %s existing email?', 'bit-integrations'),
30+
'Kit(ConvertKit)'
31+
)}
32+
/>
33+
}
3234
</div>
3335
)
3436
}

frontend-dev/src/components/AllIntegrations/ConvertKit/ConvertKitCommonFunc.js

Lines changed: 84 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// eslint-disable-next-line import/no-extraneous-dependencies
22
import { __ } from '../../../Utils/i18nwrap'
33
import bitsFetch from '../../../Utils/bitsFetch'
4+
import { create } from 'mutative'
45

56
export const handleInput = (e, convertKitConf, setConvertKitConf) => {
67
const newConf = { ...convertKitConf }
@@ -20,12 +21,16 @@ export const refreshConvertKitForm = (
2021
bitsFetch(refreshFormsRequestParams, 'convertKit_forms')
2122
.then((result) => {
2223
if (result && result.success) {
23-
const newConf = { ...convertKitConf }
2424
if (result.data.convertKitForms) {
25-
if (!newConf.default) {
26-
newConf.default = {}
27-
}
28-
newConf.default.convertKitForms = result.data.convertKitForms
25+
setConvertKitConf(prevConf => create(prevConf, draftConf => {
26+
if (!draftConf.default) {
27+
draftConf.default = {}
28+
}
29+
30+
draftConf.default.convertKitForms = result.data.convertKitForms
31+
}))
32+
refreshConvertKitTags(convertKitConf, setConvertKitConf, setIsLoading, setSnackbar)
33+
2934
setSnackbar({
3035
show: true,
3136
msg: __('Convert Kit forms refreshed', 'bit-integrations')
@@ -39,8 +44,6 @@ export const refreshConvertKitForm = (
3944
)
4045
})
4146
}
42-
43-
setConvertKitConf({ ...newConf })
4447
} else {
4548
setSnackbar({
4649
show: true,
@@ -67,12 +70,15 @@ export const refreshConvertKitTags = (
6770
bitsFetch(refreshFormsRequestParams, 'convertKit_tags')
6871
.then((result) => {
6972
if (result && result.success) {
70-
const newConf = { ...convertKitConf }
7173
if (result.data.convertKitTags) {
72-
if (!newConf.default) {
73-
newConf.default = {}
74-
}
75-
newConf.default.convertKitTags = result.data.convertKitTags
74+
setConvertKitConf(prevConf => create(prevConf, draftConf => {
75+
if (!draftConf.default) {
76+
draftConf.default = {}
77+
}
78+
79+
draftConf.default.convertKitTags = result.data.convertKitTags
80+
}))
81+
7682
setSnackbar({
7783
show: true,
7884
msg: sprintf(__('%s tags refreshed', 'bit-integrations'), 'Kit(ConvertKit)')
@@ -90,7 +96,6 @@ export const refreshConvertKitTags = (
9096
})
9197
}
9298

93-
setConvertKitConf({ ...newConf })
9499
} else {
95100
setSnackbar({
96101
show: true,
@@ -111,64 +116,86 @@ export const refreshConvertKitHeader = (
111116
setIsLoading,
112117
setSnackbar
113118
) => {
114-
const refreshFormsRequestParams = {
115-
api_secret: convertKitConf.api_secret
116-
}
117-
bitsFetch(refreshFormsRequestParams, 'convertKit_headers')
118-
.then((result) => {
119-
if (result && result.success) {
120-
const newConf = { ...convertKitConf }
121-
if (result.data.convertKitField) {
122-
if (!newConf.default) {
123-
newConf.default = {}
124-
}
125-
newConf.default.fields = result.data.convertKitField
126-
const { fields } = newConf.default
127-
newConf.field_map = Object.values(fields)
128-
.filter((f) => f.required)
129-
.map((f) => ({
130-
formField: '',
131-
convertKitField: f.fieldId,
132-
required: true
119+
if (convertKitConf?.module === 'add_tags_to_a_subscriber' || convertKitConf?.module === 'remove_tags_to_a_subscriber') {
120+
setConvertKitConf(prevConf => create(prevConf, draftConf => {
121+
if (!draftConf.default) {
122+
draftConf.default = {}
123+
}
124+
125+
draftConf.default.fields = { 'Email': { 'fieldId': 'email', 'fieldName': 'Email', 'required': true } }
126+
draftConf.field_map = [{
127+
formField: '',
128+
convertKitField: 'email',
129+
required: true
130+
}]
131+
}))
132+
133+
setSnackbar({
134+
show: true,
135+
msg: sprintf(__('%s fields refreshed', 'bit-integrations'), 'Kit(ConvertKit)')
136+
})
137+
} else {
138+
const refreshFormsRequestParams = {
139+
api_secret: convertKitConf.api_secret
140+
}
141+
142+
bitsFetch(refreshFormsRequestParams, 'convertKit_headers')
143+
.then((result) => {
144+
if (result && result.success) {
145+
if (result.data.convertKitField) {
146+
setConvertKitConf(prevConf => create(prevConf, draftConf => {
147+
if (!draftConf.default) {
148+
draftConf.default = {}
149+
}
150+
draftConf.default.fields = result.data.convertKitField
151+
const { fields } = draftConf.default
152+
draftConf.field_map = Object.values(fields)
153+
.filter((f) => f.required)
154+
.map((f) => ({
155+
formField: '',
156+
convertKitField: f.fieldId,
157+
required: true
158+
}))
159+
133160
}))
134-
setSnackbar({
135-
show: true,
136-
msg: sprintf(__('%s fields refreshed', 'bit-integrations'), 'Kit(ConvertKit)')
137-
})
161+
162+
setSnackbar({
163+
show: true,
164+
msg: sprintf(__('%s fields refreshed', 'bit-integrations'), 'Kit(ConvertKit)')
165+
})
166+
} else {
167+
setSnackbar({
168+
show: true,
169+
msg: sprintf(
170+
__(
171+
'No %s fields found. Try changing the header row number or try again',
172+
'bit-integrations'
173+
),
174+
'Kit(ConvertKit)'
175+
)
176+
})
177+
}
138178
} else {
139179
setSnackbar({
140180
show: true,
141181
msg: sprintf(
142-
__(
143-
'No %s fields found. Try changing the header row number or try again',
144-
'bit-integrations'
145-
),
182+
__('%s fields refresh failed. please try again', 'bit-integrations'),
146183
'Kit(ConvertKit)'
147184
)
148185
})
149186
}
150-
151-
setConvertKitConf({ ...newConf })
152-
} else {
153-
setSnackbar({
154-
show: true,
155-
msg: sprintf(
156-
__('%s fields refresh failed. please try again', 'bit-integrations'),
157-
'Kit(ConvertKit)'
158-
)
159-
})
160-
}
161-
setIsLoading(false)
162-
})
163-
.catch(() => setIsLoading(false))
187+
setIsLoading(false)
188+
})
189+
.catch(() => setIsLoading(false))
190+
}
164191
}
165192

166193
export const checkMappedFields = (convertKitConf) => {
167194
const mappedFields = convertKitConf?.field_map
168195
? convertKitConf.field_map.filter(
169-
(mappedField) =>
170-
!mappedField.formField && mappedField.convertKitField && mappedField.required
171-
)
196+
(mappedField) =>
197+
!mappedField.formField && mappedField.convertKitField && mappedField.required
198+
)
172199
: []
173200
if (mappedFields.length > 0) {
174201
return false

0 commit comments

Comments
 (0)