mirror of
https://github.com/lingble/chatwoot.git
synced 2025-10-30 18:47:51 +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
97 lines
2.5 KiB
Vue
97 lines
2.5 KiB
Vue
<script>
|
|
import { mapGetters } from 'vuex';
|
|
import { useAlert } from 'dashboard/composables';
|
|
import { CONTACTS_EVENTS } from '../../../../helper/AnalyticsHelper/events';
|
|
import Modal from '../../../../components/Modal.vue';
|
|
import { useTrack } from 'dashboard/composables';
|
|
|
|
export default {
|
|
components: {
|
|
Modal,
|
|
},
|
|
props: {
|
|
onClose: {
|
|
type: Function,
|
|
default: () => {},
|
|
},
|
|
},
|
|
data() {
|
|
return {
|
|
show: true,
|
|
file: '',
|
|
};
|
|
},
|
|
computed: {
|
|
...mapGetters({
|
|
uiFlags: 'contacts/getUIFlags',
|
|
}),
|
|
csvUrl() {
|
|
return '/downloads/import-contacts-sample.csv';
|
|
},
|
|
},
|
|
mounted() {
|
|
useTrack(CONTACTS_EVENTS.IMPORT_MODAL_OPEN);
|
|
},
|
|
methods: {
|
|
async uploadFile() {
|
|
try {
|
|
if (!this.file) return;
|
|
await this.$store.dispatch('contacts/import', this.file);
|
|
this.onClose();
|
|
useAlert(this.$t('IMPORT_CONTACTS.SUCCESS_MESSAGE'));
|
|
useTrack(CONTACTS_EVENTS.IMPORT_SUCCESS);
|
|
} catch (error) {
|
|
useAlert(error.message || this.$t('IMPORT_CONTACTS.ERROR_MESSAGE'));
|
|
useTrack(CONTACTS_EVENTS.IMPORT_FAILURE);
|
|
}
|
|
},
|
|
handleFileUpload() {
|
|
this.file = this.$refs.file.files[0];
|
|
},
|
|
},
|
|
};
|
|
</script>
|
|
|
|
<template>
|
|
<Modal v-model:show="show" :on-close="onClose">
|
|
<div class="flex flex-col h-auto overflow-auto">
|
|
<woot-modal-header :header-title="$t('IMPORT_CONTACTS.TITLE')">
|
|
<p>
|
|
{{ $t('IMPORT_CONTACTS.DESC') }}
|
|
<a :href="csvUrl" download="import-contacts-sample">{{
|
|
$t('IMPORT_CONTACTS.DOWNLOAD_LABEL')
|
|
}}</a>
|
|
</p>
|
|
</woot-modal-header>
|
|
<div class="flex flex-col p-8">
|
|
<div class="w-full">
|
|
<label>
|
|
<span>{{ $t('IMPORT_CONTACTS.FORM.LABEL') }}</span>
|
|
<input
|
|
id="file"
|
|
ref="file"
|
|
type="file"
|
|
accept="text/csv"
|
|
@change="handleFileUpload"
|
|
/>
|
|
</label>
|
|
</div>
|
|
<div class="flex flex-row justify-end w-full gap-2 px-0 py-2">
|
|
<div class="w-full">
|
|
<woot-button
|
|
:disabled="uiFlags.isCreating || !file"
|
|
:loading="uiFlags.isCreating"
|
|
@click="uploadFile"
|
|
>
|
|
{{ $t('IMPORT_CONTACTS.FORM.SUBMIT') }}
|
|
</woot-button>
|
|
<button class="button clear" @click.prevent="onClose">
|
|
{{ $t('IMPORT_CONTACTS.FORM.CANCEL') }}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</Modal>
|
|
</template>
|