mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-26 10:55:27 +00:00
feat(notification): improve notification system with team settings and project-level toggles
This commit is contained in:
@@ -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>
|
||||
)
|
||||
}
|
||||
@@ -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'
|
||||
@@ -120,6 +121,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 +307,16 @@ function TeamPage() {
|
||||
>
|
||||
Project Settings
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
toggleProjectNotificationsMutation.mutate(project)
|
||||
}}
|
||||
>
|
||||
{project.enableNotification
|
||||
? 'Disable Notifications'
|
||||
: 'Enable Notifications'}
|
||||
</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