fix: templateService return format and Templates page array handling

- Updated templateService to return response.data like other services
- Added fallback to empty array in Templates.jsx to prevent map errors
- Ensures consistency across all service modules
This commit is contained in:
salvacybersec
2025-11-10 19:17:13 +03:00
parent aed4f759b3
commit 64c7c392bc
2 changed files with 26 additions and 7 deletions

View File

@@ -63,10 +63,11 @@ function Templates() {
try { try {
setLoading(true); setLoading(true);
const response = await templateService.getAll(); const response = await templateService.getAll();
setTemplates(response.data); setTemplates(response.data || []);
} catch (error) { } catch (error) {
console.error('Failed to load templates:', error); console.error('Failed to load templates:', error);
alert('Şablonlar yüklenemedi'); alert('Şablonlar yüklenemedi');
setTemplates([]);
} finally { } finally {
setLoading(false); setLoading(false);
} }

View File

@@ -1,11 +1,29 @@
import api from './api'; import api from './api';
export const templateService = { export const templateService = {
getAll: () => api.get('/api/templates'), getAll: async () => {
getById: (id) => api.get(`/api/templates/${id}`), const response = await api.get('/api/templates');
create: (data) => api.post('/api/templates', data), return response.data;
update: (id, data) => api.put(`/api/templates/${id}`, data), },
delete: (id) => api.delete(`/api/templates/${id}`), getById: async (id) => {
preview: (data) => api.post('/api/templates/preview', data), const response = await api.get(`/api/templates/${id}`);
return response.data;
},
create: async (data) => {
const response = await api.post('/api/templates', data);
return response.data;
},
update: async (id, data) => {
const response = await api.put(`/api/templates/${id}`, data);
return response.data;
},
delete: async (id) => {
const response = await api.delete(`/api/templates/${id}`);
return response.data;
},
preview: async (data) => {
const response = await api.post('/api/templates/preview', data);
return response.data;
},
}; };