Skip to content

Commit 27873ef

Browse files
committed
feat: omnisend custom properties added
1 parent 97fa945 commit 27873ef

File tree

7 files changed

+134
-70
lines changed

7 files changed

+134
-70
lines changed
Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,38 @@
11
/* eslint-disable no-unused-expressions */
22
import { __ } from '../../../Utils/i18nwrap'
33

4-
export const addFieldMap = (i, confTmp, setConf) => {
4+
export const addFieldMap = (i, confTmp, setConf, type = 'field_map') => {
55
const newConf = { ...confTmp }
6-
newConf.field_map.splice(i, 0, {})
6+
if (!newConf[type]) {
7+
newConf[type] = []
8+
}
9+
10+
newConf[type].splice(i, 0, {})
711
setConf({ ...newConf })
812
}
913

10-
export const delFieldMap = (i, confTmp, setConf) => {
14+
export const delFieldMap = (i, confTmp, setConf, type = 'field_map') => {
1115
const newConf = { ...confTmp }
12-
if (newConf.field_map.length > 1) {
13-
newConf.field_map.splice(i, 1)
16+
if (newConf[type].length > 1) {
17+
newConf[type].splice(i, 1)
1418
}
1519

1620
setConf({ ...newConf })
1721
}
1822

19-
export const handleFieldMapping = (event, index, conftTmp, setConf) => {
23+
export const handleCustomValue = (event, index, conftTmp, setConf, type = 'field_map') => {
24+
const newConf = { ...conftTmp }
25+
newConf[type][index].customValue = event?.target?.value || event
26+
27+
setConf({ ...newConf })
28+
}
29+
30+
export const handleFieldMapping = (event, index, conftTmp, setConf, type = 'field_map') => {
2031
const newConf = { ...conftTmp }
21-
newConf.field_map[index][event.target.name] = event.target.value
32+
newConf[type][index][event.target.name] = event.target.value
2233

2334
if (event.target.value === 'custom') {
24-
newConf.field_map[index].customValue = ''
35+
newConf[type][index].customValue = ''
2536
}
2637
setConf({ ...newConf })
2738
}

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Steps from '../../Utilities/Steps'
99
import { saveIntegConfig } from '../IntegrationHelpers/IntegrationHelpers'
1010
import IntegrationStepThree from '../IntegrationHelpers/IntegrationStepThree'
1111
import OmniSendAuthorization from './OmniSendAuthorization'
12-
import { checkMappedFields, handleInput } from './OmniSendCommonFunc'
12+
import { checkMappedFields, generateMappedField, handleInput } from './OmniSendCommonFunc'
1313
import OmniSendIntegLayout from './OmniSendIntegLayout'
1414

1515
function OmniSend({ formFields, setFlow, flow, allIntegURL }) {
@@ -93,7 +93,8 @@ function OmniSend({ formFields, setFlow, flow, allIntegURL }) {
9393
process.env.NODE_ENV === 'development'
9494
? '6368ea4de67810becfd7638c-TeHA6oan0eO092kBbJh0BiepvUYzn5sehgbbSfhO4hXgPLax1v'
9595
: '',
96-
field_map: [{ formField: '', omniSendFormField: '' }],
96+
field_map: generateMappedField(omniSendFields),
97+
custom_field_map: [{ formField: '', omniSendFormField: '' }],
9798
channels: '',
9899
channel_types: [],
99100
email_status: '',
@@ -114,7 +115,7 @@ function OmniSend({ formFields, setFlow, flow, allIntegURL }) {
114115
'',
115116
setIsLoading
116117
)
117-
resp.then((res) => {
118+
resp.then(res => {
118119
if (res.success) {
119120
toast.success(res.data?.msg)
120121
navigate(allIntegURL)
@@ -123,7 +124,7 @@ function OmniSend({ formFields, setFlow, flow, allIntegURL }) {
123124
}
124125
})
125126
}
126-
const nextPage = (pageNo) => {
127+
const nextPage = pageNo => {
127128
setTimeout(() => {
128129
document.getElementById('btcd-settings-wrp').scrollTop = 0
129130
}, 300)
@@ -166,9 +167,7 @@ function OmniSend({ formFields, setFlow, flow, allIntegURL }) {
166167
}}>
167168
<OmniSendIntegLayout
168169
formFields={formFields}
169-
handleInput={(e) =>
170-
handleInput(e, omniSendConf, setOmniSendConf, setLoading, setSnackbar)
171-
}
170+
handleInput={e => handleInput(e, omniSendConf, setOmniSendConf, setLoading, setSnackbar)}
172171
omniSendConf={omniSendConf}
173172
setOmniSendConf={setOmniSendConf}
174173
loading={loading}

frontend-dev/src/components/AllIntegrations/OmniSend/OmniSendCommonFunc.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@ export const handleInput = (
2323
setOmniSendConf({ ...newConf })
2424
}
2525

26-
export const generateMappedField = (omniSendConf) => {
27-
const requiredFlds = omniSendConf?.omniSend_fields.filter((fld) => fld.required === true)
26+
export const generateMappedField = (fields = []) => {
27+
const requiredFlds = fields.filter(fld => fld.required === true)
2828
return requiredFlds.length > 0
29-
? requiredFlds.map((field) => ({
29+
? requiredFlds.map(field => ({
3030
formField: '',
3131
omniSendFormField: field.key
3232
}))
3333
: [{ formField: '', omniSendFormField: '' }]
3434
}
3535

36-
export const checkMappedFields = (omniSendConf) => {
36+
export const checkMappedFields = omniSendConf => {
3737
const mappedFields = omniSendConf?.field_map
3838
? omniSendConf.field_map.filter(
39-
(mappedField) =>
39+
mappedField =>
4040
!mappedField.formField ||
4141
!mappedField.omniSendFormField ||
4242
(!mappedField.formField === 'custom' && !mappedField.customValue)
@@ -66,7 +66,7 @@ export const handleOmniSendAuthorize = (
6666

6767
const requestParams = { api_key: confTmp.api_key }
6868

69-
bitsFetch(requestParams, 'Omnisend_authorization').then((result) => {
69+
bitsFetch(requestParams, 'Omnisend_authorization').then(result => {
7070
if (result && result.success) {
7171
const newConf = { ...confTmp }
7272
setConf(newConf)

frontend-dev/src/components/AllIntegrations/OmniSend/OmniSendFieldMap.jsx

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,19 @@ import { useRecoilValue } from 'recoil'
22
import { useEffect } from 'react'
33
import { __ } from '../../../Utils/i18nwrap'
44
import MtInput from '../../Utilities/MtInput'
5-
import { addFieldMap, delFieldMap, handleFieldMapping } from './IntegrationHelpers'
5+
import { addFieldMap, delFieldMap, handleCustomValue, handleFieldMapping } from './IntegrationHelpers'
66
import { SmartTagField } from '../../../Utils/StaticData/SmartTagField'
77
import { $btcbi } from '../../../GlobalStates'
88
import { generateMappedField } from './OmniSendCommonFunc'
99
import TagifyInput from '../../Utilities/TagifyInput'
10-
import { handleCustomValue } from '../IntegrationHelpers/IntegrationHelpers'
1110

12-
export default function OmniSendFieldMap({ i, formFields, field, omniSendConf, setOmniSendConf }) {
13-
if (omniSendConf?.field_map?.length === 1 && field.omniSendFormField === '') {
14-
const newConf = { ...omniSendConf }
15-
const tmp = generateMappedField(newConf)
16-
newConf.field_map = tmp
17-
// setOmniSendConf(newConf);
18-
}
19-
20-
const requiredFlds = omniSendConf?.omniSend_fields.filter((fld) => fld.required === true) || []
21-
const nonRequiredFlds =
22-
omniSendConf?.omniSend_fields.filter((fld) => fld.required === false) || []
11+
export default function OmniSendFieldMap({ i, formFields, field, omniSendConf, setOmniSendConf, type }) {
2312
const btcbi = useRecoilValue($btcbi)
2413
const { isPro } = btcbi
2514

15+
const requiredFlds = omniSendConf?.omniSend_fields.filter(fld => fld.required === true) || []
16+
const nonRequiredFlds = omniSendConf?.omniSend_fields.filter(fld => fld.required === false) || []
17+
2618
return (
2719
<div className="flx mt-2 mb-2 btcbi-field-map">
2820
<div className="pos-rel flx">
@@ -31,10 +23,10 @@ export default function OmniSendFieldMap({ i, formFields, field, omniSendConf, s
3123
className="btcd-paper-inp mr-2"
3224
name="formField"
3325
value={field.formField || ''}
34-
onChange={(ev) => handleFieldMapping(ev, i, omniSendConf, setOmniSendConf)}>
26+
onChange={ev => handleFieldMapping(ev, i, omniSendConf, setOmniSendConf, type)}>
3527
<option value="">{__('Select Field', 'bit-integrations')}</option>
3628
<optgroup label={__('Form Fields', 'bit-integrations')}>
37-
{formFields?.map((f) => (
29+
{formFields?.map(f => (
3830
<option key={`ff-rm-${f.name}`} value={f.name}>
3931
{f.label}
4032
</option>
@@ -47,7 +39,7 @@ export default function OmniSendFieldMap({ i, formFields, field, omniSendConf, s
4739
isPro ? '' : `(${__('Pro', 'bit-integrations')})`
4840
)}>
4941
{isPro &&
50-
SmartTagField?.map((f) => (
42+
SmartTagField?.map(f => (
5143
<option key={`ff-rm-${f.name}`} value={f.name}>
5244
{f.label}
5345
</option>
@@ -57,7 +49,7 @@ export default function OmniSendFieldMap({ i, formFields, field, omniSendConf, s
5749

5850
{field.formField === 'custom' && (
5951
<TagifyInput
60-
onChange={(e) => handleCustomValue(e, i, omniSendConf, setOmniSendConf)}
52+
onChange={e => handleCustomValue(e, i, omniSendConf, setOmniSendConf, type)}
6153
label={__('Custom Value', 'bit-integrations')}
6254
className="mr-2"
6355
type="text"
@@ -67,36 +59,47 @@ export default function OmniSendFieldMap({ i, formFields, field, omniSendConf, s
6759
/>
6860
)}
6961

70-
<select
71-
className="btcd-paper-inp"
72-
disabled={i < requiredFlds.length}
73-
name="omniSendFormField"
74-
value={i < requiredFlds ? requiredFlds[i].label || '' : field.omniSendFormField || ''}
75-
onChange={(ev) => handleFieldMapping(ev, i, omniSendConf, setOmniSendConf)}>
76-
<option value="">{__('Select Field', 'bit-integrations')}</option>
77-
{i < requiredFlds.length ? (
78-
<option key={requiredFlds[i].key} value={requiredFlds[i].key}>
79-
{requiredFlds[i].label}
80-
</option>
81-
) : (
82-
nonRequiredFlds.map(({ key, label }) => (
83-
<option key={key} value={key}>
84-
{label}
62+
{type === 'field_map' ? (
63+
<select
64+
className="btcd-paper-inp"
65+
disabled={i < requiredFlds.length}
66+
name="omniSendFormField"
67+
value={i < requiredFlds ? requiredFlds[i].label || '' : field.omniSendFormField || ''}
68+
onChange={ev => handleFieldMapping(ev, i, omniSendConf, setOmniSendConf, type)}>
69+
<option value="">{__('Select Field', 'bit-integrations')}</option>
70+
{i < requiredFlds.length ? (
71+
<option key={requiredFlds[i].key} value={requiredFlds[i].key}>
72+
{requiredFlds[i].label}
8573
</option>
86-
))
87-
)}
88-
</select>
74+
) : (
75+
nonRequiredFlds.map(({ key, label }) => (
76+
<option key={key} value={key}>
77+
{label}
78+
</option>
79+
))
80+
)}
81+
</select>
82+
) : (
83+
<input
84+
className="btcd-paper-inp"
85+
name="omniSendFormField"
86+
value={field['omniSendFormField'] || ''}
87+
onChange={ev => handleFieldMapping(ev, i, omniSendConf, setOmniSendConf, type)}
88+
type="text"
89+
/>
90+
)}
8991
</div>
92+
9093
{i >= requiredFlds.length && (
9194
<>
9295
<button
93-
onClick={() => addFieldMap(i, omniSendConf, setOmniSendConf)}
96+
onClick={() => addFieldMap(i, omniSendConf, setOmniSendConf, type)}
9497
className="icn-btn sh-sm ml-2 mr-1"
9598
type="button">
9699
+
97100
</button>
98101
<button
99-
onClick={() => delFieldMap(i, omniSendConf, setOmniSendConf)}
102+
onClick={() => delFieldMap(i, omniSendConf, setOmniSendConf, type)}
100103
className="icn-btn sh-sm ml-1"
101104
type="button"
102105
aria-label="btn">

frontend-dev/src/components/AllIntegrations/OmniSend/OmniSendIntegLayout.jsx

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { addFieldMap } from './IntegrationHelpers'
66
import OmniSendFieldMap from './OmniSendFieldMap'
77
import OmniSendActions from './OmniSendActions'
88
import { generateMappedField } from './OmniSendCommonFunc'
9+
import ActionProFeatureComponent from '../IntegrationHelpers/ActionProFeatureComponent'
10+
import { ProFeatureTitle } from '../IntegrationHelpers/ActionProFeatureLabels'
911

1012
export default function OmniSendIntegLayout({
1113
formFields,
@@ -76,11 +78,11 @@ export default function OmniSendIntegLayout({
7678
<MultiSelect
7779
className="msl-wrp-options w-5"
7880
defaultValue={omniSendConf?.channels}
79-
options={channels?.map((channel) => ({
81+
options={channels?.map(channel => ({
8082
label: channel.label,
8183
value: channel.value
8284
}))}
83-
onChange={(val) => setChanges(val, 'channels')}
85+
onChange={val => setChanges(val, 'channels')}
8486
customValue
8587
/>
8688
</div>
@@ -119,8 +121,7 @@ export default function OmniSendIntegLayout({
119121
</div>
120122
)}
121123

122-
{(omniSendConf.channels.search('email') !== -1 ||
123-
omniSendConf.channels.search('sms') !== -1) && (
124+
{(omniSendConf.channels.search('email') !== -1 || omniSendConf.channels.search('sms') !== -1) && (
124125
<>
125126
<br />
126127
<div className="mt-5">
@@ -158,12 +159,13 @@ export default function OmniSendIntegLayout({
158159
formFields={formFields}
159160
setOmniSendConf={setOmniSendConf}
160161
setSnackbar={setSnackbar}
162+
type="field_map"
161163
/>
162164
))}
163165
<div className="txt-center btcbi-field-map-button mt-2">
164166
<button
165167
onClick={() =>
166-
addFieldMap(omniSendConf.field_map.length, omniSendConf, setOmniSendConf, false)
168+
addFieldMap(omniSendConf.field_map.length, omniSendConf, setOmniSendConf, 'field_map')
167169
}
168170
className="icn-btn sh-sm"
169171
type="button">
@@ -173,6 +175,48 @@ export default function OmniSendIntegLayout({
173175
<br />
174176
<br />
175177

178+
<ActionProFeatureComponent title={__('Custom Properties', 'bit-integrations')}>
179+
<b className="wdt-100">
180+
{<ProFeatureTitle title={__('Custom Properties', 'bit-integrations')} />}
181+
</b>
182+
<div className="btcd-hr mt-2 mb-4" />
183+
<div className="flx flx-around mt-2 mb-2 btcbi-field-map-label">
184+
<div className="txt-dp">
185+
<b>{__('Form Fields', 'bit-integrations')}</b>
186+
</div>
187+
<div className="txt-dp">
188+
<b>{__('OmniSend Property name', 'bit-integrations')}</b>
189+
</div>
190+
</div>
191+
{omniSendConf?.custom_field_map?.map((itm, i) => (
192+
<OmniSendFieldMap
193+
key={`rp-m-${i + 9}`}
194+
i={i}
195+
field={itm}
196+
omniSendConf={omniSendConf}
197+
formFields={formFields}
198+
setOmniSendConf={setOmniSendConf}
199+
setSnackbar={setSnackbar}
200+
type="custom_field_map"
201+
/>
202+
))}
203+
<div className="txt-center btcbi-field-map-button mt-2">
204+
<button
205+
onClick={() =>
206+
addFieldMap(
207+
omniSendConf?.custom_field_map?.length,
208+
omniSendConf,
209+
setOmniSendConf,
210+
'custom_field_map'
211+
)
212+
}
213+
className="icn-btn sh-sm"
214+
type="button">
215+
+
216+
</button>
217+
</div>
218+
</ActionProFeatureComponent>
219+
176220
<div className="mt-4">
177221
<b className="wdt-100">{__('Actions', 'bit-integrations')}</b>
178222
</div>

includes/Actions/OmniSend/OmniSendController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
namespace BitCode\FI\Actions\OmniSend;
88

9-
use BitCode\FI\Core\Util\HttpHelper;
109
use WP_Error;
10+
use BitCode\FI\Core\Util\HttpHelper;
1111

1212
/**
1313
* Provide functionality for OmniSend integration
@@ -54,6 +54,7 @@ public function execute($integrationData, $fieldValues)
5454
$api_key = $integrationDetails->api_key;
5555
$channels = $integrationDetails->channels;
5656
$fieldMap = $integrationDetails->field_map;
57+
$customFieldMap = $integrationDetails->custom_field_map ?? [];
5758
$emailStatus = $integrationDetails->email_status;
5859
$smsStatus = $integrationDetails->sms_status;
5960

@@ -70,7 +71,8 @@ public function execute($integrationData, $fieldValues)
7071
$emailStatus,
7172
$smsStatus,
7273
$fieldValues,
73-
$fieldMap
74+
$fieldMap,
75+
$customFieldMap
7476
);
7577

7678
if (is_wp_error($omniSendApiResponse)) {

0 commit comments

Comments
 (0)