-
Notifications
You must be signed in to change notification settings - Fork 1
User Registration and Membership Integration added #140
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
+957
−4
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
29d6472
feat: user registration and membership integration added
RishadAlam 43eacf9
fix: user registration blank page issue
RishadAlam e441053
feat: user registration membership action doc link added
RishadAlam 46db2ec
fix: select action logo names
RishadAlam a7bd585
Merge branch 'main' into feat/user-registration
RishadAlam cb73c4c
refactor: userRegistrationMembership action directories
RishadAlam 831b7f4
refactor: userRegistrationMembership action old directories removed
RishadAlam f53f066
refactor: user registration and membership sanitize code
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
82 changes: 82 additions & 0 deletions
82
backend/Actions/UserRegistrationMembership/RecordApiHelper.php
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,82 @@ | ||
| <?php | ||
|
|
||
| namespace BitApps\Integrations\Actions\UserRegistrationMembership; | ||
|
|
||
| use BitApps\Integrations\Config; | ||
| use BitApps\Integrations\Core\Util\Common; | ||
| use BitApps\Integrations\Log\LogHandler; | ||
|
|
||
| /** | ||
| * Provide functionality for User Registration and Membership integration. | ||
| */ | ||
| 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('UserRegistration')) { | ||
| $response = [ | ||
| 'success' => false, | ||
| 'message' => __('User Registration and Membership is not installed or activated', 'bit-integrations') | ||
| ]; | ||
|
|
||
| LogHandler::save($this->_integrationID, ['type' => 'User Registration', 'type_name' => 'check'], 'error', $response); | ||
|
|
||
| return $response; | ||
| } | ||
|
|
||
| $fieldData = $this->generateReqDataFromFieldMap($fieldMap, $fieldValues); | ||
| $mainAction = $this->_integrationDetails->mainAction ?? 'create_user'; | ||
| $response = $this->processAction($mainAction, $fieldData); | ||
|
|
||
| $responseType = !empty($response['success']) ? 'success' : 'error'; | ||
| LogHandler::save($this->_integrationID, ['type' => 'User Registration', 'type_name' => $mainAction], $responseType, $response); | ||
|
|
||
| return $response; | ||
| } | ||
|
|
||
| private function processAction($mainAction, $fieldData) | ||
| { | ||
| $defaultResponse = [ | ||
| 'success' => false, | ||
| 'message' => wp_sprintf(__('%s plugin is not installed or activated', 'bit-integrations'), 'Bit Integrations Pro') | ||
| ]; | ||
|
|
||
| switch ($mainAction) { | ||
| case 'create_user': | ||
| return apply_filters(Config::withPrefix('user_registration_create_user'), $defaultResponse, $fieldData, $this->_integrationDetails); | ||
|
|
||
| default: | ||
| return [ | ||
| 'success' => false, | ||
| 'message' => __('Invalid action', 'bit-integrations') | ||
| ]; | ||
| } | ||
| } | ||
|
|
||
| private function generateReqDataFromFieldMap($fieldMap, $fieldValues) | ||
| { | ||
| $dataFinal = []; | ||
|
|
||
| foreach ($fieldMap as $item) { | ||
| if (empty($item->userRegistrationField)) { | ||
| continue; | ||
| } | ||
|
|
||
| $dataFinal[$item->userRegistrationField] = $item->formField === 'custom' && isset($item->customValue) | ||
| ? Common::replaceFieldWithValue($item->customValue, $fieldValues) | ||
| : ($fieldValues[$item->formField] ?? ''); | ||
| } | ||
|
|
||
| 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,12 @@ | ||
| <?php | ||
|
|
||
| if (!defined('ABSPATH')) { | ||
| exit; | ||
| } | ||
|
|
||
| use BitApps\Integrations\Actions\UserRegistrationMembership\UserRegistrationMembershipController; | ||
| use BitApps\Integrations\Core\Util\Route; | ||
|
|
||
| Route::post('user_registration_authorize', [UserRegistrationMembershipController::class, 'userRegistrationAuthorize']); | ||
| Route::post('refresh_user_registration_forms', [UserRegistrationMembershipController::class, 'refreshForms']); | ||
| Route::post('refresh_user_registration_form_fields', [UserRegistrationMembershipController::class, 'refreshFormFields']); |
98 changes: 98 additions & 0 deletions
98
backend/Actions/UserRegistrationMembership/UserRegistrationMembershipController.php
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,98 @@ | ||
| <?php | ||
|
|
||
| namespace BitApps\Integrations\Actions\UserRegistrationMembership; | ||
|
|
||
| use WP_Error; | ||
|
|
||
| /** | ||
| * Provide functionality for User Registration and Membership integration. | ||
| */ | ||
| class UserRegistrationMembershipController | ||
| { | ||
| public static function userRegistrationAuthorize() | ||
| { | ||
| self::checkPluginExists(); | ||
| wp_send_json_success(true); | ||
| } | ||
|
|
||
| public static function refreshForms() | ||
| { | ||
| self::checkPluginExists(); | ||
|
|
||
| $allForms = get_posts([ | ||
| 'post_type' => 'user_registration', | ||
| 'post_status' => 'publish', | ||
| 'orderby' => 'ID', | ||
| 'order' => 'DESC', | ||
| 'no_found_rows' => true, | ||
| 'nopaging' => true, | ||
| ]); | ||
|
|
||
| $forms = array_map( | ||
| fn ($form) => (object) [ | ||
| 'value' => $form->ID, | ||
| 'label' => $form->post_title, | ||
| ], | ||
| $allForms | ||
| ); | ||
|
|
||
| wp_send_json_success(['forms' => $forms], 200); | ||
| } | ||
|
|
||
| public static function refreshFormFields($request) | ||
| { | ||
| self::checkPluginExists(); | ||
|
|
||
| $formId = absint($request->form_id ?? 0); | ||
|
|
||
| if (empty($formId)) { | ||
| wp_send_json_error(__('Form ID is required', 'bit-integrations'), 400); | ||
| } | ||
|
|
||
| $fields = self::getFormFields($formId); | ||
|
|
||
| wp_send_json_success(['fields' => array_values($fields)], 200); | ||
| } | ||
|
|
||
| public function execute($integrationData, $fieldValues) | ||
| { | ||
| $integrationDetails = $integrationData->flow_details; | ||
| $fieldMap = $integrationDetails->field_map ?? []; | ||
|
|
||
| if (empty($fieldMap)) { | ||
| return new WP_Error('field_map_empty', __('Field map is empty', 'bit-integrations')); | ||
| } | ||
|
|
||
| $recordApiHelper = new RecordApiHelper($integrationDetails, $integrationData->id); | ||
|
|
||
| return $recordApiHelper->execute($fieldValues, $fieldMap); | ||
| } | ||
|
|
||
| private static function getFormFields($formId) | ||
| { | ||
| if (!\function_exists('ur_get_form_fields')) { | ||
| return []; | ||
| } | ||
|
|
||
| $formFields = ur_get_form_fields($formId); | ||
|
|
||
| return array_map( | ||
| fn ($field) => (object) [ | ||
| 'label' => $field->general_setting->label ?? $field->field_key, | ||
| 'value' => $field->field_key, | ||
| 'required' => !empty($field->general_setting->required) | ||
| ], | ||
| $formFields | ||
| ); | ||
| } | ||
|
|
||
| private static function checkPluginExists() | ||
| { | ||
| if (!class_exists('UserRegistration')) { | ||
| wp_send_json_error( | ||
| __('User Registration and Membership 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
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
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
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
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
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
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
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
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
75 changes: 75 additions & 0 deletions
75
.../components/AllIntegrations/UserRegistrationMembership/EditUserRegistrationMembership.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,75 @@ | ||
| import { useState } from 'react' | ||
| import { useNavigate, useParams } from 'react-router-dom' | ||
| import { useRecoilState, useRecoilValue } from 'recoil' | ||
| import { $actionConf, $formFields, $newFlow } from '../../../GlobalStates' | ||
| import { __ } from '../../../Utils/i18nwrap' | ||
| import SnackMsg from '../../Utilities/SnackMsg' | ||
| import { saveActionConf } from '../IntegrationHelpers/IntegrationHelpers' | ||
| import IntegrationStepThree from '../IntegrationHelpers/IntegrationStepThree' | ||
| import SetEditIntegComponents from '../IntegrationHelpers/SetEditIntegComponents' | ||
| import { checkMappedFields, handleInput } from './UserRegistrationMembershipCommonFunc' | ||
| import UserRegistrationMembershipIntegLayout from './UserRegistrationMembershipIntegLayout' | ||
|
|
||
| export default function EditUserRegistrationMembership({ allIntegURL }) { | ||
| const navigate = useNavigate() | ||
| const { id } = useParams() | ||
|
|
||
| const [userRegistrationConf, setUserRegistrationConf] = useRecoilState($actionConf) | ||
| const [flow, setFlow] = useRecoilState($newFlow) | ||
| const formFields = useRecoilValue($formFields) | ||
| const [isLoading, setIsLoading] = useState(false) | ||
| const [snack, setSnackbar] = useState({ show: false }) | ||
|
|
||
| return ( | ||
| <div style={{ width: 900 }}> | ||
| <SnackMsg snack={snack} setSnackbar={setSnackbar} /> | ||
|
|
||
| <div className="flx mt-3"> | ||
| <b className="wdt-200 d-in-b">{__('Integration Name:', 'bit-integrations')}</b> | ||
| <input | ||
| className="btcd-paper-inp w-5" | ||
| onChange={e => handleInput(e, userRegistrationConf, setUserRegistrationConf)} | ||
| name="name" | ||
| value={userRegistrationConf.name} | ||
| type="text" | ||
| placeholder={__('Integration Name...', 'bit-integrations')} | ||
| /> | ||
| </div> | ||
| <br /> | ||
|
|
||
| <SetEditIntegComponents entity={flow.triggered_entity} setSnackbar={setSnackbar} /> | ||
|
|
||
| <UserRegistrationMembershipIntegLayout | ||
| formFields={formFields} | ||
| userRegistrationConf={userRegistrationConf} | ||
| setUserRegistrationConf={setUserRegistrationConf} | ||
| setIsLoading={setIsLoading} | ||
| isLoading={isLoading} | ||
| setSnackbar={setSnackbar} | ||
| /> | ||
|
|
||
| <IntegrationStepThree | ||
| edit | ||
| saveConfig={() => | ||
| saveActionConf({ | ||
| flow, | ||
| setFlow, | ||
| allIntegURL, | ||
| conf: userRegistrationConf, | ||
| navigate, | ||
| id, | ||
| edit: 1, | ||
| setIsLoading, | ||
| setSnackbar | ||
| }) | ||
| } | ||
| disabled={!checkMappedFields(userRegistrationConf)} | ||
| isLoading={isLoading} | ||
| dataConf={userRegistrationConf} | ||
| setDataConf={setUserRegistrationConf} | ||
| formFields={formFields} | ||
| /> | ||
| <br /> | ||
| </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.