- Added image cropping functionality in CreateSubscriptionPage and EditSubscriptionPage. - Updated price input to handle decimal values and formatting. - Improved UI elements for image upload sections, including better messaging and styling. - Refactored affiliate links page to fetch data from an API and handle loading/error states. - Added Affiliate Management button in the header for easier navigation.
35 lines
831 B
TypeScript
35 lines
831 B
TypeScript
import { authFetch } from '../../../utils/authFetch';
|
|
|
|
export async function deleteAffiliate(id: string) {
|
|
const BASE_URL = process.env.NEXT_PUBLIC_API_BASE_URL || 'http://localhost:3001';
|
|
const url = `${BASE_URL}/api/admin/affiliates/${id}`;
|
|
const res = await authFetch(url, {
|
|
method: 'DELETE',
|
|
headers: {
|
|
Accept: 'application/json',
|
|
},
|
|
});
|
|
|
|
let body: any = null;
|
|
try {
|
|
body = await res.json();
|
|
} catch {
|
|
body = null;
|
|
}
|
|
|
|
const ok = res.ok;
|
|
const message =
|
|
body?.message ||
|
|
(res.status === 404
|
|
? 'Affiliate not found.'
|
|
: res.status === 403
|
|
? 'Forbidden.'
|
|
: res.status === 500
|
|
? 'Server error.'
|
|
: !ok
|
|
? `Request failed (${res.status}).`
|
|
: 'Affiliate deleted successfully.');
|
|
|
|
return { ok, status: res.status, body, message };
|
|
}
|