From ae8ee98677d6f59c2d314009bc0c2bae28ff1c3f Mon Sep 17 00:00:00 2001 From: ItzNotABug Date: Wed, 25 Sep 2024 17:57:38 +0530 Subject: [PATCH] address comments. --- src/lib/components/bottomModalAlert.svelte | 38 +++++++++++++--------- src/lib/stores/bottom-alerts.ts | 4 +-- src/routes/(console)/bottomAlerts.ts | 9 +++-- 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/lib/components/bottomModalAlert.svelte b/src/lib/components/bottomModalAlert.svelte index 96a7d6877..e70203a16 100644 --- a/src/lib/components/bottomModalAlert.svelte +++ b/src/lib/components/bottomModalAlert.svelte @@ -19,22 +19,30 @@ let currentIndex = 0; let openModalOnMobile = false; - $: pagePathName = $page.url.pathname; + function getPageScope(pathname: string) { + const isProjectPage = pathname.includes('project-[project]'); + const isOrganizationPage = pathname.includes('organization-[organization]'); - $: filteredModalAlerts = $bottomModalAlerts - .sort((a, b) => b.importance - a.importance) - .filter((alert) => { - const isProjectPage = pagePathName.includes('project-'); - const isOrganizationPage = pagePathName.includes('organization-'); + return { isProjectPage, isOrganizationPage }; + } - return ( - alert.show && - shouldShowNotification(alert.id) && - (alert.scope === 'everywhere' || - (isProjectPage && alert.scope === 'project') || - (isOrganizationPage && alert.scope === 'organization')) - ); - }); + function filterModalAlerts(alerts: BottomModalAlertItem[], pathname: string) { + const { isProjectPage, isOrganizationPage } = getPageScope(pathname); + + return alerts + .sort((a, b) => b.importance - a.importance) + .filter((alert) => { + return ( + alert.show && + shouldShowNotification(alert.id) && + (!alert.scope || + (isProjectPage && alert.scope === 'project') || + (isOrganizationPage && alert.scope === 'organization')) + ); + }); + } + + $: filteredModalAlerts = filterModalAlerts($bottomModalAlerts, $page.route.id); $: currentModalAlert = filteredModalAlerts[currentIndex] as BottomModalAlertItem; @@ -161,7 +169,7 @@ })} external={!!currentModalAlert.cta.external} fullWidthMobile> - {shouldShowUpgrade ? 'Upgrade plan' : currentModalAlert.cta.text} + {currentModalAlert.cta.text} {#if currentModalAlert.learnMore} diff --git a/src/lib/stores/bottom-alerts.ts b/src/lib/stores/bottom-alerts.ts index b457daa71..1b681dcc8 100644 --- a/src/lib/stores/bottom-alerts.ts +++ b/src/lib/stores/bottom-alerts.ts @@ -23,7 +23,7 @@ export type BottomModalAlertItem = { importance?: number; closed?: () => void; - scope?: 'organization' | 'project' | 'everywhere'; + scope?: 'organization' | 'project'; notificationHideOptions?: NotificationCoolOffOptions; }; @@ -42,11 +42,11 @@ export const showBottomModalAlert = (notification: BottomModalAlertItem) => { show: true, importance: 5, isHtml: false, - scope: 'project', ...notification }; bottomModalAlerts.update((all) => { + if (all.some((t) => t.id === notification.id)) return all; return [...all, defaults as BottomModalAlertItem]; }); }; diff --git a/src/routes/(console)/bottomAlerts.ts b/src/routes/(console)/bottomAlerts.ts index 1662303fb..e4ee69014 100644 --- a/src/routes/(console)/bottomAlerts.ts +++ b/src/routes/(console)/bottomAlerts.ts @@ -10,19 +10,18 @@ const listOfPromotions: BottomModalAlertItem[] = [ dark: RolesDark, light: RolesLight }, - title: 'Member roles now on Pro plans', + title: 'Roles are available now', message: - 'Enhance your workflow and security by assigning roles to members.
Try it now for free until 1st January 2025.', + 'Enhance your workflow and security by assigning roles to members.
Try for free until Jan 1st 2025 on paid plans.', isHtml: true, - scope: 'organization', plan: 'pro', cta: { - text: 'Try Now', + text: 'Try now', link: ({ organization }) => `${base}/organization-${organization.$id}/members` }, learnMore: { - text: 'Learn More', + text: 'Learn more', link: () => 'https://appwrite.io/docs/advanced/platform/roles' } }