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();
}, []);
async function loadPromotions() {
const loadPromotions = async () => {
setLoading(true);
try {
const response = await fetchClient<Promotion[]>('/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);

View File

@@ -18,7 +18,10 @@ export async function fetchClient<T>(
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,