🚧 Begin to refactor the manual connection hook

This commit is contained in:
Philipp Stracker 2024-11-04 16:50:50 +01:00
parent 5a1adc825c
commit c5d7ce211a
No known key found for this signature in database
3 changed files with 41 additions and 18 deletions

View file

@ -168,10 +168,47 @@ export const setProducts = ( products ) => {
};
};
/**
* Attempts to establish a connection using client ID and secret via the server-side
* connection endpoint.
*
* @return {boolean} True if the connection was successful, false otherwise.
*/
export function* connectViaIdAndSecret() {
let error = null;
try {
const path = `${ NAMESPACE }/connect_manual`;
const { clientId, clientSecret, useSandbox } =
yield select( STORE_NAME ).getPersistentData();
yield setManualConnectionIsBusy( true );
const result = yield apiFetch( {
path,
method: 'POST',
data: {
clientId,
clientSecret,
useSandbox,
},
} );
console.log( 'Manual connection result:', result );
} catch ( e ) {
error = e;
console.error( 'Manual connection failed:', e );
} finally {
yield setManualConnectionIsBusy( false );
}
return error === null;
}
/**
* Saves the persistent details to the WP database.
*
* @return {any} A generator function that handles the saving process.
* @return {boolean} True, if the values were successfully saved.
*/
export function* persist() {
let error = null;