--------- Co-authored-by: Pranav <pranavrajs@gmail.com> Co-authored-by: Pranav <pranav@chatwoot.com>
79 lines
2.5 KiB
Vue
79 lines
2.5 KiB
Vue
<script setup>
|
|
import { ref, computed } from 'vue';
|
|
import { useStore, useMapGetter } from 'dashboard/composables/store';
|
|
import { useAlert } from 'dashboard/composables';
|
|
import { useI18n } from 'vue-i18n';
|
|
import { useRouter, useRoute } from 'vue-router';
|
|
import {
|
|
DuplicateContactException,
|
|
ExceptionWithMessage,
|
|
} from 'shared/helpers/CustomErrors';
|
|
import ContactsCard from 'dashboard/components-next/Contacts/ContactsCard/ContactsCard.vue';
|
|
|
|
defineProps({ contacts: { type: Array, required: true } });
|
|
|
|
const { t } = useI18n();
|
|
const store = useStore();
|
|
const router = useRouter();
|
|
const route = useRoute();
|
|
|
|
const uiFlags = useMapGetter('contacts/getUIFlags');
|
|
const isUpdating = computed(() => uiFlags.value.isUpdating);
|
|
const expandedCardId = ref(null);
|
|
|
|
const updateContact = async updatedData => {
|
|
try {
|
|
await store.dispatch('contacts/update', updatedData);
|
|
useAlert(t('CONTACTS_LAYOUT.CARD.EDIT_DETAILS_FORM.SUCCESS_MESSAGE'));
|
|
} catch (error) {
|
|
const i18nPrefix = 'CONTACTS_LAYOUT.CARD.EDIT_DETAILS_FORM.FORM';
|
|
if (error instanceof DuplicateContactException) {
|
|
if (error.data.includes('email')) {
|
|
useAlert(t(`${i18nPrefix}.EMAIL_ADDRESS.DUPLICATE`));
|
|
} else if (error.data.includes('phone_number')) {
|
|
useAlert(t(`${i18nPrefix}.PHONE_NUMBER.DUPLICATE`));
|
|
}
|
|
} else if (error instanceof ExceptionWithMessage) {
|
|
useAlert(error.data);
|
|
} else {
|
|
useAlert(t(`${i18nPrefix}.ERROR_MESSAGE`));
|
|
}
|
|
}
|
|
};
|
|
|
|
const onClickViewDetails = async id => {
|
|
const params = { contactId: id };
|
|
if (route.name.includes('segments')) {
|
|
params.segmentId = route.params.segmentId;
|
|
} else if (route.name.includes('labels')) {
|
|
params.label = route.params.label;
|
|
}
|
|
|
|
await router.push({ name: 'contacts_edit', params, query: route.query });
|
|
};
|
|
|
|
const toggleExpanded = id => {
|
|
expandedCardId.value = expandedCardId.value === id ? null : id;
|
|
};
|
|
</script>
|
|
|
|
<template>
|
|
<div class="flex flex-col gap-4 p-6">
|
|
<ContactsCard
|
|
v-for="contact in contacts"
|
|
:id="contact.id"
|
|
:key="contact.id"
|
|
:name="contact.name"
|
|
:email="contact.email"
|
|
:thumbnail="contact.thumbnail"
|
|
:phone-number="contact.phoneNumber"
|
|
:additional-attributes="contact.additionalAttributes"
|
|
:is-expanded="expandedCardId === contact.id"
|
|
:is-updating="isUpdating"
|
|
@toggle="toggleExpanded(contact.id)"
|
|
@update-contact="updateContact"
|
|
@show-contact="onClickViewDetails"
|
|
/>
|
|
</div>
|
|
</template>
|