Skip to content

Commit

Permalink
Merge pull request #188 from newfold-labs/PRESS-2-690-make-onboarding…
Browse files Browse the repository at this point in the history
…-exit-completion-more-dynamic

Dynamic Exit Link for Brands
  • Loading branch information
arunshenoy99 authored Mar 6, 2023
2 parents eaedd52 + 0a9f452 commit d6c8cfc
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 40 deletions.
2 changes: 2 additions & 0 deletions includes/Data/Brands.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public static function get_brands() {
'accountUrl' => 'https://my.bluehost.com',
'domainsUrl' => 'https://my.bluehost.com/hosting/app?lil=1#/domains',
'emailUrl' => 'https://my.bluehost.com/hosting/app?lil=1#/email-office',
'pluginDashboardPage' => \admin_url( 'admin.php?page=bluehost' ),
'phoneNumbers' => array(
'sales' => '844-303-1730',
'support' => '888-401-4678',
Expand Down Expand Up @@ -82,6 +83,7 @@ public static function get_brands() {
'accountUrl' => 'https://my.bluehost.in',
'domainsUrl' => 'https://my.bluehost.in/hosting/app?lil=1#/domains',
'emailUrl' => 'https://my.bluehost.in/hosting/app?lil=1#/email-office',
'pluginDashboardPage' => \admin_url( 'admin.php?page=bluehost' ),
'hireExpertsInfo' => array(
'defaultLink' => 'https://www.bluehost.in/solutions/full-service',
'utmParameters' => array(
Expand Down
4 changes: 2 additions & 2 deletions src/OnboardingSPA/components/Button/NavCardButton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { store as nfdOnboardingStore } from '../../../store';
import Button from '../../Button';

import { setFlow } from '../../../utils/api/flow';
import { wpAdminPage, bluehostDashboardPage } from '../../../../constants';
import { wpAdminPage, pluginDashboardPage } from '../../../../constants';

/**
* Navigation Button Component on Card
Expand Down Expand Up @@ -37,7 +37,7 @@ const NavCardButton = ( { text, disabled } ) => {
//Redirect to Admin Page for normal customers
// and Bluehost Dashboard for ecommerce customers
const exitLink = exitToWordpressForEcommerce()
? bluehostDashboardPage
? pluginDashboardPage
: wpAdminPage;
window.location.replace( exitLink );
}
Expand Down
22 changes: 10 additions & 12 deletions src/OnboardingSPA/components/ExitToWordPress/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import classNames from 'classnames';
import { setFlow } from '../../utils/api/flow';
import { store as nfdOnboardingStore } from '../../store';
import { getSettings, setSettings } from '../../utils/api/settings';
import { wpAdminPage, bluehostDashboardPage } from '../../../constants';
import { wpAdminPage, pluginDashboardPage } from '../../../constants';

/**
* Self-contained button and confirmation modal for exiting Onboarding page.
*
* @param {*} param0
* @return
*
* @return {WPComponent} ExitToWordPress Component
*/
const ExitToWordPress = ( {
buttonText = __( 'Exit to WordPress', 'wp-module-onboarding' ),
Expand Down Expand Up @@ -62,7 +63,7 @@ const ExitToWordPress = ( {
);
}

async function syncSocialSettingsFinish( currentData ) {
async function syncSocialSettingsFinish() {
const initialData = await getSettings();
const result = await setSettings( currentData?.data?.socialData );
if ( result?.error !== null ) {
Expand All @@ -71,26 +72,25 @@ const ExitToWordPress = ( {
return result?.body;
}

async function saveData( path, currentData ) {
async function saveData( path ) {
if ( currentData ) {
currentData.hasExited = new Date().getTime();

// If Social Data is changed then sync it
if ( path?.includes( 'basic-info' ) ) {
const socialData = await syncSocialSettingsFinish(
currentData
);
const socialData = await syncSocialSettingsFinish();

// If Social Data is changed then Sync that also to the store
if ( socialData && currentData?.data )
if ( socialData && currentData?.data ) {
currentData.data.socialData = socialData;
}
}
setFlow( currentData );
}
//Redirect to Admin Page for normal customers
// and Bluehost Dashboard for ecommerce customers
const exitLink = exitToWordpressForEcommerce()
? bluehostDashboardPage
? pluginDashboardPage
: wpAdminPage;
window.location.replace( exitLink );
}
Expand Down Expand Up @@ -125,9 +125,7 @@ const ExitToWordPress = ( {
</Button>
<Button
variant="primary"
onClick={ ( e ) =>
saveData( location.pathname, currentData )
}
onClick={ () => saveData( location.pathname ) }
>
{ modalExitButtonText }
</Button>
Expand Down
25 changes: 13 additions & 12 deletions src/OnboardingSPA/components/Header/step-navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import { Icon, chevronLeft, chevronRight } from '@wordpress/icons';
import { __ } from '@wordpress/i18n';
import { setFlow } from '../../utils/api/flow';
import { store as nfdOnboardingStore } from '../../store';
import { wpAdminPage, bluehostDashboardPage } from '../../../constants';
import { wpAdminPage, pluginDashboardPage } from '../../../constants';

/**
* Back step Navigation button.
*
* @param {*} param0
* @return
*
* @return {WPComponent} Back Component
*/
const Back = ( { path } ) => {
const navigate = useNavigate();
Expand All @@ -34,7 +35,8 @@ const Back = ( { path } ) => {
* Next step naigation button
*
* @param {*} param0
* @return
*
* @return {WPComponent} Next Component
*/
const Next = ( { path } ) => {
/* [TODO]: some sense of isStepComplete to enable/disable */
Expand All @@ -61,22 +63,21 @@ async function saveDataAndExit( currentData ) {
//Redirect to Admin Page for normal customers
// and Bluehost Dashboard for ecommerce customers
const exitLink = exitToWordpressForEcommerce()
? bluehostDashboardPage
? pluginDashboardPage
: wpAdminPage;
window.location.replace( exitLink );
}

/**
* Finish step navigation button.
*
* @param root0
* @param root0.currentData
* @param root0.saveDataAndExit
* @return
* @param {*} param0
*
* @return {WPComponent} Finish Component
*/
const Finish = ( { currentData, saveDataAndExit } ) => (
const Finish = ( { currentData, saveDataAndExitFunc } ) => (
<Button
onClick={ ( e ) => saveDataAndExit( currentData ) }
onClick={ () => saveDataAndExitFunc( currentData ) }
className="navigation-buttons navigation-buttons_finish"
variant="primary"
>
Expand All @@ -88,7 +89,7 @@ const Finish = ( { currentData, saveDataAndExit } ) => (
/**
* Step buttons presented in Header.
*
* @return
* @return {WPComponent} StepNavigation Component
*/
const StepNavigation = () => {
const location = useLocation();
Expand All @@ -114,7 +115,7 @@ const StepNavigation = () => {
{ isLastStep ? (
<Finish
currentData={ currentData }
saveDataAndExit={ saveDataAndExit }
saveDataAndExitFunc={ saveDataAndExit }
/>
) : (
<Next path={ nextStep.path } />
Expand Down
20 changes: 10 additions & 10 deletions src/OnboardingSPA/components/SkipButton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import { useLocation, useNavigate } from 'react-router-dom';
import { setFlow } from '../../utils/api/flow';
import { store as nfdOnboardingStore } from '../../store';
import { getSettings, setSettings } from '../../utils/api/settings';
import { wpAdminPage, bluehostDashboardPage } from '../../../constants';
import { wpAdminPage, pluginDashboardPage } from '../../../constants';

/**
* Interface Text Inputs with standard design.
*
* @return
* @return {WPComponent} SkipButton Component
*/
const SkipButton = () => {
const navigate = useNavigate();
Expand All @@ -27,17 +27,16 @@ const SkipButton = () => {

const isLastStep = null === nextStep || false === nextStep;

async function syncSocialSettingsFinish( currentData ) {
async function syncSocialSettingsFinish() {
const initialData = await getSettings();
const result = await setSettings( currentData?.data?.socialData );
if ( result?.error != null ) {
console.error( 'Unable to Save Social Data!' );
if ( result?.error !== null ) {
return initialData?.body;
}
return result?.body;
}

async function saveData( path, currentData ) {
async function saveData( path ) {
if ( currentData ) {
currentData.isComplete = new Date().getTime();

Expand All @@ -48,15 +47,16 @@ const SkipButton = () => {
);

// If Social Data is changed then Sync that also to the store
if ( socialData && currentData?.data )
if ( socialData && currentData?.data ) {
currentData.data.socialData = socialData;
}
}
setFlow( currentData );
}
// Redirect to Admin Page for normal customers
// and Bluehost Dashboard for ecommerce customers
const exitLink = exitToWordpressForEcommerce()
? bluehostDashboardPage
? pluginDashboardPage
: wpAdminPage;
window.location.replace( exitLink );
}
Expand All @@ -66,7 +66,7 @@ const SkipButton = () => {
return (
<Button
className="skip-button"
onClick={ () => saveData( location.pathname, currentData ) }
onClick={ () => saveData( location.pathname ) }
>
{ __( 'Skip this Step', 'wp-module-onboarding' ) }
</Button>
Expand All @@ -89,7 +89,7 @@ const SkipButton = () => {
* check if this is the last step
*/
const exitToWordpressForEcommerce = () => {
if ( window.nfdOnboarding.currentFlow == 'ecommerce' ) {
if ( window.nfdOnboarding.currentFlow === 'ecommerce' ) {
return true;
}
return false;
Expand Down
8 changes: 4 additions & 4 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const onboardingRestRoute = 'newfold-onboarding/v1';
export const wpRestBase = `${ wpRestURL }/${ wpRestRoute }`;
export const onboardingRestBase = `${ wpRestURL }/${ onboardingRestRoute }`;
export const wpAdminPage = `${ wpAdminUrl }index.php`;
export const bluehostDashboardPage = `${ wpAdminPage }?page=bluehost`;
export const pluginDashboardPage = `${ window.nfdOnboarding.currentBrand?.pluginDashboardPage ?? wpAdminPage }`;
export const NFD_ONBOARDING_EVENT_PREFIX = 'nfd-module-onboarding-event';
export const VIEW_NAV_PRIMARY = 'nav-primary';
export const VIEW_NAV_DESIGN = 'nav-design';
Expand Down Expand Up @@ -39,14 +39,14 @@ export const THEME_STATUS_NOT_ACTIVE = 'inactive';
export const THEME_STATUS_INSTALLING = 'installing';
export const THEME_STATUS_ACTIVE = 'activated';
export const THEME_STATUS_FAILURE = 'failed';
export const THEME_INSTALL_WAIT_TIMEOUT = 30000
export const THEME_INSTALL_WAIT_TIMEOUT = 30000;

export const ECOMMERCE_STEPS_PLUGIN = 'woocommerce'
export const ECOMMERCE_STEPS_PLUGIN = 'woocommerce';
export const PLUGIN_STATUS_INIT = 'init';
export const PLUGIN_STATUS_NOT_ACTIVE = 'inactive';
export const PLUGIN_STATUS_INSTALLING = 'installing';
export const PLUGIN_STATUS_ACTIVE = 'activated';
export const PLUGIN_INSTALL_WAIT_TIMEOUT = 30000
export const PLUGIN_INSTALL_WAIT_TIMEOUT = 30000;

/**
* All views for the <Drawer /> component.
Expand Down

0 comments on commit d6c8cfc

Please sign in to comment.