Skip to content

Commit

Permalink
Merge pull request #214 from adobecom/dev
Browse files Browse the repository at this point in the history
Dev -> Stage Thu 12th Sep, 2024 #2
  • Loading branch information
apganapa-adobe authored Sep 13, 2024
2 parents d9612b1 + d7e9b10 commit 208aec6
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function onSubmit(component, props) {
if (selectedProducts) {
const topicsVal = props.payload.fullTopicsValue?.map((x) => JSON.parse(x));
const relatedProducts = selectedProducts
.filter((p) => topicsVal.find((t) => p.tagID.includes(t.tagID)))
.filter((p) => topicsVal.find((t) => p.tagID?.includes(t.tagID)))
.map((p) => ({
name: p.title,
showProductBlade: !!p.showProductBlade,
Expand Down Expand Up @@ -65,19 +65,19 @@ async function updateProductSelector(component, props) {
'Substance 3D Collection',
];
const caasTags = await getCaasTags();
const topicsVal = props.payload.fullTopicsValue?.map((x) => JSON.parse(x));
if (!caasTags || !topicsVal) return;
const topics = props.payload.fullTopicsValue?.map((x) => JSON.parse(x));
if (!caasTags || !topics) return;

const productGroups = component.querySelectorAll('product-selector-group');
let products = Object.values(caasTags.namespaces.caas.tags['product-categories'].tags).map((x) => [...Object.values(x.tags).map((y) => y)]).flat();

products = products.filter(
(p) => topicsVal.find((t) => p.tagID.includes(t.tagID)) && supportedProducts.includes(p.title),
(p) => topics.find((t) => p.tagID?.includes(t.tagID)) && supportedProducts?.includes(p.title),
);

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

const selectedProducts = pg.getSelectedProducts();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,28 @@ export async function onSubmit(component, props) {

const profileContainer = component.querySelector('profile-container');
if (profileContainer) {
const { eventId } = getFilteredCachedResponse();
const speakers = profileContainer.getProfiles();
if (speakers.length === 0) return;

if (speakers.length === 0) {
if (props.eventDataResp.speakers) {
const savedSpeakers = props.eventDataResp.speakers;
await savedSpeakers.reduce(async (promise, speaker) => {
await promise;
const { speakerId } = speaker;
const resp = await removeSpeakerFromEvent(speakerId, eventId);
if (resp.error) return;
props.eventDataResp = { ...props.eventDataResp, ...resp };
}, Promise.resolve());
}

return;
}

if (speakers.filter((speaker) => !speaker.speakerType).length > 0) {
throw new Error('Please select a speaker type for the speakers');
}

const { eventId } = getFilteredCachedResponse();

await speakers.reduce(async (promise, speaker) => {
await promise;

Expand Down Expand Up @@ -80,10 +93,7 @@ export async function onSubmit(component, props) {

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

if (resp.error) return;
props.eventDataResp = { ...props.eventDataResp, ...resp };
}
}, Promise.resolve());
Expand Down
2 changes: 1 addition & 1 deletion ecc/blocks/form-handler/form-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ async function saveEvent(props, options = { toPublish: false }) {
try {
await gatherValues(props);
} catch (e) {
return { message: e.message };
return { error: { message: e.message } };
}

let resp;
Expand Down
2 changes: 1 addition & 1 deletion ecc/blocks/profile-component/profile-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async function decorateProfile(element) {

const profileContainer = createTag('profile-container', { class: 'profile-component' });
profileContainer.fieldlabels = fieldlabels;
profileContainer.profiles = [{ socialMedia: [{ link: '' }] }];
profileContainer.profiles = [{ socialMedia: [{ link: '' }], isPlaceholder: true }];
element.append(profileContainer);
}

Expand Down
8 changes: 7 additions & 1 deletion ecc/components/profile-container/profile-container.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable import/prefer-default-export */
/* eslint-disable class-methods-use-this */
import { getSpeakers } from '../../scripts/esp-controller.js';
import { LIBS } from '../../scripts/scripts.js';
import { isEmptyObject } from '../../scripts/utils.js';
import { style } from './profile-container.css.js';
Expand Down Expand Up @@ -32,8 +33,14 @@ export class ProfileContainer extends LitElement {
this.requestUpdate();
}

reloadSearchData = async () => {
const spResp = await getSpeakers(this.seriesId);
if (spResp) this.searchdata = spResp.speakers;
};

updateProfile(index, profile) {
this.profiles[index] = profile;
this.reloadSearchData();
this.requestUpdate();
}

Expand All @@ -56,7 +63,6 @@ export class ProfileContainer extends LitElement {
}

enableRepeater() {
// eslint-disable-next-line max-len
return this.profiles.every((profile) => !profile.isPlaceholder && profile.type);
}

Expand Down
2 changes: 1 addition & 1 deletion ecc/components/profile/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class Profile extends LitElement {
this.attachShadow({ mode: 'open' });
this.fieldlabels = this.fieldlabels ?? DEFAULT_FIELD_LABELS;

this.profile = this.profile ?? { socialMedia: [{ link: '' }] };
this.profile = this.profile ?? { socialMedia: [{ link: '' }], isPlaceholder: true };
this.profileCopy = {};
}

Expand Down

0 comments on commit 208aec6

Please sign in to comment.