11import React from 'react' ;
2+ import { useSelector } from 'react-redux' ;
23import moment from 'moment' ;
4+ import { currentUserIsAdminSelector } from '../selectors' ;
5+ import { pushCommand } from '../middlewares/Chat' ;
36
47const Message = ( {
58 text = '' , name = '' , type, time,
69} ) => {
10+ const currentUserIsAdmin = useSelector ( state => currentUserIsAdminSelector ( state ) ) ;
11+ const handleBanClick = bannedName => {
12+ pushCommand ( { type : 'ban' , name : bannedName } ) ;
13+ } ;
14+
715 if ( ! text ) {
816 return null ;
917 }
@@ -12,9 +20,7 @@ const Message = ({
1220 return (
1321 < div className = "d-flex align-items-baseline flex-wrap" >
1422 < small className = "text-muted text-small" > { text } </ small >
15- < small className = "text-muted text-small ml-auto" >
16- { time ? moment . unix ( time ) . format ( 'HH:mm:ss' ) : '' }
17- </ small >
23+ < small className = "text-muted text-small ml-auto" > { time ? moment . unix ( time ) . format ( 'HH:mm:ss' ) : '' } </ small >
1824 </ div >
1925 ) ;
2026 }
@@ -44,9 +50,18 @@ const Message = ({
4450 { /* eslint-disable-next-line react/no-array-index-key */ }
4551 < span className = "font-weight-bold" > { `${ name } : ` } </ span >
4652 < span className = "ml-1" > { parts . map ( ( part , i ) => renderMessagePart ( part , i ) ) } </ span >
47- < small className = "text-muted text-small ml-auto" >
48- { time ? moment . unix ( time ) . format ( 'HH:mm:ss' ) : '' }
49- </ small >
53+ < small className = "text-muted text-small ml-auto" > { time ? moment . unix ( time ) . format ( 'HH:mm:ss' ) : '' } </ small >
54+ { currentUserIsAdmin ? (
55+ < button
56+ type = "button"
57+ className = "btn btn-sm btn-outline-danger"
58+ onClick = { ( ) => {
59+ handleBanClick ( name ) ;
60+ } }
61+ >
62+ Ban
63+ </ button >
64+ ) : null }
5065 </ div >
5166 ) ;
5267} ;
0 commit comments