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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { SmartTagField } from '../../../Utils/StaticData/SmartTagField'
import { $btcbi } from '../../../GlobalStates'
import { generateMappedField } from './AsanaCommonFunc'
import CustomField from './CustomField'
import TagifyInput from '../../Utilities/TagifyInput'
import { handleCustomValue } from '../IntegrationHelpers/IntegrationHelpers'

export default function AsanaFieldMap({ i, formFields, field, asanaConf, setAsanaConf }) {
let allFields = []
Expand Down Expand Up @@ -61,14 +63,14 @@ export default function AsanaFieldMap({ i, formFields, field, asanaConf, setAsan
</select>

{field.formField === 'custom' && (
<CustomField
field={field}
index={i}
conf={asanaConf}
setConf={setAsanaConf}
fieldValue="customValue"
fieldLabel="Custom Value"
<TagifyInput
onChange={(e) => handleCustomValue(e, i, asanaConf, setAsanaConf)}
label={__('Custom Value', 'bit-integrations')}
className="mr-2"
type="text"
value={field.customValue}
placeholder={__('Custom Value', 'bit-integrations')}
formFields={formFields}
/>
)}

Expand Down
5 changes: 4 additions & 1 deletion frontend-dev/src/components/Utilities/WebhookDataTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default function WebhookDataTable({ data, flow, setFlow }) {

const types = [
{ key: 'text', value: 'text' },
{ key: 'boolean', value: 'true/false' },
{ key: 'email', value: 'email' },
{ key: 'select', value: 'select' },
{ key: 'radio', value: 'radio' },
Expand All @@ -21,7 +22,9 @@ export default function WebhookDataTable({ data, flow, setFlow }) {
{ key: 'url', value: 'url' },
{ key: 'file', value: 'file' },
{ key: 'array', value: 'array' },
{ key: 'object', value: 'object' }
{ key: 'object', value: 'object' },
{ key: 'NULL', value: 'null' },
{ key: 'unknown', value: 'unknown' }
]

return (
Expand Down
19 changes: 5 additions & 14 deletions includes/Actions/Asana/RecordApiHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

namespace BitCode\FI\Actions\Asana;

use BitCode\FI\Core\Util\HttpHelper;
use BitCode\FI\Log\LogHandler;
use BitCode\FI\Core\Util\Common;
use BitCode\FI\Core\Util\HttpHelper;

/**
* Provide functionality for Record insert, upsert
Expand Down Expand Up @@ -87,19 +88,9 @@ public function generateReqDataFromFieldMap($data, $fieldMap)
foreach ($fieldMap as $value) {
$triggerValue = $value->formField;
$actionValue = $value->asanaFormField;
if ($triggerValue === 'custom') {
if ($actionValue === 'fields') {
$dataFinal[$value->customFieldKey] = $value->customValue;
} else {
$dataFinal[$actionValue] = $value->customValue;
}
} elseif (!\is_null($data[$triggerValue])) {
if ($actionValue === 'fields') {
$dataFinal[$value->customFieldKey] = $data[$triggerValue];
} else {
$dataFinal[$actionValue] = $data[$triggerValue];
}
}

$fieldKey = $actionValue === 'fields' ? $value->customFieldKey : $actionValue;
$dataFinal[$fieldKey] = $triggerValue === 'custom' && isset($value->customValue) ? Common::replaceFieldWithValue($value->customValue, $data) : $data[$triggerValue] ?? null;
}

return $dataFinal;
Expand Down
64 changes: 40 additions & 24 deletions includes/Actions/FluentSupport/RecordApiHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

namespace BitCode\FI\Actions\FluentSupport;

use BitCode\FI\Core\Util\Common;
use BitCode\FI\Core\Util\Helper as BtcbiHelper;
use BitCode\FI\Log\LogHandler;
use FluentSupport\App\Models\Customer;
use BitCode\FI\Core\Util\Common;
use FluentSupport\App\Models\Ticket;
use FluentSupport\App\Models\Customer;
use FluentSupport\App\Services\Helper;
use BitCode\FI\Core\Util\Helper as BtcbiHelper;

/**
* Provide functionality for Record insert, upsert
Expand All @@ -32,14 +32,13 @@ public function generateReqDataFromFieldMap($data, $fieldMap)
foreach ($fieldMap as $key => $value) {
$triggerValue = $value->formField;
$actionValue = $value->fluentSupportFormField;
if ($triggerValue === 'custom' && str_starts_with($actionValue, 'cf_')) {
$dataFinal['custom_fields'][$actionValue] = Common::replaceFieldWithValue($value->customValue, $data);
} elseif ($triggerValue === 'custom') {
$dataFinal[$actionValue] = Common::replaceFieldWithValue($value->customValue, $data);
} elseif (str_starts_with($actionValue, 'cf_')) {
$dataFinal['custom_fields'][$actionValue] = $data[$triggerValue];

$value = $triggerValue === 'custom' && isset($value->customValue) ? Common::replaceFieldWithValue($value->customValue, $data) : $data[$triggerValue] ?? null;

if (str_starts_with($actionValue, 'cf_')) {
$dataFinal['custom_fields'][$actionValue] = $value;
} elseif (!\is_null($data[$triggerValue])) {
$dataFinal[$actionValue] = $data[$triggerValue];
$dataFinal[$actionValue] = $value;
}
}

Expand Down Expand Up @@ -80,24 +79,41 @@ public function createTicketByExistCustomer($finalData, $customer, $attachments

$ticket = Ticket::create($finalData);

if (isset($ticket->id)) {
if (isset($finalData['custom_fields']) && \is_array($finalData['custom_fields'])) {
$ticket->syncCustomFields([$finalData['custom_fields']]);
}
if (!isset($ticket->id)) {
wp_send_json_error(
__(
'Create Ticket Failed!',
'bit-integrations'
),
400
);
}

if (isset($finalData['custom_fields']) && \is_array($finalData['custom_fields'])) {
$fields = apply_filters('fluent_support/ticket_custom_fields', []);

if (!empty($attachments)) {
static::uploadTicketFiles($finalData, $attachments, $ticket, $finalData['customer_id'], $this->_integrationID);
if (!empty($fields)) {
$customFields = [];
$keys = array_keys($fields);
$validData = array_intersect_key($finalData['custom_fields'], array_flip($keys));

foreach ($validData as $dataKey => $value) {
if ($fields[$dataKey]['type'] == 'checkbox') {
$customFields[$dataKey] = \is_array($value) ? $value : explode(',', $value);
} else {
$customFields[$dataKey] = $value;
}
}

$ticket->syncCustomFields($customFields);
}
}

return $ticket;
if (!empty($attachments)) {
static::uploadTicketFiles($finalData, $attachments, $ticket, $finalData['customer_id'], $this->_integrationID);
}
wp_send_json_error(
__(
'Create Ticket Failed!',
'bit-integrations'
),
400
);

return $ticket;
}

public function execute(
Expand Down
24 changes: 20 additions & 4 deletions includes/Core/Util/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,6 @@ public static function setTestData($optionKey, $formData, $primaryKey, $primaryK

public static function prepareFetchFormatFields(array $data, $path = '', $formattedData = [])
{
$formattedData = $formattedData;

foreach ($data as $key => $value) {
if (ctype_upper($key)) {
$key = strtolower($key);
Expand All @@ -335,11 +333,13 @@ public static function prepareFetchFormatFields(array $data, $path = '', $format
if (\is_array($value) || \is_object($value)) {
$formattedData = static::prepareFetchFormatFields((array) $value, $currentPath, $formattedData);
} else {
$label = ucwords(str_replace('_', ' ', $path ? $currentPath : $key)) . ' (' . $value . ')';
$labelValue = \is_string($value) && \strlen($value) > 20 ? substr($value, 0, 20) . '...' : $value;
$label = ucwords(str_replace('_', ' ', $path ? $currentPath : $key));
$label = preg_replace("/\b(\w+)\s+\\1\b/i", '$1', $label) . ' (' . $labelValue . ')';

$formattedData[$currentPath] = [
'name' => $currentPath . '.value',
'type' => 'text',
'type' => static::getVariableType($value),
'label' => $label,
'value' => $value,
];
Expand All @@ -348,4 +348,20 @@ public static function prepareFetchFormatFields(array $data, $path = '', $format

return $formattedData;
}

private static function getVariableType($val)
{
$types = [
'boolean' => 'boolean',
'integer' => 'number',
'double' => 'number',
'string' => 'text',
'array' => 'array',
'resource (closed)' => 'file',
'NULL' => 'textarea',
'unknown type' => 'unknown'
];

return $types[\gettype($val)] ?? 'text';
}
}