diff --git a/src/lib/components/bottomModalAlert.svelte b/src/lib/components/bottomModalAlert.svelte index dd548d788..d6984df9d 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/stores'; import { 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,6 +72,45 @@ 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; @@ -159,8 +203,8 @@
{:else} + {@const mobileConfig = getMobileWindowConfig()} - Explore new features to enhance your projects and improve security. + {#if mobileConfig.html} + {@html mobileConfig.message} + {:else} + {mobileConfig.message} + {/if} @@ -370,6 +432,22 @@ border: hsl(var(--color-neutral-80)) solid 1px; } + :global(.main-alert-wrapper .only-primary-cta) { + width: 100%; + text-align: center; + justify-content: center; + } + + .showcase-image.u-only-light { + border-radius: 8px; + border: 0.795px solid var(--border-neutral-strong, #d8d8db); + } + + .showcase-image.u-only-dark { + border-radius: 8px; + border: 0.795px solid var(--border-neutral-strong, #414146); + } + .u-gap-10 { gap: 0.625rem; } diff --git a/src/lib/images/backups/promo/backups-dark.png b/src/lib/images/backups/promo/backups-dark.png deleted file mode 100644 index 6b31eab88..000000000 Binary files a/src/lib/images/backups/promo/backups-dark.png and /dev/null differ diff --git a/src/lib/images/backups/promo/backups-light.png b/src/lib/images/backups/promo/backups-light.png deleted file mode 100644 index aa675d86b..000000000 Binary files a/src/lib/images/backups/promo/backups-light.png and /dev/null differ diff --git a/src/lib/images/promo-init3.png b/src/lib/images/promo-init3.png new file mode 100644 index 000000000..842fa51f4 Binary files /dev/null and b/src/lib/images/promo-init3.png differ diff --git a/src/lib/stores/bottom-alerts.ts b/src/lib/stores/bottom-alerts.ts index 1b681dcc8..aca0e067b 100644 --- a/src/lib/stores/bottom-alerts.ts +++ b/src/lib/stores/bottom-alerts.ts @@ -5,10 +5,28 @@ import type { Models } from '@appwrite.io/console'; type BottomModalAlertAction = { text: string; + hideOnClick?: boolean; link: (ctx: { organization: Organization; project: Models.Project }) => string; external?: boolean; }; +/** + * Special layout settings for mobile when exactly one alert is shown. + * + * Applied only if `enabled` is `true` and the number of visible alerts is exactly 1. + * + * Useful when you want to display the alert directly in the floating window, + * without opening a separate modal. + */ +export type MobileSingleAlertLayoutConfig = { + title: string; + message: string; + enabled: boolean; + isHtml?: boolean; + // because message is the text! + cta: Omit; +}; + export type BottomModalAlertItem = { id: string; title: string; @@ -23,18 +41,36 @@ export type BottomModalAlertItem = { importance?: number; closed?: () => void; - scope?: 'organization' | 'project'; + scope: 'organization' | 'project' | 'everywhere'; notificationHideOptions?: NotificationCoolOffOptions; }; -export const bottomModalAlerts = writable([]); +type BottomModalAlertState = { + alerts: BottomModalAlertItem[]; + mobileSingleLayout?: MobileSingleAlertLayoutConfig; +}; + +export const bottomModalAlertsConfig = writable({ alerts: [] }); export const hideAllModalAlerts = () => { - bottomModalAlerts.update((all) => all.map((t) => ({ ...t, show: false }))); + bottomModalAlertsConfig.update((state) => ({ + ...state, + alerts: state.alerts.map((t) => ({ ...t, show: false })) + })); +}; + +export const setMobileSingleAlertLayout = (config: MobileSingleAlertLayoutConfig) => { + bottomModalAlertsConfig.update((state) => ({ + ...state, + mobileSingleLayout: config + })); }; export const dismissBottomModalAlert = (id: string) => { - bottomModalAlerts.update((all) => all.filter((t) => t.id !== id)); + bottomModalAlertsConfig.update((state) => ({ + ...state, + alerts: state.alerts.filter((t) => t.id !== id) + })); }; export const showBottomModalAlert = (notification: BottomModalAlertItem) => { @@ -45,8 +81,11 @@ export const showBottomModalAlert = (notification: BottomModalAlertItem) => { ...notification }; - bottomModalAlerts.update((all) => { - if (all.some((t) => t.id === notification.id)) return all; - return [...all, defaults as BottomModalAlertItem]; + bottomModalAlertsConfig.update((state) => { + if (state.alerts.some((t) => t.id === notification.id)) return state; + return { + ...state, + alerts: [...state.alerts, defaults as BottomModalAlertItem] + }; }); }; diff --git a/src/routes/(console)/bottomAlerts.ts b/src/routes/(console)/bottomAlerts.ts index f02ed2f29..9397567fb 100644 --- a/src/routes/(console)/bottomAlerts.ts +++ b/src/routes/(console)/bottomAlerts.ts @@ -1,32 +1,46 @@ -import { base } from '$app/paths'; -import BackupsDark from '$lib/images/backups/promo/backups-dark.png'; -import BackupsLight from '$lib/images/backups/promo/backups-light.png'; +import Init3Promo from '$lib/images/promo-init3.png'; -import { type BottomModalAlertItem, showBottomModalAlert } from '$lib/stores/bottom-alerts'; +import { + type BottomModalAlertItem, + setMobileSingleAlertLayout, + showBottomModalAlert +} from '$lib/stores/bottom-alerts'; import { isCloud } from '$lib/system'; const listOfPromotions: BottomModalAlertItem[] = []; if (isCloud) { + const title = 'Join Init 19-23 May'; + const message = + 'Change the way you build with Appwrite forever. Claim your ticket and register for the event.'; + + const callToAction = { + external: true, + hideOnClick: true, + text: 'Register and join the give away', + link: () => 'https://apwr.dev/clcon' + }; + listOfPromotions.push({ - id: 'modal:databaseBackups', + id: 'modal:init3', src: { - dark: BackupsDark, - light: BackupsLight + dark: Init3Promo, + light: Init3Promo }, - title: 'Database Backups are available now', - message: 'Protect your data and ensure quick recovery with our new backups', - plan: 'pro', - scope: 'project', + title, + message, + plan: 'free', importance: 8, - cta: { - text: 'Try now', - link: ({ project }) => `${base}/project-${project.region}-${project.$id}/databases` - }, - learnMore: { - text: 'Learn more', - link: () => 'http://appwrite.io/docs/products/databases/backups' - } + scope: 'everywhere', + cta: callToAction + }); + + // there's only one item. + setMobileSingleAlertLayout({ + title, + message, + enabled: true, + cta: callToAction }); }