woocommerce-paypal-payments/modules/ppcp-settings/resources/js/data/onboarding/resolvers.js
Philipp Stracker 3d05c65f50
New “isReady” flag to avoid invalid page content
Before this change, the onboarding wizard was briefly displayed on every page load
2024-10-28 18:57:39 +01:00

25 lines
669 B
JavaScript

import { dispatch } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { apiFetch } from '@wordpress/data-controls';
import { NAMESPACE } from '../constants';
import { setIsReady, setOnboardingDetails } from './actions';
/**
* Retrieve settings from the site's REST API.
*/
export function* getPersistentData() {
const path = `${ NAMESPACE }/onboarding`;
try {
const result = yield apiFetch( { path } );
yield setOnboardingDetails( result );
yield setIsReady( true );
} catch ( e ) {
yield dispatch( 'core/notices' ).createErrorNotice(
__(
'Error retrieving onboarding details.',
'woocommerce-paypal-payments'
)
);
}
}