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';
|
2022-01-06 12:53:30 +00:00
|
|
|
import { getAdminSetting } from '~/utils/admin-settings';
|
2019-09-24 15:55:39 +00:00
|
|
|
import { PageLayout, EmbedLayout, PrimaryLayout as NoticeArea } from './layout';
|
2020-10-30 06:52:52 +00:00
|
|
|
import { CustomerEffortScoreTracksContainer } from './customer-effort-score-tracks';
|
2021-04-20 17:17:19 +00:00
|
|
|
import { EmbeddedBodyLayout } from './embedded-body-layout';
|
2022-04-20 07:29:29 +00:00
|
|
|
import { WcAdminPaymentsGatewaysBannerSlot } from './payments/payments-settings-banner-slotfill';
|
2022-12-15 13:04:28 +00:00
|
|
|
import { WcAdminConflictErrorSlot } from './settings/conflict-error-slotfill.js';
|
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;
|
|
|
|
|
2022-06-07 13:35:04 +00:00
|
|
|
// Modify webpack to append the ?ver parameter to JS chunk
|
|
|
|
// https://webpack.js.org/api/module-variables/#__webpack_get_script_filename__-webpack-specific
|
|
|
|
// eslint-disable-next-line no-undef,camelcase
|
|
|
|
const oldGetScriptFileNameFn = __webpack_get_script_filename__;
|
|
|
|
// eslint-disable-next-line no-undef,camelcase
|
|
|
|
__webpack_get_script_filename__ = ( chunk ) => {
|
|
|
|
const filename = oldGetScriptFileNameFn( chunk );
|
|
|
|
return `${ filename }?ver=${ window.wcAdminAssets.version }`;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Modify webpack to append the ?ver parameter to CSS chunk hrefs generated by mini-css-extract-plugin
|
|
|
|
// eslint-disable-next-line no-undef,camelcase
|
|
|
|
const oldMinCssFn = __webpack_require__.miniCssF;
|
|
|
|
// eslint-disable-next-line no-undef,camelcase
|
|
|
|
__webpack_require__.miniCssF = ( chunkId ) => {
|
|
|
|
const filename = oldMinCssFn( chunkId );
|
|
|
|
return `${ filename }?ver=${ window.wcAdminAssets.version }`;
|
|
|
|
};
|
|
|
|
|
2019-09-24 15:55:39 +00:00
|
|
|
const appRoot = document.getElementById( 'root' );
|
2020-10-30 06:52:52 +00:00
|
|
|
const embeddedRoot = document.getElementById( 'woocommerce-embedded-root' );
|
2020-03-25 03:20:17 +00:00
|
|
|
const settingsGroup = 'wc_admin';
|
2022-01-06 12:53:30 +00:00
|
|
|
const hydrateUser = getAdminSetting( 'currentUserData' );
|
2019-09-24 15:55:39 +00:00
|
|
|
|
|
|
|
if ( appRoot ) {
|
2020-07-28 02:32:58 +00:00
|
|
|
let HydratedPageLayout = withSettingsHydration(
|
|
|
|
settingsGroup,
|
2021-08-24 11:39:48 +00:00
|
|
|
window.wcSettings.admin
|
2020-07-28 02:32:58 +00:00
|
|
|
)( PageLayout );
|
2021-08-24 11:39:48 +00:00
|
|
|
const preloadSettings = window.wcSettings.admin
|
|
|
|
? window.wcSettings.admin.preloadSettings
|
|
|
|
: false;
|
|
|
|
const hydrateSettings = preloadSettings && preloadSettings.general;
|
2020-06-22 22:18:35 +00:00
|
|
|
|
|
|
|
if ( hydrateSettings ) {
|
2020-07-28 02:32:58 +00:00
|
|
|
HydratedPageLayout = withSettingsHydration( 'general', {
|
2021-08-24 11:39:48 +00:00
|
|
|
general: preloadSettings.general,
|
2020-07-28 02:32:58 +00:00
|
|
|
} )( HydratedPageLayout );
|
2020-06-22 22:18:35 +00:00
|
|
|
}
|
2020-06-10 16:46:46 +00:00
|
|
|
if ( hydrateUser ) {
|
2022-06-21 08:37:34 +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 );
|
2020-11-11 21:27:26 +00:00
|
|
|
} else if ( embeddedRoot ) {
|
2020-07-28 02:32:58 +00:00
|
|
|
let HydratedEmbedLayout = withSettingsHydration(
|
|
|
|
settingsGroup,
|
2021-08-24 11:39:48 +00:00
|
|
|
window.wcSettings.admin
|
2020-07-28 02:32:58 +00:00
|
|
|
)( EmbedLayout );
|
2020-06-10 16:46:46 +00:00
|
|
|
if ( hydrateUser ) {
|
2022-06-21 08:37:34 +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' );
|
2021-05-26 01:36:04 +00:00
|
|
|
|
2022-04-19 08:07:07 +00:00
|
|
|
const isWcAdminSettingsPaymentPage = document.getElementById(
|
2022-04-06 16:38:38 +00:00
|
|
|
'wc_payment_gateways_banner_slotfill'
|
|
|
|
);
|
2022-04-19 08:07:07 +00:00
|
|
|
|
2022-04-20 07:29:29 +00:00
|
|
|
if ( isWcAdminSettingsPaymentPage ) {
|
|
|
|
render(
|
|
|
|
WcAdminPaymentsGatewaysBannerSlot(),
|
|
|
|
isWcAdminSettingsPaymentPage
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-12-15 13:04:28 +00:00
|
|
|
const isTaxPage = document.getElementById( 'wc_conflict_error_slotfill' );
|
|
|
|
|
|
|
|
if ( isTaxPage ) {
|
|
|
|
render( WcAdminConflictErrorSlot(), isTaxPage );
|
|
|
|
}
|
|
|
|
|
2020-07-28 02:32:58 +00:00
|
|
|
const wrap =
|
|
|
|
wpBody.querySelector( '.wrap.woocommerce' ) ||
|
2022-07-04 04:41:32 +00:00
|
|
|
document.querySelector( '#wpbody-content > .woocommerce' ) ||
|
2021-05-26 01:36:04 +00:00
|
|
|
wpBody.querySelector( '.wrap' );
|
2019-09-24 15:55:39 +00:00
|
|
|
const noticeContainer = document.createElement( 'div' );
|
2022-04-06 16:38:38 +00:00
|
|
|
|
2019-09-24 15:55:39 +00:00
|
|
|
render(
|
|
|
|
<div className="woocommerce-layout">
|
|
|
|
<NoticeArea />
|
|
|
|
</div>,
|
|
|
|
wpBody.insertBefore( noticeContainer, wrap )
|
|
|
|
);
|
2021-04-20 17:17:19 +00:00
|
|
|
const embeddedBodyContainer = document.createElement( 'div' );
|
|
|
|
render(
|
|
|
|
<EmbeddedBodyLayout />,
|
|
|
|
wpBody.insertBefore( embeddedBodyContainer, wrap.nextSibling )
|
|
|
|
);
|
2019-09-24 15:55:39 +00:00
|
|
|
}
|
2020-10-13 01:40:53 +00:00
|
|
|
|
2020-12-03 22:48:51 +00:00
|
|
|
// Render the CustomerEffortScoreTracksContainer only if
|
|
|
|
// the feature flag is enabled.
|
|
|
|
if (
|
|
|
|
window.wcAdminFeatures &&
|
|
|
|
window.wcAdminFeatures[ 'customer-effort-score-tracks' ] === true
|
|
|
|
) {
|
|
|
|
// Set up customer effort score survey.
|
|
|
|
( function () {
|
|
|
|
const root = appRoot || embeddedRoot;
|
2020-10-30 06:52:52 +00:00
|
|
|
|
2020-12-03 22:48:51 +00:00
|
|
|
render(
|
|
|
|
<CustomerEffortScoreTracksContainer />,
|
|
|
|
root.insertBefore( document.createElement( 'div' ), null )
|
|
|
|
);
|
|
|
|
} )();
|
|
|
|
}
|