- Introduce SUPER_ADMIN, ADMIN, CUSTOMER_SUPPORT with admin-roles helpers and useAdminRole hook - New pages: subscription transactions, system members, issues, FAQ & support, notification broadcast - Services and API paths for admin subscription-transactions, system-members, issues, faq, broadcast - Nav and quick search filtered by role; login accepts all panel roles Made-with: Cursor
150 lines
3.7 KiB
TypeScript
150 lines
3.7 KiB
TypeScript
import apiClient from './api/client'
|
|
|
|
export interface Notification {
|
|
id: string
|
|
title: string
|
|
message: string
|
|
type: 'system' | 'user' | 'alert' | 'invoice' | 'payment'
|
|
recipient: string
|
|
status: 'sent' | 'delivered' | 'read' | 'unread'
|
|
isRead: boolean
|
|
createdAt: string
|
|
sentAt?: string
|
|
readAt?: string
|
|
}
|
|
|
|
export interface NotificationSettings {
|
|
emailNotifications: boolean
|
|
pushNotifications: boolean
|
|
invoiceReminders: boolean
|
|
paymentAlerts: boolean
|
|
systemUpdates: boolean
|
|
}
|
|
|
|
class NotificationService {
|
|
/**
|
|
* Get all notifications for current user
|
|
*/
|
|
async getNotifications(params?: {
|
|
type?: string
|
|
status?: string
|
|
search?: string
|
|
}): Promise<Notification[]> {
|
|
const response = await apiClient.get<Notification[]>('/notifications', {
|
|
params,
|
|
})
|
|
return response.data
|
|
}
|
|
|
|
/**
|
|
* Get unread notification count
|
|
*/
|
|
async getUnreadCount(): Promise<number> {
|
|
const response = await apiClient.get<{ count: number }>('/notifications/unread-count')
|
|
return response.data.count
|
|
}
|
|
|
|
/**
|
|
* Mark notification as read
|
|
*/
|
|
async markAsRead(id: string): Promise<void> {
|
|
await apiClient.post(`/notifications/${id}/read`)
|
|
}
|
|
|
|
/**
|
|
* Mark all notifications as read
|
|
*/
|
|
async markAllAsRead(): Promise<void> {
|
|
await apiClient.post('/notifications/read-all')
|
|
}
|
|
|
|
/**
|
|
* Broadcast push, SMS, and/or email (Super Admin & Admin only)
|
|
*/
|
|
async sendBroadcast(data: {
|
|
title: string
|
|
message: string
|
|
channels: ('push' | 'sms' | 'email')[]
|
|
audience?: 'all_end_users' | 'system_users_only' | 'everyone_with_access'
|
|
}): Promise<{ id: string }> {
|
|
const response = await apiClient.post<{ id: string }>(
|
|
'/admin/notifications/broadcast',
|
|
data,
|
|
)
|
|
return response.data
|
|
}
|
|
|
|
/**
|
|
* Send notification (ADMIN only)
|
|
*/
|
|
async sendNotification(data: {
|
|
title: string
|
|
message: string
|
|
type: string
|
|
recipient?: string
|
|
recipientType?: 'user' | 'all'
|
|
}): Promise<Notification> {
|
|
const response = await apiClient.post<Notification>('/notifications/send', data)
|
|
return response.data
|
|
}
|
|
|
|
/**
|
|
* Subscribe to push notifications
|
|
*/
|
|
async subscribeToPush(subscription: PushSubscription): Promise<void> {
|
|
await apiClient.post('/notifications/subscribe', subscription)
|
|
}
|
|
|
|
/**
|
|
* Unsubscribe from push notifications
|
|
*/
|
|
async unsubscribeFromPush(endpoint: string): Promise<void> {
|
|
await apiClient.delete(`/notifications/unsubscribe/${encodeURIComponent(endpoint)}`)
|
|
}
|
|
|
|
/**
|
|
* Get notification settings
|
|
*/
|
|
async getSettings(): Promise<NotificationSettings> {
|
|
const response = await apiClient.get<NotificationSettings>('/notifications/settings')
|
|
return response.data
|
|
}
|
|
|
|
/**
|
|
* Update notification settings
|
|
*/
|
|
async updateSettings(settings: Partial<NotificationSettings>): Promise<NotificationSettings> {
|
|
const response = await apiClient.put<NotificationSettings>('/notifications/settings', settings)
|
|
return response.data
|
|
}
|
|
|
|
/**
|
|
* Send invoice reminder
|
|
*/
|
|
async sendInvoiceReminder(invoiceId: string): Promise<void> {
|
|
await apiClient.post(`/notifications/invoice/${invoiceId}/reminder`)
|
|
}
|
|
|
|
/**
|
|
* Export notifications (creates CSV from current data)
|
|
*/
|
|
async exportNotifications(notifications: Notification[]): Promise<Blob> {
|
|
const csvContent = [
|
|
['ID', 'Title', 'Message', 'Type', 'Status', 'Created Date', 'Read Date'],
|
|
...notifications.map(n => [
|
|
n.id,
|
|
n.title,
|
|
n.message,
|
|
n.type,
|
|
n.status,
|
|
n.createdAt,
|
|
n.readAt || '-'
|
|
])
|
|
].map(row => row.join(',')).join('\n')
|
|
|
|
return new Blob([csvContent], { type: 'text/csv;charset=utf-8;' })
|
|
}
|
|
}
|
|
|
|
export const notificationService = new NotificationService()
|