From 6b348da807ef62399a4b20968bb1a2dfd280242f Mon Sep 17 00:00:00 2001
From: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
Date: Tue, 17 Dec 2024 18:07:58 +0530
Subject: [PATCH] feat(v4): Compose a new conversation from a phone number.
(#10568)
---
.../components/ContactSelector.vue | 20 +-
.../helpers/composeConversationHelper.js | 8 +-
.../specs/composeConversationHelper.spec.js | 22 ++
.../components-next/taginput/TagInput.vue | 133 ++++----
.../helper/spec/tagInputHelper.spec.js | 299 ++++++++++++++++++
.../taginput/helper/tagInputHelper.js | 124 ++++++++
6 files changed, 528 insertions(+), 78 deletions(-)
create mode 100644 app/javascript/dashboard/components-next/taginput/helper/spec/tagInputHelper.spec.js
create mode 100644 app/javascript/dashboard/components-next/taginput/helper/tagInputHelper.js
diff --git a/app/javascript/dashboard/components-next/NewConversation/components/ContactSelector.vue b/app/javascript/dashboard/components-next/NewConversation/components/ContactSelector.vue
index 33a2f8f20..7ff0a2efa 100644
--- a/app/javascript/dashboard/components-next/NewConversation/components/ContactSelector.vue
+++ b/app/javascript/dashboard/components-next/NewConversation/components/ContactSelector.vue
@@ -1,9 +1,11 @@
@@ -126,11 +140,11 @@ const errorClass = computed(() => {
:is-loading="isLoading"
:disabled="contactableInboxesList?.length > 0 && showInboxesDropdown"
allow-create
- type="email"
+ :type="inputType"
class="flex-1 min-h-7"
:class="errorClass"
focus-on-mount
- @input="emit('searchContacts', $event)"
+ @input="handleInput"
@on-click-outside="emit('updateDropdown', 'contacts', false)"
@add="emit('setSelectedContact', $event)"
@remove="emit('clearSelectedContact')"
diff --git a/app/javascript/dashboard/components-next/NewConversation/helpers/composeConversationHelper.js b/app/javascript/dashboard/components-next/NewConversation/helpers/composeConversationHelper.js
index 12a5e76b3..c5d3c6264 100644
--- a/app/javascript/dashboard/components-next/NewConversation/helpers/composeConversationHelper.js
+++ b/app/javascript/dashboard/components-next/NewConversation/helpers/composeConversationHelper.js
@@ -193,10 +193,12 @@ export const searchContacts = async ({ keys, query }) => {
return filteredPayload || [];
};
-export const createNewContact = async email => {
+export const createNewContact = async input => {
const payload = {
- name: getCapitalizedNameFromEmail(email),
- email,
+ name: input.startsWith('+')
+ ? input.slice(1) // Remove the '+' prefix if it exists
+ : getCapitalizedNameFromEmail(input),
+ ...(input.startsWith('+') ? { phone_number: input } : { email: input }),
};
const {
diff --git a/app/javascript/dashboard/components-next/NewConversation/helpers/specs/composeConversationHelper.spec.js b/app/javascript/dashboard/components-next/NewConversation/helpers/specs/composeConversationHelper.spec.js
index 5a2d0092d..9307e657c 100644
--- a/app/javascript/dashboard/components-next/NewConversation/helpers/specs/composeConversationHelper.spec.js
+++ b/app/javascript/dashboard/components-next/NewConversation/helpers/specs/composeConversationHelper.spec.js
@@ -429,6 +429,28 @@ describe('composeConversationHelper', () => {
email: 'john@example.com',
});
});
+
+ it('creates new contact with phone number', async () => {
+ const mockContact = {
+ id: 1,
+ name: '919999999999',
+ phone_number: '+919999999999',
+ };
+ ContactAPI.create.mockResolvedValue({
+ data: { payload: { contact: mockContact } },
+ });
+
+ const result = await helpers.createNewContact('+919999999999');
+ expect(result).toEqual({
+ id: 1,
+ name: '919999999999',
+ phoneNumber: '+919999999999',
+ });
+ expect(ContactAPI.create).toHaveBeenCalledWith({
+ name: '919999999999',
+ phone_number: '+919999999999',
+ });
+ });
});
describe('fetchContactableInboxes', () => {
diff --git a/app/javascript/dashboard/components-next/taginput/TagInput.vue b/app/javascript/dashboard/components-next/taginput/TagInput.vue
index 63d757415..8988201fb 100644
--- a/app/javascript/dashboard/components-next/taginput/TagInput.vue
+++ b/app/javascript/dashboard/components-next/taginput/TagInput.vue
@@ -1,16 +1,24 @@