add campaign observability page
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 43s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 43s
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import type { OrderData, StockData } from './types';
|
||||
import type { CampaignPreview, CampaignProcessSummary, CampaignQueueSummary, OrderData, StockData } from './types';
|
||||
|
||||
const API_URL = import.meta.env.VITE_API_URL || '/api';
|
||||
|
||||
@@ -72,6 +72,74 @@ export const fetchData = async (): Promise<OrderData[]> => {
|
||||
}
|
||||
};
|
||||
|
||||
const authFetch = async (path: string, options: RequestInit = {}): Promise<Response> => {
|
||||
const token = localStorage.getItem('auth_token');
|
||||
const response = await fetch(`${API_URL}${path}`, {
|
||||
...options,
|
||||
headers: {
|
||||
...(options.headers || {}),
|
||||
'Authorization': `Bearer ${token}`
|
||||
}
|
||||
});
|
||||
|
||||
if (response.status === 401 || response.status === 403) {
|
||||
logout();
|
||||
}
|
||||
|
||||
return response;
|
||||
};
|
||||
|
||||
export const fetchCampaigns = async (): Promise<CampaignQueueSummary | null> => {
|
||||
try {
|
||||
const response = await authFetch('/campaigns');
|
||||
if (!response.ok) return null;
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error('Fetch campaigns failed', error);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
export const fetchCampaignPreview = async (): Promise<CampaignPreview | null> => {
|
||||
try {
|
||||
const response = await authFetch('/campaigns/preview');
|
||||
if (!response.ok) return null;
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error('Fetch campaign preview failed', error);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
export const processCampaignsNow = async (): Promise<CampaignProcessSummary | null> => {
|
||||
try {
|
||||
const response = await authFetch('/campaigns/process', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({})
|
||||
});
|
||||
if (!response.ok) return null;
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error('Process campaigns failed', error);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
export const retryCampaignGroup = async (baseProductName: string): Promise<boolean> => {
|
||||
try {
|
||||
const response = await authFetch('/campaigns/retry', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ baseProductName })
|
||||
});
|
||||
return response.ok;
|
||||
} catch (error) {
|
||||
console.error('Retry campaign failed', error);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
export const parseOrderDate = (dateStr: string): Date => {
|
||||
if (!dateStr) return new Date(0);
|
||||
if (dateStr.includes('T')) return new Date(dateStr);
|
||||
|
||||
Reference in New Issue
Block a user