Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MWPW-156944] Metadata split #182

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ function buildTerms(terms) {
}

async function loadPreview(component, templateId) {
const existingPreview = component.querySelector('.terms-conditions-preview');

if (existingPreview) return;

let host;
if (window.location.href.includes('.hlx.')) {
host = window.location.origin.replace(window.location.hostname, `${ECC_ENV}--events-milo--adobecom.hlx.page`);
Expand All @@ -39,23 +43,24 @@ async function loadPreview(component, templateId) {
}

const rsvpFormLocation = `${host}${templateId.substring(0, templateId.lastIndexOf('/'))}/rsvp-form`;
const text = await fetchThrottledMemoizedText(`${rsvpFormLocation}.plain.html`).catch(() => ({}))
.catch(() => ({}));
const resp = await fetchThrottledMemoizedText(`${rsvpFormLocation}.plain.html`);

if (!text) {
if (!resp) {
component.remove();
return;
}

const doc = new DOMParser().parseFromString(text, 'text/html');
const termsConditionsRow = doc.querySelector('.events-form > div:nth-of-type(3)');
if (typeof resp === 'string') {
const doc = new DOMParser().parseFromString(resp, 'text/html');
const termsConditionsRow = doc.querySelector('.events-form > div:nth-of-type(3)');

if (!termsConditionsRow) {
component.remove();
return;
}
if (!termsConditionsRow) {
component.remove();
return;
}

component.append(buildTerms(termsConditionsRow));
component.append(buildTerms(termsConditionsRow));
}
}

export async function onUpdate(component, props) {
Expand Down
4 changes: 2 additions & 2 deletions ecc/scripts/esp-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ export async function updateEvent(eventId, payload) {

export async function publishEvent(eventId, payload) {
const { host } = getAPIConfig().esp[ECC_ENV];
const raw = JSON.stringify({ ...payload, published: true });
const raw = JSON.stringify({ ...payload, published: true, liveUpdate: true });
const options = await constructRequestOptions('PUT', raw);

try {
Expand All @@ -570,7 +570,7 @@ export async function publishEvent(eventId, payload) {

export async function unpublishEvent(eventId, payload) {
const { host } = getAPIConfig().esp[ECC_ENV];
const raw = JSON.stringify({ ...payload, published: false });
const raw = JSON.stringify({ ...payload, published: false, liveUpdate: true });
const options = await constructRequestOptions('PUT', raw);

try {
Expand Down
Loading