feat: Support multiple file upload on dashboard (#3748)

Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
This commit is contained in:
Nithin David Thomas
2022-01-25 08:16:58 +05:30
committed by GitHub
parent b304f5a826
commit 8cff690640
4 changed files with 22 additions and 9 deletions

View File

@@ -7,14 +7,16 @@ export const buildCreatePayload = ({
isPrivate, isPrivate,
contentAttributes, contentAttributes,
echoId, echoId,
file, files,
ccEmails = '', ccEmails = '',
bccEmails = '', bccEmails = '',
}) => { }) => {
let payload; let payload;
if (file) { if (files && files.length !== 0) {
payload = new FormData(); payload = new FormData();
payload.append('attachments[]', file, file.name); files.forEach(file => {
payload.append('attachments[]', file, file.name);
});
if (message) { if (message) {
payload.append('content', message); payload.append('content', message);
} }
@@ -46,7 +48,7 @@ class MessageApi extends ApiClient {
private: isPrivate, private: isPrivate,
contentAttributes, contentAttributes,
echo_id: echoId, echo_id: echoId,
file, files,
ccEmails = '', ccEmails = '',
bccEmails = '', bccEmails = '',
}) { }) {
@@ -58,7 +60,7 @@ class MessageApi extends ApiClient {
isPrivate, isPrivate,
contentAttributes, contentAttributes,
echoId, echoId,
file, files,
ccEmails, ccEmails,
bccEmails, bccEmails,
}), }),

View File

@@ -36,7 +36,7 @@ describe('#ConversationAPI', () => {
echoId: 12, echoId: 12,
isPrivate: true, isPrivate: true,
file: new Blob(['test-content'], { type: 'application/pdf' }), files: [new Blob(['test-content'], { type: 'application/pdf' })],
}); });
expect(formPayload).toBeInstanceOf(FormData); expect(formPayload).toBeInstanceOf(FormData);
expect(formPayload.get('content')).toEqual('test content'); expect(formPayload.get('content')).toEqual('test content');

View File

@@ -16,6 +16,7 @@
ref="upload" ref="upload"
:size="4096 * 4096" :size="4096 * 4096"
:accept="allowedFileTypes" :accept="allowedFileTypes"
:multiple="enableMultipleFileUpload"
:drop="true" :drop="true"
:drop-directory="false" :drop-directory="false"
@input-file="onFileUpload" @input-file="onFileUpload"
@@ -144,6 +145,10 @@ export default {
type: Boolean, type: Boolean,
default: true, default: true,
}, },
enableMultipleFileUpload: {
type: Boolean,
default: true,
},
}, },
computed: { computed: {
isNote() { isNote() {

View File

@@ -72,6 +72,7 @@
:is-format-mode="showRichContentEditor" :is-format-mode="showRichContentEditor"
:enable-rich-editor="isRichEditorEnabled" :enable-rich-editor="isRichEditorEnabled"
:enter-to-send-enabled="enterToSendEnabled" :enter-to-send-enabled="enterToSendEnabled"
:enable-multiple-file-upload="enableMultipleFileUpload"
@toggleEnterToSend="toggleEnterToSend" @toggleEnterToSend="toggleEnterToSend"
/> />
</div> </div>
@@ -283,6 +284,9 @@ export default {
showReplyHead() { showReplyHead() {
return !this.isOnPrivateNote && this.isAnEmailChannel; return !this.isOnPrivateNote && this.isAnEmailChannel;
}, },
enableMultipleFileUpload() {
return this.isAnEmailChannel || this.isAWebWidgetInbox || this.isAPIInbox;
},
}, },
watch: { watch: {
currentChat(conversation) { currentChat(conversation) {
@@ -469,7 +473,6 @@ export default {
); );
}, },
getMessagePayload(message) { getMessagePayload(message) {
const [attachment] = this.attachedFiles;
const messagePayload = { const messagePayload = {
conversationId: this.currentChat.id, conversationId: this.currentChat.id,
message, message,
@@ -480,8 +483,11 @@ export default {
messagePayload.contentAttributes = { in_reply_to: this.inReplyTo }; messagePayload.contentAttributes = { in_reply_to: this.inReplyTo };
} }
if (attachment) { if (this.attachedFiles && this.attachedFiles.length) {
messagePayload.file = attachment.resource.file; messagePayload.files = [];
this.attachedFiles.forEach(attachment => {
messagePayload.files.push(attachment.resource.file);
});
} }
if (this.ccEmails) { if (this.ccEmails) {