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

Stage to Main Sync #190

Merged
merged 19 commits into from
Aug 23, 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
18 changes: 15 additions & 3 deletions ecc/blocks/ecc-dashboard/ecc-dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ function sortData(props, config, options = {}) {
let valA;
let valB;

if ((field === 'title' || field === 'venueId')) {
if ((field === 'title')) {
valA = a[field]?.toLowerCase() || '';
valB = b[field]?.toLowerCase() || '';
return sortAscending ? valA.localeCompare(valB) : valB.localeCompare(valA);
Expand All @@ -221,6 +221,18 @@ function sortData(props, config, options = {}) {
return sortAscending ? valA - valB : valB - valA;
}

if (field === 'venueName') {
valA = a.venue?.venueName?.toLowerCase() || '';
valB = b.venue?.venueName?.toLowerCase() || '';
return sortAscending ? valA.localeCompare(valB) : valB.localeCompare(valA);
}

if (typeof a[field] === typeof b[field] && typeof a[field] === 'number') {
valA = a[field] || 0;
valB = b[field] || 0;
return sortAscending ? valA - valB : valB - valA;
}

valA = a[field]?.toString().toLowerCase() || '';
valB = b[field]?.toString().toLowerCase() || '';
return sortAscending ? valA.localeCompare(valB) : valB.localeCompare(valA);
Expand Down Expand Up @@ -538,9 +550,9 @@ function initSorting(props, config) {
published: 'PUBLISH STATUS',
startDate: 'DATE RUN',
modificationTime: 'LAST MODIFIED',
venueId: 'VENUE NAME',
venueName: 'VENUE NAME',
timezone: 'GEO',
externalEventId: 'RSVP DATA',
attendeeCount: 'RSVP DATA',
manage: 'MANAGE',
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ function prepopulateTimeZone(component) {
}

function initStepLock(component) {
const { search } = window.location;
const urlParams = new URLSearchParams(search);
const skipValidation = urlParams.get('skipValidation');

if (skipValidation === 'true' && ['stage', 'local'].includes(MILO_CONFIG.env.name)) {
return;
}

const step = component.closest('.fragment');
const inputs = component.querySelectorAll('#bu-select-input, #series-select-input');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ export function onSubmit(component, props) {
const selectedProducts = productGroup?.getSelectedProducts();

if (selectedProducts) {
const relatedProducts = selectedProducts.map((p) => ({
name: p.title,
showProductBlade: !!p.showProductBlade,
tags: p.tags.map((t) => t.tagID).join(','),
}));
const topicsVal = props.payload.fullTopicsValue?.map((x) => JSON.parse(x));
const relatedProducts = selectedProducts
.filter((p) => topicsVal.find((t) => p.tagID.includes(t.tagID)))
.map((p) => ({
name: p.title,
showProductBlade: !!p.showProductBlade,
tags: p.tags.map((t) => t.tagID).join(','),
}));

props.payload = { ...props.payload, relatedProducts };
}
Expand Down Expand Up @@ -68,12 +71,22 @@ async function updateProductSelector(component, props) {
(p) => topicsVal.find((t) => p.tagID.includes(t.tagID)) && supportedProducts.includes(p.title),
);

productGroups.forEach((p) => {
p.setAttribute('data-products', JSON.stringify(products));
p.setAttribute('data-selected-topics', JSON.stringify(topicsVal));
p.requestUpdate();
productGroups.forEach((pg) => {
pg.setAttribute('data-products', JSON.stringify(products));
pg.setAttribute('data-selected-topics', JSON.stringify(topicsVal));
pg.requestUpdate();

const selectedProducts = pg.getSelectedProducts();

selectedProducts.forEach((sp, i) => {
const isProductAvailable = products.find((p) => p.name === sp.name);

if (!isProductAvailable) {
pg.deleteProduct(i);
}
});

p.shadowRoot.querySelectorAll('product-selector').forEach((ps) => {
pg.shadowRoot.querySelectorAll('product-selector').forEach((ps) => {
ps.dispatchEvent(new CustomEvent('update-product', {
detail: { product: ps.selectedProduct },
bubbles: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,5 @@
/* eslint-disable no-unused-vars */
export function onSubmit(component, props) {
if (component.closest('.fragment')?.classList.contains('hidden')) return;

const attendeeLimitVal = component.querySelector('#attendee-count-input')?.value;
const allowWaitlisting = component.querySelector('#registration-allow-waitlist')?.checked;
const contactHost = component.querySelector('#registration-contact-host')?.checked;
const hostEmail = component.querySelector('#event-host-email-input')?.value;
const rsvpDescription = component.querySelector('#rsvp-form-detail-description')?.value;

const attendeeLimit = Number.isNaN(+attendeeLimitVal) ? null : +attendeeLimitVal;

const rsvpData = {};

if (rsvpDescription) rsvpData.rsvpDescription = rsvpDescription;
if (contactHost && hostEmail) rsvpData.hostEmail = hostEmail;
if (attendeeLimit) rsvpData.attendeeLimit = attendeeLimit;
if (allowWaitlisting) rsvpData.allowWaitlisting = allowWaitlisting;

props.payload = { ...props.payload, ...rsvpData };
}

export async function onUpdate(component, props) {
if (!props.eventDataResp) return;

if (props.eventDataResp.cloudType === 'CreativeCloud') {
component.querySelector('.attendee-count-wrapper')?.classList.add('hidden');
component.querySelector('#registration-allow-waitlist')?.classList.add('hidden');
}
}

export default function init(component, props) {
function prefillFields(component, props) {
const contactHostEl = component.querySelector('#registration-contact-host');
const hostEmailEl = component.querySelector('#event-host-email-input');
const attendeeLimitEl = component.querySelector('#attendee-count-input');
Expand Down Expand Up @@ -66,3 +36,39 @@ export default function init(component, props) {
});
}
}

export function onSubmit(component, props) {
if (component.closest('.fragment')?.classList.contains('hidden')) return;

const attendeeLimitVal = component.querySelector('#attendee-count-input')?.value;
const allowWaitlisting = component.querySelector('#registration-allow-waitlist')?.checked;
const contactHost = component.querySelector('#registration-contact-host')?.checked;
const hostEmail = component.querySelector('#event-host-email-input')?.value;
const rsvpDescription = component.querySelector('#rsvp-form-detail-description')?.value;

const attendeeLimit = Number.isNaN(+attendeeLimitVal) ? null : +attendeeLimitVal;

const rsvpData = {};

if (rsvpDescription) rsvpData.rsvpDescription = rsvpDescription;
if (contactHost && hostEmail) rsvpData.hostEmail = hostEmail;
if (attendeeLimit) rsvpData.attendeeLimit = attendeeLimit;
if (allowWaitlisting) rsvpData.allowWaitlisting = allowWaitlisting;

props.payload = { ...props.payload, ...rsvpData };
}

export async function onUpdate(component, props) {
if (!props.eventDataResp) return;

if (props.eventDataResp.cloudType === 'CreativeCloud') {
component.querySelector('.attendee-count-wrapper')?.classList.add('hidden');
component.querySelector('#registration-allow-waitlist')?.classList.add('hidden');
}

prefillFields(component, props);
}

export default function init(component, props) {
prefillFields(component, props);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
export function onSubmit(component, props) {
if (component.closest('.fragment')?.classList.contains('hidden')) return;

const defaultFields = ['firstName', 'lastName', 'email', 'jobTitle'];
const defaultFields = component.dataset.mandatedfields?.split(',');

const rsvpFormFields = {
visible: [...defaultFields, ...Array.from(component.querySelectorAll('sp-checkbox.check-appear[checked]')).map((f) => f.name)],
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ import { ECC_ENV } from '../../../scripts/scripts.js';
import { changeInputValue, getSecret } from '../../../scripts/utils.js';
import { buildErrorMessage } from '../form-handler.js';

function togglePrefillableFieldsHiddenState(component, showPrefilledFields) {
const addressInput = component.querySelector('#venue-info-venue-address');
const cityInput = component.querySelector('#location-city');
const stateInput = component.querySelector('#location-state');
const postalCodeInput = component.querySelector('#location-zip-code');
const countryInput = component.querySelector('#location-country');

[addressInput, cityInput, stateInput, postalCodeInput, countryInput].forEach((input) => {
input.classList.toggle('hidden', showPrefilledFields);
});
}

async function loadGoogleMapsAPI(callback) {
const script = document.createElement('script');
const apiKey = await getSecret(`${ECC_ENV}-google-places-api`);
Expand Down Expand Up @@ -83,6 +95,8 @@ function initAutocomplete(el) {
changeInputValue(country, 'value', addressInfo.country);
changeInputValue(placeId, 'value', place.place_id);
changeInputValue(mapUrl, 'value', place.url);

togglePrefillableFieldsHiddenState(el, false);
}

if (place.geometry) {
Expand Down Expand Up @@ -121,6 +135,8 @@ export default async function init(component, props) {
const mapUrlInput = component.querySelector('#google-map-url');
const gmtoffsetInput = component.querySelector('#google-place-gmt-offset');

togglePrefillableFieldsHiddenState(component, true);

venueNameInput.addEventListener('change', () => {
if (!venueNameInput.value) {
changeInputValue(addressInput, 'value', '');
Expand Down Expand Up @@ -163,7 +179,10 @@ export default async function init(component, props) {
changeInputValue(mapUrlInput, 'value', mapUrl);
changeInputValue(gmtoffsetInput, 'value', venue.gmtOffset);

if (venueName) component.classList.add('prefilled');
if (venueName) {
component.classList.add('prefilled');
togglePrefillableFieldsHiddenState(component, false);
}
}

if (showVenuePostEvent) {
Expand Down
Loading
Loading