Files
smoothschedule/frontend/src/api/notifications.ts
poduck 4cd6610f2a Fix double /api/ prefix in API endpoint calls
When VITE_API_URL=/api, axios baseURL is already set to /api. However, all endpoint calls included the /api/ prefix, creating double paths like /api/api/auth/login/.

Removed /api/ prefix from 81 API endpoint calls across 22 files:
- src/api/auth.ts - Fixed login, logout, me, refresh, hijack endpoints
- src/api/client.ts - Fixed token refresh endpoint
- src/api/profile.ts - Fixed all profile, email, password, MFA, sessions endpoints
- src/hooks/*.ts - Fixed all remaining API calls (users, appointments, resources, etc)
- src/pages/*.tsx - Fixed signup and email verification endpoints

This ensures API requests use the correct path: /api/auth/login/ instead of /api/api/auth/login/

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-30 15:27:57 -05:00

65 lines
1.7 KiB
TypeScript

import apiClient from './client';
export interface Notification {
id: number;
verb: string;
read: boolean;
timestamp: string;
data: Record<string, any>;
actor_type: string | null;
actor_display: string | null;
target_type: string | null;
target_display: string | null;
target_url: string | null;
}
export interface UnreadCountResponse {
count: number;
}
/**
* Get all notifications for the current user
*/
export const getNotifications = async (params?: { read?: boolean; limit?: number }): Promise<Notification[]> => {
const queryParams = new URLSearchParams();
if (params?.read !== undefined) {
queryParams.append('read', String(params.read));
}
if (params?.limit !== undefined) {
queryParams.append('limit', String(params.limit));
}
const query = queryParams.toString();
const url = query ? `/notifications/?${query}` : '/notifications/';
const response = await apiClient.get(url);
return response.data;
};
/**
* Get count of unread notifications
*/
export const getUnreadCount = async (): Promise<number> => {
const response = await apiClient.get<UnreadCountResponse>('/notifications/unread_count/');
return response.data.count;
};
/**
* Mark a single notification as read
*/
export const markNotificationRead = async (id: number): Promise<void> => {
await apiClient.post(`/notifications/${id}/mark_read/`);
};
/**
* Mark all notifications as read
*/
export const markAllNotificationsRead = async (): Promise<void> => {
await apiClient.post('/notifications/mark_all_read/');
};
/**
* Delete all read notifications
*/
export const clearAllNotifications = async (): Promise<void> => {
await apiClient.delete('/notifications/clear_all/');
};