@@ -21,6 +21,7 @@ import { Bell, Loader2, Mail, Server, Webhook } from 'lucide-react'
2121import { useTranslation } from 'react-i18next'
2222import { toast } from 'sonner'
2323import { ROLE } from '@/lib/roles'
24+ import { useAuthStore } from '@/stores/auth-store'
2425import { Button } from '@/components/ui/button'
2526import { Input } from '@/components/ui/input'
2627import { Label } from '@/components/ui/label'
@@ -65,6 +66,8 @@ interface NotificationTabProps {
6566export function NotificationTab ( { profile, onUpdate } : NotificationTabProps ) {
6667 const { t } = useTranslation ( )
6768 const isAdmin = ( profile ?. role ?? 0 ) >= ROLE . ADMIN
69+ const currentUser = useAuthStore ( ( state ) => state . auth . user )
70+ const setUser = useAuthStore ( ( state ) => state . auth . setUser )
6871 const [ loading , setLoading ] = useState ( false )
6972 const [ settings , setSettings ] = useState < UserSettings > ( {
7073 notify_type : 'email' ,
@@ -78,6 +81,7 @@ export function NotificationTab({ profile, onUpdate }: NotificationTabProps) {
7881 gotify_priority : 5 ,
7982 accept_unset_model_ratio_model : false ,
8083 record_ip_log : false ,
84+ show_ip_in_logs : false ,
8185 upstream_model_update_notify_enabled : false ,
8286 } )
8387
@@ -106,6 +110,7 @@ export function NotificationTab({ profile, onUpdate }: NotificationTabProps) {
106110 accept_unset_model_ratio_model :
107111 parsed . accept_unset_model_ratio_model || false ,
108112 record_ip_log : parsed . record_ip_log || false ,
113+ show_ip_in_logs : parsed . show_ip_in_logs || false ,
109114 upstream_model_update_notify_enabled :
110115 parsed . upstream_model_update_notify_enabled || false ,
111116 } )
@@ -118,6 +123,17 @@ export function NotificationTab({ profile, onUpdate }: NotificationTabProps) {
118123 const response = await updateUserSettings ( settings )
119124
120125 if ( response . success ) {
126+ if ( currentUser ) {
127+ const currentSetting =
128+ typeof currentUser . setting === 'string'
129+ ? parseUserSettings ( currentUser . setting )
130+ : currentUser . setting
131+ const nextSetting : Record < string , unknown > = {
132+ ...( currentSetting || { } ) ,
133+ ...settings ,
134+ }
135+ setUser ( { ...currentUser , setting : nextSetting } )
136+ }
121137 toast . success ( t ( 'Settings updated successfully' ) )
122138 onUpdate ( )
123139 } else {
@@ -375,19 +391,40 @@ export function NotificationTab({ profile, onUpdate }: NotificationTabProps) {
375391 </ div >
376392
377393 { /* Record IP Log */ }
378- < div className = 'flex items-start justify-between gap-3 rounded-lg border p-3 sm:items-center sm:p-4' >
379- < div className = 'space-y-0.5' >
380- < Label htmlFor = 'recordIp' > { t ( 'Record IP Address' ) } </ Label >
381- < p className = 'text-muted-foreground text-xs sm:text-sm' >
382- { t ( 'Log IP address for usage and error logs' ) }
383- </ p >
394+ < div className = 'grid gap-3 rounded-lg border p-3 sm:grid-cols-2 sm:p-4' >
395+ < div className = 'flex items-start justify-between gap-3 sm:items-center' >
396+ < div className = 'space-y-0.5' >
397+ < Label htmlFor = 'recordIp' > { t ( 'Record IP Address' ) } </ Label >
398+ < p className = 'text-muted-foreground text-xs sm:text-sm' >
399+ { t ( 'Log IP address for usage and error logs' ) }
400+ </ p >
401+ </ div >
402+ < Switch
403+ id = 'recordIp'
404+ className = 'shrink-0'
405+ checked = { settings . record_ip_log }
406+ onCheckedChange = { ( checked ) =>
407+ updateField ( 'record_ip_log' , checked )
408+ }
409+ />
410+ </ div >
411+
412+ < div className = 'flex items-start justify-between gap-3 sm:items-center' >
413+ < div className = 'space-y-0.5' >
414+ < Label htmlFor = 'showIpInLogs' > { t ( 'Show IP in Usage Logs' ) } </ Label >
415+ < p className = 'text-muted-foreground text-xs sm:text-sm' >
416+ { t ( 'Display the IP address column in usage logs' ) }
417+ </ p >
418+ </ div >
419+ < Switch
420+ id = 'showIpInLogs'
421+ className = 'shrink-0'
422+ checked = { settings . show_ip_in_logs }
423+ onCheckedChange = { ( checked ) =>
424+ updateField ( 'show_ip_in_logs' , checked )
425+ }
426+ />
384427 </ div >
385- < Switch
386- id = 'recordIp'
387- className = 'shrink-0'
388- checked = { settings . record_ip_log }
389- onCheckedChange = { ( checked ) => updateField ( 'record_ip_log' , checked ) }
390- />
391428 </ div >
392429 </ div >
393430
0 commit comments