From bd62b1b070d5361e14262b47fe9e03575613cc12 Mon Sep 17 00:00:00 2001 From: Qiyun Dai Date: Mon, 9 Sep 2024 13:17:28 -0500 Subject: [PATCH 01/22] test no prevent default --- events/scripts/content-update.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/events/scripts/content-update.js b/events/scripts/content-update.js index ff296039..84348c49 100644 --- a/events/scripts/content-update.js +++ b/events/scripts/content-update.js @@ -161,8 +161,7 @@ async function handleRSVPBtnBasedOnProfile(rsvpBtn, miloLibs, profile) { rsvpBtn.el.textContent = rsvpBtn.originalText; rsvpBtn.el.classList.remove('disabled'); rsvpBtn.el.setAttribute('tabindex', 0); - rsvpBtn.el.addEventListener('click', (e) => { - e.preventDefault(); + rsvpBtn.el.addEventListener('click', () => { signIn(); }); } From 683742a32c3d1075df7f49f5673d7c7e7504dda3 Mon Sep 17 00:00:00 2001 From: Qiyun Dai Date: Mon, 9 Sep 2024 13:44:25 -0500 Subject: [PATCH 02/22] wip --- events/blocks/events-form/events-form.js | 2 +- events/scripts/content-update.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/events/blocks/events-form/events-form.js b/events/blocks/events-form/events-form.js index 55ee255e..1f63c0f6 100644 --- a/events/blocks/events-form/events-form.js +++ b/events/blocks/events-form/events-form.js @@ -583,7 +583,7 @@ export default async function decorate(block, formData = null) { formContainer: block.querySelector(':scope > div:nth-of-type(2)'), form: block.querySelector(':scope > div:nth-of-type(2) a[href$=".json"]'), terms: block.querySelector(':scope > div:nth-of-type(3)'), - successMsg: block.querySelector(':scope > div:last-of-type > div'), + successMsg: block.querySelector(':scope > div:nth-of-type(4) > div'), }; await onProfile(bp, formData); diff --git a/events/scripts/content-update.js b/events/scripts/content-update.js index 84348c49..ff296039 100644 --- a/events/scripts/content-update.js +++ b/events/scripts/content-update.js @@ -161,7 +161,8 @@ async function handleRSVPBtnBasedOnProfile(rsvpBtn, miloLibs, profile) { rsvpBtn.el.textContent = rsvpBtn.originalText; rsvpBtn.el.classList.remove('disabled'); rsvpBtn.el.setAttribute('tabindex', 0); - rsvpBtn.el.addEventListener('click', () => { + rsvpBtn.el.addEventListener('click', (e) => { + e.preventDefault(); signIn(); }); } From 7ee7318aec56f5ce9b7ac0c2da7cc49152da377e Mon Sep 17 00:00:00 2001 From: Qiyun Dai Date: Mon, 9 Sep 2024 15:50:24 -0500 Subject: [PATCH 03/22] Update events-form.js --- events/blocks/events-form/events-form.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/events/blocks/events-form/events-form.js b/events/blocks/events-form/events-form.js index 1f63c0f6..8745c480 100644 --- a/events/blocks/events-form/events-form.js +++ b/events/blocks/events-form/events-form.js @@ -125,7 +125,7 @@ function showSuccessMsg(bp) { clearForm(bp.form); bp.form.classList.add('hidden'); bp.eventHero.classList.add('hidden'); - bp.successMsg.classList.remove('hidden'); + bp.rsvpSuccessScreen.classList.remove('hidden'); } function eventFormSendAnalytics(bp, view) { @@ -334,10 +334,10 @@ function addTerms(form, terms) { } function decorateSuccessMsg(form, bp) { - const ctas = bp.successMsg.querySelectorAll('a'); + const ctas = bp.rsvpSuccessScreen.querySelectorAll('a'); const hgroup = createTag('hgroup'); - const eyeBrowText = bp.successMsg.querySelector('p:first-child'); - const headings = bp.successMsg.querySelectorAll('h1, h2, h3, h4, h5, h6'); + const eyeBrowText = bp.rsvpSuccessScreen.querySelector('p:first-child'); + const headings = bp.rsvpSuccessScreen.querySelectorAll('h1, h2, h3, h4, h5, h6'); headings.forEach((h) => { hgroup.append(h); }); @@ -347,7 +347,7 @@ function decorateSuccessMsg(form, bp) { hgroup.prepend(eyeBrowText); } - bp.successMsg.prepend(hgroup); + bp.rsvpSuccessScreen.prepend(hgroup); ctas.forEach((cta, i) => { if (i === 0) { cta.parentElement.classList.add('post-rsvp-button-wrapper'); @@ -365,7 +365,7 @@ function decorateSuccessMsg(form, bp) { const resp = await deleteAttendeeFromEvent(getMetadata('event-id')); cta.classList.remove('loading'); if (resp?.espProvider?.status !== 204) { - buildErrorMsg(bp.successMsg); + buildErrorMsg(bp.rsvpSuccessScreen); return; } @@ -377,7 +377,7 @@ function decorateSuccessMsg(form, bp) { }); }); - bp.successMsg.classList.add('hidden'); + bp.rsvpSuccessScreen.classList.add('hidden'); } async function createForm(bp, formData) { @@ -496,7 +496,7 @@ function decorateHero(heroEl) { async function buildEventform(bp, formData) { if (!bp.formContainer || !bp.form) return; bp.formContainer.classList.add('form-container'); - bp.successMsg.classList.add('form-success-msg'); + bp.rsvpSuccessScreen.classList.add('form-success-msg'); const { formEl, sanitizeList } = await createForm( bp, formData, @@ -583,7 +583,8 @@ export default async function decorate(block, formData = null) { formContainer: block.querySelector(':scope > div:nth-of-type(2)'), form: block.querySelector(':scope > div:nth-of-type(2) a[href$=".json"]'), terms: block.querySelector(':scope > div:nth-of-type(3)'), - successMsg: block.querySelector(':scope > div:nth-of-type(4) > div'), + rsvpSuccessScreen: block.querySelector(':scope > div:nth-of-type(4) > div'), + waitlistSuccessScreen: block.querySelector(':scope > div:nth-of-type(5) > div'), }; await onProfile(bp, formData); From 00871adf7bedf61f9bf47ee10bd48827e3efd60f Mon Sep 17 00:00:00 2001 From: Qiyun Dai Date: Tue, 10 Sep 2024 11:57:01 -0500 Subject: [PATCH 04/22] wip with mock --- events/blocks/events-form/events-form.js | 43 +++++++++++++++++++----- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/events/blocks/events-form/events-form.js b/events/blocks/events-form/events-form.js index 8745c480..83b34410 100644 --- a/events/blocks/events-form/events-form.js +++ b/events/blocks/events-form/events-form.js @@ -122,6 +122,7 @@ async function buildErrorMsg(parent, status) { } function showSuccessMsg(bp) { + const rsvpData = BlockMediator.get('rsvpData'); clearForm(bp.form); bp.form.classList.add('hidden'); bp.eventHero.classList.add('hidden'); @@ -333,7 +334,10 @@ function addTerms(form, terms) { submit.disabled = none(Array.from(checkboxes), (c) => c.checked); } -function decorateSuccessMsg(form, bp) { +function decorateSuccessMsg(bp) { + const [firstScreen, secondScreen] = bp.rsvpSuccessScreen.querySelectorAll('div'); + + console.log(firstScreen, secondScreen); const ctas = bp.rsvpSuccessScreen.querySelectorAll('a'); const hgroup = createTag('hgroup'); const eyeBrowText = bp.rsvpSuccessScreen.querySelector('p:first-child'); @@ -372,12 +376,13 @@ function decorateSuccessMsg(form, bp) { if (resp?.espProvider?.attendeeDeleted) BlockMediator.set('rsvpData', null); } - const modal = form.closest('.dialog-modal'); + const modal = bp.el.closest('.dialog-modal'); closeModal(modal); }); }); bp.rsvpSuccessScreen.classList.add('hidden'); + bp.waitlistSuccessScreen.classList.add('hidden'); } async function createForm(bp, formData) { @@ -466,7 +471,6 @@ async function createForm(bp, formData) { }); addTerms(formEl, terms); - decorateSuccessMsg(formEl, bp); formEl.addEventListener('input', () => applyRules(formEl, rules)); applyRules(formEl, rules); @@ -497,10 +501,9 @@ async function buildEventform(bp, formData) { if (!bp.formContainer || !bp.form) return; bp.formContainer.classList.add('form-container'); bp.rsvpSuccessScreen.classList.add('form-success-msg'); - const { formEl, sanitizeList } = await createForm( - bp, - formData, - ); + bp.waitlistSuccessScreen.classList.add('form-success-msg'); + const { formEl, sanitizeList } = await createForm(bp, formData); + decorateSuccessMsg(bp); if (formEl) { bp.form.replaceWith(formEl); @@ -583,9 +586,31 @@ export default async function decorate(block, formData = null) { formContainer: block.querySelector(':scope > div:nth-of-type(2)'), form: block.querySelector(':scope > div:nth-of-type(2) a[href$=".json"]'), terms: block.querySelector(':scope > div:nth-of-type(3)'), - rsvpSuccessScreen: block.querySelector(':scope > div:nth-of-type(4) > div'), - waitlistSuccessScreen: block.querySelector(':scope > div:nth-of-type(5) > div'), + rsvpSuccessScreen: block.querySelector(':scope > div:nth-of-type(4)'), + waitlistSuccessScreen: block.querySelector(':scope > div:nth-of-type(5)'), }; + BlockMediator.set('imsProfile', { + account_type: 'type3', + utcOffset: 'null', + preferred_languages: null, + displayName: 'Qiyun Dai', + last_name: 'Dai', + userId: 'B90719A765B288680A494219@c62f24cc5b5b7e0e0a494004', + authId: 'B90719A765B288680A494219@c62f24cc5b5b7e0e0a494004', + tags: [ + 'agegroup_unknown', + 'edu', + 'edu_k12', + ], + emailVerified: 'true', + phoneNumber: null, + countryCode: 'US', + name: 'Qiyun Dai', + mrktPerm: '', + mrktPermEmail: null, + first_name: 'Qiyun', + email: 'cod87753@adobe.com', + }); await onProfile(bp, formData); } From 00866a888618ebc0bcc6c0d588fe6ce45ffbabba Mon Sep 17 00:00:00 2001 From: Qiyun Dai Date: Tue, 10 Sep 2024 14:37:29 -0500 Subject: [PATCH 05/22] mocked flow working --- events/blocks/events-form/events-form.js | 137 +++++++++++++++-------- 1 file changed, 90 insertions(+), 47 deletions(-) diff --git a/events/blocks/events-form/events-form.js b/events/blocks/events-form/events-form.js index 83b34410..2e547b8c 100644 --- a/events/blocks/events-form/events-form.js +++ b/events/blocks/events-form/events-form.js @@ -121,12 +121,21 @@ async function buildErrorMsg(parent, status) { }, 3000); } -function showSuccessMsg(bp) { +function showSuccessMsgFirstScreen(bp) { const rsvpData = BlockMediator.get('rsvpData'); clearForm(bp.form); bp.form.classList.add('hidden'); bp.eventHero.classList.add('hidden'); - bp.rsvpSuccessScreen.classList.remove('hidden'); + + if (rsvpData?.espProvider?.waitlisted) { + bp.waitlistSuccessScreen.classList.remove('hidden'); + bp.waitlistSuccessScreen.querySelector('.first-screen')?.classList.remove('hidden'); + } + + if (rsvpData?.espProvider?.registered) { + bp.rsvpSuccessScreen.classList.remove('hidden'); + bp.rsvpSuccessScreen.querySelector('.first-screen')?.classList.remove('hidden'); + } } function eventFormSendAnalytics(bp, view) { @@ -334,55 +343,84 @@ function addTerms(form, terms) { submit.disabled = none(Array.from(checkboxes), (c) => c.checked); } -function decorateSuccessMsg(bp) { - const [firstScreen, secondScreen] = bp.rsvpSuccessScreen.querySelectorAll('div'); +function decorateSuccessScreen(screen) { + screen.classList.add('form-success-msg'); + const subScreens = screen.querySelectorAll('div'); - console.log(firstScreen, secondScreen); - const ctas = bp.rsvpSuccessScreen.querySelectorAll('a'); - const hgroup = createTag('hgroup'); - const eyeBrowText = bp.rsvpSuccessScreen.querySelector('p:first-child'); - const headings = bp.rsvpSuccessScreen.querySelectorAll('h1, h2, h3, h4, h5, h6'); - headings.forEach((h) => { - hgroup.append(h); - }); + const [firstScreen, secondScreen] = subScreens; - if (eyeBrowText) { - eyeBrowText.classList.add('eyebrow'); - hgroup.prepend(eyeBrowText); - } + subScreens.forEach((ss, i) => { + ss.classList.add('hidden'); + const hgroup = createTag('hgroup'); + const eyeBrowText = ss.querySelector('p:first-child'); + const headings = ss.querySelectorAll('h1, h2, h3, h4, h5, h6'); - bp.rsvpSuccessScreen.prepend(hgroup); - ctas.forEach((cta, i) => { - if (i === 0) { - cta.parentElement.classList.add('post-rsvp-button-wrapper'); - cta.classList.add('con-button', 'outline', 'button-l'); - } else if (i === 1) { - cta.classList.add('con-button', 'black', 'button-l'); - } + headings.forEach((h) => { + hgroup.append(h); + }); - cta.addEventListener('click', async (e) => { - e.preventDefault(); + if (eyeBrowText) { + eyeBrowText.classList.add('eyebrow'); + hgroup.prepend(eyeBrowText); + } - cta.classList.add('loading'); + ss.prepend(hgroup); - if (i === 0) { - const resp = await deleteAttendeeFromEvent(getMetadata('event-id')); - cta.classList.remove('loading'); - if (resp?.espProvider?.status !== 204) { - buildErrorMsg(bp.rsvpSuccessScreen); - return; + if (i === 0) { + ss.classList.add('first-screen'); + const firstScreenCtas = ss.querySelectorAll('a'); + + firstScreenCtas.forEach((cta) => { + const ctaUrl = new URL(cta.href); + if (ctaUrl.hash.startsWith('#cancel')) { + cta.parentElement.classList.add('post-rsvp-button-wrapper'); + cta.classList.add('con-button', 'outline', 'button-l', 'cancel-button'); + } else if (ctaUrl.hash.startsWith('#ok')) { + cta.classList.add('con-button', 'black', 'button-l'); } - if (resp?.espProvider?.attendeeDeleted) BlockMediator.set('rsvpData', null); - } + cta.addEventListener('click', async (e) => { + e.preventDefault(); - const modal = bp.el.closest('.dialog-modal'); - closeModal(modal); - }); + cta.classList.add('loading'); + + if (cta.classList.contains('cancel-button')) { + const resp = await deleteAttendeeFromEvent(getMetadata('event-id')); + cta.classList.remove('loading'); + if (resp?.espProvider?.status !== 204) { + buildErrorMsg(screen); + return; + } + + if (resp?.espProvider?.attendeeDeleted) BlockMediator.set('rsvpData', null); + + firstScreen.classList.add('hidden'); + secondScreen.classList.remove('hidden'); + cta.classList.remove('loading'); + } + }); + }); + } + + if (i === 1) { + ss.classList.add('second-screen'); + const secondScreenCtas = ss.querySelectorAll('a'); + + secondScreenCtas.forEach((cta) => { + const ctaUrl = new URL(cta.href); + if (ctaUrl.hash.startsWith('#ok')) { + cta.classList.add('con-button', 'black', 'button-l'); + cta.addEventListener('click', async (e) => { + e.preventDefault(); + const modal = screen.closest('.dialog-modal'); + if (modal) closeModal(modal); + }); + } + }); + } }); - bp.rsvpSuccessScreen.classList.add('hidden'); - bp.waitlistSuccessScreen.classList.add('hidden'); + screen.classList.add('hidden'); } async function createForm(bp, formData) { @@ -500,10 +538,11 @@ function decorateHero(heroEl) { async function buildEventform(bp, formData) { if (!bp.formContainer || !bp.form) return; bp.formContainer.classList.add('form-container'); - bp.rsvpSuccessScreen.classList.add('form-success-msg'); - bp.waitlistSuccessScreen.classList.add('form-success-msg'); const { formEl, sanitizeList } = await createForm(bp, formData); - decorateSuccessMsg(bp); + + [bp.rsvpSuccessScreen, bp.waitlistSuccessScreen].forEach((screen) => { + decorateSuccessScreen(screen); + }); if (formEl) { bp.form.replaceWith(formEl); @@ -516,16 +555,20 @@ function initFormBasedOnRSVPData(bp) { const { block } = bp; const profile = BlockMediator.get('imsProfile'); const rsvpData = BlockMediator.get('rsvpData'); - if (rsvpData?.espProvider?.registered || rsvpData?.externalAttendeeId) { - showSuccessMsg(bp); + if (rsvpData?.espProvider?.registered + || rsvpData?.espProvider?.waitlisted + || rsvpData?.externalAttendeeId) { + showSuccessMsgFirstScreen(bp); eventFormSendAnalytics(bp, 'Confirmation Modal View'); } else { personalizeForm(block, profile); } BlockMediator.subscribe('rsvpData', ({ newValue }) => { - if (newValue?.espProvider?.registered || newValue?.externalAttendeeId) { - showSuccessMsg(bp); + if (newValue?.espProvider?.registered + || newValue?.espProvider?.waitlisted + || newValue?.externalAttendeeId) { + showSuccessMsgFirstScreen(bp); eventFormSendAnalytics(bp, 'Confirmation Modal View'); } }); From 74657686b0e7f12327ecf0c52cb5da02b56efd4b Mon Sep 17 00:00:00 2001 From: Qiyun Dai Date: Tue, 10 Sep 2024 14:41:25 -0500 Subject: [PATCH 06/22] added USP for mocking preview --- events/blocks/events-form/events-form.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/events/blocks/events-form/events-form.js b/events/blocks/events-form/events-form.js index 2e547b8c..a7e86cde 100644 --- a/events/blocks/events-form/events-form.js +++ b/events/blocks/events-form/events-form.js @@ -376,7 +376,7 @@ function decorateSuccessScreen(screen) { cta.parentElement.classList.add('post-rsvp-button-wrapper'); cta.classList.add('con-button', 'outline', 'button-l', 'cancel-button'); } else if (ctaUrl.hash.startsWith('#ok')) { - cta.classList.add('con-button', 'black', 'button-l'); + cta.classList.add('con-button', 'black', 'button-l', 'ok-button'); } cta.addEventListener('click', async (e) => { @@ -398,6 +398,11 @@ function decorateSuccessScreen(screen) { secondScreen.classList.remove('hidden'); cta.classList.remove('loading'); } + + if (cta.classList.contains('ok-button')) { + const modal = screen.closest('.dialog-modal'); + if (modal) closeModal(modal); + } }); }); } From 675d97d1c6651c8f28111750e667a1feef079df1 Mon Sep 17 00:00:00 2001 From: Qiyun Dai Date: Tue, 10 Sep 2024 14:58:02 -0500 Subject: [PATCH 07/22] fine tune CSS based on figma --- events/blocks/events-form/events-form.css | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/events/blocks/events-form/events-form.css b/events/blocks/events-form/events-form.css index 2e79b4c4..b931b5d3 100644 --- a/events/blocks/events-form/events-form.css +++ b/events/blocks/events-form/events-form.css @@ -309,8 +309,26 @@ } .events-form .form-success-msg { + position: relative; text-align: center; padding: 80px 40px; + min-height: 300px; +} + +.events-form .form-success-msg > div:not(.hidden) { + height: 100%; + min-height: 300px; + display: flex; + flex-direction: column; + align-items: center; + justify-content: space-between; +} + +.events-form .form-success-msg > .second-screen > hgroup { + flex-basis: 56%; + display: flex; + flex-direction: column; + justify-content: space-between; } .events-form .form-success-msg h1, @@ -419,6 +437,10 @@ width: auto; } + .events-form .form-success-msg { + min-width: 720px; + } + .events-form .form-success-msg .post-rsvp-button-wrapper { gap: 1rem; } From 23f8b93cfe07768909bf34627ca251464af7f331 Mon Sep 17 00:00:00 2001 From: Qiyun Dai Date: Fri, 30 Aug 2024 13:53:56 -0500 Subject: [PATCH 08/22] make resp.ok relevant --- events/blocks/events-form/events-form.js | 21 ++++++++++++++------- events/scripts/content-update.js | 11 ++++++----- events/scripts/esp-controller.js | 24 ++++++++++++++---------- events/scripts/profile.js | 6 +++--- 4 files changed, 37 insertions(+), 25 deletions(-) diff --git a/events/blocks/events-form/events-form.js b/events/blocks/events-form/events-form.js index a7e86cde..994d35c4 100644 --- a/events/blocks/events-form/events-form.js +++ b/events/blocks/events-form/events-form.js @@ -160,9 +160,12 @@ function createButton({ type, label }, bp) { button.removeAttribute('disabled'); button.classList.remove('submitting'); if (!respJson) return; - if (respJson.ok !== false && !respJson.error) eventFormSendAnalytics(bp, 'Form Submit'); - BlockMediator.set('rsvpData', respJson); - if (respJson.error) { + + BlockMediator.set('rsvpData', respJson.data); + + if (respJson.ok) { + eventFormSendAnalytics(bp, 'Form Submit'); + } else { let { status } = respJson; // FIXME: temporary fix for ESL 500 on ESP 400 @@ -386,13 +389,17 @@ function decorateSuccessScreen(screen) { if (cta.classList.contains('cancel-button')) { const resp = await deleteAttendeeFromEvent(getMetadata('event-id')); + if (!resp.ok) return; + + const { data } = resp; + cta.classList.remove('loading'); - if (resp?.espProvider?.status !== 204) { - buildErrorMsg(screen); + if (data?.espProvider?.status !== 204) { + buildErrorMsg(bp.successMsg); return; } - - if (resp?.espProvider?.attendeeDeleted) BlockMediator.set('rsvpData', null); + + if (data?.espProvider?.attendeeDeleted) BlockMediator.set('rsvpData', null); firstScreen.classList.add('hidden'); secondScreen.classList.remove('hidden'); diff --git a/events/scripts/content-update.js b/events/scripts/content-update.js index ff296039..66880856 100644 --- a/events/scripts/content-update.js +++ b/events/scripts/content-update.js @@ -142,15 +142,16 @@ export function signIn() { } async function handleRSVPBtnBasedOnProfile(rsvpBtn, miloLibs, profile) { - const eventInfo = await getEvent(getMetadata('event-id')); + const resp = await getEvent(getMetadata('event-id')); - if (!eventInfo) { + if (!resp.ok || resp.error) { return; } - if (profile?.noProfile || eventInfo.status === 401) { - const eventFull = +eventInfo.attendeeLimit <= +eventInfo.attendeeCount; - if (eventFull) { + const eventInfo = resp.data; + + if (profile?.noProfile || resp.status === 401) { + if (eventInfo && +eventInfo.attendeeLimit <= +eventInfo.attendeeCount) { const eventFullText = await miloReplaceKey(miloLibs, 'event-full-cta-text'); updateAnalyticTag(rsvpBtn.el, eventFullText); rsvpBtn.el.setAttribute('tabindex', -1); diff --git a/events/scripts/esp-controller.js b/events/scripts/esp-controller.js index 481dff1b..dc69f3a3 100644 --- a/events/scripts/esp-controller.js +++ b/events/scripts/esp-controller.js @@ -95,7 +95,7 @@ export async function getEvent(eventId) { return { ok: response.ok, status: response.status, error: data }; } - return data; + return { ok: true, data }; } catch (error) { window.lana?.log(`Failed to get details for event ${eventId}. Error:`, error); return { ok: false, status: 'Network Error', error: error.message }; @@ -118,7 +118,7 @@ export async function getEventAttendee(eventId) { }; } - return await response.json(); + return { ok: true, data: await response.json() }; } catch (error) { window.lana?.log(`Failed to get attendee for event ${eventId}. Error:`, error); return { ok: false, status: 'Network Error', error: error.message }; @@ -141,7 +141,7 @@ export async function getAttendee() { }; } - return response.json(); + return { ok: true, data: await response.json() }; } catch (error) { window.lana?.log('Failed to get attendee. Error:', error); return { ok: false, status: 'Network Error', error: error.message }; @@ -164,7 +164,7 @@ export async function createAttendee(attendeeData) { return { ok: response.ok, status: response.status, error: data }; } - return data; + return { ok: true, data }; } catch (error) { window.lana?.log('Failed to create attendee. Error:', error); return { ok: false, status: 'Network Error', error: error.message }; @@ -188,7 +188,7 @@ export async function addAttendeeToEvent(eventId, attendee) { return { ok: response.ok, status: response.status, error: data }; } - return data; + return { ok: true, data }; } catch (error) { window.lana?.log(`Failed to add attendee for event ${eventId}. Error:`, error); return { ok: false, status: 'Network Error', error: error.message }; @@ -211,7 +211,7 @@ export async function updateAttendee(attendeeData) { return { ok: response.ok, status: response.status, error: data }; } - return data; + return { ok: true, data }; } catch (error) { window.lana?.log('Failed to update attendee. Error:', error); return { ok: false, status: 'Network Error', error: error.message }; @@ -236,7 +236,7 @@ export async function deleteAttendeeFromEvent(eventId) { }; } - return response.json(); + return { ok: true, data: await response.json() }; } catch (error) { window.lana?.log(`Failed to delete attendee for event ${eventId}. Error:`, error); return { ok: false, status: 'Network Error', error: error.message }; @@ -250,9 +250,13 @@ export async function getAndCreateAndAddAttendee(eventId, attendeeData) { if (!attendeeResp.ok && attendeeResp.status === 404) { attendee = await createAttendee(attendeeData); - } else if (attendeeResp.attendeeId) { - attendee = await updateAttendee({ ...attendeeResp, ...attendeeData }); + } else if (attendeeResp.data?.attendeeId) { + attendee = await updateAttendee({ ...attendeeResp.data, ...attendeeData }); } - return addAttendeeToEvent(eventId, attendee); + if (!attendee?.ok) return { ok: false, error: 'Failed to create or update attendee' }; + + const newAttendeeData = attendee.data; + + return addAttendeeToEvent(eventId, newAttendeeData); } diff --git a/events/scripts/profile.js b/events/scripts/profile.js index 1d34c358..29784bb0 100644 --- a/events/scripts/profile.js +++ b/events/scripts/profile.js @@ -40,9 +40,9 @@ export function lazyCaptureProfile() { BlockMediator.set('imsProfile', profile); if (!profile.noProfile) { - const rsvpData = await getEventAttendee(getMetadata('event-id')); - if (!rsvpData.error) { - BlockMediator.set('rsvpData', rsvpData); + const resp = await getEventAttendee(getMetadata('event-id')); + if (!resp.error) { + BlockMediator.set('rsvpData', resp.data); } else { BlockMediator.set('rsvpData', null); } From 530331795798136cdcd87bd7cff228959e0c8bff Mon Sep 17 00:00:00 2001 From: Qiyun Dai Date: Wed, 11 Sep 2024 09:44:19 -0500 Subject: [PATCH 09/22] more btn states --- events/scripts/content-update.js | 101 +++++++++++++++++++++++-------- 1 file changed, 75 insertions(+), 26 deletions(-) diff --git a/events/scripts/content-update.js b/events/scripts/content-update.js index 66880856..08294bea 100644 --- a/events/scripts/content-update.js +++ b/events/scripts/content-update.js @@ -93,41 +93,90 @@ function createTag(tag, attributes, html, options = {}) { async function updateRSVPButtonState(rsvpBtn, miloLibs, eventInfo) { const rsvpData = BlockMediator.get('rsvpData'); const checkRed = getIcon('check-circle-red'); - const eventFull = +eventInfo.attendeeLimit <= +eventInfo.attendeeCount; + const { attendeeLimit, attendeeCount, allowWaitlisting, cloudType } = eventInfo; + const eventFull = +attendeeLimit <= +attendeeCount; - if (!rsvpData) { - if (eventFull) { - const eventFullText = await miloReplaceKey(miloLibs, 'event-full-cta-text'); - rsvpBtn.el.setAttribute('tabindex', -1); - rsvpBtn.el.href = ''; - rsvpBtn.el.classList.add('disabled'); - updateAnalyticTag(rsvpBtn.el, eventFullText); - rsvpBtn.el.textContent = eventFullText; - checkRed.remove(); - } else { - rsvpBtn.el.classList.remove('disabled'); - rsvpBtn.el.setAttribute('tabindex', 0); - updateAnalyticTag(rsvpBtn.el, rsvpBtn.originalText); - rsvpBtn.el.textContent = rsvpBtn.originalText; - checkRed.remove(); - } - } else if (rsvpData.espProvider?.registered || rsvpData.externalAttendeeId) { - const registeredText = await miloReplaceKey(miloLibs, 'registered-cta-text'); + const enableBtn = () => { rsvpBtn.el.classList.remove('disabled'); rsvpBtn.el.setAttribute('tabindex', 0); + }; + + const disableBtn = () => { + rsvpBtn.el.setAttribute('tabindex', -1); + rsvpBtn.el.href = ''; + rsvpBtn.el.classList.add('disabled'); + }; + + const closedState = async () => { + let placeholderKey; + + switch (cloudType) { + case 'DX': + placeholderKey = 'waitlist-full-cta-text'; + break; + case 'CreativeCloud': + default: + placeholderKey = 'event-full-cta-text'; + } + + const closedText = await miloReplaceKey(miloLibs, placeholderKey); + + disableBtn(); + updateAnalyticTag(rsvpBtn.el, closedText); + rsvpBtn.el.textContent = closedText; + checkRed.remove(); + }; + + const defaultState = () => { + enableBtn(); + updateAnalyticTag(rsvpBtn.el, rsvpBtn.originalText); + rsvpBtn.el.textContent = rsvpBtn.originalText; + checkRed.remove(); + }; + + const registeredState = async () => { + const registeredText = await miloReplaceKey(miloLibs, 'registered-cta-text'); + enableBtn(); updateAnalyticTag(rsvpBtn.el, registeredText); rsvpBtn.el.textContent = registeredText; rsvpBtn.el.prepend(checkRed); + }; + + const waitlistState = async () => { + const waitlistText = await miloReplaceKey(miloLibs, 'waitlist-cta-text'); + enableBtn(); + updateAnalyticTag(rsvpBtn.el, waitlistText); + rsvpBtn.el.textContent = waitlistText; + checkRed.remove(); + }; + + const waitlistedState = async () => { + const waitlistedText = await miloReplaceKey(miloLibs, 'waitlisted-cta-text'); + disableBtn(); + updateAnalyticTag(rsvpBtn.el, waitlistedText); + rsvpBtn.el.textContent = waitlistedText; + rsvpBtn.el.prepend(checkRed); + }; + + if (!rsvpData) { + if (eventFull) { + if (allowWaitlisting) { + await waitlistState(); + } else { + await closedState(); + } + } else { + defaultState(); + } + // RSVP data changed by register submission || rsvp data received on page load + } else if (rsvpData.espProvider?.registered || rsvpData.attendeeStatus === 'registered') { + await registeredState(); + } else if (rsvpData.espProvider?.waitlisted || rsvpData.attendeeStatus === 'waitlisted') { + await waitlistedState(); } else if (!rsvpData.ok) { // FIXME: temporary solution for ESL returning 500 on ESP 400 response if (rsvpData.error?.message === 'Request to ESP failed: Event is full') { - const eventFullText = await miloReplaceKey(miloLibs, 'event-full-cta-text'); - rsvpBtn.el.setAttribute('tabindex', -1); - rsvpBtn.el.href = ''; - rsvpBtn.el.classList.add('disabled'); - updateAnalyticTag(rsvpBtn.el, eventFullText); - rsvpBtn.el.textContent = eventFullText; - checkRed.remove(); + await closedState(); } } } From a39161e532735ad28d2fc120f48f8347631897a7 Mon Sep 17 00:00:00 2001 From: Qiyun Dai Date: Wed, 11 Sep 2024 09:46:42 -0500 Subject: [PATCH 10/22] same eventClosed text --- events/scripts/content-update.js | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/events/scripts/content-update.js b/events/scripts/content-update.js index 08294bea..6904a621 100644 --- a/events/scripts/content-update.js +++ b/events/scripts/content-update.js @@ -93,7 +93,7 @@ function createTag(tag, attributes, html, options = {}) { async function updateRSVPButtonState(rsvpBtn, miloLibs, eventInfo) { const rsvpData = BlockMediator.get('rsvpData'); const checkRed = getIcon('check-circle-red'); - const { attendeeLimit, attendeeCount, allowWaitlisting, cloudType } = eventInfo; + const { attendeeLimit, attendeeCount, allowWaitlisting } = eventInfo; const eventFull = +attendeeLimit <= +attendeeCount; const enableBtn = () => { @@ -108,19 +108,7 @@ async function updateRSVPButtonState(rsvpBtn, miloLibs, eventInfo) { }; const closedState = async () => { - let placeholderKey; - - switch (cloudType) { - case 'DX': - placeholderKey = 'waitlist-full-cta-text'; - break; - case 'CreativeCloud': - default: - placeholderKey = 'event-full-cta-text'; - } - - const closedText = await miloReplaceKey(miloLibs, placeholderKey); - + const closedText = await miloReplaceKey(miloLibs, 'event-full-cta-text'); disableBtn(); updateAnalyticTag(rsvpBtn.el, closedText); rsvpBtn.el.textContent = closedText; From 7ab9a347c415520572dacd226ddf910853332ec7 Mon Sep 17 00:00:00 2001 From: Qiyun Dai Date: Wed, 11 Sep 2024 13:17:05 -0500 Subject: [PATCH 11/22] Update content-update.js --- events/scripts/content-update.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/events/scripts/content-update.js b/events/scripts/content-update.js index 6904a621..ec31b8d5 100644 --- a/events/scripts/content-update.js +++ b/events/scripts/content-update.js @@ -93,7 +93,7 @@ function createTag(tag, attributes, html, options = {}) { async function updateRSVPButtonState(rsvpBtn, miloLibs, eventInfo) { const rsvpData = BlockMediator.get('rsvpData'); const checkRed = getIcon('check-circle-red'); - const { attendeeLimit, attendeeCount, allowWaitlisting } = eventInfo; + const { attendeeLimit, attendeeCount, allowWaitListing } = eventInfo; const eventFull = +attendeeLimit <= +attendeeCount; const enableBtn = () => { @@ -148,7 +148,7 @@ async function updateRSVPButtonState(rsvpBtn, miloLibs, eventInfo) { if (!rsvpData) { if (eventFull) { - if (allowWaitlisting) { + if (allowWaitListing) { await waitlistState(); } else { await closedState(); From fe38835dad9110db17b9c1c89b65e808c5530664 Mon Sep 17 00:00:00 2001 From: Qiyun Dai Date: Wed, 11 Sep 2024 13:42:23 -0500 Subject: [PATCH 12/22] Update content-update.js --- events/scripts/content-update.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/events/scripts/content-update.js b/events/scripts/content-update.js index ec31b8d5..85b7d11e 100644 --- a/events/scripts/content-update.js +++ b/events/scripts/content-update.js @@ -93,8 +93,21 @@ function createTag(tag, attributes, html, options = {}) { async function updateRSVPButtonState(rsvpBtn, miloLibs, eventInfo) { const rsvpData = BlockMediator.get('rsvpData'); const checkRed = getIcon('check-circle-red'); - const { attendeeLimit, attendeeCount, allowWaitListing } = eventInfo; - const eventFull = +attendeeLimit <= +attendeeCount; + const { + attendeeLimit, + attendeeCount, + waitlistAttendeeCount, + waitlistAttendeeLimit, + allowWaitListing, + cloudType, + } = eventInfo; + let eventFull = false; + + if (cloudType === 'CreativeCloud') { + eventFull = +attendeeLimit <= +attendeeCount; + } else if (cloudType === 'DX') { + eventFull = +waitlistAttendeeLimit <= +waitlistAttendeeCount; + } const enableBtn = () => { rsvpBtn.el.classList.remove('disabled'); From 5808dbe28feb9da1b7f8fca11a33f529283949f3 Mon Sep 17 00:00:00 2001 From: Qiyun Dai Date: Mon, 30 Sep 2024 08:51:15 -0500 Subject: [PATCH 13/22] retire waitlistAttendeeLimit --- events/scripts/content-update.js | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/events/scripts/content-update.js b/events/scripts/content-update.js index 85b7d11e..93d61803 100644 --- a/events/scripts/content-update.js +++ b/events/scripts/content-update.js @@ -96,18 +96,9 @@ async function updateRSVPButtonState(rsvpBtn, miloLibs, eventInfo) { const { attendeeLimit, attendeeCount, - waitlistAttendeeCount, - waitlistAttendeeLimit, allowWaitListing, - cloudType, } = eventInfo; - let eventFull = false; - - if (cloudType === 'CreativeCloud') { - eventFull = +attendeeLimit <= +attendeeCount; - } else if (cloudType === 'DX') { - eventFull = +waitlistAttendeeLimit <= +waitlistAttendeeCount; - } + const eventFull = +attendeeLimit <= +attendeeCount; const enableBtn = () => { rsvpBtn.el.classList.remove('disabled'); From 2c37c3ddbed883ca835a015603e7a2d9902d0f48 Mon Sep 17 00:00:00 2001 From: Qiyun Dai Date: Tue, 1 Oct 2024 12:54:04 -0500 Subject: [PATCH 14/22] RSVP new expected changes --- events/blocks/events-form/events-form.js | 24 ++++++++++++------------ events/scripts/content-update.js | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/events/blocks/events-form/events-form.js b/events/blocks/events-form/events-form.js index 994d35c4..0ca45dcf 100644 --- a/events/blocks/events-form/events-form.js +++ b/events/blocks/events-form/events-form.js @@ -127,12 +127,14 @@ function showSuccessMsgFirstScreen(bp) { bp.form.classList.add('hidden'); bp.eventHero.classList.add('hidden'); - if (rsvpData?.espProvider?.waitlisted) { + const registrationStatus = rsvpData?.espProvider?.registrationStatus; + + if (registrationStatus === 'waitlisted') { bp.waitlistSuccessScreen.classList.remove('hidden'); bp.waitlistSuccessScreen.querySelector('.first-screen')?.classList.remove('hidden'); } - if (rsvpData?.espProvider?.registered) { + if (registrationStatus === 'registered') { bp.rsvpSuccessScreen.classList.remove('hidden'); bp.rsvpSuccessScreen.querySelector('.first-screen')?.classList.remove('hidden'); } @@ -390,15 +392,15 @@ function decorateSuccessScreen(screen) { if (cta.classList.contains('cancel-button')) { const resp = await deleteAttendeeFromEvent(getMetadata('event-id')); if (!resp.ok) return; - + const { data } = resp; - + cta.classList.remove('loading'); if (data?.espProvider?.status !== 204) { - buildErrorMsg(bp.successMsg); + buildErrorMsg(screen); return; } - + if (data?.espProvider?.attendeeDeleted) BlockMediator.set('rsvpData', null); firstScreen.classList.add('hidden'); @@ -564,12 +566,11 @@ async function buildEventform(bp, formData) { } function initFormBasedOnRSVPData(bp) { + const validRegistrationStatus = ['registered', 'waitlisted']; const { block } = bp; const profile = BlockMediator.get('imsProfile'); const rsvpData = BlockMediator.get('rsvpData'); - if (rsvpData?.espProvider?.registered - || rsvpData?.espProvider?.waitlisted - || rsvpData?.externalAttendeeId) { + if (validRegistrationStatus.includes(rsvpData.espProvider.registrationStatus)) { showSuccessMsgFirstScreen(bp); eventFormSendAnalytics(bp, 'Confirmation Modal View'); } else { @@ -577,13 +578,12 @@ function initFormBasedOnRSVPData(bp) { } BlockMediator.subscribe('rsvpData', ({ newValue }) => { - if (newValue?.espProvider?.registered - || newValue?.espProvider?.waitlisted - || newValue?.externalAttendeeId) { + if (validRegistrationStatus.includes(newValue?.espProvider.registrationStatus)) { showSuccessMsgFirstScreen(bp); eventFormSendAnalytics(bp, 'Confirmation Modal View'); } }); + if (bp.block.querySelector('.form-success-msg.hidden')) { eventFormSendAnalytics(bp, 'Form View'); } diff --git a/events/scripts/content-update.js b/events/scripts/content-update.js index 93d61803..3287f902 100644 --- a/events/scripts/content-update.js +++ b/events/scripts/content-update.js @@ -161,9 +161,9 @@ async function updateRSVPButtonState(rsvpBtn, miloLibs, eventInfo) { defaultState(); } // RSVP data changed by register submission || rsvp data received on page load - } else if (rsvpData.espProvider?.registered || rsvpData.attendeeStatus === 'registered') { + } else if (rsvpData.espProvider?.registrationStatus === 'registered' || rsvpData.attendeeStatus === 'registered') { await registeredState(); - } else if (rsvpData.espProvider?.waitlisted || rsvpData.attendeeStatus === 'waitlisted') { + } else if (rsvpData.espProvider?.registrationStatus === 'waitlisted' || rsvpData.attendeeStatus === 'waitlisted') { await waitlistedState(); } else if (!rsvpData.ok) { // FIXME: temporary solution for ESL returning 500 on ESP 400 response From d937cc1e170f30756e48648261c5d097191bbdd2 Mon Sep 17 00:00:00 2001 From: Qiyun Dai Date: Mon, 7 Oct 2024 14:20:45 -0500 Subject: [PATCH 15/22] Update events-form.js --- events/blocks/events-form/events-form.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/events/blocks/events-form/events-form.js b/events/blocks/events-form/events-form.js index 0ca45dcf..51c6db10 100644 --- a/events/blocks/events-form/events-form.js +++ b/events/blocks/events-form/events-form.js @@ -349,6 +349,8 @@ function addTerms(form, terms) { } function decorateSuccessScreen(screen) { + if (!screen) return; + screen.classList.add('form-success-msg'); const subScreens = screen.querySelectorAll('div'); From 079a65ecd2295ecf7f81d7d1d8ff859651dcbc65 Mon Sep 17 00:00:00 2001 From: Qiyun Dai Date: Mon, 7 Oct 2024 14:21:18 -0500 Subject: [PATCH 16/22] Update events-form.js --- events/blocks/events-form/events-form.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/events/blocks/events-form/events-form.js b/events/blocks/events-form/events-form.js index 51c6db10..7f69aa6d 100644 --- a/events/blocks/events-form/events-form.js +++ b/events/blocks/events-form/events-form.js @@ -130,13 +130,13 @@ function showSuccessMsgFirstScreen(bp) { const registrationStatus = rsvpData?.espProvider?.registrationStatus; if (registrationStatus === 'waitlisted') { - bp.waitlistSuccessScreen.classList.remove('hidden'); - bp.waitlistSuccessScreen.querySelector('.first-screen')?.classList.remove('hidden'); + bp.waitlistSuccessScreen?.classList.remove('hidden'); + bp.waitlistSuccessScreen?.querySelector('.first-screen')?.classList.remove('hidden'); } if (registrationStatus === 'registered') { - bp.rsvpSuccessScreen.classList.remove('hidden'); - bp.rsvpSuccessScreen.querySelector('.first-screen')?.classList.remove('hidden'); + bp.rsvpSuccessScreen?.classList.remove('hidden'); + bp.rsvpSuccessScreen?.querySelector('.first-screen')?.classList.remove('hidden'); } } From 6008ece76a7b554ddeb116787f8b2ec84c891334 Mon Sep 17 00:00:00 2001 From: Qiyun Dai Date: Mon, 7 Oct 2024 15:24:24 -0500 Subject: [PATCH 17/22] unified resp for POST and GET --- events/blocks/events-form/events-form.js | 10 +++++----- events/scripts/content-update.js | 5 ++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/events/blocks/events-form/events-form.js b/events/blocks/events-form/events-form.js index 7f69aa6d..883f18e0 100644 --- a/events/blocks/events-form/events-form.js +++ b/events/blocks/events-form/events-form.js @@ -127,14 +127,14 @@ function showSuccessMsgFirstScreen(bp) { bp.form.classList.add('hidden'); bp.eventHero.classList.add('hidden'); - const registrationStatus = rsvpData?.espProvider?.registrationStatus; + const { attendeeStatus } = rsvpData; - if (registrationStatus === 'waitlisted') { + if (attendeeStatus === 'waitlisted') { bp.waitlistSuccessScreen?.classList.remove('hidden'); bp.waitlistSuccessScreen?.querySelector('.first-screen')?.classList.remove('hidden'); } - if (registrationStatus === 'registered') { + if (attendeeStatus === 'registered') { bp.rsvpSuccessScreen?.classList.remove('hidden'); bp.rsvpSuccessScreen?.querySelector('.first-screen')?.classList.remove('hidden'); } @@ -572,7 +572,7 @@ function initFormBasedOnRSVPData(bp) { const { block } = bp; const profile = BlockMediator.get('imsProfile'); const rsvpData = BlockMediator.get('rsvpData'); - if (validRegistrationStatus.includes(rsvpData.espProvider.registrationStatus)) { + if (validRegistrationStatus.includes(rsvpData.attendeeStatus)) { showSuccessMsgFirstScreen(bp); eventFormSendAnalytics(bp, 'Confirmation Modal View'); } else { @@ -580,7 +580,7 @@ function initFormBasedOnRSVPData(bp) { } BlockMediator.subscribe('rsvpData', ({ newValue }) => { - if (validRegistrationStatus.includes(newValue?.espProvider.registrationStatus)) { + if (validRegistrationStatus.includes(newValue?.attendeeStatus)) { showSuccessMsgFirstScreen(bp); eventFormSendAnalytics(bp, 'Confirmation Modal View'); } diff --git a/events/scripts/content-update.js b/events/scripts/content-update.js index 3287f902..c612f053 100644 --- a/events/scripts/content-update.js +++ b/events/scripts/content-update.js @@ -160,10 +160,9 @@ async function updateRSVPButtonState(rsvpBtn, miloLibs, eventInfo) { } else { defaultState(); } - // RSVP data changed by register submission || rsvp data received on page load - } else if (rsvpData.espProvider?.registrationStatus === 'registered' || rsvpData.attendeeStatus === 'registered') { + } else if (rsvpData.attendeeStatus === 'registered') { await registeredState(); - } else if (rsvpData.espProvider?.registrationStatus === 'waitlisted' || rsvpData.attendeeStatus === 'waitlisted') { + } else if (rsvpData.attendeeStatus === 'waitlisted') { await waitlistedState(); } else if (!rsvpData.ok) { // FIXME: temporary solution for ESL returning 500 on ESP 400 response From 00e0a098066a30cb70cc9bb9a5fc4475804c6576 Mon Sep 17 00:00:00 2001 From: Qiyun Dai Date: Wed, 9 Oct 2024 11:36:26 -0500 Subject: [PATCH 18/22] remove last bit of mock --- events/blocks/events-form/events-form.js | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/events/blocks/events-form/events-form.js b/events/blocks/events-form/events-form.js index 883f18e0..bc971b51 100644 --- a/events/blocks/events-form/events-form.js +++ b/events/blocks/events-form/events-form.js @@ -647,27 +647,5 @@ export default async function decorate(block, formData = null) { waitlistSuccessScreen: block.querySelector(':scope > div:nth-of-type(5)'), }; - BlockMediator.set('imsProfile', { - account_type: 'type3', - utcOffset: 'null', - preferred_languages: null, - displayName: 'Qiyun Dai', - last_name: 'Dai', - userId: 'B90719A765B288680A494219@c62f24cc5b5b7e0e0a494004', - authId: 'B90719A765B288680A494219@c62f24cc5b5b7e0e0a494004', - tags: [ - 'agegroup_unknown', - 'edu', - 'edu_k12', - ], - emailVerified: 'true', - phoneNumber: null, - countryCode: 'US', - name: 'Qiyun Dai', - mrktPerm: '', - mrktPermEmail: null, - first_name: 'Qiyun', - email: 'cod87753@adobe.com', - }); await onProfile(bp, formData); } From d50848937fa35d78888f0f2a0d30ced5f5f3268f Mon Sep 17 00:00:00 2001 From: Qiyun Dai Date: Fri, 11 Oct 2024 09:41:09 -0500 Subject: [PATCH 19/22] key change --- events/blocks/events-form/events-form.js | 10 +++++----- events/scripts/content-update.js | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/events/blocks/events-form/events-form.js b/events/blocks/events-form/events-form.js index 60a9fcab..9a0ea548 100644 --- a/events/blocks/events-form/events-form.js +++ b/events/blocks/events-form/events-form.js @@ -127,14 +127,14 @@ function showSuccessMsgFirstScreen(bp) { bp.form.classList.add('hidden'); bp.eventHero.classList.add('hidden'); - const { attendeeStatus } = rsvpData; + const { registrationStatus } = rsvpData; - if (attendeeStatus === 'waitlisted') { + if (registrationStatus === 'waitlisted') { bp.waitlistSuccessScreen?.classList.remove('hidden'); bp.waitlistSuccessScreen?.querySelector('.first-screen')?.classList.remove('hidden'); } - if (attendeeStatus === 'registered') { + if (registrationStatus === 'registered') { bp.rsvpSuccessScreen?.classList.remove('hidden'); bp.rsvpSuccessScreen?.querySelector('.first-screen')?.classList.remove('hidden'); } @@ -570,7 +570,7 @@ function initFormBasedOnRSVPData(bp) { const { block } = bp; const profile = BlockMediator.get('imsProfile'); const rsvpData = BlockMediator.get('rsvpData'); - if (validRegistrationStatus.includes(rsvpData.attendeeStatus)) { + if (validRegistrationStatus.includes(rsvpData.registrationStatus)) { showSuccessMsgFirstScreen(bp); eventFormSendAnalytics(bp, 'Confirmation Modal View'); } else { @@ -578,7 +578,7 @@ function initFormBasedOnRSVPData(bp) { } BlockMediator.subscribe('rsvpData', ({ newValue }) => { - if (validRegistrationStatus.includes(newValue?.attendeeStatus)) { + if (validRegistrationStatus.includes(newValue?.registrationStatus)) { showSuccessMsgFirstScreen(bp); eventFormSendAnalytics(bp, 'Confirmation Modal View'); } diff --git a/events/scripts/content-update.js b/events/scripts/content-update.js index ebf1fec0..abb8489e 100644 --- a/events/scripts/content-update.js +++ b/events/scripts/content-update.js @@ -160,9 +160,9 @@ async function updateRSVPButtonState(rsvpBtn, miloLibs, eventInfo) { } else { defaultState(); } - } else if (rsvpData.attendeeStatus === 'registered') { + } else if (rsvpData.registrationStatus === 'registered') { await registeredState(); - } else if (rsvpData.attendeeStatus === 'waitlisted') { + } else if (rsvpData.registrationStatus === 'waitlisted') { await waitlistedState(); } else if (!rsvpData.ok) { // FIXME: temporary solution for ESL returning 500 on ESP 400 response From 1f434b49487a4cdff931c2321639116ed20a5427 Mon Sep 17 00:00:00 2001 From: Qiyun Dai Date: Fri, 11 Oct 2024 10:38:16 -0500 Subject: [PATCH 20/22] WIP --- events/blocks/events-form/events-form.js | 15 +++++++++++++-- events/scripts/content-update.js | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/events/blocks/events-form/events-form.js b/events/blocks/events-form/events-form.js index 9a0ea548..c3c7c85b 100644 --- a/events/blocks/events-form/events-form.js +++ b/events/blocks/events-form/events-form.js @@ -92,7 +92,14 @@ async function submitForm(bp) { return acc; }, {}); - return getAndCreateAndAddAttendee(getMetadata('event-id'), cleanPayload); + let rsvpType = 'registered'; + const eventInfo = BlockMediator.get('eventInfo'); + if (eventInfo) { + const { allowWaitlisting, attendeeLimit, attendeeCount } = eventInfo; + if (allowWaitlisting && attendeeCount >= attendeeLimit) rsvpType = 'waitlisted'; + } + + return getAndCreateAndAddAttendee(getMetadata('event-id'), cleanPayload, rsvpType); } function clearForm(form) { @@ -123,6 +130,9 @@ async function buildErrorMsg(parent, status) { function showSuccessMsgFirstScreen(bp) { const rsvpData = BlockMediator.get('rsvpData'); + + if (!rsvpData) return; + clearForm(bp.form); bp.form.classList.add('hidden'); bp.eventHero.classList.add('hidden'); @@ -570,7 +580,8 @@ function initFormBasedOnRSVPData(bp) { const { block } = bp; const profile = BlockMediator.get('imsProfile'); const rsvpData = BlockMediator.get('rsvpData'); - if (validRegistrationStatus.includes(rsvpData.registrationStatus)) { + + if (validRegistrationStatus.includes(rsvpData?.registrationStatus)) { showSuccessMsgFirstScreen(bp); eventFormSendAnalytics(bp, 'Confirmation Modal View'); } else { diff --git a/events/scripts/content-update.js b/events/scripts/content-update.js index abb8489e..f41e86d7 100644 --- a/events/scripts/content-update.js +++ b/events/scripts/content-update.js @@ -185,6 +185,7 @@ async function handleRSVPBtnBasedOnProfile(rsvpBtn, miloLibs, profile) { const resp = await getEvent(getMetadata('event-id')); if (!resp) return; const eventInfo = resp.data; + BlockMediator.set('eventInfo', eventInfo); if (profile?.noProfile || resp.status === 401) { if (eventInfo && +eventInfo.attendeeLimit <= +eventInfo.attendeeCount) { const eventFullText = await miloReplaceKey(miloLibs, 'event-full-cta-text'); From 8219dcd1bd5a457efedc79c5ce5f31e67e043f33 Mon Sep 17 00:00:00 2001 From: Qiyun Dai Date: Fri, 11 Oct 2024 10:55:33 -0500 Subject: [PATCH 21/22] Update content-update.js --- events/scripts/content-update.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/events/scripts/content-update.js b/events/scripts/content-update.js index f41e86d7..6f29dd6f 100644 --- a/events/scripts/content-update.js +++ b/events/scripts/content-update.js @@ -93,12 +93,8 @@ function createTag(tag, attributes, html, options = {}) { async function updateRSVPButtonState(rsvpBtn, miloLibs, eventInfo) { const rsvpData = BlockMediator.get('rsvpData'); const checkRed = getIcon('check-circle-red'); - const { - attendeeLimit, - attendeeCount, - allowWaitListing, - } = eventInfo; - const eventFull = +attendeeLimit <= +attendeeCount; + let eventFull = false; + if (eventInfo) eventFull = +eventInfo.attendeeLimit <= +eventInfo.attendeeCount; const enableBtn = () => { rsvpBtn.el.classList.remove('disabled'); @@ -152,7 +148,7 @@ async function updateRSVPButtonState(rsvpBtn, miloLibs, eventInfo) { if (!rsvpData) { if (eventFull) { - if (allowWaitListing) { + if (eventInfo?.allowWaitListing) { await waitlistState(); } else { await closedState(); From 70ad6224a97e86f0de5a628a8966f5981fa07199 Mon Sep 17 00:00:00 2001 From: Qiyun Dai Date: Fri, 11 Oct 2024 11:03:23 -0500 Subject: [PATCH 22/22] Update esp-controller.js --- events/scripts/esp-controller.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/events/scripts/esp-controller.js b/events/scripts/esp-controller.js index dc69f3a3..831e43fc 100644 --- a/events/scripts/esp-controller.js +++ b/events/scripts/esp-controller.js @@ -171,12 +171,12 @@ export async function createAttendee(attendeeData) { } } -export async function addAttendeeToEvent(eventId, attendee) { +export async function addAttendeeToEvent(eventId, attendee, registrationStatus) { if (!eventId || !attendee) return false; const { firstName, lastName, email } = attendee; const { host } = API_CONFIG.esl[getECCEnv()]; - const raw = JSON.stringify({ firstName, lastName, email }); + const raw = JSON.stringify({ firstName, lastName, email, registrationStatus }); const options = await constructRequestOptions('POST', raw); try { @@ -244,7 +244,7 @@ export async function deleteAttendeeFromEvent(eventId) { } // compound helper functions -export async function getAndCreateAndAddAttendee(eventId, attendeeData) { +export async function getAndCreateAndAddAttendee(eventId, attendeeData, registrationStatus) { const attendeeResp = await getAttendee(eventId); let attendee; @@ -258,5 +258,5 @@ export async function getAndCreateAndAddAttendee(eventId, attendeeData) { const newAttendeeData = attendee.data; - return addAttendeeToEvent(eventId, newAttendeeData); + return addAttendeeToEvent(eventId, newAttendeeData, registrationStatus); }