'use client'; import { useState, useEffect } from 'react'; import { useSession } from 'next-auth/react'; export default function NotificationSettingsPage() { const { data: session } = useSession(); const [settings, setSettings] = useState({ email_enabled: true, telegram_enabled: false, telegram_chat_id: '', }); const [loading, setLoading] = useState(false); const [message, setMessage] = useState(''); useEffect(() => { if (session?.user) { loadSettings(); } }, [session]); async function loadSettings() { try { const userId = (session!.user as any).id; const res = await fetch(`/api/users/${userId}/notification-settings`); const data = await res.json(); setSettings(data.settings); } catch (error) { console.error('Failed to load settings:', error); } } async function handleSave() { setLoading(true); setMessage(''); try { const userId = (session!.user as any).id; const res = await fetch(`/api/users/${userId}/notification-settings`, { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(settings), }); if (res.ok) { setMessage('✅ Einstellungen gespeichert!'); } else { setMessage('❌ Fehler beim Speichern'); } } catch (error) { setMessage('❌ Fehler beim Speichern'); } finally { setLoading(false); } } async function handleTest() { setLoading(true); setMessage(''); try { const userId = (session!.user as any).id; const res = await fetch( `/api/users/${userId}/notification-settings/test`, { method: 'POST' } ); if (res.ok) { setMessage('✅ Test-Nachricht gesendet!'); } else { const data = await res.json(); setMessage(`❌ Fehler: ${data.error}`); } } catch (error) { setMessage('❌ Fehler beim Senden der Test-Nachricht'); } finally { setLoading(false); } } return (
Geofence-Ereignisse per E-Mail erhalten
Geofence-Ereignisse per Telegram erhalten (inkl. Karte und Buttons)
{settings.telegram_enabled && (Deine Telegram Chat ID findest du über @userinfobot
Schritt 2: Chat ID holen
/start@myidbot/getid an @myidbot
Alternative: @userinfobot mit /start