Skip to content

Commit b07a391

Browse files
authored
Merge pull request #76 from Bit-Apps-Pro/test/integ-migration-test
Fluent Community added as a Trigger
2 parents 648c8b0 + 269cb43 commit b07a391

File tree

7 files changed

+55
-20
lines changed

7 files changed

+55
-20
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ export const customFormIntegrations = [
2424
'GutenaForms',
2525
'PieForms',
2626
'Asgaros',
27-
'AvadaForms'
27+
'AvadaForms',
28+
'FluentCommunity'
2829
]
2930

3031
export const actionHookIntegrations = ['ActionHook']

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,26 @@
22

33
import { create } from 'mutative'
44
import { useEffect, useRef, useState } from 'react'
5+
import toast from 'react-hot-toast'
56
import MultiSelect from 'react-multiple-select-dropdown-lite'
67
import 'react-multiple-select-dropdown-lite/dist/index.css'
78
import { useRecoilState, useSetRecoilState } from 'recoil'
89
import { $formFields, $newFlow } from '../../GlobalStates'
910
import bitsFetch from '../../Utils/bitsFetch'
1011
import { __ } from '../../Utils/i18nwrap'
1112
import LoaderSm from '../Loaders/LoaderSm'
12-
import toast from 'react-hot-toast'
13-
import { deepCopy } from '../../Utils/Helpers'
13+
14+
const shouldSkipPrimaryKey = (flow) => flow?.flow_details?.multi_form && flow?.flow_details?.multi_form?.some(
15+
({ triggered_entity_id, skipPrimaryKey }) => (triggered_entity_id === flow?.triggered_entity_id && skipPrimaryKey)
16+
)
1417

1518
function EditCustomFormSubmissionInteg({ setSnackbar }) {
1619
const [flow, setFlow] = useRecoilState($newFlow)
1720
const setFormFields = useSetRecoilState($formFields)
1821
const [isLoading, setIsLoading] = useState(false)
22+
const [skipPrimaryKey, setSkipPrimaryKey] = useState(shouldSkipPrimaryKey(flow) || false)
1923
const intervalRef = useRef(null)
24+
2025
let controller = new AbortController()
2126
const signal = controller.signal
2227
const fetchAction = flow?.flow_details?.fetch?.action || ''
@@ -95,14 +100,14 @@ function EditCustomFormSubmissionInteg({ setSnackbar }) {
95100
}
96101
}, [])
97102

98-
const setTriggerEntityId = (val) => {
103+
const setTriggerEntityId = (entityId) => {
99104
if (flow?.triggered_entity_id) {
100105
removeTestData()
101106
}
102107

103108
setFlow((prevFlow) =>
104109
create(prevFlow, (draftFlow) => {
105-
draftFlow.triggered_entity_id = val
110+
draftFlow.triggered_entity_id = entityId
106111
draftFlow.flow_details['fields'] = []
107112
draftFlow.flow_details['primaryKey'] = undefined
108113

@@ -113,6 +118,13 @@ function EditCustomFormSubmissionInteg({ setSnackbar }) {
113118
}
114119
})
115120
)
121+
122+
const multiForm = flow.flow_details?.multi_form;
123+
const requiresPrimaryKey = multiForm?.some(
124+
({ triggered_entity_id, skipPrimaryKey: isSkipPrimaryKey }) => triggered_entity_id === entityId && isSkipPrimaryKey
125+
);
126+
127+
setSkipPrimaryKey(requiresPrimaryKey);
116128
setFormFields([])
117129
}
118130

@@ -138,9 +150,9 @@ function EditCustomFormSubmissionInteg({ setSnackbar }) {
138150
)}
139151
{flow?.triggered_entity_id && (
140152
<div className="flx">
141-
<b className="wdt-200 d-in-b">{__('Unique Key:', 'bit-integrations')}</b>
153+
<b className="wdt-200 d-in-b">{skipPrimaryKey ? __('Fetch Again:', 'bit-integrations') : __('Unique Key:', 'bit-integrations')}</b>
142154
<div className="w-5 flx flx-between">
143-
<MultiSelect
155+
{!skipPrimaryKey && <MultiSelect
144156
options={flow.flow_details.fields?.map((field) => ({
145157
label: field?.label,
146158
value: field?.name
@@ -154,7 +166,7 @@ function EditCustomFormSubmissionInteg({ setSnackbar }) {
154166
onChange={primaryKeySet}
155167
disabled={isLoading}
156168
closeOnSelect
157-
/>
169+
/>}
158170
<button
159171
onClick={handleFetch}
160172
className={`btn btcd-btn-lg sh-sm flx ml-1 ${isLoading ? 'red' : 'purple'}`}

frontend-dev/src/components/Triggers/CustomFormSubmission.jsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ const CustomFormSubmission = () => {
2727
const setFlowStep = useSetRecoilState($flowStep)
2828
const setFormFields = useSetRecoilState($formFields)
2929
const [primaryKey, setPrimaryKey] = useState()
30+
const [skipPrimaryKey, setSkipPrimaryKey] = useState(false)
3031
const [primaryKeyModal, setPrimaryKeyModal] = useState(false)
3132
const [isLoading, setIsLoading] = useState(false)
3233
const [snack, setSnackbar] = useState({ show: false })
3334
const [showResponse, setShowResponse] = useState(false)
3435
const intervalRef = useRef(null)
36+
3537
let controller = new AbortController()
3638
const signal = controller.signal
3739
const fetchAction = newFlow?.triggerDetail?.fetch?.action || ''
@@ -40,7 +42,7 @@ const CustomFormSubmission = () => {
4042
const removeMethod = newFlow?.triggerDetail?.fetch_remove?.method || ''
4143

4244
const setTriggerData = () => {
43-
if (!primaryKey) {
45+
if (!primaryKey && !skipPrimaryKey) {
4446
toast.error(__('Please Select a Primary Key', 'bit-integrations'))
4547
return
4648
}
@@ -51,7 +53,7 @@ const CustomFormSubmission = () => {
5153

5254
const tmpNewFlow = { ...newFlow }
5355
tmpNewFlow.triggerData = {
54-
primaryKey: primaryKey,
56+
primaryKey: skipPrimaryKey ? false : primaryKey,
5557
trigger_type: newFlow?.triggerDetail?.type || 'custom_form_submission',
5658
fields: tmpNewFlow.triggerDetail.data,
5759
fetch: newFlow?.triggerDetail?.fetch,
@@ -145,7 +147,7 @@ const CustomFormSubmission = () => {
145147
}
146148
}, [])
147149

148-
const setTriggerEntityId = (val) => {
150+
const setTriggerEntityId = (entityId) => {
149151
if (isLoading) {
150152
clearInterval(intervalRef.current)
151153
controller.abort()
@@ -156,9 +158,17 @@ const CustomFormSubmission = () => {
156158

157159
setNewFlow((prevFlow) =>
158160
create(prevFlow, (draftFlow) => {
159-
draftFlow.triggerDetail.triggered_entity_id = val
161+
draftFlow.triggerDetail.triggered_entity_id = entityId
162+
delete draftFlow.triggerDetail.data
160163
})
161164
)
165+
166+
const multiForm = newFlow?.triggerDetail?.multi_form;
167+
const requiresPrimaryKey = multiForm?.some(
168+
({ triggered_entity_id, skipPrimaryKey: isSkipPrimaryKey }) => triggered_entity_id === entityId && isSkipPrimaryKey
169+
);
170+
171+
setSkipPrimaryKey(requiresPrimaryKey);
162172
}
163173

164174
const info = `<h4>${sprintf(__('Follow these simple steps to set up the %s', 'bit-integrations'), newFlow?.triggerDetail?.name)}</h4>
@@ -201,7 +211,7 @@ const CustomFormSubmission = () => {
201211
{newFlow?.triggerDetail?.triggered_entity_id && (
202212
<>
203213
<SnackMsg snack={snack} setSnackbar={setSnackbar} />
204-
<div className={`flx mt-2 flx-${newFlow.triggerDetail?.data ? 'between' : 'around'}`}>
214+
<div className={`flx mt-2 flx-${newFlow.triggerDetail?.data && !skipPrimaryKey ? 'between' : 'around'}`}>
205215
<button
206216
onClick={handleFetch}
207217
className={`btn btcd-btn-lg sh-sm flx ${isLoading ? 'red' : 'purple'}`}
@@ -213,7 +223,7 @@ const CustomFormSubmission = () => {
213223
: __('Fetch', 'bit-integrations')}
214224
{isLoading && <LoaderSm size="20" clr="#022217" className="ml-2" />}
215225
</button>
216-
{newFlow.triggerDetail?.data?.length > 0 && (
226+
{newFlow.triggerDetail?.data?.length > 0 && !skipPrimaryKey && (
217227
<button
218228
onClick={() => setPrimaryKeyModal(true)}
219229
className={`btn btcd-btn-lg sh-sm flx ${newFlow.triggerDetail?.data?.length > 0 && 'purple'}`}
@@ -279,7 +289,7 @@ const CustomFormSubmission = () => {
279289
onClick={setTriggerData}
280290
className="btn btcd-btn-lg purple sh-sm flx"
281291
type="button"
282-
disabled={!newFlow.triggerDetail.data.length || !primaryKey}>
292+
disabled={!newFlow.triggerDetail.data.length || (!primaryKey && !skipPrimaryKey)}>
283293
{__('Set Action', 'bit-integrations')}
284294
</button>
285295
</div>
18.8 KB
Loading

frontend-dev/src/resource/sass/app.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4768,6 +4768,10 @@ _:-ms-fullscreen,
47684768
justify-content: start;
47694769
}
47704770

4771+
.flx-end {
4772+
justify-content: end;
4773+
}
4774+
47714775
.w-nwrp {
47724776
white-space: nowrap;
47734777
}

includes/Core/Util/AllTriggersName.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public static function allTriggersName()
3535
'FF' => ['name' => 'Fluent Forms', 'isPro' => true, 'is_active' => false],
3636
'FluentBooking' => ['name' => 'Fluent Booking', 'isPro' => true, 'is_active' => false],
3737
'FluentCrm' => ['name' => 'Fluent CRM', 'isPro' => true, 'is_active' => false],
38+
'FluentCommunity' => ['name' => 'Fluent Community', 'isPro' => true, 'is_active' => false],
3839
'FluentSupport' => ['name' => 'Fluent Support', 'isPro' => true, 'is_active' => false],
3940
'FormCraft' => ['name' => 'FormCraft3', 'isPro' => true, 'is_active' => false],
4041
'Formidable' => ['name' => 'Formidable', 'isPro' => true, 'is_active' => false],

includes/Core/Util/Helper.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -310,13 +310,16 @@ public static function isPrimaryKeysMatch($recordData, $PrimaryKeys)
310310
return true;
311311
}
312312

313-
public static function setTestData($optionKey, $formData, $primaryKey, $primaryKeyId)
313+
public static function setTestData($optionKey, $formData, $primaryKey = null, $primaryKeyId = null)
314314
{
315315
if (get_option($optionKey) !== false) {
316-
update_option($optionKey, [
317-
'formData' => $formData,
318-
'primaryKey' => [(object) ['key' => $primaryKey, 'value' => $primaryKeyId]]
319-
]);
316+
$value = ['formData' => $formData];
317+
318+
if (!empty($primaryKey) && !empty($primaryKeyId)) {
319+
$value['primaryKey'] = [(object) ['key' => $primaryKey, 'value' => $primaryKeyId]];
320+
}
321+
322+
update_option($optionKey, $value);
320323
}
321324
}
322325

@@ -355,6 +358,10 @@ public static function prepareFetchFormatFields(array $data, $path = '', $format
355358

356359
public static function flattenNestedData($resultArray, $parentKey, $nestedData)
357360
{
361+
if (\is_object($nestedData)) {
362+
$nestedData = !empty($nestedData->getAttributes()) ? $nestedData->getAttributes() : wp_json_encode($nestedData);
363+
}
364+
358365
if (!(\is_array($nestedData) || \is_object($nestedData))) {
359366
return $resultArray;
360367
}

0 commit comments

Comments
 (0)