Skip to content

Commit

Permalink
Merge pull request #550 from newfold-labs/revert-539-add/design-state…
Browse files Browse the repository at this point in the history
…-handler-fresh-install-check

Revert "Switch to Fresh Installation check before activating Wonder Theme"
  • Loading branch information
arunshenoy99 authored Apr 30, 2024
2 parents 308b065 + 9612806 commit ec0e4da
Show file tree
Hide file tree
Showing 9 changed files with 600 additions and 322 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"wp-cli/wp-config-transformer": "^1.3",
"newfold-labs/wp-module-onboarding-data": "^1.1",
"newfold-labs/wp-module-patterns": "^0.2",
"newfold-labs/wp-module-install-checker": "^1.0",
"newfold-labs/wp-module-facebook": "^1.0",
"wp-forge/helpers": "^2.0"
},
Expand Down
816 changes: 559 additions & 257 deletions composer.lock

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions includes/LoginRedirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use NewfoldLabs\WP\Module\Onboarding\Data\Data;
use NewfoldLabs\WP\Module\Onboarding\Data\Options;

use function NewfoldLabs\WP\ModuleLoader\container;
use function WP_Forge\Helpers\dataGet;

/**
Expand Down Expand Up @@ -71,8 +72,11 @@ public static function filter_redirect( $original_redirect, $user ) {
}

// Don't redirect to onboarding if the site is not a fresh installation.
if ( false === Data::is_fresh_installation() ) {
return $original_redirect;
if ( container()->has( 'isFreshInstallation' ) ) {
$is_fresh_installation = container()->get( 'isFreshInstallation' );
if ( false === $is_fresh_installation ) {
return $original_redirect;
}
}

// Don't redirect to onboarding if the 'coming_soon' mode is off. The user has launched their site.
Expand Down
1 change: 0 additions & 1 deletion src/OnboardingSPA/components/Button/NavCardButton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const NavCardButton = ( { text, disabled, className, icon } ) => {
async function saveDataAndExit() {
if ( currentData ) {
currentData.isComplete = new Date().getTime();
currentData.data.siteOverrideConsent = false;
setFlow( currentData );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ const Next = ( { path, showErrorDialog } ) => {
async function saveDataAndExit( currentData ) {
if ( currentData ) {
currentData.isComplete = new Date().getTime();
currentData.data.siteOverrideConsent = false;
setFlow( currentData );
}

Expand Down
11 changes: 0 additions & 11 deletions src/OnboardingSPA/components/StateHandlers/Design/contents.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,6 @@ const getContents = ( brandName ) => {
'wp-module-onboarding'
),
},
exitModal: {
title: __(
'It looks like you may have an existing website',
'wp-module-onboarding'
),
description: __(
'Going through this setup will change your active theme, WordPress settings, add content – would you like to continue?',
'wp-module-onboarding'
),
buttonText: __( 'Exit to WordPress', 'wp-module-onboarding' ),
},
};
};

Expand Down
79 changes: 33 additions & 46 deletions src/OnboardingSPA/components/StateHandlers/Design/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useSelect, useDispatch } from '@wordpress/data';
import { Fragment, useEffect } from '@wordpress/element';
import { useViewportMatch } from '@wordpress/compose';
import { __ } from '@wordpress/i18n';

import { StepLoader } from '../../Loaders';
import { store as nfdOnboardingStore } from '../../../store';
Expand All @@ -20,7 +21,6 @@ import {
import { StepErrorState } from '../../ErrorState';
import getContents from './contents';
import ExitToWordPress from '../../ExitToWordPress';
import { setFlow } from '../../../utils/api/flow';

const DesignStateHandler = ( {
children,
Expand All @@ -30,18 +30,12 @@ const DesignStateHandler = ( {
} ) => {
const isLargeViewport = useViewportMatch( 'medium' );

const { storedThemeStatus, brandName, isFreshInstallation, currentData } =
useSelect( ( select ) => {
return {
storedThemeStatus:
select( nfdOnboardingStore ).getThemeStatus(),
brandName: select( nfdOnboardingStore ).getNewfoldBrandName(),
isFreshInstallation:
select( nfdOnboardingStore ).getIsFreshInstallation(),
currentData:
select( nfdOnboardingStore ).getCurrentOnboardingData(),
};
}, [] );
const { storedThemeStatus, brandName } = useSelect( ( select ) => {
return {
storedThemeStatus: select( nfdOnboardingStore ).getThemeStatus(),
brandName: select( nfdOnboardingStore ).getNewfoldBrandName(),
};
}, [] );

const contents = getContents( brandName );

Expand All @@ -50,7 +44,6 @@ const DesignStateHandler = ( {
setIsDrawerOpened,
setIsDrawerSuppressed,
setIsHeaderNavigationEnabled,
setCurrentOnboardingData,
} = useDispatch( nfdOnboardingStore );

const checkThemeStatus = async () => {
Expand Down Expand Up @@ -114,7 +107,11 @@ const DesignStateHandler = ( {
}
break;
case THEME_STATUS_NOT_ACTIVE:
installThemeManually();
if ( false === render ) {
// When render is false add this condition because
// handleRender() func does not run here and theme is not activated.
expediteInstall();
}
break;
default:
updateThemeStatus( themeStatus );
Expand All @@ -124,18 +121,10 @@ const DesignStateHandler = ( {
useEffect( () => {
handleNavigationState();

if (
true === render &&
! isFreshInstallation &&
currentData.data.siteOverrideConsent === false
) {
return;
}

if ( storedThemeStatus === THEME_STATUS_INIT ) {
handleThemeStatus( storedThemeStatus );
}
}, [ storedThemeStatus, isFreshInstallation, currentData ] );
}, [ storedThemeStatus ] );

Check warning on line 127 in src/OnboardingSPA/components/StateHandlers/Design/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

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

const installThemeManually = async () => {
updateThemeStatus( THEME_STATUS_INSTALLING );
Expand All @@ -144,7 +133,6 @@ const DesignStateHandler = ( {
true,
false
);

if ( themeInstallStatus.error ) {
return updateThemeStatus( THEME_STATUS_FAILURE );
}
Expand All @@ -154,29 +142,28 @@ const DesignStateHandler = ( {
}
};

const handleModalClose = () => {
currentData.data.siteOverrideConsent = true;
setCurrentOnboardingData( currentData );
setFlow( currentData );
};

const handleRender = () => {
if (
! isFreshInstallation &&
currentData.data.siteOverrideConsent === false
) {
return (
<ExitToWordPress
showButton={ false }
isModalOpen={ true }
modalTitle={ contents.exitModal.title }
modalText={ contents.exitModal.description }
modalOnClose={ handleModalClose }
modalExitButtonText={ contents.exitModal.buttonText }
/>
);
}
switch ( storedThemeStatus ) {
case THEME_STATUS_NOT_ACTIVE:
return (
<ExitToWordPress
showButton={ false }
isModalOpen={ true }
modalTitle={ __(
'It looks like you may have an existing website',
'wp-module-onboarding'
) }
modalText={ __(
'Going through this setup will change your active theme, WordPress settings, add content – would you like to continue?',
'wp-module-onboarding'
) }
modalOnClose={ installThemeManually }
modalExitButtonText={ __(
'Exit to WordPress',
'wp-module-onboarding'
) }
/>
);
case THEME_STATUS_FAILURE:
return (
<StepErrorState
Expand Down
1 change: 1 addition & 0 deletions src/OnboardingSPA/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export function setRuntime( runtime ) {
siteUrl: runtime.siteUrl,
migrated: true,
currentFlow: runtime.currentFlow ?? DEFAULT_FLOW,
stepPreviewData: runtime.previewSettings.stepPreviewData,
};
return {
type: 'SET_RUNTIME',
Expand Down
4 changes: 0 additions & 4 deletions src/OnboardingSPA/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,3 @@ export function getSiteGenErrorStatus( state ) {
export function getInteractionDisabled( state ) {
return state.flow.interactionDisabled;
}

export function getIsFreshInstallation( state ) {
return state.runtime.isFreshInstallation;
}

0 comments on commit ec0e4da

Please sign in to comment.