♻️ Refactor onboarding state management

This commit is contained in:
Philipp Stracker 2024-11-18 18:26:10 +01:00
parent 81f45692f4
commit fee9a016c6
No known key found for this signature in database
6 changed files with 100 additions and 148 deletions

View file

@ -1,19 +1,20 @@
import { dispatch } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { apiFetch } from '@wordpress/data-controls';
import { NAMESPACE } from '../constants';
import { REST_HYDRATE_PATH } from './constants';
import { setIsReady, setOnboardingDetails } from './actions';
import { setIsReady, hydrateOnboardingDetails } from './actions';
/**
* Retrieve settings from the site's REST API.
*/
export function* getPersistentData() {
export function* onboardingPersistentData() {
const path = `${ NAMESPACE }/${ REST_HYDRATE_PATH }`;
try {
const result = yield apiFetch( { path } );
yield setOnboardingDetails( result );
yield hydrateOnboardingDetails( result );
yield setIsReady( true );
} catch ( e ) {
yield dispatch( 'core/notices' ).createErrorNotice(