Skip to content

Commit

Permalink
Merge pull request #126 from adobecom/dev
Browse files Browse the repository at this point in the history
Dev -> Stage July 26 #1
  • Loading branch information
rayyank10 authored Jul 26, 2024
2 parents 8e67795 + 2de95c4 commit 42aa785
Show file tree
Hide file tree
Showing 13 changed files with 662 additions and 297 deletions.
20 changes: 14 additions & 6 deletions ecc/blocks/ecc-dashboard/ecc-dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,8 @@ function highlightRow(row) {

function buildThumbnail(data) {
const container = createTag('td', { class: 'thumbnail-container' });
getEventImages(data.eventId).then(({ images }) => {
if (!images) return;

const buildThumbnailContainer = (images) => {
const cardImage = images.find((photo) => photo.imageKind === 'event-card-image');
const heroImage = images.find((photo) => photo.imageKind === 'event-hero-image');
const venueImage = images.find((photo) => photo.imageKind === 'venue-image');
Expand All @@ -133,7 +132,16 @@ function buildThumbnail(data) {
|| '/ecc/icons/icon-placeholder.svg',
});
container.append(img);
});
};

if (data.photos) {
buildThumbnailContainer(data.photos);
} else {
getEventImages(data.eventId).then(({ images }) => {
if (!images) return;
buildThumbnailContainer(images);
});
}

return container;
}
Expand Down Expand Up @@ -606,13 +614,13 @@ function buildDashboardTable(props, config) {
}

async function getEventsArray() {
const json = await getEvents();
const resp = await getEvents();

if (!json || json.errors?.length > 0) {
if (resp.error) {
return [];
}

return json.events;
return resp.events;
}

function buildNoEventScreen(el, config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function onSubmit(component, props) {
sponsorType,
}, eventId);

if (!resp || resp.errors) {
if (resp.error) {
return;
}

Expand All @@ -50,7 +50,7 @@ export async function onSubmit(component, props) {
sponsorType,
}, eventId);

if (!resp || resp.errors) {
if (resp.error) {
return;
}

Expand All @@ -64,7 +64,7 @@ export async function onSubmit(component, props) {
};
const resp = await updateSponsorInEvent(updatableData, partner.sponsorId, eventId);

if (!resp || resp.errors) {
if (resp.error) {
return;
}

Expand All @@ -82,7 +82,7 @@ export async function onSubmit(component, props) {

if (!stillNeeded) {
const resp = await removeSponsorFromEvent(sponsorId, eventId);
if (!resp || resp.errors) {
if (resp.error) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export default async function init(component, props) {
dialogDeleteBtn.disabled = true;
dialogCancelBtn.disabled = true;
const resp = await deleteImage(configs, imageId);
if (resp?.errors || resp?.message) {
if (resp.error) {
dz.dispatchEvent(new CustomEvent('show-error-toast', { detail: { message: 'Failed to delete the image. Please try again later.' }, bubbles: true, composed: true }));
} else {
dz.file = null;
Expand All @@ -145,6 +145,14 @@ export default async function init(component, props) {

const eventData = props.eventDataResp;
if (eventData.eventId) {
// TODO: would prefer to prioritize eventData.photos, but it is not reliable.
// let images;

// if (eventData.photos) {
// images = eventData.photos;
// } else {
// images = await getEventImages(eventData.eventId).images;
// }
const { images } = await getEventImages(eventData.eventId);

if (images) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export async function onSubmit(component, props) {
if (!props.eventDataResp.speakers) {
const resp = await addSpeakerToEvent(speaker, eventId);

if (!resp || resp.errors) {
if (resp.error) {
return;
}

Expand All @@ -51,17 +51,17 @@ export async function onSubmit(component, props) {
if (updateSpeaker) {
const resp = await updateSpeakerInEvent(speaker, speakerId, eventId);

if (!resp || resp.errors || resp.message) {
const { errors, message } = resp;
if (resp.error) {
const { errors, message } = resp.error;
profileContainer.dispatchEvent(new CustomEvent('show-error-toast', { detail: { errors, message } }));
}

props.eventDataResp = { ...props.eventDataResp, ...resp };
} else {
const resp = await addSpeakerToEvent(speaker, eventId);

if (!resp || resp.errors || resp.message) {
const { errors, message } = resp;
if (resp.error) {
const { errors, message } = resp.error;
profileContainer.dispatchEvent(new CustomEvent('show-error-toast', { detail: { errors, message } }));
}

Expand All @@ -80,7 +80,7 @@ export async function onSubmit(component, props) {

if (!stillNeeded) {
const resp = await removeSpeakerFromEvent(speakerId, eventId);
if (!resp || resp.errors) {
if (resp.error) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export default async function init(component, props) {
...venueData,
});

if (resp?.errors || resp?.message) {
if (resp.error) {
buildErrorMessage(props, resp);
}
}
Expand Down
7 changes: 0 additions & 7 deletions ecc/blocks/form-handler/form-handler.css
Original file line number Diff line number Diff line change
Expand Up @@ -399,13 +399,6 @@
gap: 16px;
}

.form-handler .toast-area .toast-message.dark.success-message {
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 8px;
}

@media screen and (min-width: 900px) {
.form-handler > div:first-child {
flex-direction: row;
Expand Down
96 changes: 58 additions & 38 deletions ecc/blocks/form-handler/form-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,36 +83,45 @@ export function buildErrorMessage(props, resp) {

const toastArea = props.el.querySelector('.toast-area');

if (resp.errors) {
if (resp.error) {
const messages = [];

resp.errors.forEach((error) => {
const errorPathSegments = error.path.split('/');
const text = `${camelToSentenceCase(errorPathSegments[errorPathSegments.length - 1])} ${error.message}`;
messages.push(text);
});

messages.forEach((msg, i) => {
const toast = createTag('sp-toast', { open: true, variant: 'negative', timeout: 6000 + (i * 3000) }, msg, { parent: toastArea });
toast.addEventListener('close', () => {
toast.remove();
});
});
} else if (resp.message) {
if (resp.message.endsWith('modified since last fetch')) {
const message = createTag('div', { class: 'dark' }, createTag('div', {}, resp.message));
const url = new URL(window.location.href);
url.searchParams.set('eventId', getFilteredCachedResponse().eventId);
createTag('a', { href: `${url.toString()}`, class: 'con-button outline' }, 'See the latest version.', { parent: message });
const toast = createTag('sp-toast', { open: true, variant: 'negative' }, message, { parent: toastArea });
toast.addEventListener('close', () => {
toast.remove();
const errorBag = resp.error.errors;
const errorMessage = resp.error.message;

if (errorBag) {
errorBag.forEach((error) => {
const errorPathSegments = error.path.split('/');
const text = `${camelToSentenceCase(errorPathSegments[errorPathSegments.length - 1])} ${error.message}`;
messages.push(text);
});
} else {
const toast = createTag('sp-toast', { open: true, variant: 'negative', timeout: 6000 }, resp.message, { parent: toastArea });
toast.addEventListener('close', () => {
toast.remove();

messages.forEach((msg, i) => {
const toast = createTag('sp-toast', { open: true, variant: 'negative', timeout: 6000 + (i * 3000) }, msg, { parent: toastArea });
toast.addEventListener('close', () => {
toast.remove();
});
});
} else if (errorMessage) {
if (resp.status === 409) {
const toast = createTag('sp-toast', { open: true, variant: 'negative' }, errorMessage, { parent: toastArea });
const url = new URL(window.location.href);
url.searchParams.set('eventId', getFilteredCachedResponse().eventId);

createTag('sp-button', {
slot: 'action',
variant: 'overBackground',
href: `${url.toString()}`,
}, 'See the latest version.', { parent: toast });

toast.addEventListener('close', () => {
toast.remove();
});
} else {
const toast = createTag('sp-toast', { open: true, variant: 'negative', timeout: 6000 }, errorMessage, { parent: toastArea });
toast.addEventListener('close', () => {
toast.remove();
});
}
}
}
}
Expand Down Expand Up @@ -378,7 +387,7 @@ async function saveEvent(props, options = { toPublish: false }) {
let resp;

const onEventSave = () => {
if (!resp.errors && !resp.message) {
if (!resp.error) {
showSaveSuccessMessage(props);
}

Expand Down Expand Up @@ -491,7 +500,7 @@ function initFormCtas(props) {
if (cta.classList.contains('preview-not-ready')) return;
const resp = await saveEvent(props);

if (resp?.errors || resp?.message) {
if (resp.error) {
buildErrorMessage(props, resp);
} else {
window.open(cta.href);
Expand Down Expand Up @@ -535,18 +544,29 @@ function initFormCtas(props) {
resp = await saveEvent(props);
}

if (resp?.errors || resp?.message) {
if (resp?.error) {
buildErrorMessage(props, resp);
} else if (props.currentStep === props.maxStep) {
const dashboardLink = props.el.querySelector('.side-menu > ul > li > a');
const msg = createTag('div', { class: 'toast-message dark success-message' }, 'Success! This event has been published.', { parent: cta });
createTag('a', { class: 'con-button outline', href: dashboardLink.href }, 'Go to dashboard', { parent: msg });
const toastArea = props.el.querySelector('.toast-area');
cta.textContent = cta.dataset.doneStateText;
cta.classList.add('disabled');

if (toastArea) {
const toast = createTag('sp-toast', { open: true, variant: 'positive' }, msg, { parent: toastArea });
const toast = createTag('sp-toast', { open: true, variant: 'positive' }, 'Success! This event has been published.', { parent: toastArea });
const dashboardLink = props.el.querySelector('.side-menu > ul > li > a');

createTag(
'sp-button',
{
slot: 'action',
variant: 'overBackground',
treatment: 'outline',
href: dashboardLink.href,
},
'Go to dashboard',
{ parent: toast },
);

toast.addEventListener('close', () => {
toast.remove();
});
Expand All @@ -556,7 +576,7 @@ function initFormCtas(props) {
}
} else {
const resp = await saveEvent(props);
if (resp?.errors || resp?.message) {
if (resp?.error) {
buildErrorMessage(props, resp);
}
}
Expand All @@ -569,7 +589,7 @@ function initFormCtas(props) {

backBtn.addEventListener('click', async () => {
const resp = await saveEvent(props);
if (resp?.errors || resp?.message) {
if (resp?.error) {
buildErrorMessage(props, resp);
} else {
props.currentStep -= 1;
Expand Down Expand Up @@ -621,7 +641,7 @@ function initNavigation(props) {
sideMenu.classList.add('disabled');

const resp = await saveEvent(props);
if (resp?.errors || resp?.message) {
if (resp?.error) {
buildErrorMessage(props, resp);
} else {
navigateForm(props, i);
Expand Down Expand Up @@ -706,7 +726,7 @@ async function buildECCForm(el) {
setResponseCache(value);
updateCtas(target);
updateDashboardLink(target);
if (value.message || value.errors) {
if (value.error) {
props.el.classList.add('show-error');
} else {
props.el.classList.remove('show-error');
Expand Down
7 changes: 5 additions & 2 deletions ecc/components/custom-search/custom-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class CustomSearch extends LitElement {

this.searchResults = this.searchInput?.trim().length !== 0 && this.searchdata.length > 0
// eslint-disable-next-line max-len
? this.searchdata.filter((item) => (this.searchMap.searchKeys.some((k) => item[k].toLowerCase().includes(searchVal)))) : [];
? this.searchdata.filter((item) => (item.value.toLowerCase().includes(searchVal))) : [];

if (this.searchResults.length === 0) {
return;
Expand Down Expand Up @@ -112,8 +112,11 @@ export class CustomSearch extends LitElement {
${repeat(this.searchResults, (item) => item[this.identifier], (entry) => html`
<sp-menu-item @click=${() => {
this.selectEntry(entry);
}}>${this.searchMap.renderKeys.map((rk) => entry[rk]).join(' ')}</sp-menu-item>`)}`;
this.handleCommonActionsOnCLick();
}}>${entry.displayValue}</sp-menu-item>`)}`;
}
//${profile?.photo?.imageUrl ? html`<img src=${profile?.photo?.imageUrl} style="width: 20px;"></img>` : nothing}


onSubmitSearch(e) {
e.stopPropagation();
Expand Down
Loading

0 comments on commit 42aa785

Please sign in to comment.