2024-11-18 18:51:11 +01:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2024-11-20 16:54:29 +01:00
|
|
|
import { select } from '@wordpress/data';
|
|
|
|
|
2024-10-22 15:15:55 +02:00
|
|
|
import ACTION_TYPES from './action-types';
|
2024-11-20 16:54:29 +01:00
|
|
|
import { STORE_NAME } from './constants';
|
2024-11-18 16:31:05 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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.
|
|
|
|
*/
|
2024-10-22 15:15:55 +02:00
|
|
|
|
2024-10-30 16:55:44 +01:00
|
|
|
/**
|
|
|
|
* Special. Resets all values in the onboarding store to initial defaults.
|
|
|
|
*
|
2024-11-18 18:26:10 +01:00
|
|
|
* @return {Action} The action.
|
2024-10-30 16:55:44 +01:00
|
|
|
*/
|
2024-11-20 16:54:29 +01:00
|
|
|
export const reset = () => ( { type: ACTION_TYPES.RESET } );
|
2024-10-30 16:55:44 +01:00
|
|
|
|
2024-10-28 18:57:39 +01:00
|
|
|
/**
|
2024-11-21 17:42:48 +01:00
|
|
|
* Persistent. Set the full onboarding details, usually during app initialization.
|
2024-10-28 18:57:39 +01:00
|
|
|
*
|
2024-11-21 17:42:48 +01:00
|
|
|
* @param {{data: {}, flags?: {}}} payload
|
2024-11-18 18:26:10 +01:00
|
|
|
* @return {Action} The action.
|
2024-10-28 18:57:39 +01:00
|
|
|
*/
|
2024-11-21 17:42:48 +01:00
|
|
|
export const hydrate = ( payload ) => ( {
|
|
|
|
type: ACTION_TYPES.HYDRATE,
|
|
|
|
payload,
|
2024-11-20 16:54:29 +01:00
|
|
|
} );
|
2024-10-28 18:57:39 +01:00
|
|
|
|
2024-10-28 17:00:07 +01:00
|
|
|
/**
|
2024-11-21 17:42:48 +01:00
|
|
|
* Transient. Marks the onboarding details as "ready", i.e., fully initialized.
|
2024-10-28 17:00:07 +01:00
|
|
|
*
|
2024-11-21 17:42:48 +01:00
|
|
|
* @param {boolean} isReady
|
2024-11-18 18:26:10 +01:00
|
|
|
* @return {Action} The action.
|
2024-10-28 17:00:07 +01:00
|
|
|
*/
|
2024-11-21 17:42:48 +01:00
|
|
|
export const setIsReady = ( isReady ) => ( {
|
|
|
|
type: ACTION_TYPES.SET_TRANSIENT,
|
|
|
|
payload: { isReady },
|
2024-11-20 16:54:29 +01:00
|
|
|
} );
|
2024-10-28 17:00:07 +01:00
|
|
|
|
2025-01-08 14:41:27 +01:00
|
|
|
/**
|
|
|
|
* Transient. Sets the "manualClientId" value.
|
|
|
|
*
|
|
|
|
* @param {string} manualClientId
|
|
|
|
* @return {Action} The action.
|
|
|
|
*/
|
|
|
|
export const setManualClientId = ( manualClientId ) => ( {
|
|
|
|
type: ACTION_TYPES.SET_TRANSIENT,
|
|
|
|
payload: { manualClientId },
|
|
|
|
} );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transient. Sets the "manualClientSecret" value.
|
|
|
|
*
|
|
|
|
* @param {string} manualClientSecret
|
|
|
|
* @return {Action} The action.
|
|
|
|
*/
|
|
|
|
export const setManualClientSecret = ( manualClientSecret ) => ( {
|
|
|
|
type: ACTION_TYPES.SET_TRANSIENT,
|
|
|
|
payload: { manualClientSecret },
|
|
|
|
} );
|
|
|
|
|
2024-10-22 15:15:55 +02:00
|
|
|
/**
|
2024-10-28 18:11:04 +01:00
|
|
|
* Persistent.Set the "onboarding completed" flag which shows or hides the wizard.
|
2024-10-22 15:15:55 +02:00
|
|
|
*
|
2024-10-28 18:11:04 +01:00
|
|
|
* @param {boolean} completed
|
2024-11-18 18:26:10 +01:00
|
|
|
* @return {Action} The action.
|
2024-10-22 15:15:55 +02:00
|
|
|
*/
|
2024-11-20 16:54:29 +01:00
|
|
|
export const setCompleted = ( completed ) => ( {
|
|
|
|
type: ACTION_TYPES.SET_PERSISTENT,
|
|
|
|
payload: { completed },
|
|
|
|
} );
|
2024-10-22 15:15:55 +02:00
|
|
|
|
2024-10-22 18:56:37 +02:00
|
|
|
/**
|
|
|
|
* Persistent. Sets the onboarding wizard to a new step.
|
|
|
|
*
|
|
|
|
* @param {number} step
|
2024-11-18 18:26:10 +01:00
|
|
|
* @return {Action} The action.
|
2024-10-22 18:56:37 +02:00
|
|
|
*/
|
2024-11-20 16:54:29 +01:00
|
|
|
export const setStep = ( step ) => ( {
|
|
|
|
type: ACTION_TYPES.SET_PERSISTENT,
|
|
|
|
payload: { step },
|
|
|
|
} );
|
2024-10-23 15:38:00 +02:00
|
|
|
|
2024-10-30 16:56:42 +01:00
|
|
|
/**
|
|
|
|
* Persistent. Sets the "isCasualSeller" value.
|
|
|
|
*
|
|
|
|
* @param {boolean} isCasualSeller
|
2024-11-18 18:26:10 +01:00
|
|
|
* @return {Action} The action.
|
2024-10-30 16:56:42 +01:00
|
|
|
*/
|
2024-11-20 16:54:29 +01:00
|
|
|
export const setIsCasualSeller = ( isCasualSeller ) => ( {
|
|
|
|
type: ACTION_TYPES.SET_PERSISTENT,
|
|
|
|
payload: { isCasualSeller },
|
|
|
|
} );
|
2024-10-30 16:56:42 +01:00
|
|
|
|
2024-11-25 20:47:13 -04:00
|
|
|
/**
|
|
|
|
* Persistent. Sets the "areOptionalPaymentMethodsEnabled" value.
|
|
|
|
*
|
|
|
|
* @param {boolean} areOptionalPaymentMethodsEnabled
|
|
|
|
* @return {Action} The action.
|
|
|
|
*/
|
|
|
|
export const setAreOptionalPaymentMethodsEnabled = (
|
|
|
|
areOptionalPaymentMethodsEnabled
|
|
|
|
) => ( {
|
|
|
|
type: ACTION_TYPES.SET_PERSISTENT,
|
|
|
|
payload: { areOptionalPaymentMethodsEnabled },
|
|
|
|
} );
|
|
|
|
|
2024-10-30 16:56:42 +01:00
|
|
|
/**
|
|
|
|
* Persistent. Sets the "products" array.
|
|
|
|
*
|
|
|
|
* @param {string[]} products
|
2024-11-18 18:26:10 +01:00
|
|
|
* @return {Action} The action.
|
2024-10-30 16:56:42 +01:00
|
|
|
*/
|
2024-11-20 16:54:29 +01:00
|
|
|
export const setProducts = ( products ) => ( {
|
|
|
|
type: ACTION_TYPES.SET_PERSISTENT,
|
|
|
|
payload: { products },
|
|
|
|
} );
|
2024-10-30 16:56:42 +01:00
|
|
|
|
2024-11-04 16:50:50 +01:00
|
|
|
/**
|
2024-11-18 16:31:05 +01:00
|
|
|
* Side effect. Triggers the persistence of onboarding data to the server.
|
2024-11-04 16:50:50 +01:00
|
|
|
*
|
2024-11-18 16:31:05 +01:00
|
|
|
* @return {Action} The action.
|
|
|
|
*/
|
2024-11-20 16:53:21 +01:00
|
|
|
export const persist = function* () {
|
|
|
|
const data = yield select( STORE_NAME ).persistentData();
|
|
|
|
|
|
|
|
yield { type: ACTION_TYPES.DO_PERSIST_DATA, data };
|
2024-11-18 16:31:05 +01:00
|
|
|
};
|