🎨 Minor re-organization of code

This commit is contained in:
Philipp Stracker 2024-12-05 15:04:36 +01:00
parent 67822b3b11
commit a8f12c63fa
No known key found for this signature in database

View file

@ -34,21 +34,6 @@ const handlePopupOpen = ( url, onError ) => {
return true;
};
const useConnectionAttempt = ( connectFn, errorMessage ) => {
const { handleError, createErrorNotice } = useConnectionBase();
return async ( ...args ) => {
const res = await connectFn( ...args );
if ( ! res.success || ! res.data ) {
handleError( res, errorMessage );
return false;
}
return handlePopupOpen( res.data, createErrorNotice );
};
};
const useConnectionBase = () => {
const { setCompleted } = OnboardingHooks.useSteps();
const { createSuccessNotice, createErrorNotice } =
@ -67,6 +52,21 @@ const useConnectionBase = () => {
};
};
const useConnectionAttempt = ( connectFn, errorMessage ) => {
const { handleError, createErrorNotice } = useConnectionBase();
return async ( ...args ) => {
const res = await connectFn( ...args );
if ( ! res.success || ! res.data ) {
handleError( res, errorMessage );
return false;
}
return handlePopupOpen( res.data, createErrorNotice );
};
};
export const useSandboxConnection = () => {
const { connectToSandbox, isSandboxMode, setSandboxMode } =
CommonHooks.useSandbox();
@ -83,6 +83,8 @@ export const useSandboxConnection = () => {
};
export const useManualConnection = () => {
const { handleError, handleSuccess, createErrorNotice } =
useConnectionBase();
const {
connectViaIdAndSecret,
isManualConnectionMode,
@ -92,8 +94,6 @@ export const useManualConnection = () => {
clientSecret,
setClientSecret,
} = CommonHooks.useManualConnection();
const { handleError, handleSuccess, createErrorNotice } =
useConnectionBase();
const handleConnectViaIdAndSecret = async ( { validation } = {} ) => {
if ( 'function' === typeof validation ) {
@ -104,6 +104,7 @@ export const useManualConnection = () => {
return;
}
}
const res = await connectViaIdAndSecret();
if ( res.success ) {