From 1982033ac4a3b31cf7e402f251d811638f827ea1 Mon Sep 17 00:00:00 2001 From: dwindown Date: Mon, 22 Dec 2025 20:57:33 +0700 Subject: [PATCH] Fix email template preview UX and debug template loading MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Convert EmailTemplatePreview from bottom card to modal Dialog component - Replace problematic bottom preview with clean modal popup - Add proper modal state management (open/close handlers) - Debug template loading with comprehensive error handling and logging - Add user feedback for template seeding and loading errors - Improve fetchData() and seedTemplates() with try-catch blocks - Add console logging for debugging template initialization 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- src/components/admin/EmailTemplatePreview.tsx | 249 +++++++++++------- .../admin/settings/NotifikasiTab.tsx | 135 ++++++---- 2 files changed, 242 insertions(+), 142 deletions(-) diff --git a/src/components/admin/EmailTemplatePreview.tsx b/src/components/admin/EmailTemplatePreview.tsx index 59035e3..25aa838 100644 --- a/src/components/admin/EmailTemplatePreview.tsx +++ b/src/components/admin/EmailTemplatePreview.tsx @@ -3,8 +3,16 @@ import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Alert, AlertDescription } from '@/components/ui/alert'; +import { + Dialog, + DialogContent, + DialogHeader, + DialogTitle, + DialogDescription, + DialogFooter, +} from '@/components/ui/dialog'; import { toast } from '@/hooks/use-toast'; -import { Eye, Send, Mail } from 'lucide-react'; +import { Eye, Send, Mail, X } from 'lucide-react'; import { EmailTemplateRenderer, ShortcodeProcessor } from '@/lib/email-templates/master-template'; interface NotificationTemplate { @@ -22,9 +30,17 @@ interface EmailTemplatePreviewProps { template: NotificationTemplate; onTest?: (template: NotificationTemplate) => void; isTestSending?: boolean; + open: boolean; + onClose: () => void; } -export function EmailTemplatePreview({ template, onTest, isTestSending = false }: EmailTemplatePreviewProps) { +export function EmailTemplatePreview({ + template, + onTest, + isTestSending = false, + open, + onClose +}: EmailTemplatePreviewProps) { const [previewMode, setPreviewMode] = useState<'master' | 'content'>('master'); const [testEmail, setTestEmail] = useState(''); const [showTestForm, setShowTestForm] = useState(false); @@ -60,109 +76,154 @@ export function EmailTemplatePreview({ template, onTest, isTestSending = false } const previewHtml = generatePreview(); return ( -
- {/* Preview Controls */} -
-
- - -
- -
+ + + + + + Preview: {template.name} + + + Preview template email dengan master styling + -
-
+ - {/* Test Email Form */} - {showTestForm && ( -
-
- -
- setTestEmail(e.target.value)} - placeholder="test@example.com" - className="flex-1" - /> -
-

- This will send a test email with dummy data for all available shortcodes. -

-
- )} - {/* Preview Info */} - - - - {previewMode === 'master' - ? 'Showing complete email template with header, footer, and styling applied.' - : 'Showing only the content section without master template styling.' - } - - + {/* Test Email Form */} + {showTestForm && ( +
+
+ +
+ setTestEmail(e.target.value)} + placeholder="test@example.com" + className="flex-1" + /> + +
+

+ This will send a test email with dummy data for all available shortcodes. +

+
+
+ )} - {/* Email Preview */} -
-
- - {previewMode === 'master' ? 'Full Email Preview' : 'Content Preview'} - -
-
-