@@ -4,7 +4,6 @@ import React, {
44 useState ,
55 useEffect ,
66 useCallback ,
7- useContext ,
87} from 'react' ;
98import PropTypes from 'prop-types' ;
109
@@ -17,7 +16,9 @@ import Button, { ButtonTypes, ButtonSizes } from '../Button';
1716import renderMentionLabelToString from '../MentionUserLabel/renderToString' ;
1817import Icon , { IconTypes , IconColors } from '../Icon' ;
1918import Label , { LabelTypography , LabelColors } from '../Label' ;
20- import { LocalizationContext } from '../../lib/LocalizationContext' ;
19+ import { useLocalization } from '../../lib/LocalizationContext' ;
20+ import useSendbirdStateContext from '../../hooks/useSendbirdStateContext' ;
21+
2122import { nodeListToArray , sanitizeString } from './utils' ;
2223import {
2324 arrayEqual ,
@@ -27,6 +28,7 @@ import usePaste from './hooks/usePaste';
2728import { tokenizeMessage } from '../../modules/Message/utils/tokens/tokenize' ;
2829import { USER_MENTION_PREFIX } from '../../modules/Message/consts' ;
2930import { TOKEN_TYPES } from '../../modules/Message/utils/tokens/types' ;
31+ import { checkIfFileUploadEnabled } from './messageInputUtils' ;
3032
3133const TEXT_FIELD_ID = 'sendbird-message-input-text-field' ;
3234const LINE_HEIGHT = 76 ;
@@ -97,7 +99,14 @@ const MessageInput = React.forwardRef((props, ref) => {
9799 setMentionedUsers,
98100 } = props ;
99101 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+
101110 const fileInputRef = useRef ( null ) ;
102111 const [ isInput , setIsInput ] = useState ( false ) ;
103112 const [ mentionedUserIds , setMentionedUserIds ] = useState ( [ ] ) ;
@@ -489,7 +498,10 @@ const MessageInput = React.forwardRef((props, ref) => {
489498 { /* file upload icon */ }
490499 {
491500 ( ! 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 && (
493505 < IconButton
494506 className = { `sendbird-message-input--attach ${ isVoiceMessageEnabled ? 'is-voice-message-enabled' : '' } ` }
495507 height = "32px"
@@ -512,7 +524,8 @@ const MessageInput = React.forwardRef((props, ref) => {
512524 onChange = { handleUploadFile ( onFileUpload ) }
513525 />
514526 </ IconButton >
515- ) )
527+ )
528+ ) )
516529 )
517530 }
518531 { /* voice message input trigger */ }
@@ -606,7 +619,9 @@ MessageInput.propTypes = {
606619 renderVoiceMessageIcon : PropTypes . func ,
607620 renderSendMessageIcon : PropTypes . func ,
608621 renderFileUploadIcon : PropTypes . func ,
609- channel : PropTypes . shape ( { } ) ,
622+ channel : PropTypes . shape ( {
623+ channelType : PropTypes . string ,
624+ } ) . isRequired ,
610625} ;
611626
612627MessageInput . defaultProps = {
@@ -637,7 +652,6 @@ MessageInput.defaultProps = {
637652 renderVoiceMessageIcon : noop ,
638653 renderFileUploadIcon : noop ,
639654 renderSendMessageIcon : noop ,
640- channel : { } ,
641655} ;
642656
643657export default MessageInput ;
0 commit comments