Skip to content

Commit 4023d7d

Browse files
Merge pull request #1373 from ItzNotABug/scopes-to-bottom-alerts
Scopes to Bottom Alerts
2 parents febcbdb + ecb6665 commit 4023d7d

File tree

6 files changed

+49
-21
lines changed

6 files changed

+49
-21
lines changed

src/lib/components/bottomModalAlert.svelte

+30-5
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,40 @@
1212
import { organization } from '$lib/stores/organization';
1313
import { BillingPlan } from '$lib/constants';
1414
import { upgradeURL } from '$lib/stores/billing';
15-
import { addBottomModalAlerts } from '$routes/(console)/project-[project]/bottomAlerts';
15+
import { addBottomModalAlerts } from '$routes/(console)/bottomAlerts';
1616
import { project } from '$routes/(console)/project-[project]/store';
17+
import { page } from '$app/stores';
1718
1819
let currentIndex = 0;
1920
let openModalOnMobile = false;
2021
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);
2449
2550
$: currentModalAlert = filteredModalAlerts[currentIndex] as BottomModalAlertItem;
2651
@@ -147,7 +172,7 @@
147172
})}
148173
external={!!currentModalAlert.cta.external}
149174
fullWidthMobile>
150-
{shouldShowUpgrade ? 'Upgrade plan' : currentModalAlert.cta.text}
175+
{currentModalAlert.cta.text}
151176
</Button>
152177

153178
{#if currentModalAlert.learnMore}

src/lib/stores/bottom-alerts.ts

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export type BottomModalAlertItem = {
2323
importance?: number;
2424

2525
closed?: () => void;
26+
scope?: 'organization' | 'project';
2627
notificationHideOptions?: NotificationCoolOffOptions;
2728
};
2829

@@ -45,6 +46,7 @@ export const showBottomModalAlert = (notification: BottomModalAlertItem) => {
4546
};
4647

4748
bottomModalAlerts.update((all) => {
49+
if (all.some((t) => t.id === notification.id)) return all;
4850
return [...all, defaults as BottomModalAlertItem];
4951
});
5052
};

src/routes/(console)/+layout.svelte

+10-7
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@
1515
import { requestedMigration } from '../store';
1616
import Create from './createOrganization.svelte';
1717
import {
18-
showUsageRatesModal,
19-
checkForUsageLimit,
20-
checkPaymentAuthorizationRequired,
2118
calculateTrialDay,
22-
paymentExpired,
23-
checkForMarkedForDeletion,
2419
checkForMandate,
20+
checkForMarkedForDeletion,
2521
checkForMissingPaymentMethod,
2622
checkForNewDevUpgradePro,
27-
plansInfo
23+
checkForUsageLimit,
24+
checkPaymentAuthorizationRequired,
25+
paymentExpired,
26+
plansInfo,
27+
showUsageRatesModal
2828
} from '$lib/stores/billing';
2929
import { goto } from '$app/navigation';
3030
import { CommandCenter, registerCommands, registerSearchers } from '$lib/commandCenter';
@@ -35,7 +35,7 @@
3535
import { openMigrationWizard } from './(migration-wizard)';
3636
import { project } from './project-[project]/store';
3737
import { feedback } from '$lib/stores/feedback';
38-
import { VARS, hasStripePublicKey, isCloud } from '$lib/system';
38+
import { hasStripePublicKey, isCloud, VARS } from '$lib/system';
3939
import { stripe } from '$lib/stores/stripe';
4040
import MobileSupportModal from './wizard/support/mobileSupportModal.svelte';
4141
import { showSupportModal } from './wizard/support/store';
@@ -44,6 +44,7 @@
4444
import { UsageRates } from '$lib/components/billing';
4545
import { base } from '$app/paths';
4646
import { canSeeProjects } from '$lib/stores/roles';
47+
import { BottomModalAlert } from '$lib/components';
4748
4849
function kebabToSentenceCase(str: string) {
4950
return str
@@ -337,3 +338,5 @@
337338
{#if isCloud && $showUsageRatesModal}
338339
<UsageRates bind:show={$showUsageRatesModal} org={$organization} />
339340
{/if}
341+
342+
<BottomModalAlert />

src/routes/(console)/project-[project]/bottomAlerts.ts src/routes/(console)/bottomAlerts.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@ import { type BottomModalAlertItem, showBottomModalAlert } from '$lib/stores/bot
55

66
const listOfPromotions: BottomModalAlertItem[] = [
77
{
8-
id: 'memberRolesssssss',
8+
id: 'memberRoles',
99
src: {
1010
dark: RolesDark,
1111
light: RolesLight
1212
},
13-
title: 'Member roles now on Pro plans',
13+
title: 'Roles are available now',
1414
message:
15-
'Enhance your workflow and security by assigning roles to members. <br/><b>Try it now for free until Dec 2024.</b>',
15+
'Enhance your workflow and security by assigning roles to members. <br/><b>Try for free until Jan 1st 2025 on paid plans.</b>',
1616

1717
isHtml: true,
1818
plan: 'pro',
1919
cta: {
20-
text: 'Try Now',
20+
text: 'Try now',
2121
link: ({ organization }) => `${base}/organization-${organization.$id}/members`
2222
},
2323
learnMore: {
24-
text: 'Learn More',
24+
text: 'Learn more',
2525
link: () => 'https://appwrite.io/docs/advanced/platform/roles'
2626
}
2727
}

src/routes/(console)/organization-[organization]/createMember.svelte

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
<b>{formatCurrency(plan.addons.member.price)} each per billing period</b>.
7070
</Alert> -->
7171
<Alert type="info">
72-
New roles are free until 01 December 2024. <a
72+
New roles are free until 1st January 2025. <a
7373
class="link"
7474
href="https://appwrite.io/docs/advanced/platform/roles"
7575
target="_blank"

src/routes/(console)/project-[project]/+layout.svelte

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts">
2-
import { BottomModalAlert, MigrationBox, UploadBox } from '$lib/components';
2+
import { MigrationBox, UploadBox } from '$lib/components';
33
import { sdk } from '$lib/stores/sdk';
44
import { onMount } from 'svelte';
55
import { project, stats } from './store';
@@ -105,5 +105,3 @@
105105

106106
<UploadBox />
107107
<MigrationBox />
108-
109-
<BottomModalAlert />

0 commit comments

Comments
 (0)