mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-03 08:37:53 +08:00
✨ Implement a full-store-refresh hook
This commit is contained in:
parent
2477e4d357
commit
480d15a7fb
1 changed files with 35 additions and 33 deletions
|
@ -12,48 +12,41 @@ import {
|
||||||
export const useSaveSettings = () => {
|
export const useSaveSettings = () => {
|
||||||
const { withActivity } = CommonHooks.useBusyState();
|
const { withActivity } = CommonHooks.useBusyState();
|
||||||
|
|
||||||
const { persist: persistPayment } = PaymentHooks.useStore();
|
const paymentStore = PaymentHooks.useStore();
|
||||||
const { persist: persistSettings } = SettingsHooks.useStore();
|
const settingsStore = SettingsHooks.useStore();
|
||||||
const { persist: persistStyling } = StylingHooks.useStore();
|
const stylingStore = StylingHooks.useStore();
|
||||||
const { persist: persistTodos } = TodosHooks.useStore();
|
const todosStore = TodosHooks.useStore();
|
||||||
const { persist: persistPayLaterMessaging } =
|
const payLaterStore = PayLaterMessagingHooks.useStore();
|
||||||
PayLaterMessagingHooks.useStore();
|
|
||||||
|
|
||||||
const persistActions = useMemo(
|
const storeActions = useMemo(
|
||||||
() => [
|
() => [
|
||||||
{
|
{
|
||||||
key: 'persist-methods',
|
key: 'methods',
|
||||||
message: 'Save payment methods',
|
message: 'Process payment methods',
|
||||||
action: persistPayment,
|
store: paymentStore,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'persist-settings',
|
key: 'settings',
|
||||||
message: 'Save the settings',
|
message: 'Process the settings',
|
||||||
action: persistSettings,
|
store: settingsStore,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'persist-styling',
|
key: 'styling',
|
||||||
message: 'Save styling details',
|
message: 'Process styling details',
|
||||||
action: persistStyling,
|
store: stylingStore,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'persist-todos',
|
key: 'todos',
|
||||||
message: 'Save todos state',
|
message: 'Process todos state',
|
||||||
action: persistTodos,
|
store: todosStore,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'persist-pay-later-messaging',
|
key: 'pay-later-messaging',
|
||||||
message: 'Save pay later messaging details',
|
message: 'Process pay later messaging details',
|
||||||
action: persistPayLaterMessaging,
|
store: payLaterStore,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
[
|
[ payLaterStore, paymentStore, settingsStore, stylingStore, todosStore ]
|
||||||
persistPayLaterMessaging,
|
|
||||||
persistPayment,
|
|
||||||
persistSettings,
|
|
||||||
persistStyling,
|
|
||||||
persistTodos,
|
|
||||||
]
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const persistAll = useCallback( () => {
|
const persistAll = useCallback( () => {
|
||||||
|
@ -65,10 +58,19 @@ export const useSaveSettings = () => {
|
||||||
*/
|
*/
|
||||||
document.getElementById( 'configurator-publishButton' )?.click();
|
document.getElementById( 'configurator-publishButton' )?.click();
|
||||||
|
|
||||||
persistActions.forEach( ( { key, message, action } ) => {
|
storeActions.forEach( ( { key, message, store } ) => {
|
||||||
withActivity( key, message, action );
|
withActivity( `persist-${ key }`, message, store.persist );
|
||||||
} );
|
} );
|
||||||
}, [ persistActions, withActivity ] );
|
}, [ storeActions, withActivity ] );
|
||||||
|
|
||||||
return { persistAll };
|
const refreshAll = useCallback( () => {
|
||||||
|
storeActions.forEach( ( { key, message, store } ) => {
|
||||||
|
withActivity( `refresh-${ key }`, message, store.refresh );
|
||||||
|
} );
|
||||||
|
}, [ storeActions, withActivity ] );
|
||||||
|
|
||||||
|
return {
|
||||||
|
persistAll,
|
||||||
|
refreshAll,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue