import { useState, useEffect } from "react"; import { Link } from "wouter"; import { Button } from "@/components/ui/button"; import { Card } from "@/components/ui/card"; import { ArrowLeft, Settings, Bell, Lock, Palette, HardDrive, User, Loader2 } from "lucide-react"; import { supabase } from "@/lib/supabase"; import { useAuth } from "@/lib/auth"; import { nanoid } from "nanoid"; export default function SettingsWorkspace() { const { user } = useAuth(); const [settings, setSettings] = useState({ theme: "dark", fontSize: "medium", sidebarCollapsed: false, notificationsEnabled: true, emailNotifications: true, soundEnabled: true, autoSave: true, privacyLevel: "private", }); const [loading, setLoading] = useState(true); useEffect(() => { if (user?.id) fetchSettings(); }, [user]); const fetchSettings = async () => { try { const { data } = await supabase .from('workspace_settings') .select('*') .eq('user_id', user?.id) .single(); if (data) { setSettings({ theme: data.theme || 'dark', fontSize: data.font_size === 14 ? 'medium' : 'large', sidebarCollapsed: !data.show_sidebar, notificationsEnabled: data.notifications_enabled, emailNotifications: data.email_notifications, soundEnabled: true, autoSave: data.auto_save, privacyLevel: data.privacy_profile_visible ? 'public' : 'private' }); } } catch (err) { console.error('Error fetching settings:', err); } finally { setLoading(false); } }; const saveSettings = async (newSettings: typeof settings) => { if (!user?.id) return; try { await supabase.from('workspace_settings').upsert({ id: nanoid(), user_id: user.id, theme: newSettings.theme, font_size: newSettings.fontSize === 'medium' ? 14 : 16, show_sidebar: !newSettings.sidebarCollapsed, notifications_enabled: newSettings.notificationsEnabled, email_notifications: newSettings.emailNotifications, auto_save: newSettings.autoSave, privacy_profile_visible: newSettings.privacyLevel === 'public' }, { onConflict: 'user_id' }); } catch (err) { console.error('Error saving settings:', err); } }; const handleToggle = (key: string) => { const newSettings = { ...settings, [key]: !settings[key as keyof typeof settings], }; setSettings(newSettings); saveSettings(newSettings); }; const handleChange = (key: string, value: string) => { const newSettings = { ...settings, [key]: value, }; setSettings(newSettings); saveSettings(newSettings); }; return (
Push Notifications
Get alerts for important events
Email Notifications
Receive email digests
Sound Effects
Play notification sounds
Auto-save
Automatically save your work
user@example.com
Member Since
December 23, 2025