Introduce “completed” flag for Redux store

This commit is contained in:
Philipp Stracker 2024-10-28 17:00:07 +01:00
parent b369756cfd
commit dbd37fc282
No known key found for this signature in database
5 changed files with 39 additions and 1 deletions

View file

@ -3,6 +3,7 @@ export default {
SET_IS_SAVING_ONBOARDING_DETAILS: 'SET_IS_SAVING_ONBOARDING_DETAILS',
// Persistent data.
SET_ONBOARDING_COMPLETED: 'SET_ONBOARDING_COMPLETED',
SET_ONBOARDING_DETAILS: 'SET_ONBOARDING_DETAILS',
SET_ONBOARDING_STEP: 'SET_ONBOARDING_STEP',
SET_SANDBOX_MODE: 'SET_SANDBOX_MODE',

View file

@ -16,6 +16,19 @@ export const setIsSaving = ( isSaving ) => {
};
};
/**
* Persistent.Set the "onboarding completed" flag which shows or hides the wizard.
*
* @param {boolean} completed
* @return {{type: string, payload}} The action.
*/
export const setCompleted = ( completed ) => {
return {
type: ACTION_TYPES.SET_ONBOARDING_COMPLETED,
completed,
};
};
/**
* Persistent. Set the full onboarding details, usually during app initialization.
*

View file

@ -3,6 +3,7 @@ import ACTION_TYPES from './action-types';
const defaultState = {
isSaving: false,
data: {
completed: false,
step: 0,
useSandbox: false,
useManualConnection: false,

View file

@ -57,6 +57,7 @@ class OnboardingProfile extends AbstractDataModel {
*/
protected function get_defaults() : array {
return array(
'completed' => false,
'step' => 0,
'use_sandbox' => false,
'use_manual_connection' => false,
@ -70,6 +71,24 @@ class OnboardingProfile extends AbstractDataModel {
// -----
/**
* Gets the 'completed' flag.
*
* @return bool
*/
public function get_completed() : bool {
return (bool) $this->data['completed'];
}
/**
* Sets the 'completed' flag.
*
* @param bool $step Whether the onboarding process has been completed.
*/
public function set_completed( bool $step ) : void {
$this->data['completed'] = $step;
}
/**
* Gets the 'step' setting.
*
@ -82,7 +101,7 @@ class OnboardingProfile extends AbstractDataModel {
/**
* Sets the 'step' setting.
*
* @param int $step Whether to use sandbox mode.
* @param int $step The current onboarding step.
*/
public function set_step( int $step ) : void {
$this->data['step'] = $step;

View file

@ -41,6 +41,10 @@ class OnboardingRestEndpoint extends RestEndpoint {
* @var array
*/
private array $field_map = array(
'completed' => array(
'js_name' => 'completed',
'sanitize' => 'to_boolean',
),
'step' => array(
'js_name' => 'step',
'sanitize' => 'to_number',