Skip to content

Commit

Permalink
Merge pull request #402 from newfold-labs/enhance/coming-soon-logic
Browse files Browse the repository at this point in the history
Re-enabled exits and enhance the logic for the coming soon.
  • Loading branch information
arunshenoy99 authored Jan 11, 2024
2 parents 0d7bab7 + 712c3ed commit 0ee2224
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 68 deletions.
6 changes: 6 additions & 0 deletions includes/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use NewfoldLabs\WP\Module\Onboarding\Services\PluginService;
use NewfoldLabs\WP\ModuleLoader\Container;
use NewfoldLabs\WP\Module\Onboarding\Data\Options;
use NewfoldLabs\WP\Module\Onboarding\Services\StatusService;

use function NewfoldLabs\WP\ModuleLoader\container;

/**
Expand Down Expand Up @@ -72,6 +74,10 @@ public function __construct( Container $container ) {
new WP_Admin();
}

if ( Permissions::is_authorized_admin() ) {
StatusService::track();
}

// Adds a transient to activate plugins in all scenarios.
PluginService::configure_activation_transient();

Expand Down
3 changes: 3 additions & 0 deletions includes/RestApi/FlowController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use NewfoldLabs\WP\Module\Onboarding\Permissions;
use NewfoldLabs\WP\Module\Onboarding\Data\Services\FlowService;
use NewfoldLabs\WP\Module\Onboarding\Services\PluginService;
use NewfoldLabs\WP\Module\Onboarding\Services\StatusService;

/**
* Class FlowController
Expand Down Expand Up @@ -110,7 +111,9 @@ public function get() {
public function save_onboarding_flow_data( \WP_REST_Request $request ) {
$params = json_decode( $request->get_body(), true );

// Mark Onboarding as started only on the first REST API request from the React App.
update_option( Options::get_option_name( 'redirect' ), '0' );
StatusService::handle_started();

$flow_data = FlowService::update_data( $params );
if ( is_wp_error( $flow_data ) ) {
Expand Down
43 changes: 0 additions & 43 deletions includes/RestApi/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,49 +112,6 @@ public function register_routes() {
),
)
);

\register_rest_route(
$this->namespace,
$this->rest_base . '/coming-soon',
array(
array(
'methods' => \WP_REST_Server::CREATABLE,
'callback' => array( $this, 'set_coming_soon' ),
'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ),
'args' => $this->set_coming_soon_params(),
),
)
);
}

/**
* Set query params for coming soon route.
*
* @return array
*/
public function set_coming_soon_params() {
return array(
'comingSoon' => array(
'type' => 'boolean',
'required' => true,
),
);
}
/**
* Endpoint to set Coming Soon for a website.
*
* @param \WP_REST_Request $request Request model.
*
* @return \WP_REST_Response|\WP_Error
*/
public function set_coming_soon( \WP_REST_Request $request ) {

$new_value = ( $request->get_param( 'comingSoon' ) ) ? 'true' : 'false';
update_option( 'nfd_coming_soon', $new_value );
return new \WP_REST_Response(
array(),
200
);
}

/**
Expand Down
60 changes: 60 additions & 0 deletions includes/Services/StatusService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
namespace NewfoldLabs\WP\Module\Onboarding\Services;

use NewfoldLabs\WP\Module\Onboarding\Data\Options;
use NewfoldLabs\WP\Module\Onboarding\WP_Admin;

/**
* Tracks the Status of Onboarding.
*/
class StatusService {

/**
* Handle Onboarding started event.
*
* @return void
*/
public static function handle_started() {
if ( 'started' !== get_option( Options::get_option_name( 'status' ) ) ) {
update_option( Options::get_option_name( 'status' ), 'started' );
do_action( 'newfold/onboarding/started' );
}
}

/**
* Handles Onboarding completed event.
*
* @return void
*/
public static function handle_completed() {
if ( 'started' === get_option( Options::get_option_name( 'status' ) ) ) {
update_option( Options::get_option_name( 'status' ), 'completed' );
do_action( 'newfold/onboarding/completed' );
}
}

/**
* Begin tracking the Onboarding status in an option.
*
* @return void
*/
public static function track() {
global $pagenow;

if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
return;
}

switch ( $pagenow ) {
case 'index.php':
// If the page is not nfd-onboarding.
//phpcs:ignore
if ( ! isset( $_GET['page'] ) || WP_Admin::$slug !== \sanitize_text_field( $_GET['page'] ) ) {
self::handle_completed();
}
break;
default:
self::handle_completed();
}
}
}
6 changes: 6 additions & 0 deletions src/OnboardingSPA/components/Drawer/DrawerPanel/NavPrimary.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useSelect, useDispatch } from '@wordpress/data';

import { store as nfdOnboardingStore } from '../../../store';
import classNames from 'classnames';
import ExitToWordPress from '../../ExitToWordPress';
import Animate from '../../Animate';

const NavPrimary = () => {
Expand All @@ -18,6 +19,11 @@ const NavPrimary = () => {
const { setDrawerActiveView } = useDispatch( nfdOnboardingStore );
return (
<Animate type={ 'fade-in' } duration="100ms" timingFunction="ease-in">
<ExitToWordPress
buttonClassName="nfd-onboarding-drawer__panel-back"
buttonVariant="tertiary"
origin="drawer-panel"
/>
<div className="nfd-onboarding-drawer__panel-menu">
<ul className="nfd-onboarding-drawer__panel-routes">
{ topSteps.map( ( step ) => {
Expand Down
8 changes: 6 additions & 2 deletions src/OnboardingSPA/components/ExitToWordPress/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
CATEGORY,
} from '../../utils/analytics/hiive/constants';
import { activateInitialPlugins } from '../../utils/api/plugins';
import { setComingSoon } from '../../utils/api/comingSoon';

/**
* Self-contained button and confirmation modal for exiting Onboarding page.
Expand Down Expand Up @@ -102,7 +101,12 @@ const ExitToWordPress = ( {
}
}
setFlow( currentData );
setComingSoon( currentData?.data?.comingSoon );
if (
true === currentData?.data?.comingSoon &&
window.NewfoldRuntime?.comingSoon
) {
await window.NewfoldRuntime.comingSoon.enable();
}
}
activateInitialPlugins();
trackOnboardingEvent(
Expand Down
18 changes: 18 additions & 0 deletions src/OnboardingSPA/components/Header/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
import { memo } from '@wordpress/element';
import { useSelect } from '@wordpress/data';
import { useLocation } from 'react-router-dom';

import HeaderEnd from './components/HeaderEnd';
import ExitToWordPress from '../ExitToWordPress';
import { store as nfdOnboardingStore } from '../../store';

/**
* Interface header rendered into header render prop in <InterfaceSkeleton />.
*
* @return {WPComponent} Header
*/
const Header = () => {
const location = useLocation();

const { firstStep } = useSelect( ( select ) => {
return {
firstStep: select( nfdOnboardingStore ).getFirstStep(),
};
}, [] );

const isGettingStarted = firstStep?.path === location?.pathname;
return (
<div className="nfd-onboarding-header">
<div className="nfd-onboarding-header__start">
{ isGettingStarted ? (
<ExitToWordPress origin="header-first-step" />
) : null }
</div>
<div className="nfd-onboarding-header__center">
{ /* Centered Header Slot */ }
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
import { pluginDashboardPage } from '../../../../../constants';
import { setFlow } from '../../../../utils/api/flow';
import { ACTION_ONBOARDING_COMPLETE } from '../../../../utils/analytics/hiive/constants';
import { setComingSoon } from '../../../../utils/api/comingSoon';

const ChapterInterstitialLoader = () => {
const [ countdown, setCountdown ] = useState( 15 );
Expand All @@ -30,7 +29,12 @@ const ChapterInterstitialLoader = () => {
if ( currentData ) {
currentData.isComplete = new Date().getTime();
setFlow( currentData );
setComingSoon( currentData?.data?.comingSoon );
if (
true === currentData?.data?.comingSoon &&
window.NewfoldRuntime?.comingSoon
) {
window.NewfoldRuntime.comingSoon.enable();
}
}

activateInitialPlugins();
Expand Down
12 changes: 7 additions & 5 deletions src/OnboardingSPA/steps/Complete/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { StepLoader } from '../../components/Loaders';
import { StepErrorState } from '../../components/ErrorState';
import { THEME_STATUS_INIT } from '../../../constants';
import { DesignStateHandler } from '../../components/StateHandlers';
import { setComingSoon } from '../../utils/api/comingSoon';

const StepComplete = () => {
const {
Expand Down Expand Up @@ -39,10 +38,13 @@ const StepComplete = () => {
const contents = getContents( brandName );

const checkFlowComplete = async () => {
await Promise.all( [
completeFlowRequest(),
setComingSoon( currentData?.data?.comingSoon ),
] ).then( ( values ) =>
if (
true === currentData?.data?.comingSoon &&
window.NewfoldRuntime?.comingSoon
) {
await window.NewfoldRuntime.comingSoon.enable();
}
await Promise.all( [ completeFlowRequest() ] ).then( ( values ) =>
values.forEach( ( value ) => {
// If any Request returns False then Show Error
if ( ! value ) {
Expand Down
16 changes: 0 additions & 16 deletions src/OnboardingSPA/utils/api/comingSoon.js

This file was deleted.

0 comments on commit 0ee2224

Please sign in to comment.