notifications.ts 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import type { Fetcher } from 'swr'
  2. import { get, post } from './base'
  3. export type Notification = {
  4. id: string
  5. type: string
  6. title: string
  7. content: string
  8. sender_id: string
  9. sender_name: string
  10. dataset_id: string
  11. dataset_name: string
  12. segment_id: string
  13. segment_preview: string
  14. link_url: string
  15. is_read: boolean
  16. created_at: string
  17. }
  18. export type NotificationListResponse = {
  19. notifications: Notification[]
  20. unread_count: number
  21. total: number
  22. }
  23. export type UnreadCountResponse = {
  24. unread_count: number
  25. }
  26. export type MarkAsReadRequest = {
  27. notification_ids?: string[]
  28. mark_all_as_read?: boolean
  29. }
  30. export const fetchNotifications: Fetcher<NotificationListResponse, string> = (url) => {
  31. return get<NotificationListResponse>(url)
  32. }
  33. export const fetchUnreadCount: Fetcher<UnreadCountResponse, string> = (url) => {
  34. return get<UnreadCountResponse>(url)
  35. }
  36. export const markNotificationsAsRead = (data: MarkAsReadRequest) => {
  37. return post<{ result: string }>('/datasets/notifications', { body: data })
  38. }