From de577f4fb9e338259f38cf9544651157d41c3739 Mon Sep 17 00:00:00 2001 From: Qiyun Dai Date: Mon, 30 Sep 2024 10:27:14 -0500 Subject: [PATCH 1/2] extracted onProfile actions --- .../attendee-management-table.js | 34 ++++++------------ ecc/blocks/ecc-dashboard/ecc-dashboard.js | 35 ++++++------------- ecc/scripts/event-apis.js | 35 +++++++++++++++++++ ecc/scripts/utils.js | 9 +++++ 4 files changed, 66 insertions(+), 47 deletions(-) diff --git a/ecc/blocks/attendee-management-table/attendee-management-table.js b/ecc/blocks/attendee-management-table/attendee-management-table.js index caa4f0c3..571ab17d 100644 --- a/ecc/blocks/attendee-management-table/attendee-management-table.js +++ b/ecc/blocks/attendee-management-table/attendee-management-table.js @@ -1,16 +1,16 @@ /* eslint-disable max-len */ import { getAllEventAttendees, getEvents } from '../../scripts/esp-controller.js'; -import { ALLOWED_ACCOUNT_TYPES } from '../../constants/constants.js'; import { LIBS } from '../../scripts/scripts.js'; import { getIcon, buildNoAccessScreen, camelToSentenceCase, readBlockConfig, + signIn, } from '../../scripts/utils.js'; -import BlockMediator from '../../scripts/deps/block-mediator.min.js'; import { SearchablePicker } from '../../components/searchable-picker/searchable-picker.js'; import { FilterMenu } from '../../components/filter-menu/filter-menu.js'; +import { initProfileLogicTree } from '../../scripts/event-apis.js'; const { createTag } = await import(`${LIBS}/utils/utils.js`); @@ -556,27 +556,15 @@ export default async function init(el) { const config = readBlockConfig(el); el.innerHTML = ''; buildLoadingScreen(el); - const profile = BlockMediator.get('imsProfile'); - - if (profile) { - if (profile.noProfile || !ALLOWED_ACCOUNT_TYPES.includes(profile.account_type)) { + initProfileLogicTree({ + noProfile: () => { + signIn(); + }, + noAccessProfile: () => { buildNoAccessScreen(el); - } else { + }, + validProfile: () => { buildDashboard(el, config); - } - - return; - } - - if (!profile) { - const unsubscribe = BlockMediator.subscribe('imsProfile', ({ newValue }) => { - if (newValue?.noProfile || !ALLOWED_ACCOUNT_TYPES.includes(newValue.account_type)) { - buildNoAccessScreen(el); - } else { - buildDashboard(el, config); - } - - unsubscribe(); - }); - } + }, + }); } diff --git a/ecc/blocks/ecc-dashboard/ecc-dashboard.js b/ecc/blocks/ecc-dashboard/ecc-dashboard.js index 85a920ef..6a0ba96e 100644 --- a/ecc/blocks/ecc-dashboard/ecc-dashboard.js +++ b/ecc/blocks/ecc-dashboard/ecc-dashboard.js @@ -6,11 +6,10 @@ import { publishEvent, unpublishEvent, } from '../../scripts/esp-controller.js'; -import { ALLOWED_ACCOUNT_TYPES } from '../../constants/constants.js'; import { LIBS } from '../../scripts/scripts.js'; -import { getIcon, buildNoAccessScreen, getEventPageHost, readBlockConfig } from '../../scripts/utils.js'; +import { getIcon, buildNoAccessScreen, getEventPageHost, readBlockConfig, signIn } from '../../scripts/utils.js'; import { quickFilter } from '../form-handler/data-handler.js'; -import BlockMediator from '../../scripts/deps/block-mediator.min.js'; +import { initProfileLogicTree } from '../../scripts/event-apis.js'; const { createTag } = await import(`${LIBS}/utils/utils.js`); @@ -705,27 +704,15 @@ export default async function init(el) { const config = readBlockConfig(el); el.innerHTML = ''; buildLoadingScreen(el); - const profile = BlockMediator.get('imsProfile'); - - if (profile) { - if (profile.noProfile || !ALLOWED_ACCOUNT_TYPES.includes(profile.account_type)) { + initProfileLogicTree({ + noProfile: () => { + signIn(); + }, + noAccessProfile: () => { buildNoAccessScreen(el); - } else { + }, + validProfile: () => { buildDashboard(el, config); - } - - return; - } - - if (!profile) { - const unsubscribe = BlockMediator.subscribe('imsProfile', ({ newValue }) => { - if (newValue?.noProfile || !ALLOWED_ACCOUNT_TYPES.includes(newValue.account_type)) { - buildNoAccessScreen(el); - } else { - buildDashboard(el, config); - } - - unsubscribe(); - }); - } + }, + }); } diff --git a/ecc/scripts/event-apis.js b/ecc/scripts/event-apis.js index 0587a705..5bc41b3a 100644 --- a/ecc/scripts/event-apis.js +++ b/ecc/scripts/event-apis.js @@ -1,4 +1,5 @@ import BlockMediator from './deps/block-mediator.min.js'; +import { ALLOWED_ACCOUNT_TYPES } from '../constants/constants.js'; export async function getProfile() { const { feds, adobeProfile, fedsConfig, adobeIMS } = window; @@ -61,3 +62,37 @@ export function lazyCaptureProfile() { } }, 1000); } + +export function initProfileLogicTree(callbacks) { + const { noProfile, noAccessProfile, validProfile } = callbacks; + + const profile = BlockMediator.get('imsProfile'); + + if (profile) { + if (profile.noProfile) { + noProfile(); + } else if (!ALLOWED_ACCOUNT_TYPES.includes(profile.account_type)) { + noAccessProfile(); + } else { + validProfile(profile); + } + + return; + } + + if (!profile) { + const unsubscribe = BlockMediator.subscribe('imsProfile', ({ newValue }) => { + if (newValue) { + if (newValue.noProfile) { + noProfile(); + } else if (!ALLOWED_ACCOUNT_TYPES.includes(newValue.account_type)) { + noAccessProfile(); + } else { + validProfile(newValue); + } + } + + unsubscribe(); + }); + } +} diff --git a/ecc/scripts/utils.js b/ecc/scripts/utils.js index 908ded19..8a471413 100644 --- a/ecc/scripts/utils.js +++ b/ecc/scripts/utils.js @@ -231,6 +231,15 @@ export async function decorateTextarea(cell, extraOptions) { cell.append(wrapper); } +export function signIn() { + if (typeof window.adobeIMS?.signIn !== 'function') { + window?.lana.log({ message: 'IMS signIn method not available', tags: 'errorType=warn,module=gnav' }); + return; + } + + window.adobeIMS?.signIn(); +} + export async function getSecret(key) { if (secretCache.length === 0) { const resp = await fetch('/ecc/system/secrets.json') From 0237558b96d4a17f600fbf1661abe37398cbfed1 Mon Sep 17 00:00:00 2001 From: Qiyun Dai Date: Mon, 30 Sep 2024 10:29:31 -0500 Subject: [PATCH 2/2] update susi action on formHandler --- ecc/blocks/form-handler/form-handler.js | 37 ++++++++----------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/ecc/blocks/form-handler/form-handler.js b/ecc/blocks/form-handler/form-handler.js index 9ff3c8a4..bba93097 100644 --- a/ecc/blocks/form-handler/form-handler.js +++ b/ecc/blocks/form-handler/form-handler.js @@ -1,4 +1,3 @@ -import { ALLOWED_ACCOUNT_TYPES } from '../../constants/constants.js'; import { LIBS } from '../../scripts/scripts.js'; import { getIcon, @@ -6,6 +5,7 @@ import { generateToolTip, camelToSentenceCase, getEventPageHost, + signIn, } from '../../scripts/utils.js'; import { createEvent, @@ -25,8 +25,8 @@ import ProductSelectorGroup from '../../components/product-selector-group/produc import PartnerSelector from '../../components/partner-selector/partner-selector.js'; import PartnerSelectorGroup from '../../components/partner-selector-group/partner-selector-group.js'; import getJoinedData, { getFilteredCachedResponse, quickFilter, setPayloadCache, setResponseCache } from './data-handler.js'; -import BlockMediator from '../../scripts/deps/block-mediator.min.js'; import { CustomSearch } from '../../components/custom-search/custom-search.js'; +import { initProfileLogicTree } from '../../scripts/event-apis.js'; const { createTag } = await import(`${LIBS}/utils/utils.js`); const { decorateButtons } = await import(`${LIBS}/utils/decorate.js`); @@ -857,33 +857,18 @@ export default async function init(el) { ...promises, ]); - const profile = BlockMediator.get('imsProfile'); - - if (profile) { - if (profile.noProfile || !ALLOWED_ACCOUNT_TYPES.includes(profile.account_type)) { + initProfileLogicTree({ + noProfile: () => { + signIn(); + }, + noAccessProfile: () => { buildNoAccessScreen(el); el.classList.remove('loading'); - } else { + }, + validProfile: () => { buildECCForm(el).then(() => { el.classList.remove('loading'); }); - } - - return; - } - - if (!profile) { - const unsubscribe = BlockMediator.subscribe('imsProfile', ({ newValue }) => { - if (newValue?.noProfile || !ALLOWED_ACCOUNT_TYPES.includes(newValue.account_type)) { - buildNoAccessScreen(el); - el.classList.remove('loading'); - unsubscribe(); - } else { - buildECCForm(el).then(() => { - el.classList.remove('loading'); - unsubscribe(); - }); - } - }); - } + }, + }); }