mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-01 03:27:52 +00:00
These fixes are all auto generated and can be merged directly Fixes the following issues 1. Event used on components should be hypenated 2. Attribute orders in components 3. Use `unmounted` instead of `destroyed` 4. Add explicit `emits` declarations for components, autofixed [using this script](https://gist.github.com/scmmishra/6f549109b96400006bb69bbde392eddf) We ignore the top level v-if for now, we will fix it later
125 lines
2.8 KiB
Vue
125 lines
2.8 KiB
Vue
<script>
|
|
import LoadingState from 'dashboard/components/widgets/LoadingState.vue';
|
|
export default {
|
|
components: {
|
|
LoadingState,
|
|
},
|
|
props: {
|
|
config: {
|
|
type: Array,
|
|
default: () => [],
|
|
},
|
|
currentChat: {
|
|
type: Object,
|
|
default: () => ({}),
|
|
},
|
|
isVisible: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
position: {
|
|
type: Number,
|
|
required: true,
|
|
},
|
|
},
|
|
data() {
|
|
return {
|
|
hasOpenedAtleastOnce: false,
|
|
iframeLoading: true,
|
|
};
|
|
},
|
|
computed: {
|
|
dashboardAppContext() {
|
|
return {
|
|
conversation: this.currentChat,
|
|
contact: this.$store.getters['contacts/getContact'](this.contactId),
|
|
currentAgent: this.currentAgent,
|
|
};
|
|
},
|
|
contactId() {
|
|
return this.currentChat?.meta?.sender?.id;
|
|
},
|
|
currentAgent() {
|
|
const { id, name, email } = this.$store.getters.getCurrentUser;
|
|
return { id, name, email };
|
|
},
|
|
},
|
|
watch: {
|
|
isVisible() {
|
|
if (this.isVisible) {
|
|
this.hasOpenedAtleastOnce = true;
|
|
}
|
|
},
|
|
},
|
|
|
|
mounted() {
|
|
window.onmessage = e => {
|
|
if (
|
|
typeof e.data !== 'string' ||
|
|
e.data !== 'chatwoot-dashboard-app:fetch-info'
|
|
) {
|
|
return;
|
|
}
|
|
this.onIframeLoad(0);
|
|
};
|
|
},
|
|
methods: {
|
|
getFrameId(index) {
|
|
return `dashboard-app--frame-${this.position}-${index}`;
|
|
},
|
|
onIframeLoad(index) {
|
|
// A possible alternative is to use ref instead of document.getElementById
|
|
// However, when ref is used together with v-for, the ref you get will be
|
|
// an array containing the child components mirroring the data source.
|
|
const frameElement = document.getElementById(this.getFrameId(index));
|
|
const eventData = { event: 'appContext', data: this.dashboardAppContext };
|
|
frameElement.contentWindow.postMessage(JSON.stringify(eventData), '*');
|
|
this.iframeLoading = false;
|
|
},
|
|
},
|
|
};
|
|
</script>
|
|
|
|
<!-- eslint-disable-next-line vue/no-root-v-if -->
|
|
<template>
|
|
<div v-if="hasOpenedAtleastOnce" class="dashboard-app--container">
|
|
<div
|
|
v-for="(configItem, index) in config"
|
|
:key="index"
|
|
class="dashboard-app--list"
|
|
>
|
|
<LoadingState
|
|
v-if="iframeLoading"
|
|
:message="$t('DASHBOARD_APPS.LOADING_MESSAGE')"
|
|
class="dashboard-app_loading-container"
|
|
/>
|
|
<iframe
|
|
v-if="configItem.type === 'frame' && configItem.url"
|
|
:id="getFrameId(index)"
|
|
:src="configItem.url"
|
|
@load="() => onIframeLoad(index)"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.dashboard-app--container,
|
|
.dashboard-app--list,
|
|
.dashboard-app--list iframe {
|
|
height: 100%;
|
|
width: 100%;
|
|
}
|
|
|
|
.dashboard-app--list iframe {
|
|
border: 0;
|
|
}
|
|
.dashboard-app_loading-container {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
height: 100%;
|
|
width: 100%;
|
|
}
|
|
</style>
|