From 25c11ecc56654339e793bcb3033e34e8e81eb36d Mon Sep 17 00:00:00 2001 From: Sojan Jose Date: Wed, 27 May 2026 01:17:09 +0530 Subject: [PATCH] fix(contacts): expose root country code --- .../Contacts/ContactsCard/ContactsCard.vue | 7 +++++-- .../Contacts/ContactsForm/ContactsForm.vue | 3 ++- .../components-next/Contacts/Pages/ContactsList.vue | 1 + .../search/components/SearchResultContactItem.vue | 13 +++++++++++-- .../search/components/SearchResultContactsList.vue | 1 + .../dashboard/conversation/contact/ContactInfo.vue | 4 +++- .../api/v1/accounts/search/_contact.json.jbuilder | 1 + app/views/api/v1/models/_contact.json.jbuilder | 1 + .../api/v1/accounts/contacts_controller_spec.rb | 1 + swagger/definitions/resource/contact.yml | 3 +++ 10 files changed, 29 insertions(+), 6 deletions(-) diff --git a/app/javascript/dashboard/components-next/Contacts/ContactsCard/ContactsCard.vue b/app/javascript/dashboard/components-next/Contacts/ContactsCard/ContactsCard.vue index ba887b46f..441601561 100644 --- a/app/javascript/dashboard/components-next/Contacts/ContactsCard/ContactsCard.vue +++ b/app/javascript/dashboard/components-next/Contacts/ContactsCard/ContactsCard.vue @@ -16,6 +16,7 @@ const props = defineProps({ name: { type: String, default: '' }, email: { type: String, default: '' }, additionalAttributes: { type: Object, default: () => ({}) }, + countryCode: { type: String, default: '' }, phoneNumber: { type: String, default: '' }, thumbnail: { type: String, default: '' }, availabilityStatus: { type: String, default: null }, @@ -42,6 +43,7 @@ const getInitialContactData = () => ({ name: props.name, email: props.email, phoneNumber: props.phoneNumber, + countryCode: props.countryCode, additionalAttributes: props.additionalAttributes, }); @@ -58,12 +60,13 @@ const countriesMap = computed(() => { const countryDetails = computed(() => { const attributes = props.additionalAttributes || {}; - const { country, countryCode, city } = attributes; + const { country, countryCode: additionalCountryCode, city } = attributes; + const countryCode = props.countryCode || additionalCountryCode; if (!country && !countryCode) return null; const activeCountry = - countriesMap.value[country] || countriesMap.value[countryCode]; + countriesMap.value[countryCode] || countriesMap.value[country]; if (!activeCountry) return null; diff --git a/app/javascript/dashboard/components-next/Contacts/ContactsForm/ContactsForm.vue b/app/javascript/dashboard/components-next/Contacts/ContactsForm/ContactsForm.vue index 66296257f..82ae0d21e 100644 --- a/app/javascript/dashboard/components-next/Contacts/ContactsForm/ContactsForm.vue +++ b/app/javascript/dashboard/components-next/Contacts/ContactsForm/ContactsForm.vue @@ -96,6 +96,7 @@ const prepareStateBasedOnProps = () => { name = '', email: emailAddress, phoneNumber, + countryCode: contactCountryCode = '', additionalAttributes = {}, } = props.contactData || {}; const { firstName, lastName } = splitName(name || ''); @@ -122,7 +123,7 @@ const prepareStateBasedOnProps = () => { additionalAttributes: { description, companyName, - countryCode, + countryCode: contactCountryCode || countryCode, country, city, socialProfiles: { diff --git a/app/javascript/dashboard/components-next/Contacts/Pages/ContactsList.vue b/app/javascript/dashboard/components-next/Contacts/Pages/ContactsList.vue index 72bc2c7dd..cec7c1ea3 100644 --- a/app/javascript/dashboard/components-next/Contacts/Pages/ContactsList.vue +++ b/app/javascript/dashboard/components-next/Contacts/Pages/ContactsList.vue @@ -94,6 +94,7 @@ const handleAvatarHover = (id, isHovered) => { :email="contact.email" :thumbnail="contact.thumbnail" :phone-number="contact.phoneNumber" + :country-code="contact.countryCode" :additional-attributes="contact.additionalAttributes" :availability-status="contact.availabilityStatus" :is-expanded="expandedCardId === contact.id" diff --git a/app/javascript/dashboard/modules/search/components/SearchResultContactItem.vue b/app/javascript/dashboard/modules/search/components/SearchResultContactItem.vue index 485306797..9cd98bf5e 100644 --- a/app/javascript/dashboard/modules/search/components/SearchResultContactItem.vue +++ b/app/javascript/dashboard/modules/search/components/SearchResultContactItem.vue @@ -37,6 +37,10 @@ const props = defineProps({ type: Object, default: () => ({}), }, + countryCode: { + type: String, + default: '', + }, updatedAt: { type: Number, default: 0, @@ -60,12 +64,17 @@ const updatedAtTime = computed(() => { }); const countryDetails = computed(() => { - const { country, countryCode, city } = props.additionalAttributes; + const { + country, + countryCode: additionalCountryCode, + city, + } = props.additionalAttributes; + const countryCode = props.countryCode || additionalCountryCode; if (!country && !countryCode) return null; const activeCountry = - countriesMap.value[country] || countriesMap.value[countryCode]; + countriesMap.value[countryCode] || countriesMap.value[country]; if (!activeCountry) return null; diff --git a/app/javascript/dashboard/modules/search/components/SearchResultContactsList.vue b/app/javascript/dashboard/modules/search/components/SearchResultContactsList.vue index 85f76d6c4..c1ba6e31e 100644 --- a/app/javascript/dashboard/modules/search/components/SearchResultContactsList.vue +++ b/app/javascript/dashboard/modules/search/components/SearchResultContactsList.vue @@ -41,6 +41,7 @@ const accountId = useMapGetter('getCurrentAccountId'); :name="contact.name" :email="contact.email" :phone="contact.phoneNumber" + :country-code="contact.countryCode" :additional-attributes="contact.additionalAttributes" :account-id="accountId" :thumbnail="contact.thumbnail" diff --git a/app/javascript/dashboard/routes/dashboard/conversation/contact/ContactInfo.vue b/app/javascript/dashboard/routes/dashboard/conversation/contact/ContactInfo.vue index a27b308b0..1fb16752a 100644 --- a/app/javascript/dashboard/routes/dashboard/conversation/contact/ContactInfo.vue +++ b/app/javascript/dashboard/routes/dashboard/conversation/contact/ContactInfo.vue @@ -72,12 +72,14 @@ export default { city = '', country_code: countryCode, } = this.additionalAttributes; + const canonicalCountryCode = + this.contact.country_code || this.contact.countryCode || countryCode; const cityAndCountry = [city, country].filter(item => !!item).join(', '); if (!cityAndCountry) { return ''; } - return this.findCountryFlag(countryCode, cityAndCountry); + return this.findCountryFlag(canonicalCountryCode, cityAndCountry); }, socialProfiles() { const { diff --git a/app/views/api/v1/accounts/search/_contact.json.jbuilder b/app/views/api/v1/accounts/search/_contact.json.jbuilder index ca7f5544f..11c69e067 100644 --- a/app/views/api/v1/accounts/search/_contact.json.jbuilder +++ b/app/views/api/v1/accounts/search/_contact.json.jbuilder @@ -3,5 +3,6 @@ json.id contact.id json.name contact.name json.phone_number contact.phone_number json.identifier contact.identifier +json.country_code contact.canonical_country_code json.additional_attributes contact.additional_attributes_with_canonical_country json.last_activity_at contact.last_activity_at&.to_i diff --git a/app/views/api/v1/models/_contact.json.jbuilder b/app/views/api/v1/models/_contact.json.jbuilder index 18fddea33..9b09b489a 100644 --- a/app/views/api/v1/models/_contact.json.jbuilder +++ b/app/views/api/v1/models/_contact.json.jbuilder @@ -1,5 +1,6 @@ json.additional_attributes resource.additional_attributes_with_canonical_country json.availability_status resource.availability_status +json.country_code resource.canonical_country_code json.email resource.email json.id resource.id json.name resource.name diff --git a/spec/controllers/api/v1/accounts/contacts_controller_spec.rb b/spec/controllers/api/v1/accounts/contacts_controller_spec.rb index 6f663c8b3..1b6cef1d1 100644 --- a/spec/controllers/api/v1/accounts/contacts_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/contacts_controller_spec.rb @@ -68,6 +68,7 @@ RSpec.describe 'Contacts API', type: :request do 'country_code' => 'US', 'country' => 'United States' ) + expect(response_contact['country_code']).to eq('US') end it 'returns all contacts without contact inboxes' do diff --git a/swagger/definitions/resource/contact.yml b/swagger/definitions/resource/contact.yml index 259604f0d..9957aa9c4 100644 --- a/swagger/definitions/resource/contact.yml +++ b/swagger/definitions/resource/contact.yml @@ -11,6 +11,9 @@ properties: availability_status: type: string description: The availability status of the contact + country_code: + type: string + description: The normalized ISO country code of the contact email: type: string description: The email address of the contact