From 780de61378644ff3caa24347163509f387f32bc8 Mon Sep 17 00:00:00 2001 From: baha Date: Mon, 27 Jan 2025 14:32:56 +0000 Subject: [PATCH] [test] popup --- src/layouts/Base/index.jsx | 32 +++++++++++++++++++++++++------- src/layouts/Blank/index.less | 4 ++-- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/layouts/Base/index.jsx b/src/layouts/Base/index.jsx index ddf9e951..f82c0af4 100644 --- a/src/layouts/Base/index.jsx +++ b/src/layouts/Base/index.jsx @@ -43,11 +43,18 @@ export class BaseLayout extends Component { super(props); this.state = { collapsed: false, + isOpenedInPopup: false, // State to track if opened in a popup }; this.init(); } + componentDidMount() { + // Listen for postMessage from the parent app + window.addEventListener('message', this.handleMessage, false); + } + componentWillUnmount() { + window.removeEventListener('message', this.handleMessage, false); this.autoReaction(); } @@ -134,6 +141,19 @@ export class BaseLayout extends Component { return newMenu; }; + handleMessage = (event) => { + const trustedOrigins = [ + 'https://baha-dev.felcloud.io', + 'https://demo.felcloud.io', + ]; + if (trustedOrigins.includes(event.origin)) { + const { message } = event.data; + if (message === 'openedInPopup') { + this.setState({ isOpenedInPopup: true }); + } + } + }; + checkItemEndpoints = (key) => this.rootStore.checkEndpoint(key); getMenuAllowed = (menu) => { @@ -260,8 +280,8 @@ export class BaseLayout extends Component { render() { const { pathname } = this.props.location; const currentRoutes = this.getCurrentMenu(pathname); - console.log('hapened'); - if (window.opener) { + console.log('testing popup'); + if (this.state.isOpenedInPopup) { return ( -

Connexion... Please wait !

+

Connexion... Please wait!

); } + return (
{this.renderNotice()} -
- {/* {this.renderLogo()} */} - {this.renderHeader()} -
+
{this.renderHeader()}