-
Notifications
You must be signed in to change notification settings - Fork 268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
question: how do I add custom attachment objects to MessageInput state? #2417
Comments
Hey @ElizabethSobiya, could you please create a repro with Codesandbox forked from template https://codesandbox.io/p/devbox/priceless-forest-g64slj ? Thank you |
Unfortunately, I cannot share the code due to our company policy. However, I can provide you with detailed information about the issue and the changes I've made. All the required code snippets are attached above. Please let me know how you would like to proceed. Thank you! I would appreciate it if you could solve the issue as soon as possible. |
@ElizabethSobiya could you make sure the pasted code will work in forked sandbox of https://codesandbox.io/p/devbox/priceless-forest-g64slj ? |
@MartinCupela Hi, The code in your message won't work as it is. Below is the workable code for the Home and CustomMessageInput components: // Custom Message Input const customStyles = { Modal.setAppElement("#root"); const CustomMessageInput = ({ setFilePreviews, filePreviews, onSendMessage }) => { const toggleModal = () => { const handleSmileClick = () => { const handleEmojiSelect = (emoji) => { const handleFileChange = (e) => { const handleFileClick = (acceptType) => { const handleLocationClick = () => { const handleSend = (event) => { return ( {isOpen ? ( ) : ( )} <input type="text" value={text} onChange={(e) => setText(e.target.value)} className="bg-white text-gray-800 placeholder-gray-400 px-4 py-1 rounded-lg border border-gray-300 w-full" placeholder="Type Message..." name="message" />
); export default CustomMessageInput; //Custom message input end // Home Component import React, { useState } from "react"; const Home = () => { const toggleContactInfo = () => { const removeFilePreview = (index) => { const isFileImage = (file) => { const setMainPreview = (index) => { const handleFileClick = () => { const handleSend = (message) => { return ( {filePreviews.length > 0 && ( <button onClick={() => removeFilePreview(0)} type="button" className="absolute top-0 mt-[-30px] bottom-160 left-10 text-grey p-2" > {isFileImage(filePreviews[0].file) ? ( ) : ( No preview available )} {filePreviews.length > 0 && ( {filePreviews.map((preview, index) => ( <div key={index} className={ relative mr-2 ${ index === 0 ? "border-2 border-blue-500" : "" } }onClick={() => setMainPreview(index)} > <button onClick={(e) => { e.stopPropagation(); removeFilePreview(index); }} type="button" className="absolute top-0 right-0 text-grey p-1 opacity-0 hover:opacity-100 transition-opacity duration-300 shadow-md" > {isFileImage(preview.file) ? ( ) : ( No preview )} ))} )} )} Chat HeaderToggle Info {messages.map((msg, index) => ( {msg.text} ))} ); }; export default Home; //Home component end In the above code, on the left side, there is a "+" icon. Clicking this icon opens a modal. Within the modal, there are separate icons for different attachment types. You can select a file and share it in the message input, with or without an accompanying message, according to your requirement. This is my requirement for custom message input attachment, but it is not working as expected. Please help us resolve these custom attachment issues as soon as possible. Thanks in advance |
Hey @ElizabethSobiya , if I understand well, you do not want to prepare working example from your code (which you understand) and you expect from us to setup the whole scenario for you? I think this is a misunderstanding from your side. I have to insist on providing the sandbox repro so that we can help you debug your code. |
Hey @MartinCupela, |
@MartinCupela Sorry for the delay, I tried forking the code but caught with unexpected error and I am struck there. Can I know how we can resolve this ? The fork link https://codesandbox.io/p/sandbox/support-to-fork-template-forked-64jc85 . |
The error in your sandbox is caused by using LoadingIndicator but not importing it. Please consider this GH issues list to be dedicated to solving documented issues, not debugging integration code. |
@MartinCupela Sorry for late reply and the above sandbox code. I just created a message input with my requirement, in the below sandbox link in that I had used https://getstream.io/chat/docs/sdk/react/hooks/message_input_hooks/#usemessageinputstate this hooks to custom the attachments but it is throwing me TypeError: undefined is not an object (evaluating 'props.additionalTextareaProps and I tried to get attachments for both file and image separately and pass that along with messages.If I removed the hooks that I used and just had messageInput means it is working properly but when I try to use hooks means it is either throwing me an error or just getting an blank page. |
@ElizabethSobiya I probably do not have permission to access the sandbox. |
https://codesandbox.io/p/sandbox/attachments-forked-7rlv49 Hey, this link is working, cross checked it and it is public |
The example build command fails. This definitely is not a bug but rather lack of knowledge. Therefore I will re-clasify the issue. |
Describe the bug
When customizing the MessageInput component to handle file attachments, the message does not properly accept the attachment. Specifically, when trying to send a message with an attachment (image or file), the message fails to include the attachment.
To Reproduce
Steps to reproduce the behavior:
-Implement the above CustomMessageInput component in your project.
-Try to send a message with an attachment.
Expected behavior
A clear and concise description of what you expected to happen.
onClicking the document/image/audi and so on from modal I want to open that and pass that to message input .
Package version
"react": "^18.3.1",
Desktop (please complete the following information):
Additional context
Here's the corrected sentence:
This issue is blocking my development . I tried using
overrideSubmitHandler
, but this causes a delay in sending the message and not getting attachments.The text was updated successfully, but these errors were encountered: