debug: Add extensive logging to find API response structure

## Issue:
Endless loading - React Query says query returns undefined

## Debug Logging Added:
- Log full API response
- Log response.data
- Log response type
- Check if response has template fields directly
- Check if response.data has template fields
- Return appropriate data structure

This will show us exactly what the API returns so we can fix it properly.

Refresh page and check console!
This commit is contained in:
dwindown
2025-11-13 00:37:46 +07:00
parent 97f438ed19
commit 612c7b5a72

View File

@@ -43,7 +43,24 @@ export default function EditTemplate() {
console.log('Fetching template for:', eventId, channelId);
const response = await api.get(`/notifications/templates/${eventId}/${channelId}`);
console.log('API Response:', response);
return response.data;
console.log('API Response.data:', response.data);
console.log('API Response type:', typeof response);
// The api.get might already unwrap response.data
// Return the response directly if it has the template fields
if (response && (response.subject !== undefined || response.body !== undefined)) {
console.log('Returning response directly:', response);
return response;
}
// Otherwise return response.data
if (response && response.data) {
console.log('Returning response.data:', response.data);
return response.data;
}
console.error('No valid template data found in response');
return null;
},
enabled: !!eventId && !!channelId,
});