Skip to content

Commit

Permalink
Making profile messageEventListener configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
bandana147 committed Feb 6, 2025
1 parent 9d35cec commit 8a09db3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
50 changes: 28 additions & 22 deletions libs/blocks/global-navigation/global-navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,33 @@ function getHelpChildren() {
];
}

const getMessageEventListener = () => {
const configListener = getConfig().unav?.profile?.messageEventListener;
if (configListener) return configListener;

return (event) => {
const { name, payload, executeDefaultAction } = event.detail;
if (!name || name !== 'System' || !payload || typeof executeDefaultAction !== 'function') return;
switch (payload.subType) {
case 'AppInitiated':
window.adobeProfile?.getUserProfile()
.then((data) => { setUserProfile(data); })
.catch(() => { setUserProfile({}); });
break;
case 'SignOut':
executeDefaultAction();
break;
case 'ProfileSwitch':
Promise.resolve(executeDefaultAction()).then((profile) => {
if (profile) window.location.reload();
});
break;
default:
break;
}
};
};

export const CONFIG = {
icons: isDarkMode() ? darkIcons : icons,
delays: {
Expand All @@ -78,28 +105,7 @@ export const CONFIG = {
name: 'profile',
attributes: {
isSignUpRequired: false,
messageEventListener: (event) => {
const { name, payload, executeDefaultAction } = event.detail;
if (!name || name !== 'System' || !payload || typeof executeDefaultAction !== 'function') return;
switch (payload.subType) {
case 'AppInitiated':
window.adobeProfile?.getUserProfile()
.then((data) => { setUserProfile(data); })
.catch(() => { setUserProfile({}); });
break;
case 'SignOut':
executeDefaultAction();
break;
case 'ProfileSwitch':
Promise.resolve(executeDefaultAction()).then((profile) => {
if (profile) window.location.reload();
});
break;
default:
break;
}
},
...getConfig().unav?.profile?.messageEventListener,
messageEventListener: getMessageEventListener(),
componentLoaderConfig: {
config: {
enableLocalSection: true,
Expand Down
2 changes: 1 addition & 1 deletion libs/navigation/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@adobecom/standalone-feds",
"version": "0.0.2",
"version": "0.0.3-test",
"description": "",
"main": "dist/navigation.js",
"type": "module",
Expand Down

0 comments on commit 8a09db3

Please sign in to comment.