🔥 Remove isSaving; move isBusy to common store

This commit is contained in:
Philipp Stracker 2024-11-21 16:14:26 +01:00
parent 10a3767e2f
commit 2b2b24e434
No known key found for this signature in database
7 changed files with 15 additions and 43 deletions

View file

@ -7,11 +7,11 @@ import { store as noticesStore } from '@wordpress/notices';
import SettingsToggleBlock from '../../../ReusableComponents/SettingsToggleBlock'; import SettingsToggleBlock from '../../../ReusableComponents/SettingsToggleBlock';
import Separator from '../../../ReusableComponents/Separator'; import Separator from '../../../ReusableComponents/Separator';
import DataStoreControl from '../../../ReusableComponents/DataStoreControl'; import DataStoreControl from '../../../ReusableComponents/DataStoreControl';
import { OnboardingHooks } from '../../../../data'; import { OnboardingHooks, CommonHooks } from '../../../../data';
const AdvancedOptionsForm = ( { setCompleted } ) => { const AdvancedOptionsForm = ( { setCompleted } ) => {
const { isBusy } = CommonHooks.useBusyState();
const { const {
isBusy,
isSandboxMode, isSandboxMode,
setSandboxMode, setSandboxMode,
isManualConnectionMode, isManualConnectionMode,

View file

@ -22,8 +22,8 @@ const Navigation = ( { setStep, setCompleted, currentStep, stepperOrder } ) => {
} }
}; };
const { products, toggleProduct } = OnboardingHooks.useProducts(); const { products } = OnboardingHooks.useProducts();
const { isCasualSeller, setIsCasualSeller } = OnboardingHooks.useBusiness(); const { isCasualSeller } = OnboardingHooks.useBusiness();
let navigationTitle = ''; let navigationTitle = '';
let disabled = false; let disabled = false;

View file

@ -22,3 +22,13 @@ const usePersistent = ( key ) =>
( select ) => select( STORE_NAME ).persistentData()?.[ key ], ( select ) => select( STORE_NAME ).persistentData()?.[ key ],
[ key ] [ key ]
); );
export const useBusyState = () => {
const { setIsBusy } = useDispatch( STORE_NAME );
const isBusy = useTransient( 'isBusy' );
return {
isBusy,
setIsBusy: useCallback( ( busy ) => setIsBusy( busy ), [ setIsBusy ] ),
};
};

View file

@ -14,7 +14,6 @@ import ACTION_TYPES from './action-types';
const defaultTransient = { const defaultTransient = {
isReady: false, isReady: false,
isSaving: false,
isBusy: false, isBusy: false,
}; };

View file

@ -36,28 +36,6 @@ export const setIsReady = ( isReady ) => ( {
payload: { isReady }, payload: { isReady },
} ); } );
/**
* Transient. Changes the "saving" flag.
*
* @param {boolean} isSaving
* @return {Action} The action.
*/
export const setIsSaving = ( isSaving ) => ( {
type: ACTION_TYPES.SET_TRANSIENT,
payload: { isSaving },
} );
/**
* Transient. Changes the "manual connection is busy" flag.
*
* @param {boolean} isBusy
* @return {Action} The action.
*/
export const setIsBusy = ( isBusy ) => ( {
type: ACTION_TYPES.SET_TRANSIENT,
payload: { isBusy },
} );
/** /**
* Persistent. Set the full onboarding details, usually during app initialization. * Persistent. Set the full onboarding details, usually during app initialization.
* *
@ -165,9 +143,7 @@ export const setProducts = ( products ) => ( {
export const persist = function* () { export const persist = function* () {
const data = yield select( STORE_NAME ).persistentData(); const data = yield select( STORE_NAME ).persistentData();
yield setIsSaving( true );
yield { type: ACTION_TYPES.DO_PERSIST_DATA, data }; yield { type: ACTION_TYPES.DO_PERSIST_DATA, data };
yield setIsSaving( false );
}; };
/** /**
@ -179,15 +155,12 @@ export const connectViaIdAndSecret = function* () {
const { clientId, clientSecret, useSandbox } = const { clientId, clientSecret, useSandbox } =
yield select( STORE_NAME ).persistentData(); yield select( STORE_NAME ).persistentData();
yield setIsBusy( true );
const result = yield { const result = yield {
type: ACTION_TYPES.DO_MANUAL_CONNECTION, type: ACTION_TYPES.DO_MANUAL_CONNECTION,
clientId, clientId,
clientSecret, clientSecret,
useSandbox, useSandbox,
}; };
yield setIsBusy( false );
return result; return result;
}; };

View file

@ -41,9 +41,7 @@ const useOnboardingDetails = () => {
const flags = useSelect( ( select ) => select( STORE_NAME ).flags(), [] ); const flags = useSelect( ( select ) => select( STORE_NAME ).flags(), [] );
// Transient accessors. // Transient accessors.
const isSaving = useTransient( 'isSaving' );
const isReady = useTransient( 'isReady' ); const isReady = useTransient( 'isReady' );
const isBusy = useTransient( 'isBusy' );
// Persistent accessors. // Persistent accessors.
const step = usePersistent( 'step' ); const step = usePersistent( 'step' );
@ -68,9 +66,8 @@ const useOnboardingDetails = () => {
}; };
return { return {
isSaving, flags,
isReady, isReady,
isBusy,
step, step,
setStep: ( value ) => setDetailAndPersist( setStep, value ), setStep: ( value ) => setDetailAndPersist( setStep, value ),
completed, completed,
@ -91,14 +88,11 @@ const useOnboardingDetails = () => {
setDetailAndPersist( setIsCasualSeller, value ), setDetailAndPersist( setIsCasualSeller, value ),
products, products,
toggleProduct, toggleProduct,
flags,
}; };
}; };
export const useConnection = () => { export const useConnection = () => {
const { const {
isSaving,
isBusy,
isSandboxMode, isSandboxMode,
setSandboxMode, setSandboxMode,
isManualConnectionMode, isManualConnectionMode,
@ -110,8 +104,6 @@ export const useConnection = () => {
} = useOnboardingDetails(); } = useOnboardingDetails();
return { return {
isSaving,
isBusy,
isSandboxMode, isSandboxMode,
setSandboxMode, setSandboxMode,
isManualConnectionMode, isManualConnectionMode,

View file

@ -14,8 +14,6 @@ import ACTION_TYPES from './action-types';
const defaultTransient = { const defaultTransient = {
isReady: false, isReady: false,
isSaving: false,
isBusy: false,
// Read only values, provided by the server. // Read only values, provided by the server.
flags: { flags: {