mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 09:08:09 +08:00
Merge pull request #3078 from woocommerce/PCP-4138-confirmation-message-after-saving-settings
Confirmation message after saving settings (4138)
This commit is contained in:
commit
b1adebdfe6
13 changed files with 239 additions and 101 deletions
|
@ -75,16 +75,10 @@ export const setIsReady = ( isReady ) => setTransient( 'isReady', isReady );
|
|||
*/
|
||||
export function persist() {
|
||||
return async ( { select } ) => {
|
||||
const data = select.persistentData();
|
||||
|
||||
try {
|
||||
await apiFetch( {
|
||||
path: REST_PERSIST_PATH,
|
||||
method: 'POST',
|
||||
data,
|
||||
} );
|
||||
} catch ( e ) {
|
||||
console.error( 'Error saving progress.', e );
|
||||
}
|
||||
await apiFetch( {
|
||||
path: REST_PERSIST_PATH,
|
||||
method: 'POST',
|
||||
data: select.persistentData(),
|
||||
} );
|
||||
};
|
||||
}
|
||||
|
|
|
@ -19,12 +19,10 @@ import {
|
|||
*/
|
||||
export function persist() {
|
||||
return async ( { select } ) => {
|
||||
const data = select.persistentData();
|
||||
|
||||
await apiFetch( {
|
||||
path: REST_PERSIST_PATH,
|
||||
method: 'POST',
|
||||
data,
|
||||
data: select.persistentData(),
|
||||
} );
|
||||
};
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*/
|
||||
|
||||
import { useDispatch, useSelect } from '@wordpress/data';
|
||||
import { useCallback } from '@wordpress/element';
|
||||
import { useCallback, useEffect, useState } from '@wordpress/element';
|
||||
|
||||
import { createHooksForStore } from '../utils';
|
||||
import { STORE_NAME } from './constants';
|
||||
|
@ -194,6 +194,8 @@ export const useBusyState = () => {
|
|||
const withActivity = useCallback(
|
||||
async ( id, description, asyncFn ) => {
|
||||
startActivity( id, description );
|
||||
|
||||
// Intentionally does not catch errors but propagates them to the calling module.
|
||||
try {
|
||||
return await asyncFn();
|
||||
} finally {
|
||||
|
@ -206,6 +208,54 @@ export const useBusyState = () => {
|
|||
return {
|
||||
withActivity, // HOC
|
||||
isBusy, // Boolean.
|
||||
activities, // Object.
|
||||
};
|
||||
};
|
||||
|
||||
export const useActivityObserver = () => {
|
||||
const activities = useSelect(
|
||||
( select ) => select( STORE_NAME ).getActivityList(),
|
||||
[]
|
||||
);
|
||||
|
||||
const [ prevActivities, setPrevActivities ] = useState( activities );
|
||||
|
||||
useEffect( () => {
|
||||
setPrevActivities( activities );
|
||||
}, [ activities ] );
|
||||
|
||||
const onStarted = useCallback(
|
||||
( callback ) => {
|
||||
const newActivities = Object.keys( activities ).filter(
|
||||
( id ) => ! prevActivities[ id ]
|
||||
);
|
||||
if ( ! newActivities.length ) {
|
||||
return;
|
||||
}
|
||||
newActivities.forEach( ( id ) =>
|
||||
callback( id, Object.keys( activities ) )
|
||||
);
|
||||
},
|
||||
[ activities, prevActivities ]
|
||||
);
|
||||
|
||||
const onFinished = useCallback(
|
||||
( callback ) => {
|
||||
const finishedActivities = Object.keys( prevActivities ).filter(
|
||||
( id ) => ! activities[ id ]
|
||||
);
|
||||
if ( ! finishedActivities.length ) {
|
||||
return;
|
||||
}
|
||||
finishedActivities.forEach( ( id ) =>
|
||||
callback( id, Object.keys( activities ) )
|
||||
);
|
||||
},
|
||||
[ activities, prevActivities ]
|
||||
);
|
||||
|
||||
return {
|
||||
activities,
|
||||
onStarted,
|
||||
onFinished,
|
||||
};
|
||||
};
|
||||
|
|
|
@ -75,15 +75,14 @@ export const setIsReady = ( isReady ) => setTransient( 'isReady', isReady );
|
|||
*/
|
||||
export function persist() {
|
||||
return async ( { select } ) => {
|
||||
const data = select.persistentData();
|
||||
|
||||
try {
|
||||
await apiFetch( {
|
||||
path: REST_PERSIST_PATH,
|
||||
method: 'POST',
|
||||
data,
|
||||
data: select.persistentData(),
|
||||
} );
|
||||
} catch ( e ) {
|
||||
// We catch errors here, as the onboarding module is not handled by the persistAll hook.
|
||||
console.error( 'Error saving progress.', e );
|
||||
}
|
||||
};
|
||||
|
|
|
@ -75,16 +75,10 @@ export const setIsReady = ( isReady ) => setTransient( 'isReady', isReady );
|
|||
*/
|
||||
export function persist() {
|
||||
return async ( { select } ) => {
|
||||
const data = select.persistentData();
|
||||
|
||||
try {
|
||||
await apiFetch( {
|
||||
path: REST_PERSIST_PATH,
|
||||
method: 'POST',
|
||||
data,
|
||||
} );
|
||||
} catch ( e ) {
|
||||
console.error( 'Error saving progress.', e );
|
||||
}
|
||||
await apiFetch( {
|
||||
path: REST_PERSIST_PATH,
|
||||
method: 'POST',
|
||||
data: select.persistentData(),
|
||||
} );
|
||||
};
|
||||
}
|
||||
|
|
|
@ -87,16 +87,10 @@ export const changePaymentSettings = ( id, props ) => ( {
|
|||
*/
|
||||
export function persist() {
|
||||
return async ( { select } ) => {
|
||||
const data = select.persistentData();
|
||||
|
||||
try {
|
||||
await apiFetch( {
|
||||
path: REST_PERSIST_PATH,
|
||||
method: 'POST',
|
||||
data,
|
||||
} );
|
||||
} catch ( e ) {
|
||||
console.error( 'Error saving progress.', e );
|
||||
}
|
||||
await apiFetch( {
|
||||
path: REST_PERSIST_PATH,
|
||||
method: 'POST',
|
||||
data: select.persistentData(),
|
||||
} );
|
||||
};
|
||||
}
|
||||
|
|
|
@ -77,16 +77,10 @@ export const setIsReady = ( isReady ) => setTransient( 'isReady', isReady );
|
|||
*/
|
||||
export function persist() {
|
||||
return async ( { select } ) => {
|
||||
const data = select.persistentData();
|
||||
|
||||
try {
|
||||
await apiFetch( {
|
||||
path: REST_PERSIST_PATH,
|
||||
method: 'POST',
|
||||
data,
|
||||
} );
|
||||
} catch ( e ) {
|
||||
console.error( 'Error saving progress.', e );
|
||||
}
|
||||
await apiFetch( {
|
||||
path: REST_PERSIST_PATH,
|
||||
method: 'POST',
|
||||
data: select.persistentData(),
|
||||
} );
|
||||
};
|
||||
}
|
||||
|
|
|
@ -63,10 +63,10 @@ export const setPersistent = ( prop, value ) => ( {
|
|||
/**
|
||||
* Transient. Changes the "ready-state" of the module.
|
||||
*
|
||||
* @param {boolean} state Whether the store is ready to be used.
|
||||
* @param {boolean} isReady Whether the store is ready to be used.
|
||||
* @return {Action} The action.
|
||||
*/
|
||||
export const setIsReady = ( state ) => setTransient( 'isReady', state );
|
||||
export const setIsReady = ( isReady ) => setTransient( 'isReady', isReady );
|
||||
|
||||
/**
|
||||
* Thunk action creator. Triggers the persistence of store data to the server.
|
||||
|
@ -75,16 +75,10 @@ export const setIsReady = ( state ) => setTransient( 'isReady', state );
|
|||
*/
|
||||
export function persist() {
|
||||
return async ( { select } ) => {
|
||||
const data = select.persistentData();
|
||||
|
||||
try {
|
||||
await apiFetch( {
|
||||
path: REST_PERSIST_PATH,
|
||||
method: 'POST',
|
||||
data,
|
||||
} );
|
||||
} catch ( e ) {
|
||||
console.error( 'Error saving progress.', e );
|
||||
}
|
||||
await apiFetch( {
|
||||
path: REST_PERSIST_PATH,
|
||||
method: 'POST',
|
||||
data: select.persistentData(),
|
||||
} );
|
||||
};
|
||||
}
|
||||
|
|
|
@ -48,11 +48,10 @@ export function fetchTodos() {
|
|||
|
||||
export function persist() {
|
||||
return async ( { select } ) => {
|
||||
const data = await select.persistentData();
|
||||
return await apiFetch( {
|
||||
path: REST_PERSIST_PATH,
|
||||
method: 'POST',
|
||||
data,
|
||||
data: select.persistentData(),
|
||||
} );
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue