feat(phase-18): add in-app notification system (T-128, T-129)
This commit is contained in:
51
frontend/src/api/notifications.ts
Normal file
51
frontend/src/api/notifications.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import client from "./client";
|
||||
|
||||
// ── Types ───────────────────────────────────────────────────────────
|
||||
|
||||
export interface NotificationItem {
|
||||
id: string;
|
||||
user_id: string;
|
||||
type: string;
|
||||
title: string;
|
||||
message: string | null;
|
||||
entity_type: string | null;
|
||||
entity_id: string | null;
|
||||
read: boolean;
|
||||
created_at: string | null;
|
||||
}
|
||||
|
||||
export interface UnreadCount {
|
||||
unread_count: number;
|
||||
}
|
||||
|
||||
// ── API ─────────────────────────────────────────────────────────────
|
||||
|
||||
/** Fetch notifications for the current user (paginated). */
|
||||
export async function getNotifications(
|
||||
offset = 0,
|
||||
limit = 20,
|
||||
): Promise<NotificationItem[]> {
|
||||
const { data } = await client.get<NotificationItem[]>(
|
||||
`/notifications?offset=${offset}&limit=${limit}`,
|
||||
);
|
||||
return data;
|
||||
}
|
||||
|
||||
/** Get the unread notification count. */
|
||||
export async function getUnreadCount(): Promise<UnreadCount> {
|
||||
const { data } = await client.get<UnreadCount>("/notifications/unread-count");
|
||||
return data;
|
||||
}
|
||||
|
||||
/** Mark a single notification as read. */
|
||||
export async function markAsRead(id: string): Promise<NotificationItem> {
|
||||
const { data } = await client.patch<NotificationItem>(
|
||||
`/notifications/${id}/read`,
|
||||
);
|
||||
return data;
|
||||
}
|
||||
|
||||
/** Mark all notifications as read. */
|
||||
export async function markAllAsRead(): Promise<void> {
|
||||
await client.post("/notifications/read-all");
|
||||
}
|
||||
Reference in New Issue
Block a user