diff --git a/src/lib/components/bottomModalAlert.svelte b/src/lib/components/bottomModalAlert.svelte index e10c02f63..7af6fad1a 100644 --- a/src/lib/components/bottomModalAlert.svelte +++ b/src/lib/components/bottomModalAlert.svelte @@ -4,7 +4,7 @@ import { app } from '$lib/stores/app'; import { type BottomModalAlertItem, - bottomModalAlerts, + bottomModalAlertsConfig, dismissBottomModalAlert, hideAllModalAlerts } from '$lib/stores/bottom-alerts'; @@ -16,6 +16,7 @@ import { project } from '$routes/(console)/project-[region]-[project]/store'; import { page } from '$app/state'; import { Click, trackEvent } from '$lib/actions/analytics'; + import { goto } from '$app/navigation'; let currentIndex = 0; let openModalOnMobile = false; @@ -33,23 +34,27 @@ return alerts .sort((a, b) => b.importance - a.importance) .filter((alert) => { - return ( - alert.show && - shouldShowNotification(alert.id) && - // if no scope > show in projects & org pages. - ((!alert.scope && (isProjectPage || isOrganizationPage)) || - // project scope, show only in project pages - (isProjectPage && alert.scope === 'project') || - // organization scope, show only in organization pages - (isOrganizationPage && alert.scope === 'organization')) - ); + if (!alert.show || !shouldShowNotification(alert.id)) return false; + + switch (alert.scope) { + case 'everywhere': + return true; + case 'project': + return isProjectPage; + case 'organization': + return isOrganizationPage; + default: + return false; + } }); } - $: filteredModalAlerts = filterModalAlerts($bottomModalAlerts, page.route.id); + $: filteredModalAlerts = filterModalAlerts($bottomModalAlertsConfig.alerts, page.route.id); $: currentModalAlert = filteredModalAlerts[currentIndex] as BottomModalAlertItem; + $: hasOnlyPrimaryCta = typeof currentModalAlert?.learnMore === 'undefined'; + function handleClose() { filteredModalAlerts.forEach((alert) => { const modalAlert = alert; @@ -67,9 +72,48 @@ currentIndex = (currentIndex - 1 + filteredModalAlerts.length) % filteredModalAlerts.length; } + function getMobileWindowConfig(): { + html: boolean; + cta: boolean; + title: string; + message: string; + } { + const config = $bottomModalAlertsConfig?.mobileSingleLayout; + const visibleAlerts = $bottomModalAlertsConfig.alerts.filter((a) => a.show); + + const fallback = { + title: 'New features available', + message: 'Explore new features to enhance your projects and improve security.' + }; + + const shouldApplyConfig = config?.enabled === true && visibleAlerts.length === 1; + + return { + cta: !!(shouldApplyConfig && config.cta), + html: !!(shouldApplyConfig && config.isHtml), + title: shouldApplyConfig && config.title ? config.title : fallback.title, + message: shouldApplyConfig && config.message ? config.message : fallback.message + }; + } + + function triggerMobileWindowLink() { + handleClose(); + + const url = $bottomModalAlertsConfig.mobileSingleLayout.cta.link({ + organization: $organization, + project: $project + }); + + if ($bottomModalAlertsConfig.mobileSingleLayout.cta.external) { + window.open(url, '_blank'); + } else { + goto(url); + } + } + function showUpgrade() { const plan = currentModalAlert.plan; - const organizationPlan = $organization.billingPlan; + const organizationPlan = $organization?.billingPlan; switch (plan) { case 'free': return false; @@ -87,7 +131,7 @@ }); -{#if filteredModalAlerts.length > 0 && currentModalAlert} +{#if filteredModalAlerts.length > 0 && currentModalAlert && !$page.url.pathname.includes('console/onboarding')} {@const shouldShowUpgrade = showUpgrade()}