diff --git a/admin-spa/src/routes/Settings/Notifications/EditTemplate.tsx b/admin-spa/src/routes/Settings/Notifications/EditTemplate.tsx index e5c73d6..fade92a 100644 --- a/admin-spa/src/routes/Settings/Notifications/EditTemplate.tsx +++ b/admin-spa/src/routes/Settings/Notifications/EditTemplate.tsx @@ -37,24 +37,47 @@ export default function EditTemplate() { const [codeMode, setCodeMode] = useState(false); // Fetch template - const { data: template, isLoading } = useQuery({ + const { data: template, isLoading, error } = useQuery({ queryKey: ['notification-template', eventId, channelId], queryFn: async () => { + console.log('Fetching template for:', eventId, channelId); const response = await api.get(`/notifications/templates/${eventId}/${channelId}`); + console.log('API Response:', response); return response.data; }, enabled: !!eventId && !!channelId, }); useEffect(() => { - if (template && template.subject !== undefined && template.body !== undefined) { - console.log('Setting template data:', template); + console.log('Template changed:', template); + if (template) { + console.log('Template data:', { + subject: template.subject, + body: template.body, + variables: template.variables, + event_label: template.event_label, + channel_label: template.channel_label + }); + setSubject(template.subject || ''); setBody(template.body || ''); setVariables(template.variables || {}); } }, [template]); + // Debug: Log when states change + useEffect(() => { + console.log('Subject state:', subject); + }, [subject]); + + useEffect(() => { + console.log('Body state:', body); + }, [body]); + + useEffect(() => { + console.log('Variables state:', variables); + }, [variables]); + const handleSave = async () => { try { await api.post('/notifications/templates', { @@ -186,33 +209,32 @@ export default function EditTemplate() { return ( - - {template?.event_label || __('Edit Template')} - - } + title={template?.event_label || __('Edit Template')} description={`${template?.channel_label || ''} - ${__('Customize the notification template. Use variables like {customer_name} to personalize messages.')}`} onSave={handleSave} saveLabel={__('Save Template')} isLoading={isLoading} action={ - +
+ + +
} > {/* Tabs - Sticky in header area */}