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

Switch to Fresh Installation check before activating Wonder Theme #539

Merged
merged 3 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"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: 257 additions & 559 deletions composer.lock

Large diffs are not rendered by default.

8 changes: 2 additions & 6 deletions includes/LoginRedirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
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 @@ -72,11 +71,8 @@ public static function filter_redirect( $original_redirect, $user ) {
}

// Don't redirect to onboarding if the site is not a fresh installation.
if ( container()->has( 'isFreshInstallation' ) ) {
$is_fresh_installation = container()->get( 'isFreshInstallation' );
if ( false === $is_fresh_installation ) {
return $original_redirect;
}
if ( false === Data::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: 1 addition & 0 deletions src/OnboardingSPA/components/Button/NavCardButton/index.js
arunshenoy99 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ 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,6 +78,7 @@ 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: 11 additions & 0 deletions src/OnboardingSPA/components/StateHandlers/Design/contents.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ 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: 46 additions & 33 deletions src/OnboardingSPA/components/StateHandlers/Design/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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 @@ -21,6 +20,7 @@ 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,12 +30,18 @@ const DesignStateHandler = ( {
} ) => {
const isLargeViewport = useViewportMatch( 'medium' );

const { storedThemeStatus, brandName } = useSelect( ( select ) => {
return {
storedThemeStatus: select( nfdOnboardingStore ).getThemeStatus(),
brandName: select( nfdOnboardingStore ).getNewfoldBrandName(),
};
}, [] );
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 contents = getContents( brandName );

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

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

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

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

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

if ( themeInstallStatus.error ) {
return updateThemeStatus( THEME_STATUS_FAILURE );
}
Expand All @@ -142,28 +154,29 @@ 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: 0 additions & 1 deletion src/OnboardingSPA/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ 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: 4 additions & 0 deletions src/OnboardingSPA/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,3 +446,7 @@ export function getSiteGenErrorStatus( state ) {
export function getInteractionDisabled( state ) {
return state.flow.interactionDisabled;
}

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