Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-enabled exits and enhance the logic for the coming soon. #402

Merged
merged 6 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
62 changes: 62 additions & 0 deletions includes/Services/StatusService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?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
*/
private 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
*/
private 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 nfd-onboarding
//phpcs:ignore
if ( isset( $_GET['page'] ) && WP_Admin::$slug === \sanitize_text_field( $_GET['page'] ) ) {
self::handle_started();
} else {
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
5 changes: 3 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,9 @@ const ExitToWordPress = ( {
}
}
setFlow( currentData );
setComingSoon( currentData?.data?.comingSoon );
if ( true === currentData?.data?.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 { 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,9 @@
if ( currentData ) {
currentData.isComplete = new Date().getTime();
setFlow( currentData );
setComingSoon( currentData?.data?.comingSoon );
if ( true === currentData?.data?.comingSoon ) {
window.NewfoldRuntime.comingSoon.enable();
}
}

activateInitialPlugins();
Expand All @@ -51,12 +52,12 @@
return () => {
clearInterval( interval );
};
}, [ countdown ] );

Check warning on line 55 in src/OnboardingSPA/components/Loaders/Chapter/Interstitial/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has a missing dependency: 'saveDataAndExit'. Either include it or remove the dependency array

Check warning on line 55 in src/OnboardingSPA/components/Loaders/Chapter/Interstitial/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has a missing dependency: 'saveDataAndExit'. Either include it or remove the dependency array

useEffect( () => {
setIsDrawerSuppressed( true );
setSidebarActiveView( false );
}, [] );

Check warning on line 60 in src/OnboardingSPA/components/Loaders/Chapter/Interstitial/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has missing dependencies: 'setIsDrawerSuppressed' and 'setSidebarActiveView'. Either include them or remove the dependency array

Check warning on line 60 in src/OnboardingSPA/components/Loaders/Chapter/Interstitial/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has missing dependencies: 'setIsDrawerSuppressed' and 'setSidebarActiveView'. Either include them or remove the dependency array
const { brandName, nextStep, currentData } = useSelect( ( select ) => {
return {
brandName: select( nfdOnboardingStore ).getNewfoldBrandName(),
Expand Down
9 changes: 4 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 { 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,10 @@
const contents = getContents( brandName );

const checkFlowComplete = async () => {
await Promise.all( [
completeFlowRequest(),
setComingSoon( currentData?.data?.comingSoon ),
] ).then( ( values ) =>
if ( true === currentData?.data?.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 Expand Up @@ -76,11 +75,11 @@
} else {
flushQueue();
}
}, [ isQueueEmpty ] );

Check warning on line 78 in src/OnboardingSPA/steps/Complete/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has missing dependencies: 'checkFlowComplete' and 'flushQueue'. Either include them or remove the dependency array

Check warning on line 78 in src/OnboardingSPA/steps/Complete/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has missing dependencies: 'checkFlowComplete' and 'flushQueue'. Either include them or remove the dependency array

useEffect( () => {
setNavigationState();
}, [] );

Check warning on line 82 in src/OnboardingSPA/steps/Complete/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has a missing dependency: 'setNavigationState'. Either include it or remove the dependency array

Check warning on line 82 in src/OnboardingSPA/steps/Complete/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has a missing dependency: 'setNavigationState'. Either include it or remove the dependency array

return (
<DesignStateHandler
Expand Down
16 changes: 0 additions & 16 deletions src/OnboardingSPA/utils/api/comingSoon.js

This file was deleted.