import { useState, useEffect } from 'react' import axios from 'axios' const API_BASE = import.meta.env.VITE_API_URL || 'http://localhost:8085/api' const MESSAGE_LIMIT_OPTIONS = [ { value: 100, label: '100' }, { value: 1000, label: '1,000' }, { value: 10000, label: '10,000' }, { value: 100000, label: '100,000' }, { value: 200000, label: '200,000' }, { value: 500000, label: '500,000' }, ] function SettingsModal({ show, onClose, onSettingsUpdated }) { const [settings, setSettings] = useState({ conversations: { show_calls: true, message_limit: 100000 } }) const [loading, setLoading] = useState(true) const [saving, setSaving] = useState(false) const [error, setError] = useState('') useEffect(() => { if (show) { fetchSettings() } }, [show]) const fetchSettings = async () => { try { setLoading(true) const response = await axios.get(`${API_BASE}/settings`) setSettings(response.data) } catch (err) { console.error('Failed to fetch settings:', err) setError('Failed to load settings') } finally { setLoading(false) } } const handleSave = async () => { try { setSaving(true) setError('') await axios.put(`${API_BASE}/settings`, settings) if (onSettingsUpdated) { onSettingsUpdated(settings) } onClose() } catch (err) { console.error('Failed to save settings:', err) setError('Failed to save settings') } finally { setSaving(false) } } const handleToggleShowCalls = () => { setSettings({ ...settings, conversations: { ...settings.conversations, show_calls: !settings.conversations.show_calls } }) } const handleMessageLimitChange = (e) => { setSettings({ ...settings, conversations: { ...settings.conversations, message_limit: parseInt(e.target.value, 10) } }) } if (!show) return null return (
Settings
{loading ? (
Loading...
) : ( <> {error && (
{error}
)}
Conversations
When enabled, phone calls will appear in the conversation list alongside messages.
Maximum number of messages shown when opening a conversation.
)}
) } export default SettingsModal