'use client' import { useState, useEffect } from 'react' import Link from 'next/link' import { SettingsModal, type SettingsSection } from '@ciphera-net/ui' import { UserIcon, LockIcon, ChevronRightIcon } from '@ciphera-net/ui' import ProfileSettings from '@/components/settings/ProfileSettings' import TrustedDevicesCard from '@/components/settings/TrustedDevicesCard' import SecurityActivityCard from '@/components/settings/SecurityActivityCard' import { useSettingsModal } from '@/lib/settings-modal-context' import { useAuth } from '@/lib/auth/context' import { updateUserPreferences } from '@/lib/api/user' // Inline SVG icons not available in ciphera-ui function BellIcon({ className }: { className?: string }) { return ( ) } // --- Security Alerts --- 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 SecurityAlertsCard() { const { user } = useAuth() const [emailNotifications, setEmailNotifications] = useState>({}) useEffect(() => { if (user?.preferences?.email_notifications) { setEmailNotifications(user.preferences.email_notifications) } else { const defaults = SECURITY_ALERT_OPTIONS.reduce((acc, option) => ({ ...acc, [option.key]: true }), {} as Record) setEmailNotifications(defaults) } }, [user]) const handleToggle = async (key: string) => { const newState = { ...emailNotifications, [key]: !emailNotifications[key] } setEmailNotifications(newState) try { await updateUserPreferences({ email_notifications: newState as { new_file_received: boolean; file_downloaded: boolean; login_alerts: boolean; password_alerts: boolean; two_factor_alerts: boolean } }) } catch { setEmailNotifications(prev => ({ ...prev, [key]: !prev[key] })) } } return ( Security Alerts Choose which security events trigger email alerts {SECURITY_ALERT_OPTIONS.map((item) => ( {item.label} {item.description} handleToggle(item.key)} className={`relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none ${ emailNotifications[item.key] ? 'bg-brand-orange' : 'bg-neutral-200 dark:bg-neutral-700' }`} > ))} ) } // --- Notification Center Placeholder --- function NotificationCenterPlaceholder() { return ( Notification Center View and manage all your notifications in one place. Open Notification Center ) } // --- Main Wrapper --- export default function SettingsModalWrapper() { const { isOpen, closeSettings } = useSettingsModal() const sections: SettingsSection[] = [ { id: 'pulse', label: 'Pulse Settings', description: 'Profile and preferences', icon: UserIcon, defaultExpanded: true, items: [ { id: 'profile', label: 'Profile', content: }, { id: 'security', label: 'Security', content: }, { id: 'preferences', label: 'Preferences', content: }, ], }, { id: 'notifications', label: 'Notifications', description: 'Email and in-app notifications', icon: BellIcon, items: [ { id: 'security-alerts', label: 'Security Alerts', content: }, { id: 'center', label: 'Notification Center', content: }, ], }, { id: 'account', label: 'Ciphera Account', description: 'Security, 2FA, and sessions', icon: LockIcon, items: [ { id: 'auth-profile', label: 'Profile & Personal Info', href: 'https://auth.ciphera.net/settings', external: true }, { id: 'auth-security', label: 'Security & 2FA', href: 'https://auth.ciphera.net/settings?tab=security', external: true }, { id: 'auth-sessions', label: 'Active Sessions', href: 'https://auth.ciphera.net/settings?tab=sessions', external: true }, { id: 'devices', label: 'Trusted Devices', content: }, { id: 'activity', label: 'Security Activity', content: }, ], }, ] return }
Choose which security events trigger email alerts
View and manage all your notifications in one place.