'use client'; import { useState } from 'react'; import { FiMapPin, FiMail, FiSettings, FiCheck, FiX, FiRefreshCw } from 'react-icons/fi'; import { formatDateTime } from '@/lib/date-utils'; interface LocationsManagerProps { locations: any[]; user: any; } export default function LocationsManager({ locations, user }: LocationsManagerProps) { const [selectedLocation, setSelectedLocation] = useState(null); const [showEmailSettings, setShowEmailSettings] = useState(false); const [syncingLocation, setSyncingLocation] = useState(null); const handleManualSync = async (locationId: string) => { setSyncingLocation(locationId); try { const res = await fetch('/api/email-sync', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ locationId }), }); const data = await res.json(); if (res.ok) { alert(`Sync erfolgreich! ${data.newEmails} neue E-Mails, ${data.newBookings} neue Buchungen`); window.location.reload(); } else { alert(`Fehler beim Sync: ${data.error}`); } } catch (error) { alert('Fehler beim Sync'); } finally { setSyncingLocation(null); } }; return (

Standortverwaltung

E-Mail-Konfiguration und Standort-Einstellungen

{locations.map(location => (

{location.name}

{location.city}

{location.emailSyncEnabled ? ( E-Mail aktiv ) : ( E-Mail inaktiv )}
E-Mail: {location.contactEmail}

Fotoboxen

{location._count.photoboxes}

Buchungen

{location._count.bookings}

{location.lastEmailSync && (
Letzter Sync: {formatDateTime(location.lastEmailSync)}
)}
{location.emailSyncEnabled && ( )}
))}
{showEmailSettings && selectedLocation && (

E-Mail-Einstellungen: {selectedLocation.name}

{ e.preventDefault(); const formData = new FormData(e.currentTarget); try { const res = await fetch(`/api/locations/${selectedLocation.id}/email-settings`, { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ imapHost: formData.get('imapHost'), imapPort: parseInt(formData.get('imapPort') as string), imapUser: formData.get('imapUser'), imapPassword: formData.get('imapPassword'), imapSecure: formData.get('imapSecure') === 'on', smtpHost: formData.get('smtpHost'), smtpPort: parseInt(formData.get('smtpPort') as string), smtpUser: formData.get('smtpUser'), smtpPassword: formData.get('smtpPassword'), smtpSecure: formData.get('smtpSecure') === 'on', emailSyncEnabled: formData.get('emailSyncEnabled') === 'on', }), }); if (res.ok) { alert('Einstellungen gespeichert!'); window.location.reload(); } else { alert('Fehler beim Speichern'); } } catch (error) { alert('Fehler beim Speichern'); } }} className="space-y-6" >

Wichtig: Die E-Mail-Zugangsdaten werden verschlüsselt gespeichert.

IMAP-Einstellungen (Empfang)

SMTP-Einstellungen (Versand)

)}
); }