-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Settings UI: Add Settings tab Redux store
- Loading branch information
1 parent
d1a6740
commit 6993038
Showing
17 changed files
with
811 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 7 additions & 22 deletions
29
modules/ppcp-settings/resources/js/Components/Screens/Overview/TabSettings.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
modules/ppcp-settings/resources/js/data/settings-tab/action-types.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Settings action types | ||
* | ||
* Defines the constants used for dispatching actions in the settings store. | ||
* Each constant represents a unique action type that can be handled by reducers. | ||
* | ||
* @file | ||
*/ | ||
|
||
export default { | ||
/** | ||
* Represents setting transient (temporary) state data. | ||
* These values are not persisted and will reset on page reload. | ||
*/ | ||
SET_TRANSIENT: 'ppcp/settings/SET_TRANSIENT', | ||
|
||
/** | ||
* Represents setting persistent state data. | ||
* These values are meant to be saved to the server and persist between page loads. | ||
*/ | ||
SET_PERSISTENT: 'ppcp/settings/SET_PERSISTENT', | ||
|
||
/** | ||
* Resets the store state to its initial values. | ||
* Used when needing to clear all settings data. | ||
*/ | ||
RESET: 'ppcp/settings/RESET', | ||
|
||
/** | ||
* Initializes the store with data, typically used during store initialization | ||
* to set up the initial state with data from the server. | ||
*/ | ||
HYDRATE: 'ppcp/settings/HYDRATE', | ||
|
||
/** | ||
* Triggers the persistence of store data to the server. | ||
* Used when changes need to be saved to the backend. | ||
*/ | ||
DO_PERSIST_DATA: 'ppcp/settings/DO_PERSIST_DATA', | ||
}; |
71 changes: 71 additions & 0 deletions
71
modules/ppcp-settings/resources/js/data/settings-tab/actions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* Action Creators: Define functions to create action objects. | ||
* | ||
* These functions update state or trigger side effects (e.g., async operations). | ||
* Actions are categorized as Transient, Persistent, or Side effect. | ||
* | ||
* @file | ||
*/ | ||
|
||
import { select } from '@wordpress/data'; | ||
import ACTION_TYPES from './action-types'; | ||
import { STORE_NAME } from './constants'; | ||
|
||
/** | ||
* @typedef {Object} Action An action object that is handled by a reducer or control. | ||
* @property {string} type - The action type. | ||
* @property {Object?} payload - Optional payload for the action. | ||
*/ | ||
|
||
/** | ||
* Special. Resets all values in the store to initial defaults. | ||
* | ||
* @return {Action} The action. | ||
*/ | ||
export const reset = () => ( { | ||
type: ACTION_TYPES.RESET, | ||
} ); | ||
|
||
/** | ||
* Persistent. Sets the full store details during app initialization. | ||
* | ||
* @param {Object} payload Initial store data | ||
* @return {Action} The action. | ||
*/ | ||
export const hydrate = ( payload ) => ( { | ||
type: ACTION_TYPES.HYDRATE, | ||
payload, | ||
} ); | ||
|
||
/** | ||
* Transient. Marks the store as "ready", i.e., fully initialized. | ||
* | ||
* @param {boolean} isReady Whether the store is ready | ||
* @return {Action} The action. | ||
*/ | ||
export const setIsReady = ( isReady ) => ( { | ||
type: ACTION_TYPES.SET_TRANSIENT, | ||
payload: { isReady }, | ||
} ); | ||
|
||
/** | ||
* Persistent. Updates the settings data in the store. | ||
* | ||
* @param {Object} settings The settings object to store | ||
* @return {Action} The action. | ||
*/ | ||
export const setSettings = ( settings ) => ( { | ||
type: ACTION_TYPES.SET_PERSISTENT, | ||
payload: settings, | ||
} ); | ||
|
||
/** | ||
* Side effect. Triggers the persistence of store data to the server. | ||
* Yields an action with the current persistent data to be saved. | ||
* | ||
* @return {Action} The action. | ||
*/ | ||
export const persist = function* () { | ||
const data = yield select( STORE_NAME ).persistentData(); | ||
yield { type: ACTION_TYPES.DO_PERSIST_DATA, data }; | ||
}; |
28 changes: 28 additions & 0 deletions
28
modules/ppcp-settings/resources/js/data/settings-tab/constants.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Name of the Redux store module. | ||
* | ||
* Used by: Reducer, Selector, Index | ||
* | ||
* @type {string} | ||
*/ | ||
export const STORE_NAME = 'wc/paypal/settings'; | ||
|
||
/** | ||
* REST path to hydrate data of this module by loading data from the WP DB. | ||
* | ||
* Used by: Resolvers | ||
* See: SettingsRestEndpoint.php | ||
* | ||
* @type {string} | ||
*/ | ||
export const REST_HYDRATE_PATH = '/wc/v3/wc_paypal/settings'; | ||
|
||
/** | ||
* REST path to persist data of this module to the WP DB. | ||
* | ||
* Used by: Controls | ||
* See: SettingsRestEndpoint.php | ||
* | ||
* @type {string} | ||
*/ | ||
export const REST_PERSIST_PATH = '/wc/v3/wc_paypal/settings'; |
Oops, something went wrong.