From 89da4a2292386b5a8bc9680752ba9df0a14ddc1d Mon Sep 17 00:00:00 2001 From: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Date: Mon, 2 Mar 2026 18:27:51 +0530 Subject: [PATCH] feat: compose form improvements (#13668) --- app/javascript/dashboard/api/contacts.js | 4 +- .../dashboard/api/specs/contacts.spec.js | 14 ++- .../components-next/Editor/Editor.vue | 5 +- .../NewConversation/ComposeConversation.vue | 14 ++- .../components/ComposeNewConversationForm.vue | 49 ++++++++- .../components/EmailOptions.vue | 2 - .../components/InboxEmptyState.vue | 8 +- .../components/InboxSelector.vue | 7 ++ .../components/MessageEditor.vue | 82 ++++++++++---- .../helpers/composeConversationHelper.js | 47 ++++++-- .../specs/composeConversationHelper.spec.js | 104 ++++++++++++++++-- .../components-next/taginput/TagInput.vue | 2 +- .../widgets/WootWriter/CopilotMenuBar.vue | 37 +++++-- .../components/widgets/WootWriter/Editor.vue | 23 +++- .../widgets/WootWriter/ReplyTopPanel.vue | 10 +- .../widgets/conversation/ReplyBox.vue | 1 + .../dashboard/i18n/locale/en/contact.json | 6 +- .../components/SearchContactAgentSelector.vue | 12 +- 18 files changed, 354 insertions(+), 73 deletions(-) diff --git a/app/javascript/dashboard/api/contacts.js b/app/javascript/dashboard/api/contacts.js index 1e76ac987..bae5623a7 100644 --- a/app/javascript/dashboard/api/contacts.js +++ b/app/javascript/dashboard/api/contacts.js @@ -57,14 +57,14 @@ class ContactAPI extends ApiClient { return axios.post(`${this.url}/${contactId}/labels`, { labels }); } - search(search = '', page = 1, sortAttr = 'name', label = '') { + search(search = '', page = 1, sortAttr = 'name', label = '', options = {}) { let requestURL = `${this.url}/search?${buildContactParams( page, sortAttr, label, search )}`; - return axios.get(requestURL); + return axios.get(requestURL, { signal: options.signal }); } active(page = 1, sortAttr = 'name') { diff --git a/app/javascript/dashboard/api/specs/contacts.spec.js b/app/javascript/dashboard/api/specs/contacts.spec.js index 0059518b0..b21aeb102 100644 --- a/app/javascript/dashboard/api/specs/contacts.spec.js +++ b/app/javascript/dashboard/api/specs/contacts.spec.js @@ -68,7 +68,19 @@ describe('#ContactsAPI', () => { it('#search', () => { contactAPI.search('leads', 1, 'date', 'customer-support'); expect(axiosMock.get).toHaveBeenCalledWith( - '/api/v1/contacts/search?include_contact_inboxes=false&page=1&sort=date&q=leads&labels[]=customer-support' + '/api/v1/contacts/search?include_contact_inboxes=false&page=1&sort=date&q=leads&labels[]=customer-support', + { signal: undefined } + ); + }); + + it('#search with signal', () => { + const controller = new AbortController(); + contactAPI.search('leads', 1, 'date', 'customer-support', { + signal: controller.signal, + }); + expect(axiosMock.get).toHaveBeenCalledWith( + '/api/v1/contacts/search?include_contact_inboxes=false&page=1&sort=date&q=leads&labels[]=customer-support', + { signal: controller.signal } ); }); diff --git a/app/javascript/dashboard/components-next/Editor/Editor.vue b/app/javascript/dashboard/components-next/Editor/Editor.vue index c2cde6d17..847bbd600 100644 --- a/app/javascript/dashboard/components-next/Editor/Editor.vue +++ b/app/javascript/dashboard/components-next/Editor/Editor.vue @@ -28,7 +28,7 @@ const props = defineProps({ medium: { type: String, default: '' }, }); -const emit = defineEmits(['update:modelValue']); +const emit = defineEmits(['update:modelValue', 'executeCopilotAction']); const slots = useSlots(); @@ -113,6 +113,9 @@ watch( @input="handleInput" @focus="handleFocus" @blur="handleBlur" + @execute-copilot-action=" + (...args) => emit('executeCopilotAction', ...args) + " />
{ contact = rest; } selectedContact.value = contact; + contacts.value = []; if (contact?.id) { isFetchingInboxes.value = true; try { diff --git a/app/javascript/dashboard/components-next/NewConversation/components/ComposeNewConversationForm.vue b/app/javascript/dashboard/components-next/NewConversation/components/ComposeNewConversationForm.vue index 0ed22ad0c..455abf996 100644 --- a/app/javascript/dashboard/components-next/NewConversation/components/ComposeNewConversationForm.vue +++ b/app/javascript/dashboard/components-next/NewConversation/components/ComposeNewConversationForm.vue @@ -15,6 +15,9 @@ import { prepareWhatsAppMessagePayload, } from 'dashboard/components-next/NewConversation/helpers/composeConversationHelper.js'; +import { useCopilotReply } from 'dashboard/composables/useCopilotReply'; +import { useKeyboardEvents } from 'dashboard/composables/useKeyboardEvents'; + import ContactSelector from './ContactSelector.vue'; import InboxSelector from './InboxSelector.vue'; import EmailOptions from './EmailOptions.vue'; @@ -22,6 +25,7 @@ import MessageEditor from './MessageEditor.vue'; import ActionButtons from './ActionButtons.vue'; import InboxEmptyState from './InboxEmptyState.vue'; import AttachmentPreviews from './AttachmentPreviews.vue'; +import CopilotReplyBottomPanel from 'dashboard/components/widgets/WootWriter/CopilotReplyBottomPanel.vue'; const props = defineProps({ contacts: { type: Array, default: () => [] }, @@ -42,6 +46,7 @@ const props = defineProps({ const emit = defineEmits([ 'searchContacts', + 'resetContactSearch', 'discard', 'updateSelectedContact', 'updateTargetInbox', @@ -51,6 +56,8 @@ const emit = defineEmits([ const DEFAULT_FORMATTING = 'Context::Default'; +const copilot = useCopilotReply(); + const showContactsDropdown = ref(false); const showInboxesDropdown = ref(false); const showCcEmailsDropdown = ref(false); @@ -157,7 +164,7 @@ const isAnyDropdownActive = computed(() => { }); const handleContactSearch = value => { - showContactsDropdown.value = true; + showContactsDropdown.value = value.trim().length > 1; emit('searchContacts', value); }; @@ -172,12 +179,16 @@ const handleDropdownUpdate = (type, value) => { }; const searchCcEmails = value => { - showCcEmailsDropdown.value = true; + showBccEmailsDropdown.value = false; + emit('resetContactSearch'); + showCcEmailsDropdown.value = value.trim().length >= 2; emit('searchContacts', value); }; const searchBccEmails = value => { - showBccEmailsDropdown.value = true; + showCcEmailsDropdown.value = false; + emit('resetContactSearch'); + showBccEmailsDropdown.value = value.trim().length >= 2; emit('searchContacts', value); }; @@ -196,6 +207,7 @@ const stripMessageFormatting = channelType => { const handleInboxAction = ({ value, action, channelType, medium, ...rest }) => { v$.value.$reset(); + copilot.reset(false); // Strip unsupported formatting when changing the target inbox if (channelType) { @@ -222,6 +234,7 @@ const removeSignatureFromMessage = () => { const removeTargetInbox = value => { v$.value.$reset(); + copilot.reset(false); removeSignatureFromMessage(); stripMessageFormatting(DEFAULT_FORMATTING); @@ -231,6 +244,7 @@ const removeTargetInbox = value => { }; const clearSelectedContact = () => { + copilot.reset(false); removeSignatureFromMessage(); emit('clearSelectedContact'); state.message = ''; @@ -262,6 +276,7 @@ const handleAttachFile = files => { }; const clearForm = () => { + copilot.reset(false); Object.assign(state, { message: '', subject: '', @@ -324,6 +339,24 @@ const shouldShowMessageEditor = computed(() => { !inboxTypes.value.isTwilioWhatsapp ); }); + +const isCopilotActive = computed(() => copilot.isActive?.value ?? false); + +const onSubmitCopilotReply = () => { + const acceptedMessage = copilot.accept(); + state.message = acceptedMessage; +}; + +useKeyboardEvents({ + '$mod+Enter': { + action: () => { + if (isCopilotActive.value && !copilot.isButtonDisabled.value) { + onSubmitCopilotReply(); + } + }, + allowOnFocusedInput: true, + }, +});