feat: Add SMTP testing and improve Docker setup
Introduce a new feature to test SMTP configuration directly from the settings page. This involves adding a new API endpoint and corresponding UI elements to trigger and display the results of an SMTP test. Additionally, this commit refactors the Docker setup by consolidating Dockerfiles and removing unnecessary configuration files. The goal is to streamline the build process and reduce image size and complexity.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { CondoService } from '../services/mockDb';
|
||||
import { AppSettings, Family, User, AlertDefinition, Condo, Notice, NoticeIconType, NoticeRead } from '../types';
|
||||
import { Save, Building, Coins, Plus, Pencil, Trash2, X, CalendarCheck, AlertTriangle, User as UserIcon, Server, Bell, Clock, FileText, Lock, Megaphone, CheckCircle2, Info, Hammer, Link as LinkIcon, Eye, Calendar, List, UserCog, Mail, Power, MapPin, CreditCard, ToggleLeft, ToggleRight, LayoutGrid, PieChart, Users } from 'lucide-react';
|
||||
import { Save, Building, Coins, Plus, Pencil, Trash2, X, CalendarCheck, AlertTriangle, User as UserIcon, Server, Bell, Clock, FileText, Lock, Megaphone, CheckCircle2, Info, Hammer, Link as LinkIcon, Eye, Calendar, List, UserCog, Mail, Power, MapPin, CreditCard, ToggleLeft, ToggleRight, LayoutGrid, PieChart, Users, Send } from 'lucide-react';
|
||||
|
||||
export const SettingsPage: React.FC = () => {
|
||||
const currentUser = CondoService.getCurrentUser();
|
||||
@@ -91,6 +91,8 @@ export const SettingsPage: React.FC = () => {
|
||||
|
||||
// SMTP Modal State
|
||||
const [showSmtpModal, setShowSmtpModal] = useState(false);
|
||||
const [testingSmtp, setTestingSmtp] = useState(false);
|
||||
const [testSmtpMsg, setTestSmtpMsg] = useState('');
|
||||
|
||||
// Notices (Bacheca) State
|
||||
const [notices, setNotices] = useState<Notice[]>([]);
|
||||
@@ -238,6 +240,20 @@ export const SettingsPage: React.FC = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleSmtpTest = async () => {
|
||||
if (!globalSettings?.smtpConfig) return;
|
||||
setTestingSmtp(true);
|
||||
setTestSmtpMsg('');
|
||||
try {
|
||||
await CondoService.testSmtpConfig(globalSettings.smtpConfig);
|
||||
setTestSmtpMsg('Successo! Email di prova inviata.');
|
||||
} catch(e: any) {
|
||||
setTestSmtpMsg('Errore: ' + (e.message || "Impossibile connettersi"));
|
||||
} finally {
|
||||
setTestingSmtp(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleNewYear = async () => {
|
||||
if (!globalSettings) return;
|
||||
const nextYear = globalSettings.currentYear + 1;
|
||||
@@ -1041,10 +1057,21 @@ export const SettingsPage: React.FC = () => {
|
||||
<label className="text-xs font-bold text-slate-500 uppercase mb-1 block">Email Mittente</label>
|
||||
<input type="email" value={globalSettings?.smtpConfig?.fromEmail || ''} onChange={(e) => setGlobalSettings(prev => prev ? {...prev, smtpConfig: {...(prev.smtpConfig || {}), fromEmail: e.target.value} as any} : null)} className="w-full border p-2.5 rounded-lg text-slate-700" placeholder="no-reply@condominio.it"/>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<input type="checkbox" checked={globalSettings?.smtpConfig?.secure || false} onChange={(e) => setGlobalSettings(prev => prev ? {...prev, smtpConfig: {...(prev.smtpConfig || {}), secure: e.target.checked} as any} : null)} className="w-4 h-4 text-blue-600"/>
|
||||
<label className="text-sm text-slate-700 font-medium">Usa SSL/TLS (Secure)</label>
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
<input type="checkbox" checked={globalSettings?.smtpConfig?.secure || false} onChange={(e) => setGlobalSettings(prev => prev ? {...prev, smtpConfig: {...(prev.smtpConfig || {}), secure: e.target.checked} as any} : null)} className="w-4 h-4 text-blue-600"/>
|
||||
<label className="text-sm text-slate-700 font-medium">Usa SSL/TLS (Secure)</label>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleSmtpTest}
|
||||
disabled={testingSmtp}
|
||||
className="text-xs font-bold bg-amber-100 text-amber-700 px-3 py-1.5 rounded hover:bg-amber-200 transition-colors flex items-center gap-1 disabled:opacity-50"
|
||||
>
|
||||
{testingSmtp ? <span className="animate-pulse">Test...</span> : <><Send className="w-3 h-3"/> Test Configurazione</>}
|
||||
</button>
|
||||
</div>
|
||||
{testSmtpMsg && <p className={`text-xs font-medium text-center ${testSmtpMsg.startsWith('Errore') ? 'text-red-500' : 'text-green-600'}`}>{testSmtpMsg}</p>}
|
||||
|
||||
<div className="pt-2 flex justify-between items-center border-t border-slate-100 mt-2">
|
||||
<span className="text-green-600 text-sm font-medium">{successMsg}</span>
|
||||
|
||||
Reference in New Issue
Block a user