From 9037fa9b7dbb0af8f4ac27079bcfff1d2d68e73a Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Mon, 10 Feb 2025 16:27:52 +0100
Subject: [PATCH 01/13] =?UTF-8?q?=F0=9F=A6=BA=20Losen=20the=20validation?=
=?UTF-8?q?=20rules=20for=20Client=20ID?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Screens/Onboarding/Components/ManualConnectionForm.js | 2 +-
.../ppcp-settings/src/Endpoint/AuthenticationRestEndpoint.php | 1 -
modules/ppcp-settings/src/Service/AuthenticationManager.php | 2 +-
3 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Components/ManualConnectionForm.js b/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Components/ManualConnectionForm.js
index 6602c335b..9524ed553 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Components/ManualConnectionForm.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Components/ManualConnectionForm.js
@@ -96,7 +96,7 @@ const ManualConnectionForm = () => {
// On-the-fly form validation.
useEffect( () => {
setClientValid(
- ! manualClientId || /^A[\w-]{79}$/.test( manualClientId )
+ ! manualClientId || /^[\w-]{80,}$/.test( manualClientId )
);
setSecretValid( manualClientSecret && manualClientSecret.length > 0 );
}, [ manualClientId, manualClientSecret ] );
diff --git a/modules/ppcp-settings/src/Endpoint/AuthenticationRestEndpoint.php b/modules/ppcp-settings/src/Endpoint/AuthenticationRestEndpoint.php
index 7ac964b2d..40c82ffab 100644
--- a/modules/ppcp-settings/src/Endpoint/AuthenticationRestEndpoint.php
+++ b/modules/ppcp-settings/src/Endpoint/AuthenticationRestEndpoint.php
@@ -88,7 +88,6 @@ class AuthenticationRestEndpoint extends RestEndpoint {
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'minLength' => 80,
- 'maxLength' => 80,
),
'clientSecret' => array(
'required' => true,
diff --git a/modules/ppcp-settings/src/Service/AuthenticationManager.php b/modules/ppcp-settings/src/Service/AuthenticationManager.php
index 95acf068b..fc3d8da74 100644
--- a/modules/ppcp-settings/src/Service/AuthenticationManager.php
+++ b/modules/ppcp-settings/src/Service/AuthenticationManager.php
@@ -147,7 +147,7 @@ class AuthenticationManager {
throw new RuntimeException( 'No client ID provided.' );
}
- if ( false === preg_match( '/^A[\w-]{79}$/', $client_secret ) ) {
+ if ( false === preg_match( '/^[\w-]{80,}$/', $client_secret ) ) {
throw new RuntimeException( 'Invalid client ID provided.' );
}
From 5e6f73d30b64ae3103d95fcfc4eeb7b69e45fa22 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Mon, 10 Feb 2025 16:29:09 +0100
Subject: [PATCH 02/13] =?UTF-8?q?=F0=9F=94=A7=20Fix=20psalm=20errors=20whe?=
=?UTF-8?q?n=20node=5Fmodules=20is=20missing?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Due to a modified Mutagen ignore-list, the node_modules folder might not sync with the container; this adjustment fixes psalm errors in those events.
---
psalm.xml.dist | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/psalm.xml.dist b/psalm.xml.dist
index 46f4e8a49..470d5ceb9 100644
--- a/psalm.xml.dist
+++ b/psalm.xml.dist
@@ -28,7 +28,7 @@
-
+
From e09ad9d74d38b159ce0687627f1503e2b9cf3653 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Wed, 12 Feb 2025 13:10:41 +0100
Subject: [PATCH 03/13] :bug: Fix REST response for manual connection
---
.../ppcp-settings/src/Endpoint/AuthenticationRestEndpoint.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/ppcp-settings/src/Endpoint/AuthenticationRestEndpoint.php b/modules/ppcp-settings/src/Endpoint/AuthenticationRestEndpoint.php
index 40c82ffab..23f08631b 100644
--- a/modules/ppcp-settings/src/Endpoint/AuthenticationRestEndpoint.php
+++ b/modules/ppcp-settings/src/Endpoint/AuthenticationRestEndpoint.php
@@ -174,7 +174,7 @@ class AuthenticationRestEndpoint extends RestEndpoint {
}
$account = $this->authentication_manager->get_account_details();
- $response = $this->sanitize_for_javascript( $this->response_map, $account );
+ $response = $this->sanitize_for_javascript( $account, $this->response_map );
return $this->return_success( $response );
}
From 67522b9557bbb4278322a14dd80c47ad38d1904b Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Wed, 12 Feb 2025 13:24:52 +0100
Subject: [PATCH 04/13] =?UTF-8?q?=E2=9C=A8=20Add=20store=20action=20to=20u?=
=?UTF-8?q?pdate=20merchant=20details?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../resources/js/data/common/action-types.js | 1 +
.../ppcp-settings/resources/js/data/common/actions.js | 11 +++++++++++
.../ppcp-settings/resources/js/data/common/reducer.js | 4 ++++
3 files changed, 16 insertions(+)
diff --git a/modules/ppcp-settings/resources/js/data/common/action-types.js b/modules/ppcp-settings/resources/js/data/common/action-types.js
index 4a5569b11..ca44a470e 100644
--- a/modules/ppcp-settings/resources/js/data/common/action-types.js
+++ b/modules/ppcp-settings/resources/js/data/common/action-types.js
@@ -12,6 +12,7 @@ export default {
SET_PERSISTENT: 'ppcp/common/SET_PERSISTENT',
RESET: 'ppcp/common/RESET',
HYDRATE: 'ppcp/common/HYDRATE',
+ SET_MERCHANT: 'ppcp/common/SET_MERCHANT',
RESET_MERCHANT: 'ppcp/common/RESET_MERCHANT',
// Activity management (advanced solution that replaces the isBusy state).
diff --git a/modules/ppcp-settings/resources/js/data/common/actions.js b/modules/ppcp-settings/resources/js/data/common/actions.js
index 4dded01ac..fbbe022de 100644
--- a/modules/ppcp-settings/resources/js/data/common/actions.js
+++ b/modules/ppcp-settings/resources/js/data/common/actions.js
@@ -110,6 +110,17 @@ export const setManualConnectionMode = ( useManualConnection ) =>
export const setWebhooks = ( webhooks ) =>
setPersistent( 'webhooks', webhooks );
+/**
+ * Replace merchant details in the store.
+ *
+ * @param {Object} merchant - The new merchant details.
+ * @return {Action} The action.
+ */
+export const setMerchant = ( merchant ) => ( {
+ type: ACTION_TYPES.SET_MERCHANT,
+ payload: { merchant },
+} );
+
/**
* Reset merchant details in the store.
*
diff --git a/modules/ppcp-settings/resources/js/data/common/reducer.js b/modules/ppcp-settings/resources/js/data/common/reducer.js
index c8fb9a8dc..2f207b335 100644
--- a/modules/ppcp-settings/resources/js/data/common/reducer.js
+++ b/modules/ppcp-settings/resources/js/data/common/reducer.js
@@ -113,6 +113,10 @@ const commonReducer = createReducer( defaultTransient, defaultPersistent, {
features: Object.freeze( { ...defaultTransient.features } ),
} ),
+ [ ACTION_TYPES.SET_MERCHANT ]: ( state, payload ) => {
+ return changePersistent( state, { merchant: payload.merchant } );
+ },
+
[ ACTION_TYPES.HYDRATE ]: ( state, payload ) => {
const newState = changePersistent( state, payload.data );
From 93f517e50ff17a3646df599d405d97ad0f362346 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Wed, 12 Feb 2025 13:25:11 +0100
Subject: [PATCH 05/13] =?UTF-8?q?=F0=9F=90=9B=20Fix=20the=20manual=20conne?=
=?UTF-8?q?ction=20confirmation=20logic?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../resources/js/data/common/hooks.js | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/modules/ppcp-settings/resources/js/data/common/hooks.js b/modules/ppcp-settings/resources/js/data/common/hooks.js
index cd13e02e6..a584c4e99 100644
--- a/modules/ppcp-settings/resources/js/data/common/hooks.js
+++ b/modules/ppcp-settings/resources/js/data/common/hooks.js
@@ -145,18 +145,27 @@ export const useWebhooks = () => {
export const useMerchantInfo = () => {
const { isReady, merchant, features } = useHooks();
- const { refreshMerchantData } = useDispatch( STORE_NAME );
+ const { refreshMerchantData, setMerchant } = useDispatch( STORE_NAME );
const verifyLoginStatus = useCallback( async () => {
const result = await refreshMerchantData();
- if ( ! result.success ) {
+ if ( ! result.success || ! result.merchant ) {
throw new Error( result?.message || result?.error?.message );
}
+ const newMerchant = result.merchant;
+
// Verify if the server state is "connected" and we have a merchant ID.
- return merchant?.isConnected && merchant?.id;
- }, [ refreshMerchantData, merchant ] );
+ if ( newMerchant?.isConnected && newMerchant?.id ) {
+ // Update the verified merchant details in Redux.
+ setMerchant( newMerchant );
+
+ return true;
+ }
+
+ return false;
+ }, [ refreshMerchantData, setMerchant ] );
return {
isReady,
From 1f3a18a6901993e2ee396ea30ee657cd25e93eac Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Wed, 12 Feb 2025 13:26:02 +0100
Subject: [PATCH 06/13] =?UTF-8?q?=E2=8F=AA=EF=B8=8F=20Losen=20the=20valida?=
=?UTF-8?q?tion=20rules=20for=20Client=20ID?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This reverts commit 9037fa9b7dbb0af8f4ac27079bcfff1d2d68e73a.
---
.../Screens/Onboarding/Components/ManualConnectionForm.js | 2 +-
.../ppcp-settings/src/Endpoint/AuthenticationRestEndpoint.php | 1 +
modules/ppcp-settings/src/Service/AuthenticationManager.php | 2 +-
3 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Components/ManualConnectionForm.js b/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Components/ManualConnectionForm.js
index 9524ed553..6602c335b 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Components/ManualConnectionForm.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Components/ManualConnectionForm.js
@@ -96,7 +96,7 @@ const ManualConnectionForm = () => {
// On-the-fly form validation.
useEffect( () => {
setClientValid(
- ! manualClientId || /^[\w-]{80,}$/.test( manualClientId )
+ ! manualClientId || /^A[\w-]{79}$/.test( manualClientId )
);
setSecretValid( manualClientSecret && manualClientSecret.length > 0 );
}, [ manualClientId, manualClientSecret ] );
diff --git a/modules/ppcp-settings/src/Endpoint/AuthenticationRestEndpoint.php b/modules/ppcp-settings/src/Endpoint/AuthenticationRestEndpoint.php
index 23f08631b..55a3b8353 100644
--- a/modules/ppcp-settings/src/Endpoint/AuthenticationRestEndpoint.php
+++ b/modules/ppcp-settings/src/Endpoint/AuthenticationRestEndpoint.php
@@ -88,6 +88,7 @@ class AuthenticationRestEndpoint extends RestEndpoint {
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'minLength' => 80,
+ 'maxLength' => 80,
),
'clientSecret' => array(
'required' => true,
diff --git a/modules/ppcp-settings/src/Service/AuthenticationManager.php b/modules/ppcp-settings/src/Service/AuthenticationManager.php
index fc3d8da74..95acf068b 100644
--- a/modules/ppcp-settings/src/Service/AuthenticationManager.php
+++ b/modules/ppcp-settings/src/Service/AuthenticationManager.php
@@ -147,7 +147,7 @@ class AuthenticationManager {
throw new RuntimeException( 'No client ID provided.' );
}
- if ( false === preg_match( '/^[\w-]{80,}$/', $client_secret ) ) {
+ if ( false === preg_match( '/^A[\w-]{79}$/', $client_secret ) ) {
throw new RuntimeException( 'Invalid client ID provided.' );
}
From 2c4df18728703274f5e67a55fb989f328f07200e Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Wed, 12 Feb 2025 15:24:35 +0100
Subject: [PATCH 07/13] =?UTF-8?q?=F0=9F=92=84=20Display=20loading=20spinne?=
=?UTF-8?q?rs=20while=20authenticating?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../js/hooks/useHandleConnections.js | 29 ++++++++++++-------
1 file changed, 19 insertions(+), 10 deletions(-)
diff --git a/modules/ppcp-settings/resources/js/hooks/useHandleConnections.js b/modules/ppcp-settings/resources/js/hooks/useHandleConnections.js
index f6837c488..55058a82c 100644
--- a/modules/ppcp-settings/resources/js/hooks/useHandleConnections.js
+++ b/modules/ppcp-settings/resources/js/hooks/useHandleConnections.js
@@ -173,6 +173,7 @@ const useConnectionBase = () => {
const { createSuccessNotice, createErrorNotice } =
useDispatch( noticesStore );
const { verifyLoginStatus } = CommonHooks.useMerchantInfo();
+ const { withActivity } = CommonHooks.useBusyState();
return {
handleFailed: ( res, genericMessage ) => {
@@ -180,18 +181,26 @@ const useConnectionBase = () => {
createErrorNotice( res?.message ?? genericMessage );
},
handleCompleted: async () => {
- try {
- const loginSuccessful = await verifyLoginStatus();
+ await withActivity(
+ 'auth',
+ 'Verifying Authentication',
+ async () => {
+ try {
+ const loginSuccessful = await verifyLoginStatus();
- if ( loginSuccessful ) {
- createSuccessNotice( MESSAGES.CONNECTED );
- await setCompleted( true );
- } else {
- createErrorNotice( MESSAGES.LOGIN_FAILED );
+ if ( loginSuccessful ) {
+ createSuccessNotice( MESSAGES.CONNECTED );
+ await setCompleted( true );
+ } else {
+ createErrorNotice( MESSAGES.LOGIN_FAILED );
+ }
+ } catch ( error ) {
+ createErrorNotice(
+ error.message ?? MESSAGES.LOGIN_FAILED
+ );
+ }
}
- } catch ( error ) {
- createErrorNotice( error.message ?? MESSAGES.LOGIN_FAILED );
- }
+ );
},
createErrorNotice,
};
From 7a8a190c3e795d58fec51f447e6803599a8ad8a8 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Wed, 12 Feb 2025 15:29:35 +0100
Subject: [PATCH 08/13] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Rename=20internal=20?=
=?UTF-8?q?busy-state=20IDs?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../resources/js/hooks/useHandleConnections.js | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/modules/ppcp-settings/resources/js/hooks/useHandleConnections.js b/modules/ppcp-settings/resources/js/hooks/useHandleConnections.js
index 55058a82c..2a6423f96 100644
--- a/modules/ppcp-settings/resources/js/hooks/useHandleConnections.js
+++ b/modules/ppcp-settings/resources/js/hooks/useHandleConnections.js
@@ -33,10 +33,9 @@ const MESSAGES = {
};
const ACTIVITIES = {
- CONNECT_SANDBOX: 'ISU_LOGIN_SANDBOX',
- CONNECT_PRODUCTION: 'ISU_LOGIN_PRODUCTION',
- CONNECT_ISU: 'ISU_LOGIN',
- CONNECT_MANUAL: 'MANUAL_LOGIN',
+ OAUTH_VERIFY: 'oauth/login',
+ API_LOGIN: 'auth/api-login',
+ API_VERIFY: 'auth/verify-login',
};
export const useHandleOnboardingButton = ( isSandbox ) => {
@@ -124,7 +123,7 @@ export const useHandleOnboardingButton = ( isSandbox ) => {
* visual cue to the user that something is still processing in the background.
*/
await withActivity(
- ACTIVITIES.CONNECT_ISU,
+ ACTIVITIES.OAUTH_VERIFY,
'Validating the connection details',
async () => {
await authenticateWithOAuth(
@@ -182,7 +181,7 @@ const useConnectionBase = () => {
},
handleCompleted: async () => {
await withActivity(
- 'auth',
+ ACTIVITIES.API_VERIFY,
'Verifying Authentication',
async () => {
try {
@@ -227,7 +226,7 @@ export const useDirectAuthentication = () => {
const handleDirectAuthentication = async ( connectionDetails ) => {
return withActivity(
- ACTIVITIES.CONNECT_MANUAL,
+ ACTIVITIES.API_LOGIN,
'Connecting manually via Client ID and Secret',
async () => {
let data;
From 976b7c987bcd86af85ac6ad3765efb4be520a697 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Wed, 12 Feb 2025 15:31:34 +0100
Subject: [PATCH 09/13] =?UTF-8?q?=F0=9F=94=A5=20Remove=20unused=20messages?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../resources/js/hooks/useHandleConnections.js | 17 +++--------------
1 file changed, 3 insertions(+), 14 deletions(-)
diff --git a/modules/ppcp-settings/resources/js/hooks/useHandleConnections.js b/modules/ppcp-settings/resources/js/hooks/useHandleConnections.js
index 2a6423f96..ce7f0e1e3 100644
--- a/modules/ppcp-settings/resources/js/hooks/useHandleConnections.js
+++ b/modules/ppcp-settings/resources/js/hooks/useHandleConnections.js
@@ -10,19 +10,7 @@ const PAYPAL_PARTNER_SDK_URL =
const MESSAGES = {
CONNECTED: __( 'Connected to PayPal', 'woocommerce-paypal-payments' ),
- POPUP_BLOCKED: __(
- 'Popup blocked. Please allow popups for this site to connect to PayPal.',
- 'woocommerce-paypal-payments'
- ),
- SANDBOX_ERROR: __(
- 'Could not generate a Sandbox login link.',
- 'woocommerce-paypal-payments'
- ),
- PRODUCTION_ERROR: __(
- 'Could not generate a login link.',
- 'woocommerce-paypal-payments'
- ),
- MANUAL_ERROR: __(
+ API_ERROR: __(
'Could not connect to PayPal. Please make sure your Client ID and Secret Key are correct.',
'woocommerce-paypal-payments'
),
@@ -167,6 +155,7 @@ export const useHandleOnboardingButton = ( isSandbox ) => {
};
};
+// Base connection is only used for API login (manual connection).
const useConnectionBase = () => {
const { setCompleted } = OnboardingHooks.useSteps();
const { createSuccessNotice, createErrorNotice } =
@@ -258,7 +247,7 @@ export const useDirectAuthentication = () => {
if ( res.success ) {
await handleCompleted();
} else {
- handleFailed( res, MESSAGES.MANUAL_ERROR );
+ handleFailed( res, MESSAGES.API_ERROR );
}
return res.success;
From 696f8ec6e00ad2158d2ac369986dda0e4643ac38 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Wed, 12 Feb 2025 15:37:20 +0100
Subject: [PATCH 10/13] =?UTF-8?q?=E2=9C=A8=20Expose=20startActivity=20and?=
=?UTF-8?q?=20stopActivity=20actions?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
modules/ppcp-settings/resources/js/data/common/hooks.js | 2 ++
1 file changed, 2 insertions(+)
diff --git a/modules/ppcp-settings/resources/js/data/common/hooks.js b/modules/ppcp-settings/resources/js/data/common/hooks.js
index a584c4e99..f33d55183 100644
--- a/modules/ppcp-settings/resources/js/data/common/hooks.js
+++ b/modules/ppcp-settings/resources/js/data/common/hooks.js
@@ -215,6 +215,8 @@ export const useBusyState = () => {
);
return {
+ startActivity,
+ stopActivity,
withActivity, // HOC
isBusy, // Boolean.
};
From 92a0977ae8a26ce730a5a93ac3113839d11f349b Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Wed, 12 Feb 2025 15:38:55 +0100
Subject: [PATCH 11/13] =?UTF-8?q?=F0=9F=92=84=20Lock=20app=20in=20?=
=?UTF-8?q?=E2=80=9Cloading=20state=E2=80=9D=20in=20last=20oauth=20stage?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
A redirect happens, and the current page should stay locked preventing users from interacting with the wizard before the refresh is finished.
---
.../js/hooks/useHandleConnections.js | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/modules/ppcp-settings/resources/js/hooks/useHandleConnections.js b/modules/ppcp-settings/resources/js/hooks/useHandleConnections.js
index ce7f0e1e3..e605b61ef 100644
--- a/modules/ppcp-settings/resources/js/hooks/useHandleConnections.js
+++ b/modules/ppcp-settings/resources/js/hooks/useHandleConnections.js
@@ -30,7 +30,7 @@ export const useHandleOnboardingButton = ( isSandbox ) => {
const { sandboxOnboardingUrl } = CommonHooks.useSandbox();
const { productionOnboardingUrl } = CommonHooks.useProduction();
const products = OnboardingHooks.useDetermineProducts();
- const { withActivity } = CommonHooks.useBusyState();
+ const { withActivity, startActivity } = CommonHooks.useBusyState();
const { authenticateWithOAuth } = CommonHooks.useAuthentication();
const [ onboardingUrl, setOnboardingUrl ] = useState( '' );
const [ scriptLoaded, setScriptLoaded ] = useState( false );
@@ -110,16 +110,15 @@ export const useHandleOnboardingButton = ( isSandbox ) => {
* frame before the REST endpoint returns a value. Using "withActivity" is more of a
* visual cue to the user that something is still processing in the background.
*/
- await withActivity(
+ startActivity(
ACTIVITIES.OAUTH_VERIFY,
- 'Validating the connection details',
- async () => {
- await authenticateWithOAuth(
- sharedId,
- authCode,
- 'sandbox' === environment
- );
- }
+ 'Validating the connection details'
+ );
+
+ await authenticateWithOAuth(
+ sharedId,
+ authCode,
+ 'sandbox' === environment
);
};
From 0fc0c116530294ee36551fee499513b8d3d05b46 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Wed, 12 Feb 2025 15:57:03 +0100
Subject: [PATCH 12/13] =?UTF-8?q?=E2=9C=A8=20Add=20a=20=E2=80=9ConConfirm?=
=?UTF-8?q?=E2=80=9D=20prop=20to=20DataStoreControl?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../ReusableComponents/DataStoreControl.js | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/modules/ppcp-settings/resources/js/Components/ReusableComponents/DataStoreControl.js b/modules/ppcp-settings/resources/js/Components/ReusableComponents/DataStoreControl.js
index 90bf6dfbd..d336d458c 100644
--- a/modules/ppcp-settings/resources/js/Components/ReusableComponents/DataStoreControl.js
+++ b/modules/ppcp-settings/resources/js/Components/ReusableComponents/DataStoreControl.js
@@ -18,6 +18,7 @@ const DataStoreControl = React.forwardRef(
control: ControlComponent,
value: externalValue,
onChange,
+ onConfirm = null,
delay = 300,
...props
},
@@ -25,7 +26,9 @@ const DataStoreControl = React.forwardRef(
) => {
const [ internalValue, setInternalValue ] = useState( externalValue );
const onChangeRef = useRef( onChange );
+ const onConfirmRef = useRef( onConfirm );
onChangeRef.current = onChange;
+ onConfirmRef.current = onConfirm;
const debouncedUpdate = useRef(
debounce( ( value ) => {
@@ -36,7 +39,7 @@ const DataStoreControl = React.forwardRef(
useEffect( () => {
setInternalValue( externalValue );
debouncedUpdate?.cancel();
- }, [ externalValue ] );
+ }, [ debouncedUpdate, externalValue ] );
useEffect( () => {
return () => debouncedUpdate?.cancel();
@@ -50,12 +53,25 @@ const DataStoreControl = React.forwardRef(
[ debouncedUpdate ]
);
+ const handleKeyDown = useCallback(
+ ( event ) => {
+ if ( onConfirmRef.current && event.key === 'Enter' ) {
+ event.preventDefault();
+ debouncedUpdate.flush();
+ onConfirmRef.current();
+ return false;
+ }
+ },
+ [ debouncedUpdate ]
+ );
+
return (
);
}
From a75204804dc532d0bec705924e340ef4fef51c99 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Wed, 12 Feb 2025 15:58:02 +0100
Subject: [PATCH 13/13] =?UTF-8?q?=E2=9C=A8=20Allow=20manual=20connection?=
=?UTF-8?q?=20by=20pressing=20Enter?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Screens/Onboarding/Components/ManualConnectionForm.js | 2 ++
1 file changed, 2 insertions(+)
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Components/ManualConnectionForm.js b/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Components/ManualConnectionForm.js
index 6602c335b..2c65e21e8 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Components/ManualConnectionForm.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Components/ManualConnectionForm.js
@@ -157,6 +157,7 @@ const ManualConnectionForm = () => {
label={ clientIdLabel }
value={ manualClientId }
onChange={ setManualClientId }
+ onConfirm={ handleManualConnect }
className={ classNames( {
'ppcp--has-error': ! clientValid,
} ) }
@@ -173,6 +174,7 @@ const ManualConnectionForm = () => {
label={ secretKeyLabel }
value={ manualClientSecret }
onChange={ setManualClientSecret }
+ onConfirm={ handleManualConnect }
type="password"
/>