|
12 | 12 | import { organization } from '$lib/stores/organization';
|
13 | 13 | import { BillingPlan } from '$lib/constants';
|
14 | 14 | import { upgradeURL } from '$lib/stores/billing';
|
15 |
| - import { addBottomModalAlerts } from '$routes/(console)/project-[project]/bottomAlerts'; |
| 15 | + import { addBottomModalAlerts } from '$routes/(console)/bottomAlerts'; |
16 | 16 | import { project } from '$routes/(console)/project-[project]/store';
|
| 17 | + import { page } from '$app/stores'; |
17 | 18 |
|
18 | 19 | let currentIndex = 0;
|
19 | 20 | let openModalOnMobile = false;
|
20 | 21 |
|
21 |
| - $: filteredModalAlerts = $bottomModalAlerts |
22 |
| - .sort((a, b) => b.importance - a.importance) |
23 |
| - .filter((alert) => alert.show && shouldShowNotification(alert.id)); |
| 22 | + function getPageScope(pathname: string) { |
| 23 | + const isProjectPage = pathname.includes('project-[project]'); |
| 24 | + const isOrganizationPage = pathname.includes('organization-[organization]'); |
| 25 | +
|
| 26 | + return { isProjectPage, isOrganizationPage }; |
| 27 | + } |
| 28 | +
|
| 29 | + function filterModalAlerts(alerts: BottomModalAlertItem[], pathname: string) { |
| 30 | + const { isProjectPage, isOrganizationPage } = getPageScope(pathname); |
| 31 | +
|
| 32 | + return alerts |
| 33 | + .sort((a, b) => b.importance - a.importance) |
| 34 | + .filter((alert) => { |
| 35 | + return ( |
| 36 | + alert.show && |
| 37 | + shouldShowNotification(alert.id) && |
| 38 | + // if no scope > show in projects & org pages. |
| 39 | + ((!alert.scope && (isProjectPage || isOrganizationPage)) || |
| 40 | + // project scope, show only in project pages |
| 41 | + (isProjectPage && alert.scope === 'project') || |
| 42 | + // organization scope, show only in organization pages |
| 43 | + (isOrganizationPage && alert.scope === 'organization')) |
| 44 | + ); |
| 45 | + }); |
| 46 | + } |
| 47 | +
|
| 48 | + $: filteredModalAlerts = filterModalAlerts($bottomModalAlerts, $page.route.id); |
24 | 49 |
|
25 | 50 | $: currentModalAlert = filteredModalAlerts[currentIndex] as BottomModalAlertItem;
|
26 | 51 |
|
|
147 | 172 | })}
|
148 | 173 | external={!!currentModalAlert.cta.external}
|
149 | 174 | fullWidthMobile>
|
150 |
| - {shouldShowUpgrade ? 'Upgrade plan' : currentModalAlert.cta.text} |
| 175 | + {currentModalAlert.cta.text} |
151 | 176 | </Button>
|
152 | 177 |
|
153 | 178 | {#if currentModalAlert.learnMore}
|
|
0 commit comments