import React, { useState, useEffect } from 'react'; import { X, Plus } from 'lucide-react'; import { toast } from 'react-toastify'; import notificationService, { NotificationTemplate } from '../services/notificationService'; interface NotificationTemplatesModalProps { onClose: () => void; } const NotificationTemplatesModal: React.FC = ({ onClose }) => { const [templates, setTemplates] = useState([]); const [loading, setLoading] = useState(true); const [showCreate, setShowCreate] = useState(false); const [formData, setFormData] = useState({ name: '', notification_type: 'booking_confirmation', channel: 'email', subject: '', content: '', }); useEffect(() => { loadTemplates(); }, []); const loadTemplates = async () => { try { setLoading(true); const response = await notificationService.getTemplates(); setTemplates(response.data.data || []); } catch (error: any) { toast.error(error.message || 'Failed to load templates'); } finally { setLoading(false); } }; const handleCreate = async (e: React.FormEvent) => { e.preventDefault(); if (!formData.name.trim() || !formData.content.trim()) { toast.error('Name and content are required'); return; } try { await notificationService.createTemplate(formData); toast.success('Template created successfully'); setShowCreate(false); setFormData({ name: '', notification_type: 'booking_confirmation', channel: 'email', subject: '', content: '', }); loadTemplates(); } catch (error: any) { toast.error(error.message || 'Failed to create template'); } }; return (

Notification Templates

{showCreate ? (
setFormData({ ...formData, name: e.target.value })} className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500" required />
{(formData.channel === 'email' || formData.channel === 'push') && (
setFormData({ ...formData, subject: e.target.value })} className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500" placeholder="Use {{variable_name}} for variables" />
)}