diff --git a/src/components/applications/MasterPage.tsx b/src/components/applications/MasterPage.tsx index 6511391..bce53d1 100644 --- a/src/components/applications/MasterPage.tsx +++ b/src/components/applications/MasterPage.tsx @@ -353,8 +353,9 @@ export const MasterPage: React.FC = () => { setPreviewLoading(true); try { const res = await masterService.previewEmailTemplate({ - template: editingTemplate, - testData: JSON.parse(testDataInput) + subject: editingTemplate?.subject, + body: editingTemplate?.body, + data: JSON.parse(testDataInput) }) as any; if (res.success) setPreviewContent(res.data); } catch (error) { toast.error('Preview failed'); } @@ -516,8 +517,27 @@ export const MasterPage: React.FC = () => { - setShowTemplateDialog(true)} - onEditTemplate={() => toast.info('Template Editor being updated')} onDeleteTemplate={() => toast.error('Delete Template restricted')} /> + { + setEditingTemplate({ templateCode: '', subject: '', body: '', description: '', placeholders: [] }); + setTestDataInput('{}'); + setShowTemplateDialog(true); + }} + onEditTemplate={(template) => { + setEditingTemplate(template); + if (template.placeholders && Array.isArray(template.placeholders)) { + const defaults = template.placeholders.reduce((acc: any, p: string) => { + acc[p] = `[${p}]`; + return acc; + }, {}); + setTestDataInput(JSON.stringify(defaults, null, 2)); + } else { + setTestDataInput('{}'); + } + setShowTemplateDialog(true); + }} + onDeleteTemplate={() => toast.error('Delete Template restricted')} + /> diff --git a/src/components/applications/MasterPage/TemplateDialog.tsx b/src/components/applications/MasterPage/TemplateDialog.tsx index fb7ff83..996c95e 100644 --- a/src/components/applications/MasterPage/TemplateDialog.tsx +++ b/src/components/applications/MasterPage/TemplateDialog.tsx @@ -5,7 +5,8 @@ import { Label } from '../../ui/label'; import { Input } from '../../ui/input'; import { Textarea } from '../../ui/textarea'; import { Switch } from '../../ui/switch'; -import { Loader2, Play } from 'lucide-react'; +import { Loader2, Play, Info, Copy, CheckCircle2, Settings, Edit2 } from 'lucide-react'; +import { Badge } from '../../ui/badge'; interface TemplateDialogProps { isOpen: boolean; @@ -25,6 +26,26 @@ export const TemplateDialog: React.FC = ({ testDataInput, setTestDataInput, previewLoading, handlePreviewTemplate, previewContent, handleSaveTemplate }) => { + const textareaRef = React.useRef(null); + + const insertPlaceholder = (placeholder: string) => { + if (!textareaRef.current) return; + const { selectionStart, selectionEnd } = textareaRef.current; + const text = editingTemplate?.body || ''; + const newText = text.substring(0, selectionStart) + `{{${placeholder}}}` + text.substring(selectionEnd); + setEditingTemplate({ ...editingTemplate!, body: newText }); + + // Set focus back and move cursor + setTimeout(() => { + if (textareaRef.current) { + textareaRef.current.focus(); + textareaRef.current.setSelectionRange(selectionStart + placeholder.length + 4, selectionStart + placeholder.length + 4); + } + }, 0); + }; + + const placeholders = editingTemplate?.placeholders || []; + return ( @@ -33,88 +54,194 @@ export const TemplateDialog: React.FC = ({ Configure automated email template with dynamic content -
-
-
- - setEditingTemplate({ ...editingTemplate!, name: e.target.value })} - /> -
-
- - setEditingTemplate({ ...editingTemplate!, templateCode: e.target.value })} - /> -
-
- - setEditingTemplate({ ...editingTemplate!, subject: e.target.value })} - /> -
+
+ {/* Left Column: Template Configuration */} +
+
+
+

+ + General Settings +

+
+ + setEditingTemplate({ ...editingTemplate!, name: e.target.value })} + /> +
+
+ + setEditingTemplate({ ...editingTemplate!, templateCode: e.target.value })} + /> +
+
+ + setEditingTemplate({ ...editingTemplate!, description: e.target.value })} + /> +
+
+
+ setEditingTemplate({ ...editingTemplate!, isActive: checked })} + /> + +
+ + {editingTemplate?.isActive ? 'Template Enabled' : 'Template Disabled'} + +
+
-
- -