Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion frontend-dev/src/Utils/StaticData/webhookIntegrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export const customFormIntegrations = [
'GutenaForms',
'PieForms',
'Asgaros',
'AvadaForms'
'AvadaForms',
'FluentCommunity'
]

export const actionHookIntegrations = ['ActionHook']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@

import { create } from 'mutative'
import { useEffect, useRef, useState } from 'react'
import toast from 'react-hot-toast'
import MultiSelect from 'react-multiple-select-dropdown-lite'
import 'react-multiple-select-dropdown-lite/dist/index.css'
import { useRecoilState, useSetRecoilState } from 'recoil'
import { $formFields, $newFlow } from '../../GlobalStates'
import bitsFetch from '../../Utils/bitsFetch'
import { __ } from '../../Utils/i18nwrap'
import LoaderSm from '../Loaders/LoaderSm'
import toast from 'react-hot-toast'
import { deepCopy } from '../../Utils/Helpers'

const shouldSkipPrimaryKey = (flow) => flow?.flow_details?.multi_form && flow?.flow_details?.multi_form?.some(
({ triggered_entity_id, skipPrimaryKey }) => (triggered_entity_id === flow?.triggered_entity_id && skipPrimaryKey)
)

function EditCustomFormSubmissionInteg({ setSnackbar }) {
const [flow, setFlow] = useRecoilState($newFlow)
const setFormFields = useSetRecoilState($formFields)
const [isLoading, setIsLoading] = useState(false)
const [skipPrimaryKey, setSkipPrimaryKey] = useState(shouldSkipPrimaryKey(flow) || false)
const intervalRef = useRef(null)

let controller = new AbortController()
const signal = controller.signal
const fetchAction = flow?.flow_details?.fetch?.action || ''
Expand Down Expand Up @@ -95,14 +100,14 @@ function EditCustomFormSubmissionInteg({ setSnackbar }) {
}
}, [])

const setTriggerEntityId = (val) => {
const setTriggerEntityId = (entityId) => {
if (flow?.triggered_entity_id) {
removeTestData()
}

setFlow((prevFlow) =>
create(prevFlow, (draftFlow) => {
draftFlow.triggered_entity_id = val
draftFlow.triggered_entity_id = entityId
draftFlow.flow_details['fields'] = []
draftFlow.flow_details['primaryKey'] = undefined

Expand All @@ -113,6 +118,13 @@ function EditCustomFormSubmissionInteg({ setSnackbar }) {
}
})
)

const multiForm = flow.flow_details?.multi_form;
const requiresPrimaryKey = multiForm?.some(
({ triggered_entity_id, skipPrimaryKey: isSkipPrimaryKey }) => triggered_entity_id === entityId && isSkipPrimaryKey
);

setSkipPrimaryKey(requiresPrimaryKey);
setFormFields([])
}

Expand All @@ -138,9 +150,9 @@ function EditCustomFormSubmissionInteg({ setSnackbar }) {
)}
{flow?.triggered_entity_id && (
<div className="flx">
<b className="wdt-200 d-in-b">{__('Unique Key:', 'bit-integrations')}</b>
<b className="wdt-200 d-in-b">{skipPrimaryKey ? __('Fetch Again:', 'bit-integrations') : __('Unique Key:', 'bit-integrations')}</b>
<div className="w-5 flx flx-between">
<MultiSelect
{!skipPrimaryKey && <MultiSelect
options={flow.flow_details.fields?.map((field) => ({
label: field?.label,
value: field?.name
Expand All @@ -154,7 +166,7 @@ function EditCustomFormSubmissionInteg({ setSnackbar }) {
onChange={primaryKeySet}
disabled={isLoading}
closeOnSelect
/>
/>}
<button
onClick={handleFetch}
className={`btn btcd-btn-lg sh-sm flx ml-1 ${isLoading ? 'red' : 'purple'}`}
Expand Down
24 changes: 17 additions & 7 deletions frontend-dev/src/components/Triggers/CustomFormSubmission.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ const CustomFormSubmission = () => {
const setFlowStep = useSetRecoilState($flowStep)
const setFormFields = useSetRecoilState($formFields)
const [primaryKey, setPrimaryKey] = useState()
const [skipPrimaryKey, setSkipPrimaryKey] = useState(false)
const [primaryKeyModal, setPrimaryKeyModal] = useState(false)
const [isLoading, setIsLoading] = useState(false)
const [snack, setSnackbar] = useState({ show: false })
const [showResponse, setShowResponse] = useState(false)
const intervalRef = useRef(null)

let controller = new AbortController()
const signal = controller.signal
const fetchAction = newFlow?.triggerDetail?.fetch?.action || ''
Expand All @@ -40,7 +42,7 @@ const CustomFormSubmission = () => {
const removeMethod = newFlow?.triggerDetail?.fetch_remove?.method || ''

const setTriggerData = () => {
if (!primaryKey) {
if (!primaryKey && !skipPrimaryKey) {
toast.error(__('Please Select a Primary Key', 'bit-integrations'))
return
}
Expand All @@ -51,7 +53,7 @@ const CustomFormSubmission = () => {

const tmpNewFlow = { ...newFlow }
tmpNewFlow.triggerData = {
primaryKey: primaryKey,
primaryKey: skipPrimaryKey ? false : primaryKey,
trigger_type: newFlow?.triggerDetail?.type || 'custom_form_submission',
fields: tmpNewFlow.triggerDetail.data,
fetch: newFlow?.triggerDetail?.fetch,
Expand Down Expand Up @@ -145,7 +147,7 @@ const CustomFormSubmission = () => {
}
}, [])

const setTriggerEntityId = (val) => {
const setTriggerEntityId = (entityId) => {
if (isLoading) {
clearInterval(intervalRef.current)
controller.abort()
Expand All @@ -156,9 +158,17 @@ const CustomFormSubmission = () => {

setNewFlow((prevFlow) =>
create(prevFlow, (draftFlow) => {
draftFlow.triggerDetail.triggered_entity_id = val
draftFlow.triggerDetail.triggered_entity_id = entityId
delete draftFlow.triggerDetail.data
})
)

const multiForm = newFlow?.triggerDetail?.multi_form;
const requiresPrimaryKey = multiForm?.some(
({ triggered_entity_id, skipPrimaryKey: isSkipPrimaryKey }) => triggered_entity_id === entityId && isSkipPrimaryKey
);

setSkipPrimaryKey(requiresPrimaryKey);
}

const info = `<h4>${sprintf(__('Follow these simple steps to set up the %s', 'bit-integrations'), newFlow?.triggerDetail?.name)}</h4>
Expand Down Expand Up @@ -201,7 +211,7 @@ const CustomFormSubmission = () => {
{newFlow?.triggerDetail?.triggered_entity_id && (
<>
<SnackMsg snack={snack} setSnackbar={setSnackbar} />
<div className={`flx mt-2 flx-${newFlow.triggerDetail?.data ? 'between' : 'around'}`}>
<div className={`flx mt-2 flx-${newFlow.triggerDetail?.data && !skipPrimaryKey ? 'between' : 'around'}`}>
<button
onClick={handleFetch}
className={`btn btcd-btn-lg sh-sm flx ${isLoading ? 'red' : 'purple'}`}
Expand All @@ -213,7 +223,7 @@ const CustomFormSubmission = () => {
: __('Fetch', 'bit-integrations')}
{isLoading && <LoaderSm size="20" clr="#022217" className="ml-2" />}
</button>
{newFlow.triggerDetail?.data?.length > 0 && (
{newFlow.triggerDetail?.data?.length > 0 && !skipPrimaryKey && (
<button
onClick={() => setPrimaryKeyModal(true)}
className={`btn btcd-btn-lg sh-sm flx ${newFlow.triggerDetail?.data?.length > 0 && 'purple'}`}
Expand Down Expand Up @@ -279,7 +289,7 @@ const CustomFormSubmission = () => {
onClick={setTriggerData}
className="btn btcd-btn-lg purple sh-sm flx"
type="button"
disabled={!newFlow.triggerDetail.data.length || !primaryKey}>
disabled={!newFlow.triggerDetail.data.length || (!primaryKey && !skipPrimaryKey)}>
{__('Set Action', 'bit-integrations')}
</button>
</div>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions frontend-dev/src/resource/sass/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4768,6 +4768,10 @@ _:-ms-fullscreen,
justify-content: start;
}

.flx-end {
justify-content: end;
}

.w-nwrp {
white-space: nowrap;
}
Expand Down
1 change: 1 addition & 0 deletions includes/Core/Util/AllTriggersName.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static function allTriggersName()
'FF' => ['name' => 'Fluent Forms', 'isPro' => true, 'is_active' => false],
'FluentBooking' => ['name' => 'Fluent Booking', 'isPro' => true, 'is_active' => false],
'FluentCrm' => ['name' => 'Fluent CRM', 'isPro' => true, 'is_active' => false],
'FluentCommunity' => ['name' => 'Fluent Community', 'isPro' => true, 'is_active' => false],
'FluentSupport' => ['name' => 'Fluent Support', 'isPro' => true, 'is_active' => false],
'FormCraft' => ['name' => 'FormCraft3', 'isPro' => true, 'is_active' => false],
'Formidable' => ['name' => 'Formidable', 'isPro' => true, 'is_active' => false],
Expand Down
17 changes: 12 additions & 5 deletions includes/Core/Util/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,16 @@ public static function isPrimaryKeysMatch($recordData, $PrimaryKeys)
return true;
}

public static function setTestData($optionKey, $formData, $primaryKey, $primaryKeyId)
public static function setTestData($optionKey, $formData, $primaryKey = null, $primaryKeyId = null)
{
if (get_option($optionKey) !== false) {
update_option($optionKey, [
'formData' => $formData,
'primaryKey' => [(object) ['key' => $primaryKey, 'value' => $primaryKeyId]]
]);
$value = ['formData' => $formData];

if (!empty($primaryKey) && !empty($primaryKeyId)) {
$value['primaryKey'] = [(object) ['key' => $primaryKey, 'value' => $primaryKeyId]];
}

update_option($optionKey, $value);
}
}

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

public static function flattenNestedData($resultArray, $parentKey, $nestedData)
{
if (\is_object($nestedData)) {
$nestedData = !empty($nestedData->getAttributes()) ? $nestedData->getAttributes() : wp_json_encode($nestedData);
}

if (!(\is_array($nestedData) || \is_object($nestedData))) {
return $resultArray;
}
Expand Down