mirror of
https://github.com/koala73/worldmonitor.git
synced 2026-04-25 17:14:57 +02:00
fix(settings): show locked Notifications [PRO] section for all non-PRO users (#2915)
* fix(settings): show locked Notifications [PRO] section for non-PRO and anonymous users Previously, anonymous users saw plain text 'Sign in to link notification channels' and free users with unloaded entitlements fell into the PRO branch. Now both see the same locked [PRO] details group with upgrade CTA. * fix: simplify notification gate to hasTier(1) only hasTier(1) returns false when entitlements are null (not loaded yet), so free users never see the full notification UI during the loading race. Removes getEntitlementState() guard entirely.
This commit is contained in:
@@ -27,7 +27,7 @@ import {
|
||||
type DigestMode,
|
||||
} from '@/services/notification-channels';
|
||||
import { getCurrentClerkUser } from '@/services/clerk';
|
||||
import { hasTier, getEntitlementState } from '@/services/entitlements';
|
||||
import { hasTier } from '@/services/entitlements';
|
||||
import { SITE_VARIANT } from '@/config/variant';
|
||||
// When VITE_QUIET_HOURS_BATCH_ENABLED=0 the relay does not honour batch_on_wake.
|
||||
// Hide that option so users cannot select a mode that silently behaves as critical_only.
|
||||
@@ -358,24 +358,24 @@ export function renderPreferences(host: PreferencesHost): PreferencesResult {
|
||||
</a>`;
|
||||
html += `</div></details>`;
|
||||
|
||||
// ── Notifications group (web-only, signed-in, PRO only) ──
|
||||
// ── Notifications group (web-only) ──
|
||||
// Three states: (a) confirmed PRO → full UI, (b) everything else → locked [PRO] section.
|
||||
// When entitlements haven't loaded yet (null), show locked to avoid flashing full UI to free users.
|
||||
if (!host.isDesktopApp) {
|
||||
if (!host.isSignedIn) {
|
||||
html += `<div class="ai-flow-toggle-desc us-notif-signin">Sign in to link notification channels.</div>`;
|
||||
} else if (getEntitlementState() !== null && !hasTier(1)) {
|
||||
html += `<details class="wm-pref-group">`;
|
||||
html += `<summary>Notifications <span class="panel-toggle-pro-badge">PRO</span></summary>`;
|
||||
html += `<div class="wm-pref-group-content">`;
|
||||
html += `<div class="ai-flow-toggle-desc">Get real-time intelligence alerts delivered to Telegram, Slack, Discord, and Email with configurable sensitivity, quiet hours, and digest scheduling.</div>`;
|
||||
html += `<button type="button" class="panel-locked-cta" id="usNotifUpgradeBtn">Upgrade to Pro</button>`;
|
||||
html += `</div></details>`;
|
||||
} else {
|
||||
if (host.isSignedIn && hasTier(1)) {
|
||||
html += `<details class="wm-pref-group" id="usNotifGroup">`;
|
||||
html += `<summary>Notifications</summary>`;
|
||||
html += `<div class="wm-pref-group-content">`;
|
||||
html += `<div class="us-notif-loading" id="usNotifLoading">Loading...</div>`;
|
||||
html += `<div class="us-notif-content" id="usNotifContent" style="display:none"></div>`;
|
||||
html += `</div></details>`;
|
||||
} else {
|
||||
html += `<details class="wm-pref-group">`;
|
||||
html += `<summary>Notifications <span class="panel-toggle-pro-badge">PRO</span></summary>`;
|
||||
html += `<div class="wm-pref-group-content">`;
|
||||
html += `<div class="ai-flow-toggle-desc">Get real-time intelligence alerts delivered to Telegram, Slack, Discord, and Email with configurable sensitivity, quiet hours, and digest scheduling.</div>`;
|
||||
html += `<button type="button" class="panel-locked-cta" id="usNotifUpgradeBtn">Upgrade to Pro</button>`;
|
||||
html += `</div></details>`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -627,18 +627,25 @@ export function renderPreferences(host: PreferencesHost): PreferencesResult {
|
||||
|
||||
if (!host.isDesktopApp) updateAiStatus(container);
|
||||
|
||||
// ── Notifications section ──
|
||||
if (!host.isDesktopApp && host.isSignedIn && getEntitlementState() !== null && !hasTier(1)) {
|
||||
// ── Notifications section: locked [PRO] upgrade button ──
|
||||
if (!host.isDesktopApp && !(host.isSignedIn && hasTier(1))) {
|
||||
const upgradeBtn = container.querySelector<HTMLButtonElement>('#usNotifUpgradeBtn');
|
||||
if (upgradeBtn) {
|
||||
upgradeBtn.addEventListener('click', () => {
|
||||
if (!host.isSignedIn) {
|
||||
import('@/services/clerk').then(m => m.openSignIn()).catch(() => {
|
||||
window.open('https://worldmonitor.app/pro', '_blank');
|
||||
});
|
||||
return;
|
||||
}
|
||||
import('@/services/checkout').then(m => import('@/config/products').then(p => m.startCheckout(p.DEFAULT_UPGRADE_PRODUCT))).catch(() => {
|
||||
window.open('https://worldmonitor.app/pro', '_blank');
|
||||
});
|
||||
}, { signal });
|
||||
}
|
||||
}
|
||||
if (!host.isDesktopApp && host.isSignedIn && (getEntitlementState() === null || hasTier(1))) {
|
||||
// ── Notifications section: full PRO UI ──
|
||||
if (!host.isDesktopApp && host.isSignedIn && hasTier(1)) {
|
||||
let notifPollInterval: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
function clearNotifPoll(): void {
|
||||
|
||||
Reference in New Issue
Block a user