import React, { useState } from 'react'; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from "@/components/ui/dialog"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { useLanguage } from "@/contexts/LanguageContext"; import { Mail, X } from "lucide-react"; import { toast } from "@/hooks/use-toast"; interface TestEmailDialogProps { open: boolean; onOpenChange: (open: boolean) => void; onSendTest: (data: TestEmailData) => Promise; isTesting: boolean; } export interface TestEmailData { email: string; template: string; collection?: string; } const TestEmailDialog: React.FC = ({ open, onOpenChange, onSendTest, isTesting }) => { const { t } = useLanguage(); const [email, setEmail] = useState(''); const [template, setTemplate] = useState('verification'); const [collection, setCollection] = useState('_superusers'); const handleSend = async () => { if (!email) { toast({ title: "Error", description: "Please enter an email address", variant: "destructive", }); return; } try { await onSendTest({ email, template, collection: template === 'verification' ? collection : undefined }); toast({ title: "Success", description: "Test email sent successfully", variant: "default", }); // Close dialog on success handleClose(); } catch (error) { console.error('Error sending test email:', error); toast({ title: "Error", description: "Failed to send test email", variant: "destructive", }); } }; const handleClose = () => { onOpenChange(false); // Reset form setEmail(''); setTemplate('verification'); setCollection('_superusers'); }; return ( {t("sendTestEmail", "settings")}
{/* Template Selection */}
{/* Auth Collection - only show for verification template */} {template === 'verification' && (
)} {/* Email Address */}
setEmail(e.target.value)} placeholder={t("enterEmailAddress", "settings")} required />
); }; export default TestEmailDialog;