@@ -4,7 +4,6 @@ import React, {
4
4
useState ,
5
5
useEffect ,
6
6
useCallback ,
7
- useContext ,
8
7
} from 'react' ;
9
8
import PropTypes from 'prop-types' ;
10
9
@@ -17,7 +16,9 @@ import Button, { ButtonTypes, ButtonSizes } from '../Button';
17
16
import renderMentionLabelToString from '../MentionUserLabel/renderToString' ;
18
17
import Icon , { IconTypes , IconColors } from '../Icon' ;
19
18
import Label , { LabelTypography , LabelColors } from '../Label' ;
20
- import { LocalizationContext } from '../../lib/LocalizationContext' ;
19
+ import { useLocalization } from '../../lib/LocalizationContext' ;
20
+ import useSendbirdStateContext from '../../hooks/useSendbirdStateContext' ;
21
+
21
22
import { nodeListToArray , sanitizeString } from './utils' ;
22
23
import {
23
24
arrayEqual ,
@@ -27,6 +28,7 @@ import usePaste from './hooks/usePaste';
27
28
import { tokenizeMessage } from '../../modules/Message/utils/tokens/tokenize' ;
28
29
import { USER_MENTION_PREFIX } from '../../modules/Message/consts' ;
29
30
import { TOKEN_TYPES } from '../../modules/Message/utils/tokens/types' ;
31
+ import { checkIfFileUploadEnabled } from './messageInputUtils' ;
30
32
31
33
const TEXT_FIELD_ID = 'sendbird-message-input-text-field' ;
32
34
const LINE_HEIGHT = 76 ;
@@ -97,7 +99,14 @@ const MessageInput = React.forwardRef((props, ref) => {
97
99
setMentionedUsers,
98
100
} = props ;
99
101
const textFieldId = messageFieldId || TEXT_FIELD_ID ;
100
- const { stringSet } = useContext ( LocalizationContext ) ;
102
+ const { stringSet } = useLocalization ( ) ;
103
+ const { config } = useSendbirdStateContext ( ) ;
104
+
105
+ const isFileUploadEnabled = checkIfFileUploadEnabled ( {
106
+ channel,
107
+ config,
108
+ } ) ;
109
+
101
110
const fileInputRef = useRef ( null ) ;
102
111
const [ isInput , setIsInput ] = useState ( false ) ;
103
112
const [ mentionedUserIds , setMentionedUserIds ] = useState ( [ ] ) ;
@@ -489,7 +498,10 @@ const MessageInput = React.forwardRef((props, ref) => {
489
498
{ /* file upload icon */ }
490
499
{
491
500
( ! isEdit && ! isInput ) && (
492
- ( renderFileUploadIcon ?. ( ) || (
501
+ ( renderFileUploadIcon ?. ( )
502
+ // UIKit Dashboard configuration should have lower priority than
503
+ // renderFileUploadIcon which is set in code level
504
+ || ( isFileUploadEnabled && (
493
505
< IconButton
494
506
className = { `sendbird-message-input--attach ${ isVoiceMessageEnabled ? 'is-voice-message-enabled' : '' } ` }
495
507
height = "32px"
@@ -512,7 +524,8 @@ const MessageInput = React.forwardRef((props, ref) => {
512
524
onChange = { handleUploadFile ( onFileUpload ) }
513
525
/>
514
526
</ IconButton >
515
- ) )
527
+ )
528
+ ) )
516
529
)
517
530
}
518
531
{ /* voice message input trigger */ }
@@ -606,7 +619,9 @@ MessageInput.propTypes = {
606
619
renderVoiceMessageIcon : PropTypes . func ,
607
620
renderSendMessageIcon : PropTypes . func ,
608
621
renderFileUploadIcon : PropTypes . func ,
609
- channel : PropTypes . shape ( { } ) ,
622
+ channel : PropTypes . shape ( {
623
+ channelType : PropTypes . string ,
624
+ } ) . isRequired ,
610
625
} ;
611
626
612
627
MessageInput . defaultProps = {
@@ -637,7 +652,6 @@ MessageInput.defaultProps = {
637
652
renderVoiceMessageIcon : noop ,
638
653
renderFileUploadIcon : noop ,
639
654
renderSendMessageIcon : noop ,
640
- channel : { } ,
641
655
} ;
642
656
643
657
export default MessageInput ;
0 commit comments