2018-04-17 23:51:48 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2019-07-23 03:26:46 +00:00
|
|
|
import '@wordpress/notices';
|
2018-05-18 17:31:08 +00:00
|
|
|
import { render } from '@wordpress/element';
|
2018-04-17 23:51:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2018-08-06 15:30:43 +00:00
|
|
|
import './stylesheets/_index.scss';
|
2019-09-24 15:55:39 +00:00
|
|
|
import { PageLayout, EmbedLayout, PrimaryLayout as NoticeArea } from './layout';
|
2018-11-29 15:57:49 +00:00
|
|
|
import 'wc-api/wp-data-store';
|
2020-06-10 16:46:46 +00:00
|
|
|
import { withCurrentUserHydration, withSettingsHydration } from '@woocommerce/data';
|
2018-05-15 15:06:15 +00:00
|
|
|
|
2020-04-29 18:01:27 +00:00
|
|
|
// Modify webpack pubilcPath at runtime based on location of WordPress Plugin.
|
|
|
|
// eslint-disable-next-line no-undef,camelcase
|
|
|
|
__webpack_public_path__ = global.wcAdminAssets.path;
|
|
|
|
|
2019-09-24 15:55:39 +00:00
|
|
|
const appRoot = document.getElementById( 'root' );
|
2020-03-25 03:20:17 +00:00
|
|
|
const settingsGroup = 'wc_admin';
|
2020-06-10 16:46:46 +00:00
|
|
|
const hydrateUser = window.wcSettings.currentUserData;
|
2019-09-24 15:55:39 +00:00
|
|
|
|
|
|
|
if ( appRoot ) {
|
2020-06-10 16:46:46 +00:00
|
|
|
let HydratedPageLayout = withSettingsHydration( settingsGroup, window.wcSettings )(
|
2020-03-25 03:20:17 +00:00
|
|
|
PageLayout
|
|
|
|
);
|
2020-06-22 22:18:35 +00:00
|
|
|
const hydrateSettings =
|
|
|
|
window.wcSettings.preloadSettings &&
|
|
|
|
window.wcSettings.preloadSettings.general;
|
|
|
|
|
|
|
|
if ( hydrateSettings ) {
|
|
|
|
HydratedPageLayout = withSettingsHydration( 'general', { general: window.wcSettings.preloadSettings.general, } )( HydratedPageLayout );
|
|
|
|
}
|
2020-06-10 16:46:46 +00:00
|
|
|
if ( hydrateUser ) {
|
|
|
|
HydratedPageLayout = withCurrentUserHydration( hydrateUser )( HydratedPageLayout );
|
|
|
|
}
|
2020-03-25 03:20:17 +00:00
|
|
|
render( <HydratedPageLayout />, appRoot );
|
2019-09-24 15:55:39 +00:00
|
|
|
} else {
|
|
|
|
const embeddedRoot = document.getElementById( 'woocommerce-embedded-root' );
|
2020-06-10 16:46:46 +00:00
|
|
|
let HydratedEmbedLayout = withSettingsHydration( settingsGroup, window.wcSettings )(
|
2020-03-25 03:20:17 +00:00
|
|
|
EmbedLayout
|
|
|
|
);
|
2020-06-10 16:46:46 +00:00
|
|
|
if ( hydrateUser ) {
|
|
|
|
HydratedEmbedLayout = withCurrentUserHydration( hydrateUser )( HydratedEmbedLayout );
|
|
|
|
}
|
2019-09-24 15:55:39 +00:00
|
|
|
// Render the header.
|
2020-03-25 03:20:17 +00:00
|
|
|
render( <HydratedEmbedLayout />, embeddedRoot );
|
2019-09-24 15:55:39 +00:00
|
|
|
|
|
|
|
embeddedRoot.classList.remove( 'is-embed-loading' );
|
|
|
|
|
|
|
|
// Render notices just above the WP content div.
|
|
|
|
const wpBody = document.getElementById( 'wpbody-content' );
|
2020-05-06 23:17:50 +00:00
|
|
|
const wrap = wpBody.querySelector( '.wrap.woocommerce' ) || wpBody.querySelector( '[class="wrap"]' );
|
2019-09-24 15:55:39 +00:00
|
|
|
const noticeContainer = document.createElement( 'div' );
|
|
|
|
|
|
|
|
render(
|
|
|
|
<div className="woocommerce-layout">
|
|
|
|
<NoticeArea />
|
|
|
|
</div>,
|
|
|
|
wpBody.insertBefore( noticeContainer, wrap )
|
|
|
|
);
|
|
|
|
}
|