-
Notifications
You must be signed in to change notification settings - Fork 1
Asgaros Forum Integration added #148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1a4fd6b
feat: asgaros new action init
RishadAlam 76cbac7
Merge branch 'main' into feat/asgaros-action
RishadAlam a1f6fe2
refactor: asgaros forum actions
RishadAlam 67b51ed
refactor: asgaros forum component imports
RishadAlam 35fc811
Merge branch 'main' into feat/asgaros-action
RishadAlam 3863379
Merge branch 'main' into feat/asgaros-action
RishadAlam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <?php | ||
|
|
||
| namespace BitApps\Integrations\Actions\AsgarosForum; | ||
|
|
||
| /** | ||
| * Provide functionality for Asgaros Forum integration. | ||
| */ | ||
| class AsgarosForumController | ||
| { | ||
| public static function asgarosForumAuthorize() | ||
| { | ||
| self::checkPluginExists(); | ||
| wp_send_json_success(true); | ||
| } | ||
|
|
||
| public function execute($integrationData, $fieldValues) | ||
| { | ||
| $integrationDetails = $integrationData->flow_details; | ||
| $fieldMap = $integrationDetails->field_map ?? []; | ||
|
|
||
| $recordApiHelper = new RecordApiHelper($integrationDetails, $integrationData->id); | ||
|
|
||
| return $recordApiHelper->execute($fieldValues, $fieldMap); | ||
| } | ||
|
|
||
| private static function checkPluginExists() | ||
| { | ||
| if (!class_exists('AsgarosForum')) { | ||
| wp_send_json_error(__('Asgaros Forum is not activated or not installed', 'bit-integrations'), 400); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| <?php | ||
|
|
||
| namespace BitApps\Integrations\Actions\AsgarosForum; | ||
|
|
||
| use BitApps\Integrations\Config; | ||
| use BitApps\Integrations\Core\Util\Common; | ||
| use BitApps\Integrations\Core\Util\Hooks; | ||
| use BitApps\Integrations\Log\LogHandler; | ||
|
|
||
| /** | ||
| * Provide functionality for Asgaros Forum record operations. | ||
| */ | ||
| 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('AsgarosForum')) { | ||
| $response = [ | ||
| 'success' => false, | ||
| 'message' => __('Asgaros Forum is not installed or activated', 'bit-integrations'), | ||
| ]; | ||
|
|
||
| LogHandler::save($this->_integrationID, ['type' => 'Asgaros Forum', 'type_name' => 'check'], 'error', $response); | ||
|
|
||
| return $response; | ||
| } | ||
|
|
||
| $mainAction = $this->_integrationDetails->mainAction ?? ''; | ||
| $payload = $this->generateReqDataFromFieldMap($fieldMap, $fieldValues); | ||
|
|
||
| $defaultResponse = [ | ||
| 'success' => false, | ||
| // translators: %s is the plugin name. | ||
| 'message' => wp_sprintf(__('%s plugin is not installed or activated', 'bit-integrations'), 'Bit Integrations Pro'), | ||
| ]; | ||
|
|
||
| switch ($mainAction) { | ||
| case 'create_topic': | ||
| $response = Hooks::apply(Config::withPrefix('asgaros_forum_create_topic'), $defaultResponse, $payload); | ||
| $actionType = 'create_topic'; | ||
|
|
||
| break; | ||
|
|
||
| case 'create_forum': | ||
| $response = Hooks::apply(Config::withPrefix('asgaros_forum_create_forum'), $defaultResponse, $payload); | ||
| $actionType = 'create_forum'; | ||
|
|
||
| break; | ||
|
|
||
| case 'post_reply_in_topic': | ||
| $response = Hooks::apply(Config::withPrefix('asgaros_forum_post_reply_in_topic'), $defaultResponse, $payload); | ||
| $actionType = 'post_reply_in_topic'; | ||
|
|
||
| break; | ||
|
|
||
| case 'subscribe_user_in_forum': | ||
| $response = Hooks::apply(Config::withPrefix('asgaros_forum_subscribe_user_in_forum'), $defaultResponse, $payload); | ||
| $actionType = 'subscribe_user_in_forum'; | ||
|
|
||
| break; | ||
|
|
||
| default: | ||
| $response = [ | ||
| 'success' => false, | ||
| 'message' => __('Invalid action', 'bit-integrations'), | ||
| ]; | ||
| $actionType = 'unknown'; | ||
|
|
||
| break; | ||
| } | ||
|
|
||
| $responseType = !empty($response['success']) ? 'success' : 'error'; | ||
| LogHandler::save($this->_integrationID, ['type' => 'Asgaros Forum', 'type_name' => $actionType], $responseType, $response); | ||
|
|
||
| return $response; | ||
| } | ||
|
|
||
| private function generateReqDataFromFieldMap($fieldMap, $fieldValues) | ||
| { | ||
| $dataFinal = []; | ||
|
|
||
| if (!\is_array($fieldMap)) { | ||
| return $dataFinal; | ||
| } | ||
|
|
||
| foreach ($fieldMap as $item) { | ||
| $triggerValue = $item->formField ?? ''; | ||
| $actionValue = $item->asgarosForumField ?? ''; | ||
|
|
||
| if (empty($actionValue)) { | ||
| continue; | ||
| } | ||
|
|
||
| $dataFinal[$actionValue] = $triggerValue === 'custom' && isset($item->customValue) | ||
| ? Common::replaceFieldWithValue($item->customValue, $fieldValues) | ||
| : ($fieldValues[$triggerValue] ?? ''); | ||
| } | ||
|
|
||
| return $dataFinal; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <?php | ||
|
|
||
| use BitApps\Integrations\Actions\AsgarosForum\AsgarosForumController; | ||
| use BitApps\Integrations\Core\Util\Route; | ||
|
|
||
| Route::post('asgaros_forum_authorize', [AsgarosForumController::class, 'asgarosForumAuthorize']); | ||
106 changes: 106 additions & 0 deletions
106
frontend/src/components/AllIntegrations/AsgarosForum/AsgarosForum.jsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| 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 AsgarosForumAuthorization from './AsgarosForumAuthorization' | ||
| import { checkMappedFields } from './AsgarosForumCommonFunc' | ||
| import AsgarosForumIntegLayout from './AsgarosForumIntegLayout' | ||
|
|
||
| export default function AsgarosForum({ formFields, setFlow, flow, allIntegURL }) { | ||
| const navigate = useNavigate() | ||
| const { formID } = useParams() | ||
| const [isLoading, setIsLoading] = useState(false) | ||
| const [step, setStep] = useState(1) | ||
| const [snack, setSnackbar] = useState({ show: false }) | ||
| const [asgarosForumConf, setAsgarosForumConf] = useState({ | ||
| name: 'Asgaros Forum', | ||
| type: 'Asgaros Forum', | ||
| field_map: [], | ||
| asgarosForumFields: [], | ||
| actions: {}, | ||
| mainAction: '' | ||
| }) | ||
|
|
||
| const nextPage = val => { | ||
| setTimeout(() => { | ||
| const settingsWrapper = document.getElementById('btcd-settings-wrp') | ||
| if (settingsWrapper) settingsWrapper.scrollTop = 0 | ||
| }, 300) | ||
|
|
||
| if (val === 3) { | ||
| if (!checkMappedFields(asgarosForumConf)) { | ||
| setSnackbar({ | ||
| show: true, | ||
| msg: __('Please complete all required fields to continue.', 'bit-integrations') | ||
| }) | ||
| return | ||
| } | ||
|
|
||
| if (asgarosForumConf.name !== '') { | ||
| setStep(val) | ||
| } | ||
| return | ||
| } | ||
|
|
||
| setStep(val) | ||
| } | ||
|
|
||
| return ( | ||
| <div> | ||
| <SnackMsg snack={snack} setSnackbar={setSnackbar} /> | ||
| <div className="txt-center mt-2" /> | ||
|
|
||
| <AsgarosForumAuthorization | ||
| formID={formID} | ||
| asgarosForumConf={asgarosForumConf} | ||
| setAsgarosForumConf={setAsgarosForumConf} | ||
| step={step} | ||
| nextPage={nextPage} | ||
| isLoading={isLoading} | ||
| setIsLoading={setIsLoading} | ||
| setSnackbar={setSnackbar} | ||
| /> | ||
|
|
||
| <div | ||
| className="btcd-stp-page" | ||
| style={{ | ||
| width: step === 2 && 900, | ||
| height: step === 2 && 'auto', | ||
| minHeight: step === 2 && `${500}px` | ||
RishadAlam marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }}> | ||
| <AsgarosForumIntegLayout | ||
| formID={formID} | ||
| formFields={formFields} | ||
| asgarosForumConf={asgarosForumConf} | ||
| setAsgarosForumConf={setAsgarosForumConf} | ||
| setSnackbar={setSnackbar} | ||
| setIsLoading={setIsLoading} | ||
| isLoading={isLoading} | ||
| /> | ||
| <br /> | ||
| <br /> | ||
| <br /> | ||
RishadAlam marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <button | ||
| onClick={() => nextPage(3)} | ||
| disabled={!asgarosForumConf.mainAction || !checkMappedFields(asgarosForumConf)} | ||
| className="btn f-right btcd-btn-lg purple sh-sm flx" | ||
| type="button"> | ||
| {__('Next', 'bit-integrations')} | ||
| <BackIcn className="ml-1 rev-icn" /> | ||
| </button> | ||
| </div> | ||
|
|
||
| <IntegrationStepThree | ||
| step={step} | ||
| saveConfig={() => | ||
| saveIntegConfig(flow, setFlow, allIntegURL, asgarosForumConf, navigate, '', '', setIsLoading) | ||
| } | ||
| isLoading={isLoading} | ||
| /> | ||
| </div> | ||
| ) | ||
| } | ||
81 changes: 81 additions & 0 deletions
81
frontend/src/components/AllIntegrations/AsgarosForum/AsgarosForumAuthorization.jsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import { useState } from 'react' | ||
| import { __ } from '../../../Utils/i18nwrap' | ||
| import LoaderSm from '../../Loaders/LoaderSm' | ||
| import Note from '../../Utilities/Note' | ||
| import { asgarosForumAuthentication } from './AsgarosForumCommonFunc' | ||
|
|
||
| export default function AsgarosForumAuthorization({ | ||
| asgarosForumConf, | ||
| setAsgarosForumConf, | ||
| step, | ||
| nextPage, | ||
| isLoading, | ||
| setIsLoading, | ||
| isInfo | ||
| }) { | ||
| const [isAuthorized, setIsAuthorized] = useState(false) | ||
| const [error, setError] = useState({ name: '' }) | ||
|
|
||
| const handleInput = e => { | ||
| const newConf = { ...asgarosForumConf } | ||
| newConf[e.target.name] = e.target.value | ||
| setAsgarosForumConf(newConf) | ||
| } | ||
|
|
||
| return ( | ||
| <div | ||
| className="btcd-stp-page" | ||
| style={{ ...{ width: step === 1 && 900 }, ...{ height: step === 1 && 'auto' } }}> | ||
RishadAlam marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <div className="mt-3"> | ||
| <b>{__('Integration Name:', 'bit-integrations')}</b> | ||
| </div> | ||
| <input | ||
| className="btcd-paper-inp w-6 mt-1" | ||
| onChange={handleInput} | ||
| name="name" | ||
| value={asgarosForumConf.name} | ||
| type="text" | ||
| placeholder={__('Integration Name...', 'bit-integrations')} | ||
| disabled={isInfo} | ||
| /> | ||
| <div style={{ color: 'red', fontSize: '15px' }}>{error.name}</div> | ||
|
|
||
| <Note | ||
| note={__( | ||
| 'To use Asgaros Forum integration, make sure the Asgaros Forum plugin is installed and active on your site.', | ||
| 'bit-integrations' | ||
| )} | ||
| /> | ||
|
|
||
| {!isInfo && ( | ||
| <> | ||
| <button | ||
| onClick={() => | ||
| asgarosForumAuthentication( | ||
| asgarosForumConf, | ||
| setAsgarosForumConf, | ||
| setError, | ||
| setIsAuthorized, | ||
| setIsLoading | ||
| ) | ||
| } | ||
| className="btn btcd-btn-lg purple sh-sm flx" | ||
| type="button" | ||
| disabled={isAuthorized || isLoading}> | ||
| {isAuthorized ? __('Authorized ✔', 'bit-integrations') : __('Authorize', 'bit-integrations')} | ||
| {isLoading && <LoaderSm size={20} clr="#022217" className="ml-2" />} | ||
| </button> | ||
| <br /> | ||
| <button | ||
| onClick={() => nextPage(2)} | ||
| className="btn f-right btcd-btn-lg purple sh-sm flx" | ||
| type="button" | ||
| disabled={!isAuthorized}> | ||
| {__('Next', 'bit-integrations')} | ||
| <div className="btcd-icn icn-arrow_back rev-icn d-in-b" /> | ||
| </button> | ||
| </> | ||
| )} | ||
| </div> | ||
| ) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.