lets hope this doesn't break stuff
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user