mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-19 14:16:29 +00:00
Merge pull request #38 from shumaiOne/feat/improve-notification-system
feat(notification): improve notification system and settings toggles
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest'
|
||||
import { Hono, type Context, type Next } from 'hono'
|
||||
import { prisma } from '@/db'
|
||||
import fileRoute from './file'
|
||||
import { assetService } from '@/services/asset/asset'
|
||||
import { metadataService } from '@/services/metadata/metadata'
|
||||
@@ -202,6 +203,60 @@ describe('file api', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('POST /files/:fileId/comments - reply_created targets parent comment creator', async () => {
|
||||
vi.mocked(assetService.createComment).mockResolvedValue({
|
||||
id: 'comment-id',
|
||||
assetId: 'file-id',
|
||||
message: 'hello reply',
|
||||
annotations: null,
|
||||
second: null,
|
||||
creator: { id: 'user-id', name: 'Test User' },
|
||||
replies: [],
|
||||
attachments: [],
|
||||
mentions: [],
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
sessionId: null,
|
||||
})
|
||||
|
||||
// Mock assetService.getAsset to return teamId for notification
|
||||
vi.mocked(assetService.getAsset).mockResolvedValue({
|
||||
id: 'test-id',
|
||||
project: { teamId: 'test-team' },
|
||||
} as any) // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
|
||||
const mockFindUnique = vi.spyOn(prisma.assetComment, 'findUnique').mockResolvedValue({
|
||||
id: 'parent-comment-id',
|
||||
creatorId: 'parent-comment-creator-id',
|
||||
} as any) // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
|
||||
const app = new Hono().use('*', authMiddleware).route('/', fileRoute)
|
||||
const res = await app.request('/files/test-id/comments', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
message: 'hello reply',
|
||||
replyToId: 'parent-comment-id',
|
||||
attachmentIds: [],
|
||||
}),
|
||||
})
|
||||
|
||||
expect(res.status).toBe(201)
|
||||
const json = await res.json()
|
||||
expect(json.message).toBe('hello reply')
|
||||
|
||||
expect(notificationService.create).toHaveBeenCalledWith({
|
||||
type: 'reply_created',
|
||||
teamId: 'test-team',
|
||||
creatorId: 'user1',
|
||||
assetId: 'test-id',
|
||||
userId: 'parent-comment-creator-id',
|
||||
commentMessage: 'hello reply',
|
||||
})
|
||||
|
||||
mockFindUnique.mockRestore()
|
||||
})
|
||||
|
||||
it('GET /files/:fileId/comments', async () => {
|
||||
vi.mocked(assetService.listComments).mockResolvedValue({
|
||||
data: [
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Hono } from 'hono'
|
||||
import { zValidator } from '@hono/zod-validator'
|
||||
import { prisma } from '@/db'
|
||||
import { authzService, Permission, ResourceType } from '@/services/authz/authz'
|
||||
import { assetService } from '@/services/asset/asset'
|
||||
import { metadataService } from '@/services/metadata/metadata'
|
||||
@@ -156,11 +157,22 @@ const route = new Hono<{ Variables: { user: User } }>()
|
||||
const context = await assetService.getAssetContext(fileId)
|
||||
|
||||
if (context?.teamId) {
|
||||
let targetUserId: string | undefined
|
||||
if (req.replyToId) {
|
||||
const parentComment = await prisma.assetComment.findUnique({
|
||||
where: { id: req.replyToId },
|
||||
})
|
||||
if (parentComment?.creatorId) {
|
||||
targetUserId = parentComment.creatorId
|
||||
}
|
||||
}
|
||||
|
||||
notificationService.create({
|
||||
type: notifType,
|
||||
teamId: context.teamId,
|
||||
creatorId: user.id,
|
||||
assetId: fileId,
|
||||
userId: targetUserId,
|
||||
commentMessage: req.message,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Hono, type Context, type Next } from 'hono'
|
||||
import notificationRoute from './notification'
|
||||
import { notificationService } from '@/services/notification/notification'
|
||||
import { authzService, Permission, ResourceType } from '@/services/authz/authz'
|
||||
import { userMetadataService } from '@/services/user-metadata/user-metadata'
|
||||
|
||||
vi.mock('@/api/middleware/auth', () => ({
|
||||
authMiddleware: async (
|
||||
@@ -16,6 +17,7 @@ vi.mock('@/api/middleware/auth', () => ({
|
||||
|
||||
vi.mock('@/services/authz/authz')
|
||||
vi.mock('@/services/notification/notification')
|
||||
vi.mock('@/services/user-metadata/user-metadata')
|
||||
|
||||
describe('notification api', () => {
|
||||
const app = new Hono<{ Variables: { user: { id: string; name: string } } }>()
|
||||
@@ -77,4 +79,78 @@ describe('notification api', () => {
|
||||
id: 't1',
|
||||
})
|
||||
})
|
||||
|
||||
it('GET /teams/:teamId/notifications/settings - returns default settings', async () => {
|
||||
vi.mocked(userMetadataService.getMetadata).mockResolvedValue(null)
|
||||
|
||||
const res = await app.request('/teams/t1/notifications/settings')
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
const json = await res.json()
|
||||
expect(json.comments).toBe(true)
|
||||
expect(json.yourUploads).toBe(false)
|
||||
|
||||
expect(userMetadataService.getMetadata).toHaveBeenCalledWith(
|
||||
'user1',
|
||||
't1',
|
||||
'notification_settings',
|
||||
)
|
||||
})
|
||||
|
||||
it('GET /teams/:teamId/notifications/settings - returns saved settings', async () => {
|
||||
vi.mocked(userMetadataService.getMetadata).mockResolvedValue({
|
||||
key: 'notification_settings',
|
||||
value: {
|
||||
comments: false,
|
||||
replies: false,
|
||||
mentions: true,
|
||||
yourUploads: true,
|
||||
otherUploads: false,
|
||||
statusUpdates: true,
|
||||
},
|
||||
})
|
||||
|
||||
const res = await app.request('/teams/t1/notifications/settings')
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
const json = await res.json()
|
||||
expect(json.comments).toBe(false)
|
||||
expect(json.yourUploads).toBe(true)
|
||||
})
|
||||
|
||||
it('POST /teams/:teamId/notifications/settings - saves settings', async () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
vi.mocked(userMetadataService.upsertMetadata).mockResolvedValue(undefined as any)
|
||||
|
||||
const res = await app.request('/teams/t1/notifications/settings', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
comments: false,
|
||||
replies: false,
|
||||
mentions: true,
|
||||
yourUploads: true,
|
||||
otherUploads: false,
|
||||
statusUpdates: true,
|
||||
}),
|
||||
})
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
const json = await res.json()
|
||||
expect(json.success).toBe(true)
|
||||
|
||||
expect(userMetadataService.upsertMetadata).toHaveBeenCalledWith(
|
||||
'user1',
|
||||
't1',
|
||||
'notification_settings',
|
||||
{
|
||||
comments: false,
|
||||
replies: false,
|
||||
mentions: true,
|
||||
yourUploads: true,
|
||||
otherUploads: false,
|
||||
statusUpdates: true,
|
||||
},
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -5,7 +5,9 @@ import { authzService, Permission, ResourceType } from '@/services/authz/authz'
|
||||
import {
|
||||
listNotificationsRequestSchema,
|
||||
markNotificationReadRequestSchema,
|
||||
notificationSettingsSchema,
|
||||
} from '@/dtos/notification'
|
||||
import { userMetadataService } from '@/services/user-metadata/user-metadata'
|
||||
import type { Prisma } from '@/generated/prisma/client'
|
||||
|
||||
type User = Prisma.UserGetPayload<Record<string, never>>
|
||||
@@ -62,5 +64,50 @@ const route = new Hono<{ Variables: { user: User } }>()
|
||||
return new Response(null, { status: 204 })
|
||||
},
|
||||
)
|
||||
.get('/teams/:teamId/notifications/settings', async (c) => {
|
||||
const teamId = c.req.param('teamId')
|
||||
const user = c.get('user')
|
||||
|
||||
await authzService.hasPermission({
|
||||
user,
|
||||
permission: Permission.Read,
|
||||
type: ResourceType.Team,
|
||||
id: teamId,
|
||||
})
|
||||
|
||||
const metadata = await userMetadataService.getMetadata(user.id, teamId, 'notification_settings')
|
||||
const settings = metadata
|
||||
? metadata.value
|
||||
: {
|
||||
comments: true,
|
||||
replies: true,
|
||||
mentions: true,
|
||||
yourUploads: false,
|
||||
otherUploads: true,
|
||||
statusUpdates: true,
|
||||
}
|
||||
|
||||
return c.json(settings)
|
||||
})
|
||||
.post(
|
||||
'/teams/:teamId/notifications/settings',
|
||||
zValidator('json', notificationSettingsSchema),
|
||||
async (c) => {
|
||||
const teamId = c.req.param('teamId')
|
||||
const user = c.get('user')
|
||||
const req = c.req.valid('json')
|
||||
|
||||
await authzService.hasPermission({
|
||||
user,
|
||||
permission: Permission.Read,
|
||||
type: ResourceType.Team,
|
||||
id: teamId,
|
||||
})
|
||||
|
||||
await userMetadataService.upsertMetadata(user.id, teamId, 'notification_settings', req)
|
||||
|
||||
return c.json({ success: true })
|
||||
},
|
||||
)
|
||||
|
||||
export default route
|
||||
|
||||
@@ -110,8 +110,8 @@ describe('Upload API', () => {
|
||||
expect(res.status).toBe(200)
|
||||
expect(authzService.hasPermission).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
type: ResourceType.Team,
|
||||
id: 'team1',
|
||||
type: ResourceType.Asset,
|
||||
id: 'file1',
|
||||
permission: Permission.Edit,
|
||||
}),
|
||||
)
|
||||
|
||||
+2
-2
@@ -92,8 +92,8 @@ const route = new Hono<{ Variables: { user: User } }>()
|
||||
await authzService.hasPermission({
|
||||
user,
|
||||
permission: Permission.Edit,
|
||||
type: ResourceType.Team,
|
||||
id: teamId,
|
||||
type: ResourceType.Asset,
|
||||
id: req.fileId,
|
||||
})
|
||||
|
||||
await uploadService.confirmFileUpload(user.id, taskId, req)
|
||||
|
||||
@@ -73,3 +73,14 @@ export interface ListNotificationParams {
|
||||
after?: string
|
||||
pageSize?: number
|
||||
}
|
||||
|
||||
export const notificationSettingsSchema = z.object({
|
||||
comments: z.boolean().default(true),
|
||||
replies: z.boolean().default(true),
|
||||
mentions: z.boolean().default(true),
|
||||
yourUploads: z.boolean().default(false),
|
||||
otherUploads: z.boolean().default(true),
|
||||
statusUpdates: z.boolean().default(true),
|
||||
})
|
||||
|
||||
export type NotificationSettings = z.infer<typeof notificationSettingsSchema>
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ import { paginationPageInfoSchema, paginationParamsSchema } from './pagination'
|
||||
export const createProjectRequestSchema = z.object({
|
||||
name: z.string(),
|
||||
coverImageKey: z.string().optional(),
|
||||
enableNotification: z.boolean().default(false),
|
||||
enableNotification: z.boolean().default(true),
|
||||
})
|
||||
export type CreateProjectRequest = z.infer<typeof createProjectRequestSchema>
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ export const getMeResponseSchema = z.object({
|
||||
name: z.string(),
|
||||
email: z.string().optional(),
|
||||
role: z.string(),
|
||||
unreadNotificationCount: z.number().optional(),
|
||||
})
|
||||
export type GetMeResponse = z.infer<typeof getMeResponseSchema>
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import { prisma } from '@/db'
|
||||
import { setupTestDbHooks } from '@/db-test-hooks'
|
||||
import { NotificationType } from '@/generated/prisma/client'
|
||||
import { notificationService } from './notification'
|
||||
import { userMetadataService } from '@/services/user-metadata/user-metadata'
|
||||
|
||||
describe('NotificationService', () => {
|
||||
setupTestDbHooks()
|
||||
@@ -247,4 +248,118 @@ describe('NotificationService', () => {
|
||||
const p2Notification = res.data.find((n) => n.id === '002')
|
||||
expect(p2Notification).toBeUndefined()
|
||||
})
|
||||
|
||||
it('Respects user metadata notification settings', async () => {
|
||||
const tm = await prisma.team.create({ data: { name: 'Team 1' } })
|
||||
const u1 = await prisma.user.create({
|
||||
data: { name: 'u1', email: `u1-${Date.now()}@example.com`, password: 'p' },
|
||||
})
|
||||
const u2 = await prisma.user.create({
|
||||
data: { name: 'u2', email: `u2-${Date.now()}@example.com`, password: 'p' },
|
||||
})
|
||||
await prisma.teamMember.create({
|
||||
data: { teamId: tm.id, userId: u1.id, role: 'owner' },
|
||||
})
|
||||
|
||||
// Create comments, replies, mentions, uploads, etc.
|
||||
const commentNotif = await prisma.notification.create({
|
||||
data: { id: '001', teamId: tm.id, type: NotificationType.comment_created },
|
||||
})
|
||||
const replyNotif = await prisma.notification.create({
|
||||
data: { id: '002', teamId: tm.id, type: NotificationType.reply_created, userId: u1.id },
|
||||
})
|
||||
const uploadNotifOther = await prisma.notification.create({
|
||||
data: {
|
||||
id: '003',
|
||||
teamId: tm.id,
|
||||
type: NotificationType.successful_file_uploaded,
|
||||
creatorId: u2.id,
|
||||
},
|
||||
})
|
||||
const uploadNotifSelf = await prisma.notification.create({
|
||||
data: {
|
||||
id: '004',
|
||||
teamId: tm.id,
|
||||
type: NotificationType.successful_file_uploaded,
|
||||
creatorId: u1.id,
|
||||
},
|
||||
})
|
||||
|
||||
const svc = notificationService
|
||||
|
||||
// Default settings: comments=true, replies=true, mentions=true, yourUploads=false, otherUploads=true
|
||||
const resDefault = await svc.list(tm.id, u1.id, {})
|
||||
expect(resDefault.data.some((n) => n.id === commentNotif.id)).toBe(true)
|
||||
expect(resDefault.data.some((n) => n.id === replyNotif.id)).toBe(true)
|
||||
expect(resDefault.data.some((n) => n.id === uploadNotifOther.id)).toBe(true)
|
||||
expect(resDefault.data.some((n) => n.id === uploadNotifSelf.id)).toBe(false) // yourUploads is false by default
|
||||
|
||||
// Disable comments and replies, but enable yourUploads
|
||||
await userMetadataService.upsertMetadata(u1.id, tm.id, 'notification_settings', {
|
||||
comments: false,
|
||||
replies: false,
|
||||
mentions: true,
|
||||
yourUploads: true,
|
||||
otherUploads: false,
|
||||
statusUpdates: true,
|
||||
})
|
||||
|
||||
const resCustom = await svc.list(tm.id, u1.id, {})
|
||||
expect(resCustom.data.some((n) => n.id === commentNotif.id)).toBe(false)
|
||||
expect(resCustom.data.some((n) => n.id === replyNotif.id)).toBe(false)
|
||||
expect(resCustom.data.some((n) => n.id === uploadNotifOther.id)).toBe(false) // otherUploads is now false
|
||||
expect(resCustom.data.some((n) => n.id === uploadNotifSelf.id)).toBe(true) // yourUploads is now true
|
||||
})
|
||||
|
||||
it('getUnreadCount retrieves correct count of unread notifications', async () => {
|
||||
const tm = await prisma.team.create({ data: { name: 'Team 2' } })
|
||||
const u1 = await prisma.user.create({
|
||||
data: { name: 'u3', email: `u3-${Date.now()}@example.com`, password: 'p' },
|
||||
})
|
||||
const u2 = await prisma.user.create({
|
||||
data: { name: 'u4', email: `u4-${Date.now()}@example.com`, password: 'p' },
|
||||
})
|
||||
const member = await prisma.teamMember.create({
|
||||
data: { teamId: tm.id, userId: u1.id, role: 'owner' },
|
||||
})
|
||||
|
||||
// No notifications initially
|
||||
let count = await notificationService.getUnreadCount(tm.id, u1.id)
|
||||
expect(count).toBe(0)
|
||||
|
||||
// Create unread notifications from other user
|
||||
const n1 = await prisma.notification.create({
|
||||
data: { id: '101', teamId: tm.id, type: NotificationType.comment_created, creatorId: u2.id },
|
||||
})
|
||||
const n2 = await prisma.notification.create({
|
||||
data: {
|
||||
id: '102',
|
||||
teamId: tm.id,
|
||||
type: NotificationType.reply_created,
|
||||
userId: u1.id,
|
||||
creatorId: u2.id,
|
||||
},
|
||||
})
|
||||
|
||||
count = await notificationService.getUnreadCount(tm.id, u1.id)
|
||||
expect(count).toBe(2)
|
||||
|
||||
// Mark up to n1 as read
|
||||
await prisma.teamMember.update({
|
||||
where: { id: member.id },
|
||||
data: { lastReadNotificationId: n1.id },
|
||||
})
|
||||
|
||||
count = await notificationService.getUnreadCount(tm.id, u1.id)
|
||||
expect(count).toBe(1) // n2 is still unread
|
||||
|
||||
// Mark all as read (up to n2)
|
||||
await prisma.teamMember.update({
|
||||
where: { id: member.id },
|
||||
data: { lastReadNotificationId: n2.id },
|
||||
})
|
||||
|
||||
count = await notificationService.getUnreadCount(tm.id, u1.id)
|
||||
expect(count).toBe(0)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -5,10 +5,12 @@ import {
|
||||
NotificationInfo,
|
||||
CreateNotificationRequest,
|
||||
ListNotificationParams,
|
||||
NotificationSettings,
|
||||
} from '@/dtos/notification'
|
||||
import { paginateQuery, PaginatedData } from '@/services/pagination'
|
||||
import '@/prisma-json-types'
|
||||
import { s3Service } from '@/services/s3/s3'
|
||||
import { userMetadataService } from '@/services/user-metadata/user-metadata'
|
||||
|
||||
const mentionRegex = /<@([^>]+)>/g
|
||||
|
||||
@@ -95,6 +97,142 @@ export class NotificationService {
|
||||
}
|
||||
}
|
||||
|
||||
private async getListWhere(
|
||||
teamId: string,
|
||||
userId: string,
|
||||
teamMember: Prisma.TeamMemberGetPayload<{ include: { lastReadNotification: true } }>,
|
||||
unreadOnly: boolean,
|
||||
): Promise<Prisma.NotificationWhereInput> {
|
||||
// Permission Filtering based on Scope
|
||||
let projectFilter: string[] = []
|
||||
if (teamMember.scope === 'project') {
|
||||
const pms = await prisma.projectMember.findMany({
|
||||
where: { teamMemberId: teamMember.id },
|
||||
include: { project: true },
|
||||
})
|
||||
projectFilter = pms.filter((pm) => pm.project).map((pm) => pm.projectId)
|
||||
}
|
||||
|
||||
// Load notification settings
|
||||
const settingsMeta = await userMetadataService.getMetadata(
|
||||
userId,
|
||||
teamId,
|
||||
'notification_settings',
|
||||
)
|
||||
const settings: NotificationSettings = settingsMeta
|
||||
? (settingsMeta.value as NotificationSettings)
|
||||
: {
|
||||
comments: true,
|
||||
replies: true,
|
||||
mentions: true,
|
||||
yourUploads: false,
|
||||
otherUploads: true,
|
||||
statusUpdates: true,
|
||||
}
|
||||
|
||||
const typeConditions: Prisma.NotificationWhereInput[] = []
|
||||
|
||||
// 1. Comments
|
||||
if (settings.comments) {
|
||||
typeConditions.push({ type: NotificationType.comment_created, userId: null })
|
||||
}
|
||||
|
||||
// 2. Replies
|
||||
if (settings.replies) {
|
||||
typeConditions.push({ type: NotificationType.reply_created, userId: userId })
|
||||
typeConditions.push({ type: NotificationType.reply_created, userId: null })
|
||||
}
|
||||
|
||||
// 3. Mentions
|
||||
if (settings.mentions) {
|
||||
typeConditions.push({ type: NotificationType.mention, userId: userId })
|
||||
}
|
||||
|
||||
// 4. Uploads
|
||||
if (settings.yourUploads && settings.otherUploads) {
|
||||
typeConditions.push({ type: NotificationType.successful_file_uploaded })
|
||||
} else if (settings.yourUploads) {
|
||||
typeConditions.push({ type: NotificationType.successful_file_uploaded, creatorId: userId })
|
||||
} else if (settings.otherUploads) {
|
||||
typeConditions.push({
|
||||
type: NotificationType.successful_file_uploaded,
|
||||
creatorId: { not: userId },
|
||||
})
|
||||
}
|
||||
|
||||
// 5. Status Updates
|
||||
if (settings.statusUpdates) {
|
||||
typeConditions.push({ type: NotificationType.metadata_field_updated_status })
|
||||
}
|
||||
|
||||
// 6. Always include team/project join notifications
|
||||
typeConditions.push({ type: NotificationType.new_user_join_team })
|
||||
typeConditions.push({ type: NotificationType.new_user_join_project })
|
||||
|
||||
const where: Prisma.NotificationWhereInput = {
|
||||
teamId,
|
||||
OR: typeConditions,
|
||||
AND: [
|
||||
{
|
||||
OR: [
|
||||
...(settings.yourUploads
|
||||
? [{ type: NotificationType.successful_file_uploaded, creatorId: userId }]
|
||||
: []),
|
||||
{ creatorId: null },
|
||||
{ creatorId: { not: userId } },
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
if (teamMember.scope === 'project') {
|
||||
// Must be AND applied after the general rules
|
||||
const currentAnd = Array.isArray(where.AND) ? where.AND : where.AND ? [where.AND] : []
|
||||
where.AND = [
|
||||
...currentAnd,
|
||||
{
|
||||
OR: [
|
||||
{ type: NotificationType.mention }, // Always allow mentions (targeted)
|
||||
{ projectId: { in: projectFilter } }, // Only show notifications for projects user is member of
|
||||
],
|
||||
},
|
||||
] as Prisma.NotificationWhereInput[]
|
||||
}
|
||||
|
||||
if (unreadOnly && teamMember.lastReadNotification) {
|
||||
// We want notifications NEWER than the last read one.
|
||||
// String comparison works for ULID/KSUID.
|
||||
const currentAnd = Array.isArray(where.AND) ? where.AND : where.AND ? [where.AND] : []
|
||||
where.AND = [
|
||||
...currentAnd,
|
||||
{ id: { gt: teamMember.lastReadNotification.id } },
|
||||
] as Prisma.NotificationWhereInput[]
|
||||
}
|
||||
|
||||
return where
|
||||
}
|
||||
|
||||
async getUnreadCount(teamId: string, userId: string): Promise<number> {
|
||||
const teamMember = await prisma.teamMember.findUnique({
|
||||
where: {
|
||||
teamIdUserId: {
|
||||
teamId,
|
||||
userId,
|
||||
},
|
||||
},
|
||||
include: {
|
||||
lastReadNotification: true,
|
||||
},
|
||||
})
|
||||
|
||||
if (!teamMember) {
|
||||
return 0
|
||||
}
|
||||
|
||||
const where = await this.getListWhere(teamId, userId, teamMember, true)
|
||||
return prisma.notification.count({ where })
|
||||
}
|
||||
|
||||
async list(
|
||||
teamId: string,
|
||||
userId: string,
|
||||
@@ -117,48 +255,7 @@ export class NotificationService {
|
||||
throw new Error('failed to get team member')
|
||||
}
|
||||
|
||||
// Permission Filtering based on Scope
|
||||
let projectFilter: string[] = []
|
||||
if (teamMember.scope === 'project') {
|
||||
const pms = await prisma.projectMember.findMany({
|
||||
where: { teamMemberId: teamMember.id },
|
||||
include: { project: true },
|
||||
})
|
||||
projectFilter = pms.filter((pm) => pm.project).map((pm) => pm.projectId)
|
||||
}
|
||||
|
||||
const where: Prisma.NotificationWhereInput = {
|
||||
teamId,
|
||||
OR: [
|
||||
{ type: { not: NotificationType.mention } },
|
||||
{ type: NotificationType.mention, userId: userId },
|
||||
],
|
||||
AND: [{ OR: [{ creatorId: null }, { creatorId: { not: userId } }] }],
|
||||
}
|
||||
|
||||
if (teamMember.scope === 'project') {
|
||||
// Must be AND applied after the general rules
|
||||
const currentAnd = Array.isArray(where.AND) ? where.AND : where.AND ? [where.AND] : []
|
||||
where.AND = [
|
||||
...currentAnd,
|
||||
{
|
||||
OR: [
|
||||
{ type: NotificationType.mention }, // Always allow mentions (targeted)
|
||||
{ projectId: { in: projectFilter } }, // Only show notifications for projects user is member of
|
||||
],
|
||||
},
|
||||
] as Prisma.NotificationWhereInput[]
|
||||
}
|
||||
|
||||
if (params.unreadOnly && teamMember.lastReadNotification) {
|
||||
// We want notifications NEWER than the last read one.
|
||||
// String comparison works for ULID/KSUID.
|
||||
const currentAnd = Array.isArray(where.AND) ? where.AND : where.AND ? [where.AND] : []
|
||||
where.AND = [
|
||||
...currentAnd,
|
||||
{ id: { gt: teamMember.lastReadNotification.id } },
|
||||
] as Prisma.NotificationWhereInput[]
|
||||
}
|
||||
const where = await this.getListWhere(teamId, userId, teamMember, !!params.unreadOnly)
|
||||
|
||||
return paginateQuery<NotificationInfo>(
|
||||
async (skip, take) => {
|
||||
|
||||
@@ -32,7 +32,7 @@ export class ProjectService {
|
||||
data: {
|
||||
name: req.name,
|
||||
teamId: req.teamId,
|
||||
enableNotification: req.enableNotification || false,
|
||||
enableNotification: req.enableNotification ?? true,
|
||||
coverImageKey: req.coverImageKey,
|
||||
},
|
||||
})
|
||||
@@ -304,7 +304,7 @@ export class ProjectService {
|
||||
const pi: ProjectInfo = {
|
||||
id: p.id,
|
||||
name: p.name,
|
||||
enableNotification: p.enableNotification || false,
|
||||
enableNotification: p.enableNotification ?? true,
|
||||
coverImageKey: p.coverImageKey || undefined,
|
||||
updatedAt: p.updatedAt,
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { prisma } from '@/db'
|
||||
import { Prisma } from '@/generated/prisma/client'
|
||||
import { PaginatedData, paginateQuery } from '@/services/pagination'
|
||||
import { ProviderService, providerService } from '@/services/provider/provider'
|
||||
import { notificationService } from '@/services/notification/notification'
|
||||
import {
|
||||
ServiceCreateTeamRequest,
|
||||
ServiceGetUserTeamsRequest,
|
||||
@@ -138,11 +139,17 @@ export class TeamService {
|
||||
|
||||
if (!member) throw new Error('user is not a team member')
|
||||
|
||||
const unreadNotificationCount = await notificationService.getUnreadCount(
|
||||
req.teamId,
|
||||
req.user.id,
|
||||
)
|
||||
|
||||
return {
|
||||
id: req.user.id,
|
||||
name: req.user.name,
|
||||
email: undefined,
|
||||
role: member.role,
|
||||
unreadNotificationCount,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import { UserMenu } from './user-menu'
|
||||
interface DualSidebarItemProps {
|
||||
icon: React.ReactNode
|
||||
label: string
|
||||
badge?: React.ReactNode
|
||||
children?: React.ReactNode
|
||||
onItemClick?: () => void
|
||||
}
|
||||
@@ -113,13 +114,14 @@ export const DualSidebar: React.FC<DualSidebarProps> = ({ children }) => {
|
||||
onClick={() => handleItemClick(index)}
|
||||
aria-label={item.props.label}
|
||||
aria-expanded={activeItem === index}
|
||||
className={`w-12 h-12 [&_svg:not([class*='size-'])]:size-6 transition-all duration-200 ${
|
||||
className={`relative w-12 h-12 [&_svg:not([class*='size-'])]:size-6 transition-all duration-200 ${
|
||||
activeItem === index
|
||||
? 'bg-blue-600 text-white shadow-lg hover:bg-blue-600 hover:text-white'
|
||||
: 'text-slate-400 hover:text-slate-500 dark:hover:text-slate-400 dark:text-slate-500 hover:bg-slate-200 dark:hover:bg-slate-800'
|
||||
}`}
|
||||
>
|
||||
{item.props.icon}
|
||||
{item.props.badge}
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent
|
||||
|
||||
@@ -8,6 +8,7 @@ import { CheckCheckIcon, Loader2 } from 'lucide-react'
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { useInView } from 'react-intersection-observer'
|
||||
import type { InferResponseType } from 'hono/client'
|
||||
import type { GetMeResponse } from '@/dtos/team'
|
||||
|
||||
export const NotificationList = () => {
|
||||
const { teamId } = useTeamContextStore()
|
||||
@@ -55,6 +56,14 @@ export const NotificationList = () => {
|
||||
[data],
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
if (teamId) {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['teams', teamId, 'me'],
|
||||
})
|
||||
}
|
||||
}, [teamId, notifications.length, queryClient])
|
||||
|
||||
const $post = client.api.teams[':teamId'].notifications.read.$post
|
||||
const markReadMutation = useMutation<
|
||||
InferResponseType<typeof $post>,
|
||||
@@ -75,14 +84,31 @@ export const NotificationList = () => {
|
||||
if (notifications.length > 0 && teamId) {
|
||||
const topId = notifications[0].id
|
||||
if (topId) {
|
||||
await markReadMutation.mutateAsync({
|
||||
teamId,
|
||||
notificationId: topId,
|
||||
// Optimistically clear the unread count in React Query cache instantly
|
||||
queryClient.setQueryData(['teams', teamId, 'me'], (oldData: GetMeResponse | undefined) => {
|
||||
if (!oldData) return oldData
|
||||
return {
|
||||
...oldData,
|
||||
unreadNotificationCount: 0,
|
||||
}
|
||||
})
|
||||
// Invalidate queries
|
||||
|
||||
try {
|
||||
await markReadMutation.mutateAsync({
|
||||
teamId,
|
||||
notificationId: topId,
|
||||
})
|
||||
} catch (err) {
|
||||
console.error('Failed to mark all as read:', err)
|
||||
}
|
||||
|
||||
// Invalidate queries to trigger sync refetches
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['notifications', teamId],
|
||||
})
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['teams', teamId, 'me'],
|
||||
})
|
||||
// Refetch to update UI state immediately
|
||||
refetch()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,227 @@
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { client } from '@/ui/api/client'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/ui/components/ui/card'
|
||||
import { Switch } from '@/ui/components/ui/switch'
|
||||
import {
|
||||
Loader2,
|
||||
MessageSquare,
|
||||
MessageCircle,
|
||||
AtSign,
|
||||
UploadCloud,
|
||||
Activity,
|
||||
Bell,
|
||||
} from 'lucide-react'
|
||||
import { toast } from 'sonner'
|
||||
import type { NotificationSettings as Settings } from '@/dtos/notification'
|
||||
|
||||
export function NotificationSettings({ teamId }: { teamId: string }) {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
const { data: settings, isLoading } = useQuery({
|
||||
queryKey: ['teams', teamId, 'notification-settings'],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.teams[':teamId'].notifications.settings.$get({
|
||||
param: { teamId },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch notification settings')
|
||||
return (await res.json()) as Settings
|
||||
},
|
||||
})
|
||||
|
||||
const { mutate: updateSettings, isPending: isUpdating } = useMutation({
|
||||
mutationFn: async (updated: Settings) => {
|
||||
const res = await client.api.teams[':teamId'].notifications.settings.$post({
|
||||
param: { teamId },
|
||||
json: updated,
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to update notification settings')
|
||||
return await res.json()
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['teams', teamId, 'notification-settings'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['teams', teamId, 'notifications'] })
|
||||
toast.success('Notification settings updated')
|
||||
},
|
||||
onError: (err) => {
|
||||
toast.error(err instanceof Error ? err.message : 'Failed to update notification settings')
|
||||
},
|
||||
})
|
||||
|
||||
const handleToggle = (key: keyof Settings) => {
|
||||
if (!settings) return
|
||||
const updated = {
|
||||
...settings,
|
||||
[key]: !settings[key],
|
||||
}
|
||||
updateSettings(updated)
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center p-8">
|
||||
<Loader2 className="h-8 w-8 animate-spin text-muted-foreground" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="h-full overflow-y-auto space-y-6 pr-1">
|
||||
{/* Comments Settings */}
|
||||
<Card className="border border-slate-200 dark:border-slate-800">
|
||||
<CardHeader className="border-b border-slate-100 dark:border-slate-800 bg-slate-50/50 dark:bg-slate-900/50">
|
||||
<div className="flex items-center gap-2">
|
||||
<MessageSquare className="w-5 h-5 text-blue-500" />
|
||||
<CardTitle className="text-lg">Comments & Replies</CardTitle>
|
||||
</div>
|
||||
<CardDescription>
|
||||
Control notification preferences when other users comment on assets you collaborate on
|
||||
or mention you.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="divide-y divide-slate-100 dark:divide-slate-800 p-0">
|
||||
{/* General Comments */}
|
||||
<div className="flex items-center justify-between p-6">
|
||||
<div className="flex gap-4">
|
||||
<div className="mt-1 flex items-center justify-center w-8 h-8 rounded-lg bg-blue-50 dark:bg-blue-900/20 text-blue-600 dark:text-blue-400">
|
||||
<MessageSquare className="w-4 h-4" />
|
||||
</div>
|
||||
<div className="space-y-0.5">
|
||||
<h4 className="text-sm font-semibold text-slate-900 dark:text-white">
|
||||
General Comments
|
||||
</h4>
|
||||
<p className="text-sm text-slate-500 dark:text-slate-400">
|
||||
When someone comments on an asset
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<Switch
|
||||
checked={settings?.comments ?? true}
|
||||
onCheckedChange={() => handleToggle('comments')}
|
||||
disabled={isUpdating}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Comment Replies */}
|
||||
<div className="flex items-center justify-between p-6">
|
||||
<div className="flex gap-4">
|
||||
<div className="mt-1 flex items-center justify-center w-8 h-8 rounded-lg bg-purple-50 dark:bg-purple-900/20 text-purple-600 dark:text-purple-400">
|
||||
<MessageCircle className="w-4 h-4" />
|
||||
</div>
|
||||
<div className="space-y-0.5">
|
||||
<h4 className="text-sm font-semibold text-slate-900 dark:text-white">
|
||||
Comment Replies
|
||||
</h4>
|
||||
<p className="text-sm text-slate-500 dark:text-slate-400">
|
||||
When someone replies to your comment
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<Switch
|
||||
checked={settings?.replies ?? true}
|
||||
onCheckedChange={() => handleToggle('replies')}
|
||||
disabled={isUpdating}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Mentions */}
|
||||
<div className="flex items-center justify-between p-6">
|
||||
<div className="flex gap-4">
|
||||
<div className="mt-1 flex items-center justify-center w-8 h-8 rounded-lg bg-pink-50 dark:bg-pink-900/20 text-pink-600 dark:text-pink-400">
|
||||
<AtSign className="w-4 h-4" />
|
||||
</div>
|
||||
<div className="space-y-0.5">
|
||||
<h4 className="text-sm font-semibold text-slate-900 dark:text-white">@Mentions</h4>
|
||||
<p className="text-sm text-slate-500 dark:text-slate-400">
|
||||
When someone @mentions you in a comment
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<Switch
|
||||
checked={settings?.mentions ?? true}
|
||||
onCheckedChange={() => handleToggle('mentions')}
|
||||
disabled={isUpdating}
|
||||
/>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Assets Settings */}
|
||||
<Card className="border border-slate-200 dark:border-slate-800">
|
||||
<CardHeader className="border-b border-slate-100 dark:border-slate-800 bg-slate-50/50 dark:bg-slate-900/50">
|
||||
<div className="flex items-center gap-2">
|
||||
<UploadCloud className="w-5 h-5 text-emerald-500" />
|
||||
<CardTitle className="text-lg">Assets & Statuses</CardTitle>
|
||||
</div>
|
||||
<CardDescription>
|
||||
Manage notifications related to file uploads and metadata field status updates.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="divide-y divide-slate-100 dark:divide-slate-800 p-0">
|
||||
{/* Your Uploads */}
|
||||
<div className="flex items-center justify-between p-6">
|
||||
<div className="flex gap-4">
|
||||
<div className="mt-1 flex items-center justify-center w-8 h-8 rounded-lg bg-slate-100 dark:bg-slate-800 text-slate-600 dark:text-slate-400">
|
||||
<Bell className="w-4 h-4" />
|
||||
</div>
|
||||
<div className="space-y-0.5">
|
||||
<h4 className="text-sm font-semibold text-slate-900 dark:text-white">
|
||||
Your Uploads
|
||||
</h4>
|
||||
<p className="text-sm text-slate-500 dark:text-slate-400">When you upload assets</p>
|
||||
</div>
|
||||
</div>
|
||||
<Switch
|
||||
checked={settings?.yourUploads ?? false}
|
||||
onCheckedChange={() => handleToggle('yourUploads')}
|
||||
disabled={isUpdating}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Other Uploads */}
|
||||
<div className="flex items-center justify-between p-6">
|
||||
<div className="flex gap-4">
|
||||
<div className="mt-1 flex items-center justify-center w-8 h-8 rounded-lg bg-emerald-50 dark:bg-emerald-900/20 text-emerald-600 dark:text-emerald-400">
|
||||
<UploadCloud className="w-4 h-4" />
|
||||
</div>
|
||||
<div className="space-y-0.5">
|
||||
<h4 className="text-sm font-semibold text-slate-900 dark:text-white">
|
||||
Other Uploads
|
||||
</h4>
|
||||
<p className="text-sm text-slate-500 dark:text-slate-400">
|
||||
When other users upload assets
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<Switch
|
||||
checked={settings?.otherUploads ?? true}
|
||||
onCheckedChange={() => handleToggle('otherUploads')}
|
||||
disabled={isUpdating}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Status Updates */}
|
||||
<div className="flex items-center justify-between p-6">
|
||||
<div className="flex gap-4">
|
||||
<div className="mt-1 flex items-center justify-center w-8 h-8 rounded-lg bg-amber-50 dark:bg-amber-900/20 text-amber-600 dark:text-amber-400">
|
||||
<Activity className="w-4 h-4" />
|
||||
</div>
|
||||
<div className="space-y-0.5">
|
||||
<h4 className="text-sm font-semibold text-slate-900 dark:text-white">
|
||||
Status Updates
|
||||
</h4>
|
||||
<p className="text-sm text-slate-500 dark:text-slate-400">
|
||||
When someone changes an asset’s status
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<Switch
|
||||
checked={settings?.statusUpdates ?? true}
|
||||
onCheckedChange={() => handleToggle('statusUpdates')}
|
||||
disabled={isUpdating}
|
||||
/>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -13,6 +13,8 @@ import {
|
||||
useNavigate,
|
||||
useRouterState,
|
||||
} from '@tanstack/react-router'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { client } from '@/ui/api/client'
|
||||
import { useEffect } from 'react'
|
||||
|
||||
function RootComponent() {
|
||||
@@ -45,6 +47,28 @@ function RootComponent() {
|
||||
}
|
||||
}, [teamId, projectId, setTeamId, ensureTeamIdForProject])
|
||||
|
||||
const { data: me } = useQuery({
|
||||
queryKey: ['teams', storedTeamId, 'me'],
|
||||
queryFn: async () => {
|
||||
if (!storedTeamId) return null
|
||||
const res = await client.api.teams[':teamId'].me.$get({
|
||||
param: { teamId: storedTeamId },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch me')
|
||||
return await res.json()
|
||||
},
|
||||
enabled: !!storedTeamId,
|
||||
})
|
||||
|
||||
const unreadCount = me?.unreadNotificationCount ?? 0
|
||||
const displayCount = unreadCount > 99 ? '99+' : unreadCount
|
||||
const badge =
|
||||
unreadCount > 0 ? (
|
||||
<div className="absolute -top-1 -right-1 min-w-[18px] h-[18px] px-1 bg-red-500 text-white rounded-full flex items-center justify-center text-[10px] font-bold border-2 border-slate-100 dark:border-slate-900 animate-pulse">
|
||||
{displayCount}
|
||||
</div>
|
||||
) : null
|
||||
|
||||
return (
|
||||
<div className="flex h-screen w-full bg-background overflow-hidden">
|
||||
<Toaster />
|
||||
@@ -61,7 +85,7 @@ function RootComponent() {
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<DualSidebarItem icon={<NotificationFillIcon />} label="Notifications">
|
||||
<DualSidebarItem icon={<NotificationFillIcon />} label="Notifications" badge={badge}>
|
||||
<NotificationList />
|
||||
</DualSidebarItem>
|
||||
<DualSidebarItem
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { ProjectInfo } from '@/dtos/project'
|
||||
import { client } from '@/ui/api/client'
|
||||
import { useMutation } from '@tanstack/react-query'
|
||||
import { toast } from 'sonner'
|
||||
import type { InferRequestType, InferResponseType } from 'hono/client'
|
||||
import { MembersDialog } from '@/ui/components/members-dialog'
|
||||
import { ProjectDialog } from '@/ui/components/project-dialog'
|
||||
@@ -30,6 +31,7 @@ import { useQuery, useSuspenseQuery, useQueryClient } from '@tanstack/react-quer
|
||||
import { createFileRoute, useNavigate } from '@tanstack/react-router'
|
||||
import { MoreHorizontal, PlusIcon } from 'lucide-react'
|
||||
import { useState } from 'react'
|
||||
import { Switch } from '@/ui/components/ui/switch'
|
||||
import { Input } from '@/ui/components/ui/input'
|
||||
|
||||
function TeamPage() {
|
||||
@@ -120,6 +122,28 @@ function TeamPage() {
|
||||
},
|
||||
})
|
||||
|
||||
const toggleProjectNotificationsMutation = useMutation({
|
||||
mutationFn: async (project: ProjectInfo) => {
|
||||
const res = await client.api.projects[':projectId'].$put({
|
||||
param: { projectId: project.id! },
|
||||
json: {
|
||||
enableNotification: !project.enableNotification,
|
||||
},
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to update project notification settings')
|
||||
return await res.json()
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['teams', teamId, 'projects'] })
|
||||
toast.success('Project notification settings updated')
|
||||
},
|
||||
onError: (err) => {
|
||||
toast.error(
|
||||
err instanceof Error ? err.message : 'Failed to update project notification settings',
|
||||
)
|
||||
},
|
||||
})
|
||||
|
||||
const handleCreateProjectClick = () => {
|
||||
setProjectDialogMode('create')
|
||||
setSelectedProject(undefined)
|
||||
@@ -284,6 +308,19 @@ function TeamPage() {
|
||||
>
|
||||
Project Settings
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
className="flex items-center justify-between gap-4 cursor-pointer"
|
||||
onSelect={(e) => {
|
||||
e.preventDefault()
|
||||
toggleProjectNotificationsMutation.mutate(project)
|
||||
}}
|
||||
>
|
||||
<span>Notification</span>
|
||||
<Switch
|
||||
checked={project.enableNotification ?? true}
|
||||
className="pointer-events-none"
|
||||
/>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
className="text-destructive focus:text-destructive"
|
||||
onClick={() => handleDeleteProjectClick(project)}
|
||||
|
||||
@@ -4,15 +4,23 @@ import { AgentsSettings } from '@/ui/components/settings/AgentsSettings'
|
||||
import { ProvidersSettings } from '@/ui/components/settings/ProvidersSettings'
|
||||
import { SandboxSettings } from '@/ui/components/settings/SandboxSettings'
|
||||
import { SkillsConfigCard } from '@/ui/components/settings/SkillsConfigCard'
|
||||
import { NotificationSettings } from '@/ui/components/settings/NotificationSettings'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/ui/components/ui/card'
|
||||
import { Switch } from '@/ui/components/ui/switch'
|
||||
import { cn } from '@/ui/lib/utils'
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { createFileRoute } from '@tanstack/react-router'
|
||||
import { Bot, Cpu, Film, Loader2, Puzzle, Shield, User } from 'lucide-react'
|
||||
import { Bot, Cpu, Film, Loader2, Puzzle, Shield, User, Bell } from 'lucide-react'
|
||||
import { useState } from 'react'
|
||||
|
||||
type SettingsTab = 'general' | 'transcode' | 'skills' | 'providers' | 'agents' | 'sandbox'
|
||||
type SettingsTab =
|
||||
| 'general'
|
||||
| 'transcode'
|
||||
| 'skills'
|
||||
| 'providers'
|
||||
| 'agents'
|
||||
| 'sandbox'
|
||||
| 'notifications'
|
||||
|
||||
function TeamSettingsPage() {
|
||||
const { teamId } = Route.useParams()
|
||||
@@ -145,6 +153,22 @@ function TeamSettingsPage() {
|
||||
)}
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={() => setActiveTab('notifications')}
|
||||
className={cn(
|
||||
'w-full flex items-center gap-3 px-4 py-3 text-sm font-medium rounded-lg transition-all',
|
||||
activeTab === 'notifications'
|
||||
? 'bg-blue-50 dark:bg-blue-900/20 text-blue-700 dark:text-blue-300 ring-1 ring-blue-200 dark:ring-blue-800'
|
||||
: 'text-slate-600 dark:text-slate-400 hover:bg-slate-50 dark:hover:bg-slate-800 hover:text-slate-900 dark:hover:text-white',
|
||||
)}
|
||||
>
|
||||
<Bell className="w-5 h-5" />
|
||||
Notifications
|
||||
{activeTab === 'notifications' && (
|
||||
<div className="ml-auto w-1.5 h-1.5 rounded-full bg-blue-600 dark:bg-blue-400" />
|
||||
)}
|
||||
</button>
|
||||
|
||||
<div className="mt-6 mb-2 px-4 text-xs font-semibold text-slate-400 dark:text-slate-500 uppercase tracking-wider pt-4 border-t border-slate-100 dark:border-slate-800">
|
||||
AI
|
||||
</div>
|
||||
@@ -227,6 +251,7 @@ function TeamSettingsPage() {
|
||||
{activeTab === 'providers' && 'AI Providers'}
|
||||
{activeTab === 'agents' && 'AI Agents'}
|
||||
{activeTab === 'sandbox' && 'Agent Sandbox Settings'}
|
||||
{activeTab === 'notifications' && 'Notification Settings'}
|
||||
</h2>
|
||||
<p className="text-sm text-slate-500 dark:text-slate-400 mt-1">
|
||||
{activeTab === 'general' && 'View your personal information and team role.'}
|
||||
@@ -238,6 +263,8 @@ function TeamSettingsPage() {
|
||||
{activeTab === 'agents' && 'Manage AI agents and their personalities.'}
|
||||
{activeTab === 'sandbox' &&
|
||||
'Configure security and network restrictions for the AI agent.'}
|
||||
{activeTab === 'notifications' &&
|
||||
'Configure your personal notification preferences for this team.'}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -422,6 +449,8 @@ function TeamSettingsPage() {
|
||||
<SandboxSettings teamId={teamId} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{activeTab === 'notifications' && <NotificationSettings teamId={teamId} />}
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
Reference in New Issue
Block a user