Skip to content
Open
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
37 changes: 37 additions & 0 deletions backend/Actions/BookingPress/BookingPressController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace BitApps\Integrations\Actions\BookingPress;

use WP_Error;

class BookingPressController
{
public static function isExists()
{
if (!class_exists('BookingPress')) {
wp_send_json_error(
__('BookingPress is not activated or not installed', 'bit-integrations'),
400
);
}
}

public static function bookingPressAuthorize()
{
self::isExists();
wp_send_json_success(true);
}

public function execute($integrationData, $fieldValues)
{
$integrationDetails = $integrationData->flow_details;
$integId = $integrationData->id;
$fieldMap = $integrationDetails->field_map;

if (empty($fieldMap)) {
return new WP_Error('field_map_empty', __('Field map is empty', 'bit-integrations'));
}

return (new RecordApiHelper($integrationDetails, $integId))->execute($fieldValues, $fieldMap);
}
}
118 changes: 118 additions & 0 deletions backend/Actions/BookingPress/RecordApiHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php

namespace BitApps\Integrations\Actions\BookingPress;

use BitApps\Integrations\Config;
use BitApps\Integrations\Core\Util\Common;
use BitApps\Integrations\Core\Util\Hooks;
use BitApps\Integrations\Log\LogHandler;

class RecordApiHelper
{
private $_integrationID;

private $_integrationDetails;

public function __construct($integrationDetails, $integId)
{
$this->_integrationDetails = $integrationDetails;
$this->_integrationID = $integId;
}

public function execute($fieldValues, $fieldMap)
{
if (!class_exists('BookingPress')) {
return [
'success' => false,
'message' => __('BookingPress is not installed or activated', 'bit-integrations'),
];
}

$fieldData = $this->generateReqDataFromFieldMap($fieldMap, $fieldValues);
$mainAction = $this->_integrationDetails->mainAction ?? 'cancel_appointment';

$defaultResponse = [
'success' => false,
// translators: %s: Plugin name
'message' => wp_sprintf(__('%s plugin is not installed or activated', 'bit-integrations'), 'Bit Integrations Pro'),
];
Comment thread
RishadAlam marked this conversation as resolved.

switch ($mainAction) {
case 'cancel_appointment':
$response = Hooks::apply(Config::withPrefix('bookingpress_cancel_appointment'), $defaultResponse, $fieldData);
$type = 'appointment';
$actionType = 'cancel_appointment';

break;

case 'update_appointment_status':
$response = Hooks::apply(Config::withPrefix('bookingpress_update_appointment_status'), $defaultResponse, $fieldData);
$type = 'appointment';
$actionType = 'update_appointment_status';

break;

case 'create_customer':
$response = Hooks::apply(Config::withPrefix('bookingpress_create_customer'), $defaultResponse, $fieldData);
$type = 'customer';
$actionType = 'create_customer';

break;

case 'update_customer':
$response = Hooks::apply(Config::withPrefix('bookingpress_update_customer'), $defaultResponse, $fieldData);
$type = 'customer';
$actionType = 'update_customer';

break;

case 'delete_appointment':
$response = Hooks::apply(Config::withPrefix('bookingpress_delete_appointment'), $defaultResponse, $fieldData);
$type = 'appointment';
$actionType = 'delete_appointment';

break;

case 'delete_customer':
$response = Hooks::apply(Config::withPrefix('bookingpress_delete_customer'), $defaultResponse, $fieldData);
$type = 'customer';
$actionType = 'delete_customer';

break;

default:
$response = [
'success' => false,
'message' => __('Invalid action', 'bit-integrations'),
];
$type = 'BookingPress';
$actionType = 'unknown';

break;
}

$responseType = isset($response['success']) && $response['success'] ? 'success' : 'error';
LogHandler::save($this->_integrationID, ['type' => $type, 'type_name' => $actionType], $responseType, $response);

return $response;
}

private function generateReqDataFromFieldMap($fieldMap, $fieldValues)
Comment thread
RishadAlam marked this conversation as resolved.
{
$dataFinal = [];
foreach ($fieldMap as $item) {
if (empty($item->formField) || empty($item->bookingPressField)) {
continue;
}

$triggerValue = $item->formField;
$actionValue = $item->bookingPressField;

$dataFinal[$actionValue] = $triggerValue === 'custom' && isset($item->customValue)
? Common::replaceFieldWithValue($item->customValue, $fieldValues)
: $fieldValues[$triggerValue] ?? '';
}

return $dataFinal;
}
}
10 changes: 10 additions & 0 deletions backend/Actions/BookingPress/Routes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

if (!defined('ABSPATH')) {
exit;
}

use BitApps\Integrations\Actions\BookingPress\BookingPressController;
use BitApps\Integrations\Core\Util\Route;

Route::post('bookingpress_authorize', [BookingPressController::class, 'bookingPressAuthorize']);
1 change: 1 addition & 0 deletions backend/Core/Util/AllTriggersName.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public static function allTriggersName()
'Buddypress' => ['name' => 'Buddypress', 'isPro' => true, 'is_active' => false],
'BbPress' => ['name' => 'bbPress', 'isPro' => true, 'is_active' => false],
'BookingCalendarContactForm' => ['name' => 'Booking Calendar Contact Form', 'isPro' => true, 'is_active' => false],
'BookingPress' => ['name' => 'BookingPress', 'isPro' => true, 'is_active' => false],
'CalculatedFieldsForm' => ['name' => 'Calculated Fields Form Pro', 'isPro' => true, 'is_active' => false],
'CartFlow' => ['name' => 'CartFlow', 'isPro' => true, 'is_active' => false],
'CustomTrigger' => ['name' => 'Custom Trigger', 'isPro' => true, 'is_active' => false],
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/Utils/StaticData/tutorialLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,10 @@ const tutorialLinks = {
userRegistrationMembership: {
youTubeLink: '',
docLink: 'https://bit-integrations.com/wp-docs/actions/user-registration-and-membership-as-action/'
},
bookingPress: {
youTubeLink: '',
docLink: ''
}
}
export default tutorialLinks
1 change: 1 addition & 0 deletions frontend/src/Utils/StaticData/webhookIntegrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export const customFormIntegrations = [
'WeDocs',
'UserRegistrationMembership',
'UltimateAffiliatePro',
'BookingPress',
]

export const actionHookIntegrations = ['ActionHook']
Expand Down
102 changes: 102 additions & 0 deletions frontend/src/components/AllIntegrations/BookingPress/BookingPress.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { useState } from 'react'
import 'react-multiple-select-dropdown-lite/dist/index.css'
import { useNavigate, useParams } from 'react-router'
import BackIcn from '../../../Icons/BackIcn'
import { __ } from '../../../Utils/i18nwrap'
import SnackMsg from '../../Utilities/SnackMsg'
import { saveIntegConfig } from '../IntegrationHelpers/IntegrationHelpers'
import IntegrationStepThree from '../IntegrationHelpers/IntegrationStepThree'
import BookingPressAuthorization from './BookingPressAuthorization'
import { checkMappedFields } from './BookingPressCommonFunc'
import BookingPressIntegLayout from './BookingPressIntegLayout'

export default function BookingPress({ formFields, setFlow, flow, allIntegURL }) {
const navigate = useNavigate()
const [isLoading, setIsLoading] = useState(false)
Comment thread
RishadAlam marked this conversation as resolved.
const [step, setStep] = useState(1)
const [snack, setSnackbar] = useState({ show: false })
const [bookingPressConf, setBookingPressConf] = useState({
name: 'BookingPress',
type: 'BookingPress',
field_map: [{ formField: '', bookingPressField: '' }],
mainAction: '',
})

const nextPage = val => {
setTimeout(() => {
document.getElementById('btcd-settings-wrp').scrollTop = 0
}, 300)

if (val === 3) {
if (!checkMappedFields(bookingPressConf)) {
setSnackbar({
show: true,
msg: __('Please map all required fields to continue.', 'bit-integrations'),
})
return
}

if (bookingPressConf.name !== '' && bookingPressConf.field_map.length > 0) {
setStep(val)
}
} else {
setStep(val)
}
}

return (
<div>
<SnackMsg snack={snack} setSnackbar={setSnackbar} />
<div className="txt-center mt-2" />

{/* STEP 1 */}
<BookingPressAuthorization
Comment thread
RishadAlam marked this conversation as resolved.
bookingPressConf={bookingPressConf}
setBookingPressConf={setBookingPressConf}
step={step}
nextPage={nextPage}
isLoading={isLoading}
setIsLoading={setIsLoading}
Comment thread
RishadAlam marked this conversation as resolved.
setSnackbar={setSnackbar}
/>

{/* STEP 2 */}
<div
className="btcd-stp-page"
style={{
width: step === 2 && 900,
height: step === 2 && 'auto',
minHeight: step === 2 && '500px',
}}>
<BookingPressIntegLayout
formFields={formFields}
bookingPressConf={bookingPressConf}
setBookingPressConf={setBookingPressConf}
setSnackbar={setSnackbar}
setIsLoading={setIsLoading}
isLoading={isLoading}
/>
<br />
<br />
<br />
<button
onClick={() => nextPage(3)}
disabled={bookingPressConf.field_map.length < 1}
className="btn f-right btcd-btn-lg purple sh-sm flx"
type="button">
{__('Next', 'bit-integrations')}
<BackIcn className="ml-1 rev-icn" />
</button>
</div>

{/* STEP 3 */}
<IntegrationStepThree
step={step}
saveConfig={() =>
saveIntegConfig(flow, setFlow, allIntegURL, bookingPressConf, navigate, '', '', setIsLoading)
}
isLoading={isLoading}
/>
</div>
)
}
Loading
Loading