mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-01 19:48:08 +00:00
References - https://v3-migration.vuejs.org/breaking-changes/v-model - https://v3-migration.vuejs.org/breaking-changes/v-on-native-modifier-removed.html
92 lines
2.2 KiB
Vue
92 lines
2.2 KiB
Vue
<script>
|
|
import { defineModel } from 'vue';
|
|
import { useAlert, useTrack } from 'dashboard/composables';
|
|
import MergeContact from 'dashboard/modules/contact/components/MergeContact.vue';
|
|
|
|
import ContactAPI from 'dashboard/api/contacts';
|
|
|
|
import { mapGetters } from 'vuex';
|
|
import { CONTACTS_EVENTS } from '../../helper/AnalyticsHelper/events';
|
|
|
|
export default {
|
|
components: { MergeContact },
|
|
props: {
|
|
primaryContact: {
|
|
type: Object,
|
|
required: true,
|
|
},
|
|
},
|
|
setup() {
|
|
const show = defineModel('show', { type: Boolean, default: false });
|
|
|
|
return { show };
|
|
},
|
|
data() {
|
|
return {
|
|
isSearching: false,
|
|
searchResults: [],
|
|
};
|
|
},
|
|
computed: {
|
|
...mapGetters({
|
|
uiFlags: 'contacts/getUIFlags',
|
|
}),
|
|
},
|
|
|
|
methods: {
|
|
onClose() {
|
|
this.$emit('close');
|
|
},
|
|
async onContactSearch(query) {
|
|
this.isSearching = true;
|
|
this.searchResults = [];
|
|
|
|
try {
|
|
const {
|
|
data: { payload },
|
|
} = await ContactAPI.search(query);
|
|
this.searchResults = payload.filter(
|
|
contact => contact.id !== this.primaryContact.id
|
|
);
|
|
} catch (error) {
|
|
useAlert(this.$t('MERGE_CONTACTS.SEARCH.ERROR_MESSAGE'));
|
|
} finally {
|
|
this.isSearching = false;
|
|
}
|
|
},
|
|
async onMergeContacts(parentContactId) {
|
|
useTrack(CONTACTS_EVENTS.MERGED_CONTACTS);
|
|
try {
|
|
await this.$store.dispatch('contacts/merge', {
|
|
childId: this.primaryContact.id,
|
|
parentId: parentContactId,
|
|
});
|
|
useAlert(this.$t('MERGE_CONTACTS.FORM.SUCCESS_MESSAGE'));
|
|
this.onClose();
|
|
} catch (error) {
|
|
useAlert(this.$t('MERGE_CONTACTS.FORM.ERROR_MESSAGE'));
|
|
}
|
|
},
|
|
},
|
|
};
|
|
</script>
|
|
|
|
<template>
|
|
<woot-modal v-model:show="show" :on-close="onClose">
|
|
<woot-modal-header
|
|
:header-title="$t('MERGE_CONTACTS.TITLE')"
|
|
:header-content="$t('MERGE_CONTACTS.DESCRIPTION')"
|
|
/>
|
|
|
|
<MergeContact
|
|
:primary-contact="primaryContact"
|
|
:is-searching="isSearching"
|
|
:is-merging="uiFlags.isMerging"
|
|
:search-results="searchResults"
|
|
@search="onContactSearch"
|
|
@cancel="onClose"
|
|
@submit="onMergeContacts"
|
|
/>
|
|
</woot-modal>
|
|
</template>
|