lets hope this doesn't break stuff

This commit is contained in:
NotII
2025-03-08 05:49:04 +00:00
parent 47e23caf66
commit 9fe457dee7
2 changed files with 9 additions and 6 deletions

View File

@@ -49,13 +49,13 @@ export default function PromotionsList() {
loadPromotions(); loadPromotions();
}, []); }, []);
async function loadPromotions() { const loadPromotions = async () => {
setLoading(true); setLoading(true);
try { try {
const response = await fetchClient<Promotion[]>('/promotions'); const response = await fetchClient<Promotion[]>('/promotions');
setPromotions(response || []); setPromotions(response || []);
} catch (error) { } catch (error) {
console.error('Error loading promotions:', error); console.error('Failed to fetch promotions:', error);
toast({ toast({
title: 'Error', title: 'Error',
description: 'Failed to load promotions', description: 'Failed to load promotions',
@@ -64,9 +64,9 @@ export default function PromotionsList() {
} finally { } finally {
setLoading(false); setLoading(false);
} }
} };
async function deletePromotion(id: string) { const deletePromotion = async (id: string) => {
try { try {
await fetchClient(`/promotions/${id}`, { await fetchClient(`/promotions/${id}`, {
method: 'DELETE', method: 'DELETE',
@@ -90,7 +90,7 @@ export default function PromotionsList() {
setShowDeleteDialog(false); setShowDeleteDialog(false);
setPromotionToDelete(null); setPromotionToDelete(null);
} }
} };
function handleOpenEditDialog(promotion: Promotion) { function handleOpenEditDialog(promotion: Promotion) {
setEditingPromotion(promotion); setEditingPromotion(promotion);

View File

@@ -18,7 +18,10 @@ export async function fetchClient<T>(
const { method = 'GET', body, headers = {}, ...rest } = options; const { method = 'GET', body, headers = {}, ...rest } = options;
const apiUrl = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3001'; 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 = { const fetchOptions: RequestInit = {
method, method,