import React, { useState, useEffect } from 'react'; import axios from 'axios'; import './SettingsWizard.css'; function SettingsWizard() { const [settings, setSettings] = useState({ email_enabled: false, email_host: 'smtp.gmail.com', email_port: 587, email_user: '', email_pass: '', email_from: '', email_to: '', webhook_enabled: false, webhook_url: '', check_interval: 60000, timeout: 5000, timezone: 'UTC', }); const [testResult, setTestResult] = useState(null); const [saving, setSaving] = useState(false); const [testing, setTesting] = useState(false); useEffect(() => { loadSettings(); }, []); const loadSettings = async () => { try { const response = await axios.get('/api/settings'); setSettings(response.data); } catch (error) { console.error('Error loading settings:', error); } }; const handleSave = async () => { setSaving(true); try { await axios.post('/api/settings', settings); alert('Settings saved successfully! Changes apply immediately.'); } catch (error) { console.error('Error saving settings:', error); alert('Error saving settings'); } finally { setSaving(false); } }; const handleTestEmail = async () => { setTesting(true); setTestResult(null); try { const response = await axios.post('/api/test-email', { email_host: settings.email_host, email_port: settings.email_port, email_user: settings.email_user, email_pass: settings.email_pass, email_from: settings.email_from, email_to: settings.email_to, }); setTestResult({ success: true, message: response.data.message }); } catch (error) { setTestResult({ success: false, message: error.response?.data?.error || 'Failed to send test email' }); } finally { setTesting(false); } }; const handleTestWebhook = async () => { setTesting(true); setTestResult(null); try { const response = await axios.post('/api/test-webhook', { webhook_url: settings.webhook_url, }); setTestResult({ success: true, message: response.data.message }); } catch (error) { setTestResult({ success: false, message: error.response?.data?.error || 'Failed to send test webhook' }); } finally { setTesting(false); } }; const emailProviders = [ { name: 'Gmail', host: 'smtp.gmail.com', port: 587 }, { name: 'Outlook', host: 'smtp-mail.outlook.com', port: 587 }, { name: 'Yahoo', host: 'smtp.mail.yahoo.com', port: 587 }, { name: 'Custom', host: '', port: 587 }, ]; return (
Configure email and webhook notifications to receive alerts when your resources go offline.
{/* Email Settings */}{JSON.stringify({
resource: "ZimaOS Server",
url: "https://example.com",
status: "down",
message: "Resource is DOWN",
timestamp: new Date().toISOString()
}, null, 2)}
{testResult.message}