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!