1- import { useEffect } from 'react' ;
1+ import { useEffect , useState } from 'react' ;
22import { useService , view } from '@rabjs/react' ;
3- import { Bell , Plus , Pencil , Trash2 } from 'lucide-react' ;
3+ import { Bell , Plus , Pencil , Trash2 , Send } from 'lucide-react' ;
44import type { PushRuleDto , PushChannelConfigDto } from '@aimo/dto' ;
55import { PushRuleService } from './push-rule.service' ;
6+ import { toast } from '../../../../services/toast.service' ;
67
78interface PushRulesListProps {
89 onAddRule : ( ) => void ;
@@ -11,6 +12,7 @@ interface PushRulesListProps {
1112
1213export const PushRulesList = view ( ( { onAddRule, onEditRule } : PushRulesListProps ) => {
1314 const pushRuleService = useService ( PushRuleService ) ;
15+ const [ testingRuleId , setTestingRuleId ] = useState < string | null > ( null ) ;
1416
1517 useEffect ( ( ) => {
1618 pushRuleService . fetchRules ( ) ;
@@ -25,6 +27,22 @@ export const PushRulesList = view(({ onAddRule, onEditRule }: PushRulesListProps
2527 await pushRuleService . deleteRule ( ruleId ) ;
2628 } ;
2729
30+ const handleTest = async ( ruleId : string ) => {
31+ setTestingRuleId ( ruleId ) ;
32+ try {
33+ const result = await pushRuleService . testPush ( ruleId ) ;
34+ if ( result . success ) {
35+ toast . success ( result . message || '测试消息已发送' ) ;
36+ } else {
37+ toast . error ( `发送失败: ${ result . message || '未知错误' } ` ) ;
38+ }
39+ } catch ( error ) {
40+ toast . error ( `发送失败: ${ error instanceof Error ? error . message : '未知错误' } ` ) ;
41+ } finally {
42+ setTestingRuleId ( null ) ;
43+ }
44+ } ;
45+
2846 if ( pushRuleService . loading ) {
2947 return (
3048 < div className = "flex items-center justify-center py-8" >
@@ -88,6 +106,14 @@ export const PushRulesList = view(({ onAddRule, onEditRule }: PushRulesListProps
88106 </ div >
89107 </ div >
90108 < div className = "flex items-center gap-2" >
109+ < button
110+ onClick = { ( ) => handleTest ( rule . id ) }
111+ disabled = { testingRuleId === rule . id }
112+ className = "p-2 text-gray-500 hover:text-blue-600 dark:text-gray-400 dark:hover:text-blue-400 hover:bg-gray-100 dark:hover:bg-dark-700 rounded-lg transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
113+ title = "测试推送"
114+ >
115+ < Send className = { `w-4 h-4 ${ testingRuleId === rule . id ? 'animate-pulse' : '' } ` } />
116+ </ button >
91117 < button
92118 onClick = { ( ) => onEditRule ( rule ) }
93119 className = "p-2 text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 hover:bg-gray-100 dark:hover:bg-dark-700 rounded-lg transition-colors"
0 commit comments