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);
|
||||
|
||||
// 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,24 +209,22 @@ export default function EditTemplate() {
|
||||
|
||||
return (
|
||||
<SettingsLayout
|
||||
title={
|
||||
<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>
|
||||
}
|
||||
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={
|
||||
<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
|
||||
variant="outline"
|
||||
size="sm"
|
||||
@@ -213,6 +234,7 @@ export default function EditTemplate() {
|
||||
<RotateCcw className="h-4 w-4" />
|
||||
{__('Reset to Default')}
|
||||
</Button>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
{/* Tabs - Sticky in header area */}
|
||||
|
||||
Reference in New Issue
Block a user