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';
|
2020-08-13 02:05:22 +00:00
|
|
|
import {
|
|
|
|
withCurrentUserHydration,
|
|
|
|
withSettingsHydration,
|
|
|
|
} from '@woocommerce/data';
|
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';
|
2020-08-13 02:05:22 +00:00
|
|
|
import './wc-api/wp-data-store';
|
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-07-28 02:32:58 +00:00
|
|
|
let HydratedPageLayout = withSettingsHydration(
|
|
|
|
settingsGroup,
|
|
|
|
window.wcSettings
|
|
|
|
)( PageLayout );
|
2020-06-22 22:18:35 +00:00
|
|
|
const hydrateSettings =
|
2020-07-28 02:32:58 +00:00
|
|
|
window.wcSettings.preloadSettings &&
|
|
|
|
window.wcSettings.preloadSettings.general;
|
2020-06-22 22:18:35 +00:00
|
|
|
|
|
|
|
if ( hydrateSettings ) {
|
2020-07-28 02:32:58 +00:00
|
|
|
HydratedPageLayout = withSettingsHydration( 'general', {
|
|
|
|
general: window.wcSettings.preloadSettings.general,
|
|
|
|
} )( HydratedPageLayout );
|
2020-06-22 22:18:35 +00:00
|
|
|
}
|
2020-06-10 16:46:46 +00:00
|
|
|
if ( hydrateUser ) {
|
2020-07-28 02:32:58 +00:00
|
|
|
HydratedPageLayout = withCurrentUserHydration( hydrateUser )(
|
|
|
|
HydratedPageLayout
|
|
|
|
);
|
2020-06-10 16:46:46 +00:00
|
|
|
}
|
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-07-28 02:32:58 +00:00
|
|
|
let HydratedEmbedLayout = withSettingsHydration(
|
|
|
|
settingsGroup,
|
|
|
|
window.wcSettings
|
|
|
|
)( EmbedLayout );
|
2020-06-10 16:46:46 +00:00
|
|
|
if ( hydrateUser ) {
|
2020-07-28 02:32:58 +00:00
|
|
|
HydratedEmbedLayout = withCurrentUserHydration( hydrateUser )(
|
|
|
|
HydratedEmbedLayout
|
|
|
|
);
|
2020-06-10 16:46:46 +00:00
|
|
|
}
|
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-07-28 02:32:58 +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 )
|
|
|
|
);
|
|
|
|
}
|