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 { getSetting } from '@woocommerce/wc-admin-settings';
|
|
|
|
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';
|
2020-04-29 18:01:27 +00:00
|
|
|
|
2021-03-24 21:29:37 +00:00
|
|
|
type HomescreenProps = ReturnType< typeof withSelectHandler > & {
|
|
|
|
query: Record< string, string >;
|
|
|
|
};
|
|
|
|
|
|
|
|
const Homescreen = ( { profileItems, query }: HomescreenProps ) => {
|
2020-07-16 15:17:10 +00:00
|
|
|
const { completed: profilerCompleted, skipped: profilerSkipped } =
|
|
|
|
profileItems || {};
|
2020-08-24 21:51:41 +00:00
|
|
|
if ( ! 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
|
|
|
};
|
|
|
|
|
2020-08-24 13:20:57 +00:00
|
|
|
const onboardingData = getSetting( 'onboarding', {} );
|
|
|
|
|
2021-03-24 21:29:37 +00:00
|
|
|
const withSelectHandler = ( select: WCDataSelector ) => {
|
|
|
|
const { getProfileItems } = select( ONBOARDING_STORE_NAME );
|
|
|
|
const profileItems = getProfileItems();
|
|
|
|
|
|
|
|
return { profileItems };
|
|
|
|
};
|
|
|
|
|
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 );
|