Skip to content

Commit

Permalink
Merge pull request #5089 from kiva/CIT-556-contentful-global-promo-gu…
Browse files Browse the repository at this point in the history
…ards

fix: guard against missing fields and draft ui-global-promo banners
  • Loading branch information
mcstover authored Dec 5, 2023
2 parents 1e54d8b + dfa8c8e commit aecdf03
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ export default {
// if setting is enabled determine which banner to display
if (isGlobalSettingEnabled) {
const activePromoBanner = uiGlobalPromoSetting.fields.content.find(promoContent => {
// guard against drafts
if (promoContent?.sys?.revision === 0) {
return false;
}
// guard against missing fields
if (!promoContent?.fields
|| !promoContent?.fields?.active
|| !promoContent?.fields?.startDate
|| !promoContent?.fields?.endDate) {
return false;
}
return settingEnabled(
promoContent.fields,
'active',
Expand All @@ -84,7 +95,8 @@ export default {
);
});
if (activePromoBanner) {
// check for activePromoBanner and ensure it has content fields
if (activePromoBanner && activePromoBanner?.fields) {
// check for visibility based on current route and hiddenUrls field
const hiddenUrls = globalBannerDenyList.concat(activePromoBanner?.fields?.hiddenUrls ?? []);
const visibleUrls = [];
Expand Down

0 comments on commit aecdf03

Please sign in to comment.