11import React , { useState } from 'react' ;
2- import { Table , Input , Button , Space , Badge , Spin } from 'antd' ;
2+ import { Table , Input , Button , Space , Badge , Spin , Modal } from 'antd' ;
33import { StopOutlined , SearchOutlined , FlagOutlined } from '@ant-design/icons' ;
44import { useModerationStats , UserStat } from '@app/hooks/useModerationStats' ;
55import { BlockedPubkey } from '@app/api/blockedPubkeys.api' ;
6+ import * as S from '../BlockedPubkeys.styles' ;
67
78interface FlaggedPubkeysTableProps {
89 blockedPubkeys : BlockedPubkey [ ] ; // Already blocked pubkeys to filter out
@@ -16,6 +17,9 @@ export const FlaggedPubkeysTable: React.FC<FlaggedPubkeysTableProps> = ({
1617 disabled = false ,
1718} ) => {
1819 const [ searchText , setSearchText ] = useState ( '' ) ;
20+ const [ blockModalVisible , setBlockModalVisible ] = useState ( false ) ;
21+ const [ currentPubkey , setCurrentPubkey ] = useState ( '' ) ;
22+ const [ blockReason , setBlockReason ] = useState ( '' ) ;
1923 const { stats, loading : statsLoading } = useModerationStats ( ) ;
2024
2125 // Filter out already blocked pubkeys and return the rest
@@ -40,10 +44,17 @@ export const FlaggedPubkeysTable: React.FC<FlaggedPubkeysTableProps> = ({
4044 item => item . pubkey . toLowerCase ( ) . includes ( searchText . toLowerCase ( ) )
4145 ) ;
4246
43- const handleBlock = ( pubkey : string ) => {
44- // Default reason
45- const reason = "Blocked due to high flag count" ;
46- onBlock ( pubkey , reason ) ;
47+ // Show block modal with default reason
48+ const showBlockModal = ( pubkey : string , flagCount : number ) => {
49+ setCurrentPubkey ( pubkey ) ;
50+ setBlockReason ( `Blocked due to high flag count (${ flagCount } flags)` ) ;
51+ setBlockModalVisible ( true ) ;
52+ } ;
53+
54+ // Handle block confirmation with custom reason
55+ const handleConfirmBlock = async ( ) => {
56+ await onBlock ( currentPubkey , blockReason ) ;
57+ setBlockModalVisible ( false ) ;
4758 } ;
4859
4960 const columns = [
@@ -58,15 +69,13 @@ export const FlaggedPubkeysTable: React.FC<FlaggedPubkeysTableProps> = ({
5869 dataIndex : 'count' ,
5970 key : 'count' ,
6071 render : ( count : number ) => (
61- < Space >
62- < Badge
63- count = { count }
64- showZero
65- color = { count > 10 ? 'red' : count > 5 ? 'orange' : 'blue' }
66- style = { { marginRight : '5px' } }
67- />
68- < FlagOutlined style = { { color : count > 0 ? undefined : '#d9d9d9' } } />
69- </ Space >
72+ < S . FlagCountContainer >
73+ < S . CircularBadge
74+ color = { count > 10 ? 'var(--error-color)' : count > 5 ? 'var(--warning-color)' : 'var(--primary-color)' }
75+ >
76+ { count }
77+ </ S . CircularBadge >
78+ </ S . FlagCountContainer >
7079 ) ,
7180 sorter : ( a : UserStat , b : UserStat ) => a . count - b . count ,
7281 defaultSortOrder : 'descend' as const ,
@@ -79,7 +88,7 @@ export const FlaggedPubkeysTable: React.FC<FlaggedPubkeysTableProps> = ({
7988 type = "primary"
8089 danger
8190 icon = { < StopOutlined /> }
82- onClick = { ( ) => handleBlock ( record . pubkey ) }
91+ onClick = { ( ) => showBlockModal ( record . pubkey , record . count ) }
8392 disabled = { disabled }
8493 >
8594 Block
@@ -112,6 +121,28 @@ export const FlaggedPubkeysTable: React.FC<FlaggedPubkeysTableProps> = ({
112121 } }
113122 locale = { { emptyText : statsLoading ? 'Loading...' : 'No flagged pubkeys found' } }
114123 />
124+
125+ { /* Block Confirmation Modal */ }
126+ < Modal
127+ title = "Block Pubkey"
128+ open = { blockModalVisible }
129+ onOk = { handleConfirmBlock }
130+ onCancel = { ( ) => setBlockModalVisible ( false ) }
131+ okText = "Block"
132+ okButtonProps = { { danger : true } }
133+ >
134+ < p > Are you sure you want to block this pubkey?</ p >
135+ < p > < strong > { formatPubkey ( currentPubkey ) } </ strong > </ p >
136+ < div style = { { marginTop : '16px' } } >
137+ < p > Reason:</ p >
138+ < Input . TextArea
139+ value = { blockReason }
140+ onChange = { ( e ) => setBlockReason ( e . target . value ) }
141+ placeholder = "Enter reason for blocking"
142+ rows = { 3 }
143+ />
144+ </ div >
145+ </ Modal >
115146 </ >
116147 ) ;
117148} ;
0 commit comments