feat: notifikasi real-time bug baru via WebSocket

- presence.ts: tambah notifSubs (ADMIN+DEVELOPER) dan broadcastNotification
- app.ts: broadcast new_bug event setelah bug dibuat, update WS handler
- usePresence: terima callback onNewBug, expose NewBugPayload type
- DashboardLayout: pasang usePresence, tampilkan Mantine notification saat bug baru masuk
This commit is contained in:
2026-05-25 11:35:21 +08:00
parent 8c33003b17
commit e32addbc85
4 changed files with 61 additions and 5 deletions

View File

@@ -8,7 +8,7 @@ import { prisma } from './lib/db'
import { env } from './lib/env'
import { createSystemLog } from './lib/logger'
import { getMinioDownloadUrl, uploadBugImage } from './lib/minio'
import { addConnection, broadcastToAdmins, getOnlineUserIds, removeConnection } from './lib/presence'
import { addConnection, broadcastNotification, broadcastToAdmins, getOnlineUserIds, removeConnection } from './lib/presence'
import { parseSchema } from './lib/schema-parser'
const isProduction = process.env.NODE_ENV === 'production'
@@ -921,6 +921,18 @@ export function createApp() {
},
})
broadcastNotification({
type: 'new_bug',
bug: {
id: bug.id,
description: bug.description,
appId: bug.appId,
source: bug.source,
affectedVersion: bug.affectedVersion,
createdAt: bug.createdAt,
},
})
return bug
}, {
body: t.Object({
@@ -1241,9 +1253,11 @@ export function createApp() {
include: { user: { select: { id: true, role: true } } },
})
if (!session || session.expiresAt < new Date()) { ws.close(4001, 'Unauthorized'); return }
const isAdmin = session.user.role === 'DEVELOPER'
const role = session.user.role
const isAdmin = role === 'DEVELOPER'
const canReceiveNotifs = role === 'DEVELOPER' || role === 'ADMIN'
;(ws.data as unknown as { userId: string }).userId = session.user.id
addConnection(ws as any, session.user.id, isAdmin)
addConnection(ws as any, session.user.id, isAdmin, canReceiveNotifs)
},
close(ws) { removeConnection(ws as any) },
message() {},