Add gorgias component and services

This commit is contained in:
2024-12-27 16:51:19 -05:00
parent 6b7eae3473
commit 9e0a6a9b6a
24 changed files with 4287 additions and 1 deletions

View File

@@ -0,0 +1,39 @@
// src/services/gorgiasService.js
import axios from "axios";
const API_BASE_URL = "/api/gorgias";
// Helper function for consistent error handling
const handleError = (error, context) => {
console.error(`Error ${context}:`, error.response?.data || error.message);
throw error;
};
// Export the service object directly
const gorgiasService = {
async fetchTickets() {
try {
const response = await axios.get(`${API_BASE_URL}/tickets`);
return response.data.data || [];
} catch (error) {
handleError(error, "fetching tickets");
}
},
async fetchStatistics(name, filters = {}) {
if (!name) {
throw new Error("Statistic name is required");
}
try {
const response = await axios.post(`${API_BASE_URL}/stats/${name}`, {
filters,
});
return response.data;
} catch (error) {
handleError(error, `fetching statistics: ${name}`);
}
},
};
export default gorgiasService;