2020-04-27 14:56:15 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { compose } from '@wordpress/compose';
|
2020-08-05 00:14:56 +00:00
|
|
|
import { withSelect } from '@wordpress/data';
|
2023-06-16 12:28:25 +00:00
|
|
|
import { useEffect } from '@wordpress/element';
|
2020-05-28 08:51:40 +00:00
|
|
|
import {
|
|
|
|
ONBOARDING_STORE_NAME,
|
|
|
|
withOnboardingHydration,
|
2022-04-25 06:16:39 +00:00
|
|
|
WCDataSelector,
|
2020-05-28 08:51:40 +00:00
|
|
|
} from '@woocommerce/data';
|
2022-08-04 08:57:53 +00:00
|
|
|
import { getHistory, getNewPath, useQuery } from '@woocommerce/navigation';
|
2023-06-16 12:28:25 +00:00
|
|
|
|
2020-04-27 14:56:15 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2020-05-12 23:14:08 +00:00
|
|
|
import Layout from './layout';
|
2022-01-06 12:53:30 +00:00
|
|
|
import { getAdminSetting } from '~/utils/admin-settings';
|
2020-04-29 18:01:27 +00:00
|
|
|
|
2021-03-24 21:29:37 +00:00
|
|
|
type HomescreenProps = ReturnType< typeof withSelectHandler > & {
|
2022-01-06 01:47:09 +00:00
|
|
|
hasFinishedResolution: boolean;
|
2021-03-24 21:29:37 +00:00
|
|
|
};
|
|
|
|
|
2022-01-06 01:47:09 +00:00
|
|
|
const Homescreen = ( {
|
|
|
|
profileItems: {
|
|
|
|
completed: profilerCompleted,
|
|
|
|
skipped: profilerSkipped,
|
|
|
|
} = {},
|
|
|
|
hasFinishedResolution,
|
|
|
|
}: HomescreenProps ) => {
|
2023-06-16 12:28:25 +00:00
|
|
|
useEffect( () => {
|
|
|
|
if (
|
|
|
|
hasFinishedResolution &&
|
|
|
|
! profilerCompleted &&
|
|
|
|
! profilerSkipped
|
|
|
|
) {
|
|
|
|
getHistory().push( getNewPath( {}, '/setup-wizard', {} ) );
|
|
|
|
}
|
|
|
|
}, [ hasFinishedResolution, profilerCompleted, profilerSkipped ] );
|
2020-04-27 14:56:15 +00:00
|
|
|
|
2022-08-04 08:57:53 +00:00
|
|
|
const query = useQuery();
|
2024-06-13 02:39:21 +00:00
|
|
|
|
2020-05-21 17:15:08 +00:00
|
|
|
return <Layout query={ query } />;
|
2020-04-22 21:32:44 +00:00
|
|
|
};
|
|
|
|
|
2022-01-06 12:53:30 +00:00
|
|
|
const onboardingData = getAdminSetting( 'onboarding', {} );
|
2020-08-24 13:20:57 +00:00
|
|
|
|
2021-03-24 21:29:37 +00:00
|
|
|
const withSelectHandler = ( select: WCDataSelector ) => {
|
2022-01-06 01:47:09 +00:00
|
|
|
const { getProfileItems, hasFinishedResolution } = select(
|
|
|
|
ONBOARDING_STORE_NAME
|
|
|
|
);
|
2021-03-24 21:29:37 +00:00
|
|
|
|
2022-01-06 01:47:09 +00:00
|
|
|
return {
|
|
|
|
profileItems: getProfileItems(),
|
|
|
|
hasFinishedResolution: hasFinishedResolution( 'getProfileItems', [] ),
|
|
|
|
};
|
2021-03-24 21:29:37 +00:00
|
|
|
};
|
|
|
|
|
2020-04-27 14:56:15 +00:00
|
|
|
export default compose(
|
2023-04-11 07:27:38 +00:00
|
|
|
withOnboardingHydration( {
|
|
|
|
profileItems: onboardingData.profile,
|
|
|
|
} ),
|
2021-03-24 21:29:37 +00:00
|
|
|
withSelect( withSelectHandler )
|
2020-06-15 02:17:12 +00:00
|
|
|
)( Homescreen );
|