diff --git a/components/dashboard/promotions/PromotionsList.tsx b/components/dashboard/promotions/PromotionsList.tsx index 426684c..05338bc 100644 --- a/components/dashboard/promotions/PromotionsList.tsx +++ b/components/dashboard/promotions/PromotionsList.tsx @@ -49,13 +49,13 @@ export default function PromotionsList() { loadPromotions(); }, []); - async function loadPromotions() { + const loadPromotions = async () => { setLoading(true); try { const response = await fetchClient('/promotions'); setPromotions(response || []); } catch (error) { - console.error('Error loading promotions:', error); + console.error('Failed to fetch promotions:', error); toast({ title: 'Error', description: 'Failed to load promotions', @@ -64,9 +64,9 @@ export default function PromotionsList() { } finally { setLoading(false); } - } + }; - async function deletePromotion(id: string) { + const deletePromotion = async (id: string) => { try { await fetchClient(`/promotions/${id}`, { method: 'DELETE', @@ -90,7 +90,7 @@ export default function PromotionsList() { setShowDeleteDialog(false); setPromotionToDelete(null); } - } + }; function handleOpenEditDialog(promotion: Promotion) { setEditingPromotion(promotion); diff --git a/lib/client-service.ts b/lib/client-service.ts index 849a68e..10c91d6 100644 --- a/lib/client-service.ts +++ b/lib/client-service.ts @@ -18,7 +18,10 @@ export async function fetchClient( const { method = 'GET', body, headers = {}, ...rest } = options; const apiUrl = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3001'; - const url = `${apiUrl}/api${endpoint.startsWith('/') ? endpoint : `/${endpoint}`}`; + + // Check if endpoint already includes /api + const apiPrefix = endpoint.includes('/api/') ? '' : '/api'; + const url = `${apiUrl}${apiPrefix}${endpoint.startsWith('/') ? endpoint : `/${endpoint}`}`; const fetchOptions: RequestInit = { method,