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:
@@ -63,10 +63,11 @@ function Templates() {
|
||||
try {
|
||||
setLoading(true);
|
||||
const response = await templateService.getAll();
|
||||
setTemplates(response.data);
|
||||
setTemplates(response.data || []);
|
||||
} catch (error) {
|
||||
console.error('Failed to load templates:', error);
|
||||
alert('Şablonlar yüklenemedi');
|
||||
setTemplates([]);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,29 @@
|
||||
import api from './api';
|
||||
|
||||
export const templateService = {
|
||||
getAll: () => api.get('/api/templates'),
|
||||
getById: (id) => api.get(`/api/templates/${id}`),
|
||||
create: (data) => api.post('/api/templates', data),
|
||||
update: (id, data) => api.put(`/api/templates/${id}`, data),
|
||||
delete: (id) => api.delete(`/api/templates/${id}`),
|
||||
preview: (data) => api.post('/api/templates/preview', data),
|
||||
getAll: async () => {
|
||||
const response = await api.get('/api/templates');
|
||||
return response.data;
|
||||
},
|
||||
getById: async (id) => {
|
||||
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;
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user