From 5ef6eafc633ee43dbae302e0119c252625f2c462 Mon Sep 17 00:00:00 2001 From: Usman Baig Date: Sat, 28 Feb 2026 21:18:57 +0100 Subject: [PATCH] feat: update notification preferences to include granular security alerts --- app/settings/SettingsPageClient.tsx | 32 +++++++++++++++-------------- lib/api/user.ts | 4 +++- lib/auth/context.tsx | 4 +++- package-lock.json | 8 ++++---- package.json | 2 +- 5 files changed, 28 insertions(+), 22 deletions(-) diff --git a/app/settings/SettingsPageClient.tsx b/app/settings/SettingsPageClient.tsx index 2269181..a98fa56 100644 --- a/app/settings/SettingsPageClient.tsx +++ b/app/settings/SettingsPageClient.tsx @@ -30,7 +30,7 @@ function BellIcon({ className }: { className?: string }) { // --- Types --- type ProfileSubTab = 'profile' | 'security' | 'preferences' -type NotificationSubTab = 'email' | 'center' +type NotificationSubTab = 'security' | 'center' type ActiveSelection = | { section: 'profile'; subTab: ProfileSubTab } @@ -139,12 +139,14 @@ function ExpandableSubItems({ expanded, children }: { expanded: boolean; childre // --- Content Components --- -// Email Notification Preferences Card -const PULSE_NOTIFICATION_OPTIONS = [ - { key: 'security_alerts', label: 'Security Alerts', description: 'Important security events like new logins, password changes, and 2FA updates.' }, +// Security Alerts Card (granular security toggles) +const SECURITY_ALERT_OPTIONS = [ + { key: 'login_alerts', label: 'Login Activity', description: 'New device sign-ins and suspicious login attempts.' }, + { key: 'password_alerts', label: 'Password Changes', description: 'Password changes and session revocations.' }, + { key: 'two_factor_alerts', label: 'Two-Factor Authentication', description: '2FA enabled/disabled and recovery code changes.' }, ] -function EmailNotificationPreferencesCard() { +function SecurityAlertsCard() { const { user } = useAuth() const [emailNotifications, setEmailNotifications] = useState>({}) @@ -152,7 +154,7 @@ function EmailNotificationPreferencesCard() { if (user?.preferences?.email_notifications) { setEmailNotifications(user.preferences.email_notifications) } else { - const defaults = PULSE_NOTIFICATION_OPTIONS.reduce((acc, option) => ({ + const defaults = SECURITY_ALERT_OPTIONS.reduce((acc, option) => ({ ...acc, [option.key]: true }), {} as Record) @@ -168,7 +170,7 @@ function EmailNotificationPreferencesCard() { setEmailNotifications(newState) try { await updateUserPreferences({ - email_notifications: newState as { new_file_received: boolean; file_downloaded: boolean; security_alerts: boolean } + email_notifications: newState as { new_file_received: boolean; file_downloaded: boolean; login_alerts: boolean; password_alerts: boolean; two_factor_alerts: boolean } }) } catch { setEmailNotifications(prev => ({ @@ -185,13 +187,13 @@ function EmailNotificationPreferencesCard() {
-

Email Notifications

-

Choose which email notifications you receive

+

Security Alerts

+

Choose which security events trigger email alerts

- {PULSE_NOTIFICATION_OPTIONS.map((item) => ( + {SECURITY_ALERT_OPTIONS.map((item) => (
case 'notifications': - if (active.subTab === 'email') return + if (active.subTab === 'security') return if (active.subTab === 'center') return (
@@ -410,7 +412,7 @@ function AppSettingsSection() { onToggle={() => { toggleSection('notifications') if (!expanded.has('notifications')) { - selectSubTab({ section: 'notifications', subTab: 'email' }) + selectSubTab({ section: 'notifications', subTab: 'security' }) } }} icon={BellIcon} @@ -419,9 +421,9 @@ function AppSettingsSection() { /> selectSubTab({ section: 'notifications', subTab: 'email' })} - label="Email Preferences" + active={active.section === 'notifications' && active.subTab === 'security'} + onClick={() => selectSubTab({ section: 'notifications', subTab: 'security' })} + label="Security Alerts" />