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';
|
2020-05-28 08:51:40 +00:00
|
|
|
import { identity } from 'lodash';
|
|
|
|
import {
|
|
|
|
ONBOARDING_STORE_NAME,
|
|
|
|
withOnboardingHydration,
|
2021-03-24 21:29:37 +00:00
|
|
|
WCDataSelector,
|
2020-05-28 08:51:40 +00:00
|
|
|
} from '@woocommerce/data';
|
2020-07-16 15:17:10 +00:00
|
|
|
import { getHistory, getNewPath } from '@woocommerce/navigation';
|
2021-03-24 21:29:37 +00:00
|
|
|
import type { History } from 'history';
|
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
|
|
|
query: Record< string, string >;
|
|
|
|
};
|
|
|
|
|
2022-01-06 01:47:09 +00:00
|
|
|
const Homescreen = ( {
|
|
|
|
profileItems: {
|
|
|
|
completed: profilerCompleted,
|
|
|
|
skipped: profilerSkipped,
|
|
|
|
} = {},
|
|
|
|
hasFinishedResolution,
|
|
|
|
query,
|
|
|
|
}: HomescreenProps ) => {
|
|
|
|
if ( hasFinishedResolution && ! profilerCompleted && ! profilerSkipped ) {
|
2021-03-24 21:29:37 +00:00
|
|
|
( getHistory() as History ).push(
|
|
|
|
getNewPath( {}, '/setup-wizard', {} )
|
|
|
|
);
|
2020-04-27 14:56:15 +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(
|
2021-11-09 12:42:33 +00:00
|
|
|
onboardingData.profile
|
2020-08-24 13:20:57 +00:00
|
|
|
? withOnboardingHydration( {
|
|
|
|
profileItems: onboardingData.profile,
|
|
|
|
} )
|
2020-05-28 08:51:40 +00:00
|
|
|
: identity,
|
2021-03-24 21:29:37 +00:00
|
|
|
withSelect( withSelectHandler )
|
2020-06-15 02:17:12 +00:00
|
|
|
)( Homescreen );
|