mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
🚧 Initial store-module for common details
This commit is contained in:
parent
ef873dcda2
commit
0f03a636b2
10 changed files with 308 additions and 1 deletions
32
modules/ppcp-settings/resources/js/data/common/controls.js
vendored
Normal file
32
modules/ppcp-settings/resources/js/data/common/controls.js
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
/**
|
||||
* Controls: Implement side effects, typically asynchronous operations.
|
||||
*
|
||||
* Controls use ACTION_TYPES keys as identifiers to ensure uniqueness.
|
||||
* They are triggered by corresponding actions and handle external interactions.
|
||||
*
|
||||
* @file
|
||||
*/
|
||||
|
||||
import { select } from '@wordpress/data';
|
||||
import { apiFetch } from '@wordpress/api-fetch';
|
||||
|
||||
import { NAMESPACE, STORE_NAME } from '../constants';
|
||||
import { REST_PERSIST_PATH } from './constants';
|
||||
import ACTION_TYPES from './action-types';
|
||||
export const controls = {
|
||||
[ ACTION_TYPES.DO_PERSIST_DATA ]: async () => {
|
||||
const path = `${ NAMESPACE }/${ REST_PERSIST_PATH }`;
|
||||
const data = select( STORE_NAME ).getPersistentData();
|
||||
|
||||
try {
|
||||
return await apiFetch( {
|
||||
path,
|
||||
method: 'post',
|
||||
data,
|
||||
} );
|
||||
} catch ( error ) {
|
||||
console.error( 'Error saving progress.', error );
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue