Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(settings): add Notifications preferences page (#5901)
teo632f8a332c94
diff --git a/apps/web/src/features/notifications/apply-preference-toggle.ts b/apps/web/src/features/notifications/apply-preference-toggle.tsnew file mode 100644index 0000000000..2dbfc7bb8a--- /dev/null+++ b/apps/web/src/features/notifications/apply-preference-toggle.ts@@ -0,0 +1,15 @@+import type { GetNotificationTypePreferencesResponse } from '@service-notification/generated/schemas/getNotificationTypePreferencesResponse';++export function applyPreferenceToggle(+ current: GetNotificationTypePreferencesResponse | undefined,+ type: string,+ enabled: boolean+): GetNotificationTypePreferencesResponse {+ const disabled = new Set(current?.disabled_types ?? []);+ if (enabled) {+ disabled.delete(type);+ } else {+ disabled.add(type);+ }+ return { disabled_types: [...disabled] };+}diff --git a/apps/web/src/features/notifications/notification-event-catalog.ts b/apps/web/src/features/notifications/notification-event-catalog.tsnew file mode 100644index 0000000000..423cbcb02c--- /dev/null+++ b/apps/web/src/features/notifications/notification-event-catalog.ts@@ -0,0 +1,178 @@+/**+ * Event types the notification service lets a user disable.+ * Keep this list aligned with `BLOCKABLE_NOTIFICATIONS` in+ * `services/notification_service/src/api/user_notification.rs`.+ * `email-digest-notification` is a delivery control, not an inbox event.+ */++export const EMAIL_DIGEST_NOTIFICATION_TYPE =+ 'email-digest-notification' as const;++export type NotificationEventGroupId =+ | 'channels'+ | 'documents'+ | 'tasks'+ | 'calendar'+ | 'email'+ | 'ai'+ | 'github';++export type NotificationEventDefinition = {+ type: string;+ label: string;+ description: string;+};++export type NotificationEventGroup = {+ id: NotificationEventGroupId;+ label: string;+ events: readonly NotificationEventDefinition[];+};++export const NOTIFICATION_EVENT_GROUPS: readonly NotificationEventGroup[] = [+ {+ id: 'channels',+ label: 'Channels',+ events: [+ {+ type: 'channel_message_send',+ label: 'New messages',+ description: 'Messages in channels you belong to',+ },+ {+ type: 'channel_mention',+ label: 'Mentions',+ description: 'When someone mentions you in a channel',+ },+ {+ type: 'channel_message_reply',+ label: 'Thread replies',+ description: 'Replies in threads you are part of',+ },+ ],+ },+ {+ id: 'documents',+ label: 'Documents',+ events: [+ {+ type: 'document_mention',+ label: 'Document mentions',+ description: 'When a document is mentioned in a channel',+ },+ {+ type: 'mentioned_in_document_comment',+ label: 'Comment mentions',+ description: 'When you are mentioned in a document comment',+ },+ {+ type: 'replied_to_document_comment_thread',+ label: 'Comment replies',+ description: 'Replies on comment threads you are part of',+ },+ {+ type: 'commented_on_document',+ label: 'New comments',+ description: 'Comments on documents you own',+ },+ ],+ },+ {+ id: 'tasks',+ label: 'Tasks',+ events: [+ {+ type: 'task_assigned',+ label: 'Assignments',+ description: 'When a task is assigned to you',+ },+ ],+ },+ {+ id: 'calendar',+ label: 'Calendar',+ events: [+ {+ type: 'calendar_event_reminder',+ label: 'Event reminders',+ description: 'When a calendar event is about to start',+ },+ ],+ },+ {+ id: 'email',+ label: 'Email',+ events: [+ {+ type: 'new_email',+ label: 'New email',+ description: 'When a new email arrives',+ },+ ],+ },+ {+ id: 'ai',+ label: 'AI',+ events: [+ {+ type: 'ai_response',+ label: 'AI replies',+ description: 'When an AI chat responds',+ },+ ],+ },+ {+ id: 'github',+ label: 'GitHub',+ events: [+ {+ type: 'github_pr_status_changed',+ label: 'PR status',+ description: 'When a pull request changes lifecycle state',+ },+ {+ type: 'github_review_requested',+ label: 'Review requested',+ description: 'When your review is requested',+ },+ {+ type: 'github_pr_comment',+ label: 'PR comments',+ description: 'When someone comments on a pull request',+ },+ {+ type: 'github_pr_mention',+ label: 'PR mentions',+ description: 'When you are mentioned on a pull request',+ },+ {+ type: 'github_pr_review',+ label: 'PR reviews',+ description: 'When a review is submitted on your pull request',+ },+ ],+ },+];++export const BLOCKABLE_NOTIFICATION_EVENT_TYPES: readonly string[] =+ NOTIFICATION_EVENT_GROUPS.flatMap((group) =>+ group.events.map((event) => event.type)+ );++export const MUTED_ENTITY_TYPE_LABELS: Record<string, string> = {+ calendar_event: 'Calendar event',+ channel: 'Channel',+ channel_message: 'Thread',+ chat: 'Chat',+ document: 'Document',+ email: 'Email',+ email_thread: 'Email',+ foreign: 'GitHub',+ foreign_entity: 'GitHub',+ reminder: 'Reminder',+ team: 'Team',+};++export function mutedEntityTypeLabel(itemType: string): string {+ return MUTED_ENTITY_TYPE_LABELS[itemType] ?? itemType.replace(/_/g, ' ');+}diff --git a/apps/web/src/features/notifications/notification-source.ts b/apps/web/src/features/notifications/notification-source.tsindex d95e9d1e8b..6933cd5b2b 100644--- a/apps/web/src/features/notifications/notification-source.ts+++ b/apps/web/src/features/notifications/notification-source.ts@@ -4,6 +4,10 @@ import {} from '@core/constant/featureFlags';import type { Entity } from '@core/types';import { createSocketEffect } from '@macro-inc/collaboration/websocket';+import {+ useMuteItemMutation,+ useUnmuteItemMutation,+} from '@queries/notification/unsubscribes';import {optimisticInsertNotification,type UserNotificationsQuery,@@ -12,7 +16,6 @@ import {useUserNotificationsQuery,} from '@queries/notification/user-notifications';import type { ConnectionGatewayWebsocket } from '@service-connection/websocket';-import { notificationServiceClient } from '@service-notification/client';import type {ConnGatewayNotificationPayload,NotifEvent,@@ -148,6 +151,8 @@ export function createNotificationSource(limit: QUERY_LIMIT,}));const mutedEntitiesQuery = createMutedEntitiesQuery({ limit: QUERY_LIMIT });+ const muteItem = useMuteItemMutation();+ const unmuteItem = useUnmuteItemMutation();const markNotificationsAsSeenMutation = useMarkNotificationsAsSeenMutation();const markNotificationsAsDoneMutation = useMarkNotificationsAsDoneMutation();@@ -405,21 +410,17 @@ export function createNotificationSource(};const muteEntity = async (entity: Entity) => {- await notificationServiceClient.unsubscribeItem({+ await muteItem.mutateAsync({item_id: entity.id,item_type: entity.type,});-- await mutedEntitiesQuery.refetch();};const unmuteEntity = async (entity: Entity) => {- await notificationServiceClient.removeUnsubscribeItem({+ await unmuteItem.mutateAsync({item_id: entity.id,item_type: entity.type,});-- await mutedEntitiesQuery.refetch();};const subscribe = (subscribeFn: SubscribeFn) => {diff --git a/apps/web/src/features/notifications/queries/muted-entities-query.ts b/apps/web/src/features/notifications/queries/muted-entities-query.tsindex 4f8c740b03..9f58aa52c3 100644--- a/apps/web/src/features/notifications/queries/muted-entities-query.ts+++ b/apps/web/src/features/notifications/queries/muted-entities-query.ts@@ -1,25 +1,4 @@-import { notificationServiceClient } from '@service-notification/client';-import { useQuery } from '@tanstack/solid-query';--const fetchUnsubscriptions = async () => {- const response = await notificationServiceClient.getUnsubscribes();-- if (response.isErr())- throw new Error('Failed to fetch unsubscribers', { cause: response });-- const result = response.value.data;- return result;-};--export function createMutedEntitiesQuery(args?: { limit?: number }) {- const limit =- args?.limit && args.limit > 0 && args.limit <= 500 ? args.limit : 20;-- return useQuery(() => ({- queryKey: ['unsubscribers', { infinite: true }],- queryFn: () => fetchUnsubscriptions(),- initialPageParam: { limit },- staleTime: 1000 * 60 * 5, // 5 minutes- gcTime: 1000 * 60 * 10, // 10 minutes- }));-}+export {+ createMutedEntitiesQuery,+ useMutedEntitiesQuery,+} from '@queries/notification/unsubscribes';diff --git a/apps/web/src/features/notifications/tests/apply-preference-toggle.test.ts b/apps/web/src/features/notifications/tests/apply-preference-toggle.test.tsnew file mode 100644index 0000000000..2297e1b21a--- /dev/null+++ b/apps/web/src/features/notifications/tests/apply-preference-toggle.test.ts@@ -0,0 +1,26 @@+import { describe, expect, it } from 'vitest';+import { applyPreferenceToggle } from '../apply-preference-toggle';++describe('applyPreferenceToggle', () => {+ it('disables a type that was on', () => {+ expect(+ applyPreferenceToggle({ disabled_types: [] }, 'channel_mention', false)+ ).toEqual({ disabled_types: ['channel_mention'] });+ });++ it('enables a type that was off', () => {+ expect(+ applyPreferenceToggle(+ { disabled_types: ['channel_mention', 'new_email'] },+ 'channel_mention',+ true+ )+ ).toEqual({ disabled_types: ['new_email'] });+ });++ it('treats a missing cache as every type enabled', () => {+ expect(applyPreferenceToggle(undefined, 'new_email', false)).toEqual({+ disabled_types: ['new_email'],+ });+ });+});diff --git a/apps/web/src/features/notifications/tests/notification-source.test.ts b/apps/web/src/features/notifications/tests/notification-source.test.tsindex 0d80ed0c83..b4f7995b44 100644--- a/apps/web/src/features/notifications/tests/notification-source.test.ts+++ b/apps/web/src/features/notifications/tests/notification-source.test.ts@@ -48,11 +48,9 @@ vi.mock('@queries/notification/user-notifications', () => ({useUserNotificationsQuery: () => mocks.notificationsQuery,}));-vi.mock('@service-notification/client', () => ({- notificationServiceClient: {- removeUnsubscribeItem: vi.fn(),- unsubscribeItem: vi.fn(),- },+vi.mock('@queries/notification/unsubscribes', () => ({+ useMuteItemMutation: () => ({ mutateAsync: vi.fn() }),+ useUnmuteItemMutation: () => ({ mutateAsync: vi.fn() }),}));vi.mock('@service-storage/graphql-soup', () => ({diff --git a/apps/web/src/features/settings/Account.tsx b/apps/web/src/features/settings/Account.tsxindex 6b37edfad8..81364912b6 100644--- a/apps/web/src/features/settings/Account.tsx+++ b/apps/web/src/features/settings/Account.tsx@@ -11,6 +11,8 @@ import {import {DISABLE_AUTO_UPDATE_UI_FLAG,ENABLE_AUTO_UPDATE_UI_OVERRIDE,+ ENABLE_NOTIFICATION_SETTINGS_FLAG,+ ENABLE_NOTIFICATION_SETTINGS_OVERRIDE,ENABLE_PROFILE_PICTURES,} from '@core/constant/featureFlags';import { staticFileIdEndpoint } from '@core/constant/servers';@@ -318,6 +320,12 @@ export function Account() {const autoUpdateUIEnabled = createMemo(() => ENABLE_AUTO_UPDATE_UI_OVERRIDE ?? !disableAutoUpdateUIFlag().enabled);+ const notificationSettingsFlag = useFeatureFlag(+ ENABLE_NOTIFICATION_SETTINGS_FLAG,+ {+ enabledOverride: ENABLE_NOTIFICATION_SETTINGS_OVERRIDE,+ }+ );const [showDeleteModal, setShowDeleteModal] = createSignal<boolean>(false);const [showDeleteConfirmModal, setShowDeleteConfirmModal] =createSignal<boolean>(false);@@ -454,7 +462,9 @@ export function Account() {<BundleUpdateRow /></Show>- <NotificationToggle />+ <Show when={!notificationSettingsFlag().enabled}>+ <NotificationToggle />+ </Show></SettingsCard></SettingsSection>@@ -650,6 +660,48 @@ function Row(props: { label: string; children?: any }) {);}+function NotificationToggle() {+ const settings = useNotificationSettings();++ return (+ <Show+ when={settings.isSupported && settings}+ fallback={<NotificationNotSupported />}+ >+ {(s) => <NotificationSettings settings={s()} />}+ </Show>+ );+}++function NotificationSettings(props: {+ settings: SupportedNotificationSettings;+}) {+ const analytics = useAnalytics();++ const handleToggle = (checked: boolean) => {+ analytics.track('notifications_toggled');+ props.settings.toggle(checked);+ };++ return (+ <Row label="Notifications">+ <ToggleSwitch+ size="md"+ checked={props.settings.isEnabled()}+ onChange={handleToggle}+ />+ </Row>+ );+}++function NotificationNotSupported() {+ return (+ <Row label="Notifications">+ <span class="text-sm text-ink-muted">Not supported on this device</span>+ </Row>+ );+}+type SaveStatus = 'idle' | 'saving' | 'saved' | 'error';function NameInput(props: {@@ -750,48 +802,6 @@ function NameInput(props: {);}-function NotificationToggle() {- const settings = useNotificationSettings();-- return (- <Show- when={settings.isSupported && settings}- fallback={<NotificationNotSupported />}- >- {(s) => <NotificationSettings settings={s()} />}- </Show>- );-}--function NotificationSettings(props: {- settings: SupportedNotificationSettings;-}) {- const analytics = useAnalytics();-- const handleToggle = (checked: boolean) => {- analytics.track('notifications_toggled');- props.settings.toggle(checked);- };-- return (- <Row label="Notifications">- <ToggleSwitch- size="md"- checked={props.settings.isEnabled()}- onChange={handleToggle}- />- </Row>- );-}--function NotificationNotSupported() {- return (- <Row label="Notifications">- <span class="text-sm text-ink-muted">Not supported on this device</span>- </Row>- );-}-function bundleUpdateAction(status: BundleUpdateStatus): { label: string; action: () => void } | null {diff --git a/apps/web/src/features/settings/Notifications.tsx b/apps/web/src/features/settings/Notifications.tsxnew file mode 100644index 0000000000..7759285206--- /dev/null+++ b/apps/web/src/features/settings/Notifications.tsx@@ -0,0 +1,185 @@+import { useAnalytics } from '@app/lib/analytics/analytics-context';+import { toast } from '@core/component/Toast/Toast';+import { isNativeMobilePlatform } from '@core/mobile/isNativeMobilePlatform';+import {+ EMAIL_DIGEST_NOTIFICATION_TYPE,+ mutedEntityTypeLabel,+ NOTIFICATION_EVENT_GROUPS,+} from '@notifications/notification-event-catalog';+import { useNotificationSettings } from '@notifications/notification-settings';+import { queryReadyGate } from '@queries/gate';+import {+ useNotificationTypePreferencesQuery,+ useSetNotificationTypeEnabledMutation,+} from '@queries/notification/type-preferences';+import {+ useMutedEntitiesQuery,+ useUnmuteItemMutation,+} from '@queries/notification/unsubscribes';+import { ToggleSwitch } from '@ui';+import { For, Show } from 'solid-js';+import {+ SettingsCard,+ SettingsPage,+ SettingsRow,+ SettingsSection,+} from './primitives';++export function Notifications() {+ const analytics = useAnalytics();+ const platformSettings = useNotificationSettings();+ const preferencesQuery = useNotificationTypePreferencesQuery();+ const setTypeEnabled = useSetNotificationTypeEnabledMutation();+ const mutedEntitiesQuery = useMutedEntitiesQuery({ limit: 100 });+ const unmuteItem = useUnmuteItemMutation();+ const prefsReady = () =>+ !preferencesQuery.isError && queryReadyGate(preferencesQuery);+ const mutedEntities = () =>+ !mutedEntitiesQuery.isError && queryReadyGate(mutedEntitiesQuery)+ ? mutedEntitiesQuery.data+ : [];++ const disabledTypes = () =>+ new Set(+ !preferencesQuery.isError && queryReadyGate(preferencesQuery)+ ? preferencesQuery.data.disabled_types+ : []+ );++ const isTypeEnabled = (type: string) => !disabledTypes().has(type);++ const toggleType = async (type: string, enabled: boolean) => {+ try {+ await setTypeEnabled.mutateAsync({ type, enabled });+ } catch {+ toast.failure('Could not update notification preference');+ }+ };++ const unmuteEntity = async (item: { item_id: string; item_type: string }) => {+ try {+ await unmuteItem.mutateAsync(item);+ } catch {+ toast.failure('Could not unmute item');+ }+ };++ const pushLabel = isNativeMobilePlatform()+ ? 'Mobile notifications'+ : 'Desktop notifications';+ const pushDescription = isNativeMobilePlatform()+ ? 'Receive push notifications on this device'+ : 'Receive notifications on this browser or desktop app';++ return (+ <SettingsPage+ title="Notifications"+ description="Choose when you'll be notified. Inbox items always arrive unless you mute a type or an item."+ >+ <SettingsSection title="Delivery">+ <SettingsCard>+ <SettingsRow+ label="Inbox"+ description="Always on for types you have not muted"+ >+ <span class="text-sm text-ink-muted">Always on</span>+ </SettingsRow>+ <Show+ when={platformSettings.isSupported && platformSettings}+ fallback={+ <SettingsRow label={pushLabel} description={pushDescription}>+ <span class="text-sm text-ink-muted">+ Not supported on this device+ </span>+ </SettingsRow>+ }+ >+ {(settings) => (+ <SettingsRow label={pushLabel} description={pushDescription}>+ <ToggleSwitch+ size="md"+ checked={settings().isEnabled()}+ onChange={(enabled) => {+ analytics.track('notifications_toggled');+ void settings().toggle(enabled);+ }}+ />+ </SettingsRow>+ )}+ </Show>+ <SettingsRow+ label="Email digest"+ description="A periodic email of unread notifications. Inbox items are unchanged."+ >+ <ToggleSwitch+ size="md"+ checked={isTypeEnabled(EMAIL_DIGEST_NOTIFICATION_TYPE)}+ disabled={!prefsReady()}+ onChange={(enabled) =>+ toggleType(EMAIL_DIGEST_NOTIFICATION_TYPE, enabled)+ }+ />+ </SettingsRow>+ </SettingsCard>+ </SettingsSection>++ <For each={NOTIFICATION_EVENT_GROUPS}>+ {(group) => (+ <SettingsSection title={group.label}>+ <SettingsCard>+ <For each={group.events}>+ {(event) => (+ <SettingsRow+ label={event.label}+ description={event.description}+ >+ <ToggleSwitch+ size="md"+ checked={isTypeEnabled(event.type)}+ disabled={!prefsReady()}+ onChange={(enabled) => toggleType(event.type, enabled)}+ />+ </SettingsRow>+ )}+ </For>+ </SettingsCard>+ </SettingsSection>+ )}+ </For>++ <SettingsSection+ title="Muted items"+ description="These items will not send you notifications."+ >+ <SettingsCard>+ <Show+ when={mutedEntities().length > 0}+ fallback={+ <SettingsRow+ label="Nothing muted"+ description="Items you mute stop sending notifications."+ />+ }+ >+ <For each={mutedEntities()}>+ {(item) => (+ <SettingsRow+ label={mutedEntityTypeLabel(item.item_type)}+ description={item.item_id}+ >+ <button+ type="button"+ class="text-sm text-ink-muted hover:text-ink"+ onClick={() => unmuteEntity(item)}+ >+ Unmute+ </button>+ </SettingsRow>+ )}+ </For>+ </Show>+ </SettingsCard>+ </SettingsSection>+ </SettingsPage>+ );+}diff --git a/apps/web/src/features/settings/Settings.tsx b/apps/web/src/features/settings/Settings.tsxindex 333375ceef..2b205a7d02 100644--- a/apps/web/src/features/settings/Settings.tsx+++ b/apps/web/src/features/settings/Settings.tsx@@ -43,6 +43,7 @@ import { Appearance } from './Appearance';import { ConnectedAccounts } from './ConnectedAccounts';import { Crm } from './Crm';import { MobileApp } from './MobileApp';+import { Notifications } from './Notifications';import { Shortcuts } from './Shortcuts';import { Tags } from './Tags';import { Team } from './Team';@@ -389,6 +390,9 @@ export function SettingsPanel(props: SettingsPanelProps) {<Account /></Suspense></Show>+ <Show when={isCurrentTab('Notifications')}>+ <Notifications />+ </Show><Show when={isCurrentTab('Billing')}><Suspense><Billing />diff --git a/apps/web/src/features/settings/primitives.tsx b/apps/web/src/features/settings/primitives.tsxindex 99f3863318..78b1c88305 100644--- a/apps/web/src/features/settings/primitives.tsx+++ b/apps/web/src/features/settings/primitives.tsx@@ -30,7 +30,7 @@ export function SettingsPage(props: {children: JSX.Element;}) {return (- <div class="h-full overflow-y-auto">+ <div class="h-full min-h-0 overflow-y-auto [overflow-anchor:none]">{/* On mobile/tablet the page is full-frame: the chrome insets live inside thescroll content (plus the usual breathing room) so pages scroll underthe floating header and bottom rows like every other block. */}diff --git a/apps/web/src/lib/core/constant/SettingsState.tsx b/apps/web/src/lib/core/constant/SettingsState.tsxindex 2c8a6b2043..7f5c299015 100644--- a/apps/web/src/lib/core/constant/SettingsState.tsx+++ b/apps/web/src/lib/core/constant/SettingsState.tsx@@ -15,6 +15,7 @@ import { settingsSlugToTab, settingsTabToSlug } from './settingsTabsConfig';export type SettingsTab =| 'Account'+ | 'Notifications'| 'Billing'| 'Subscription'| 'Organization'diff --git a/apps/web/src/lib/core/constant/featureFlags.ts b/apps/web/src/lib/core/constant/featureFlags.tsindex aedcfeb674..d0bbde1a7d 100644--- a/apps/web/src/lib/core/constant/featureFlags.ts+++ b/apps/web/src/lib/core/constant/featureFlags.ts@@ -706,3 +706,12 @@ export const ENABLE_RECENT_VIEW_FLAG = 'enable-recent-view';export const ENABLE_RECENT_VIEW_OVERRIDE =getFeatureFlagOverride('ENABLE_RECENT_VIEW') ??(DEV_MODE_ENV ? true : undefined);++// Settings › Notifications: the dedicated preferences tab (delivery, per-type+// opt-outs, muted items). When off, the tab is hidden and Account keeps the+// existing desktop/mobile toggle. PostHog-gated with a dev-mode default;+// override with VITE_ENABLE_NOTIFICATION_SETTINGS.+export const ENABLE_NOTIFICATION_SETTINGS_FLAG = 'enable-notification-settings';+export const ENABLE_NOTIFICATION_SETTINGS_OVERRIDE =+ getFeatureFlagOverride('ENABLE_NOTIFICATION_SETTINGS') ??+ (DEV_MODE_ENV ? true : undefined);diff --git a/apps/web/src/lib/core/constant/settingsTabsConfig.tsx b/apps/web/src/lib/core/constant/settingsTabsConfig.tsxindex 34d609403b..e8e096307b 100644--- a/apps/web/src/lib/core/constant/settingsTabsConfig.tsx+++ b/apps/web/src/lib/core/constant/settingsTabsConfig.tsx@@ -1,5 +1,6 @@import { useFeatureFlag } from '@app/lib/analytics/posthog';import BotIcon from '@icon/wide-bot.svg';+import BellIcon from '@phosphor/bell-simple.svg';import BugIcon from '@phosphor/bug.svg';import BuildingsIcon from '@phosphor/buildings.svg';import CpuIcon from '@phosphor/cpu.svg';@@ -22,6 +23,8 @@ import {ENABLE_APP_STORE_QR_CODE,ENABLE_CRM_FLAG,ENABLE_CRM_OVERRIDE,+ ENABLE_NOTIFICATION_SETTINGS_FLAG,+ ENABLE_NOTIFICATION_SETTINGS_OVERRIDE,} from './featureFlags';import { PERMISSION_IDS } from './permissions';import type { SettingsTab } from './SettingsState';@@ -50,6 +53,7 @@ export const SETTINGS_TAB_GROUPS: SettingsTabGroup[] = [label: 'General',items: [{ tab: 'Account', label: 'Account', icon: UserIconPhosphor },+ { tab: 'Notifications', label: 'Notifications', icon: BellIcon },{ tab: 'Billing', label: 'Billing', icon: CreditCardIcon },{ tab: 'Appearance', label: 'Appearance', icon: SwatchesIcon },{ tab: 'Mobile App', label: 'Mobile App', icon: DeviceMobileIcon },@@ -88,6 +92,7 @@ const SETTINGS_TAB_ITEMS = SETTINGS_TAB_GROUPS.flatMap((group) => group.items);*/const SETTINGS_TAB_SLUGS: Record<SettingsTab, string> = {Account: 'account',+ Notifications: 'notifications',Billing: 'billing',Subscription: 'subscription',Organization: 'organization',@@ -147,6 +152,12 @@ export const useSettingsTabAvailable = () => {const crmFlag = useFeatureFlag(ENABLE_CRM_FLAG, {enabledOverride: ENABLE_CRM_OVERRIDE,});+ const notificationSettingsFlag = useFeatureFlag(+ ENABLE_NOTIFICATION_SETTINGS_FLAG,+ {+ enabledOverride: ENABLE_NOTIFICATION_SETTINGS_OVERRIDE,+ }+ );const hasAdminPanel = useHasPermission(PERMISSION_IDS.WRITE_ADMIN_PANEL);return (tab: SettingsTab): boolean => {@@ -155,6 +166,8 @@ export const useSettingsTabAvailable = () => {case 'Account':case 'Billing':return true;+ case 'Notifications':+ return notificationSettingsFlag().enabled;case 'Team':case 'Tags':return true;diff --git a/apps/web/src/lib/queries/notification/keys.ts b/apps/web/src/lib/queries/notification/keys.tsindex 4dc2fb73ce..3caed2c960 100644--- a/apps/web/src/lib/queries/notification/keys.ts+++ b/apps/web/src/lib/queries/notification/keys.ts@@ -16,4 +16,5 @@ export const notificationKeys = createQueryKeys('notification', {queryKey: ['entities', { infinite: true, ...params }],}),unsubscribes: null,+ preferences: null,});diff --git a/apps/web/src/lib/queries/notification/type-preferences.ts b/apps/web/src/lib/queries/notification/type-preferences.tsnew file mode 100644index 0000000000..a04b05581c--- /dev/null+++ b/apps/web/src/lib/queries/notification/type-preferences.ts@@ -0,0 +1,67 @@+import { throwOnErr } from '@core/util/result';+import { applyPreferenceToggle } from '@notifications/apply-preference-toggle';+import { notificationServiceClient } from '@service-notification/client';+import type { GetNotificationTypePreferencesResponse } from '@service-notification/generated/schemas/getNotificationTypePreferencesResponse';+import { useMutation, useQuery } from '@tanstack/solid-query';+import { queryClient } from '../client';+import { notificationKeys } from './keys';++const PREFERENCES_STALE_TIME = 5 * 60 * 1000;+const PREFERENCES_GC_TIME = 10 * 60 * 1000;++async function fetchNotificationTypePreferences() {+ return throwOnErr(() =>+ notificationServiceClient.getNotificationTypePreferences()+ );+}++export function useNotificationTypePreferencesQuery() {+ return useQuery(() => ({+ queryKey: notificationKeys.preferences.queryKey,+ queryFn: fetchNotificationTypePreferences,+ staleTime: PREFERENCES_STALE_TIME,+ gcTime: PREFERENCES_GC_TIME,+ }));+}++export function useSetNotificationTypeEnabledMutation() {+ return useMutation(() => ({+ mutationFn: async (vars: { type: string; enabled: boolean }) => {+ if (vars.enabled) {+ await throwOnErr(() =>+ notificationServiceClient.enableNotificationType(vars.type)+ );+ } else {+ await throwOnErr(() =>+ notificationServiceClient.disableNotificationType(vars.type)+ );+ }+ },+ onMutate: async (vars) => {+ await queryClient.cancelQueries({+ queryKey: notificationKeys.preferences.queryKey,+ });+ const previous =+ queryClient.getQueryData<GetNotificationTypePreferencesResponse>(+ notificationKeys.preferences.queryKey+ );+ queryClient.setQueryData<GetNotificationTypePreferencesResponse>(+ notificationKeys.preferences.queryKey,+ (current) => applyPreferenceToggle(current, vars.type, vars.enabled)+ );+ return { previous };+ },+ onError: (_error, _vars, context) => {+ if (context?.previous === undefined) return;+ queryClient.setQueryData(+ notificationKeys.preferences.queryKey,+ context.previous+ );+ },+ onSettled: () => {+ void queryClient.invalidateQueries({+ queryKey: notificationKeys.preferences.queryKey,+ });+ },+ }));+}diff --git a/apps/web/src/lib/queries/notification/unsubscribes.ts b/apps/web/src/lib/queries/notification/unsubscribes.tsnew file mode 100644index 0000000000..78f0450a23--- /dev/null+++ b/apps/web/src/lib/queries/notification/unsubscribes.ts@@ -0,0 +1,60 @@+import { throwOnErr } from '@core/util/result';+import { notificationServiceClient } from '@service-notification/client';+import type { UserUnsubscribe } from '@service-notification/generated/schemas/userUnsubscribe';+import { useMutation, useQuery } from '@tanstack/solid-query';+import { queryClient } from '../client';+import { notificationKeys } from './keys';++async function fetchUnsubscribes() {+ const response = await notificationServiceClient.getUnsubscribes();+ if (response.isErr()) {+ throw new Error('Failed to fetch unsubscribers', { cause: response });+ }+ return response.value.data;+}++export function useMutedEntitiesQuery(args?: { limit?: number }) {+ const limit =+ args?.limit && args.limit > 0 && args.limit <= 500 ? args.limit : 20;++ return useQuery(() => ({+ queryKey: notificationKeys.unsubscribes.queryKey,+ queryFn: fetchUnsubscribes,+ initialPageParam: { limit },+ staleTime: 1000 * 60 * 5,+ gcTime: 1000 * 60 * 10,+ }));+}++/** @deprecated Use `useMutedEntitiesQuery`. */+export const createMutedEntitiesQuery = useMutedEntitiesQuery;++function invalidateUnsubscribes() {+ return queryClient.invalidateQueries({+ queryKey: notificationKeys.unsubscribes.queryKey,+ });+}++export function useMuteItemMutation() {+ return useMutation(() => ({+ mutationFn: async (item: UserUnsubscribe) => {+ await throwOnErr(() => notificationServiceClient.unsubscribeItem(item));+ },+ onSettled: () => {+ void invalidateUnsubscribes();+ },+ }));+}++export function useUnmuteItemMutation() {+ return useMutation(() => ({+ mutationFn: async (item: UserUnsubscribe) => {+ await throwOnErr(() =>+ notificationServiceClient.removeUnsubscribeItem(item)+ );+ },+ onSettled: () => {+ void invalidateUnsubscribes();+ },+ }));+}diff --git a/apps/web/src/lib/service-clients/service-notification/client.ts b/apps/web/src/lib/service-clients/service-notification/client.tsindex 4b23f8e30e..09ff980c77 100644--- a/apps/web/src/lib/service-clients/service-notification/client.ts+++ b/apps/web/src/lib/service-clients/service-notification/client.ts@@ -13,6 +13,7 @@ import type {} from './generated/schemas';import type { ApiUserNotification } from './generated/schemas/apiUserNotification';import type { DeviceRequest } from './generated/schemas/deviceRequest';+import type { GetNotificationTypePreferencesResponse } from './generated/schemas/getNotificationTypePreferencesResponse';import type { NotificationBulkRequest } from './generated/schemas/notificationBulkRequest';import type { UserUnsubscribe } from './generated/schemas/userUnsubscribe';@@ -199,6 +200,24 @@ export const notificationServiceClient = {body: JSON.stringify(args),});},+ async getNotificationTypePreferences() {+ return notificationFetch<GetNotificationTypePreferencesResponse>(+ '/user_notifications/preferences',+ { method: 'GET' }+ );+ },+ async disableNotificationType(notificationEventType: string) {+ return notificationFetch<{}>(+ `/user_notifications/preferences/${encodeURIComponent(notificationEventType)}/disable`,+ { method: 'PUT' }+ );+ },+ async enableNotificationType(notificationEventType: string) {+ return notificationFetch<{}>(+ `/user_notifications/preferences/${encodeURIComponent(notificationEventType)}/enable`,+ { method: 'PUT' }+ );+ },async getUnsubscribes() {return (await notificationFetch<UserUnsubscribe[]>('/unsubscribe', {