woocommerce-paypal-payments/modules/ppcp-settings/resources/js/data/onboarding/resolvers.js
2025-06-06 13:33:32 +02:00

34 lines
918 B
JavaScript

/**
* Resolvers: Handle asynchronous data fetching for the store.
*
* These functions update store state with data from external sources.
* Each resolver corresponds to a specific selector (selector with same name must exist).
* Resolvers are called automatically when selectors request unavailable data.
*
* @file
*/
import { __ } from '@wordpress/i18n';
import apiFetch from '@wordpress/api-fetch';
import { REST_HYDRATE_PATH } from './constants';
export function persistentData() {
return async ( { dispatch, registry } ) => {
try {
const result = await apiFetch( { path: REST_HYDRATE_PATH } );
await dispatch.hydrate( result, 'system' );
await dispatch.setIsReady( true, 'system' );
} catch ( e ) {
await registry
.dispatch( 'core/notices' )
.createErrorNotice(
__(
'Error retrieving onboarding details.',
'woocommerce-paypal-payments'
)
);
}
};
}