fix(contacts): expose root country code

This commit is contained in:
Sojan Jose
2026-05-27 01:17:09 +05:30
parent 4705a5c3ff
commit 25c11ecc56
10 changed files with 29 additions and 6 deletions
@@ -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;
@@ -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: {
@@ -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"
@@ -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;
@@ -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"
@@ -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 {
@@ -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
@@ -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
@@ -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
+3
View File
@@ -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