fix: Restore contextual header + add debugging
## Fixes: 1. **Contextual Header Restored** ✅ - Title back to string (not ReactNode) - Header now shows properly - Back button moved to action area 2. **Comprehensive Debugging Added** 🔍 - Log API fetch - Log API response - Log template data - Log state changes (subject, body, variables) - Will help identify why defaults not loading ## Changes: ```tsx // Before: ReactNode title (broke header) title={<div><BackButton /><span>Title</span></div>} // After: String title (header works) title={template?.event_label || "Edit Template"} action={ <div> <BackButton /> <ResetButton /> </div> } ``` ## Debug Logs: - "Fetching template for:" eventId, channelId - "API Response:" full response - "Template changed:" template object - "Template data:" destructured fields - "Subject state:", "Body state:", "Variables state:" Check browser console to see what is happening!
This commit is contained in:
@@ -37,24 +37,47 @@ export default function EditTemplate() {
|
|||||||
const [codeMode, setCodeMode] = useState(false);
|
const [codeMode, setCodeMode] = useState(false);
|
||||||
|
|
||||||
// Fetch template
|
// Fetch template
|
||||||
const { data: template, isLoading } = useQuery({
|
const { data: template, isLoading, error } = useQuery({
|
||||||
queryKey: ['notification-template', eventId, channelId],
|
queryKey: ['notification-template', eventId, channelId],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
|
console.log('Fetching template for:', eventId, channelId);
|
||||||
const response = await api.get(`/notifications/templates/${eventId}/${channelId}`);
|
const response = await api.get(`/notifications/templates/${eventId}/${channelId}`);
|
||||||
|
console.log('API Response:', response);
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
enabled: !!eventId && !!channelId,
|
enabled: !!eventId && !!channelId,
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (template && template.subject !== undefined && template.body !== undefined) {
|
console.log('Template changed:', template);
|
||||||
console.log('Setting template data:', 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 || '');
|
setSubject(template.subject || '');
|
||||||
setBody(template.body || '');
|
setBody(template.body || '');
|
||||||
setVariables(template.variables || {});
|
setVariables(template.variables || {});
|
||||||
}
|
}
|
||||||
}, [template]);
|
}, [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 () => {
|
const handleSave = async () => {
|
||||||
try {
|
try {
|
||||||
await api.post('/notifications/templates', {
|
await api.post('/notifications/templates', {
|
||||||
@@ -186,24 +209,22 @@ export default function EditTemplate() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<SettingsLayout
|
<SettingsLayout
|
||||||
title={
|
title={template?.event_label || __('Edit Template')}
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
size="sm"
|
|
||||||
onClick={() => navigate(-1)}
|
|
||||||
className="-ml-2 px-2"
|
|
||||||
>
|
|
||||||
<ArrowLeft className="h-5 w-5" />
|
|
||||||
</Button>
|
|
||||||
<span>{template?.event_label || __('Edit Template')}</span>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
description={`${template?.channel_label || ''} - ${__('Customize the notification template. Use variables like {customer_name} to personalize messages.')}`}
|
description={`${template?.channel_label || ''} - ${__('Customize the notification template. Use variables like {customer_name} to personalize messages.')}`}
|
||||||
onSave={handleSave}
|
onSave={handleSave}
|
||||||
saveLabel={__('Save Template')}
|
saveLabel={__('Save Template')}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
action={
|
action={
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => navigate(-1)}
|
||||||
|
className="gap-2"
|
||||||
|
>
|
||||||
|
<ArrowLeft className="h-4 w-4" />
|
||||||
|
{__('Back')}
|
||||||
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="sm"
|
size="sm"
|
||||||
@@ -213,6 +234,7 @@ export default function EditTemplate() {
|
|||||||
<RotateCcw className="h-4 w-4" />
|
<RotateCcw className="h-4 w-4" />
|
||||||
{__('Reset to Default')}
|
{__('Reset to Default')}
|
||||||
</Button>
|
</Button>
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{/* Tabs - Sticky in header area */}
|
{/* Tabs - Sticky in header area */}
|
||||||
|
|||||||
Reference in New Issue
Block a user