2019-08-14 09:48:44 +00:00
|
|
|
<template>
|
2022-04-14 15:24:26 +00:00
|
|
|
<div v-if="!authUIFlags.isFetching" id="app" class="app-wrapper app-root">
|
2022-03-15 15:39:14 +00:00
|
|
|
<update-banner :latest-chatwoot-version="latestChatwootVersion" />
|
2019-08-14 09:48:44 +00:00
|
|
|
<transition name="fade" mode="out-in">
|
|
|
|
<router-view></router-view>
|
|
|
|
</transition>
|
2021-08-02 03:24:53 +00:00
|
|
|
<add-account-modal
|
|
|
|
:show="showAddAccountModal"
|
|
|
|
:has-accounts="hasAccounts"
|
|
|
|
/>
|
2019-12-16 12:53:14 +00:00
|
|
|
<woot-snackbar-box />
|
2021-10-12 06:27:36 +00:00
|
|
|
<network-notification />
|
2019-08-14 09:48:44 +00:00
|
|
|
</div>
|
2022-04-14 15:24:26 +00:00
|
|
|
<loading-state v-else />
|
2019-08-14 09:48:44 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-04-06 16:47:07 +00:00
|
|
|
import { mapGetters } from 'vuex';
|
2021-08-02 03:24:53 +00:00
|
|
|
import AddAccountModal from '../dashboard/components/layout/sidebarComponents/AddAccountModal';
|
2022-04-14 15:24:26 +00:00
|
|
|
import LoadingState from './components/widgets/LoadingState.vue';
|
2021-10-12 06:27:36 +00:00
|
|
|
import NetworkNotification from './components/NetworkNotification';
|
2022-03-15 15:39:14 +00:00
|
|
|
import UpdateBanner from './components/app/UpdateBanner.vue';
|
2022-04-14 15:24:26 +00:00
|
|
|
import vueActionCable from './helper/actionCable';
|
2022-03-15 15:39:14 +00:00
|
|
|
import WootSnackbarBox from './components/SnackbarContainer';
|
2022-04-14 15:24:26 +00:00
|
|
|
import {
|
|
|
|
registerSubscription,
|
|
|
|
verifyServiceWorkerExistence,
|
|
|
|
} from './helper/pushHelper';
|
2019-08-14 09:48:44 +00:00
|
|
|
|
|
|
|
export default {
|
2019-08-25 06:13:15 +00:00
|
|
|
name: 'App',
|
2019-08-14 09:48:44 +00:00
|
|
|
|
|
|
|
components: {
|
2021-08-02 03:24:53 +00:00
|
|
|
AddAccountModal,
|
2022-04-14 15:24:26 +00:00
|
|
|
LoadingState,
|
2021-10-12 06:27:36 +00:00
|
|
|
NetworkNotification,
|
2022-03-15 15:39:14 +00:00
|
|
|
UpdateBanner,
|
|
|
|
WootSnackbarBox,
|
2021-08-02 03:24:53 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
showAddAccountModal: false,
|
2022-03-15 15:39:14 +00:00
|
|
|
latestChatwootVersion: null,
|
2021-08-02 03:24:53 +00:00
|
|
|
};
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
|
|
|
|
2020-04-06 16:47:07 +00:00
|
|
|
computed: {
|
|
|
|
...mapGetters({
|
|
|
|
getAccount: 'accounts/getAccount',
|
2021-08-02 03:24:53 +00:00
|
|
|
currentUser: 'getCurrentUser',
|
2022-03-15 15:39:14 +00:00
|
|
|
globalConfig: 'globalConfig/get',
|
2022-04-14 15:24:26 +00:00
|
|
|
authUIFlags: 'getAuthUIFlags',
|
|
|
|
currentAccountId: 'getCurrentAccountId',
|
2020-04-06 16:47:07 +00:00
|
|
|
}),
|
2021-08-02 03:24:53 +00:00
|
|
|
hasAccounts() {
|
2022-04-14 15:24:26 +00:00
|
|
|
const { accounts = [] } = this.currentUser || {};
|
|
|
|
return accounts.length > 0;
|
2021-08-02 03:24:53 +00:00
|
|
|
},
|
2020-04-06 16:47:07 +00:00
|
|
|
},
|
|
|
|
|
2021-08-02 03:24:53 +00:00
|
|
|
watch: {
|
|
|
|
currentUser() {
|
|
|
|
if (!this.hasAccounts) {
|
|
|
|
this.showAddAccountModal = true;
|
|
|
|
}
|
2022-04-14 15:24:26 +00:00
|
|
|
verifyServiceWorkerExistence(registration =>
|
|
|
|
registration.pushManager.getSubscription().then(subscription => {
|
|
|
|
if (subscription) {
|
|
|
|
registerSubscription();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
},
|
|
|
|
currentAccountId() {
|
|
|
|
if (this.currentAccountId) {
|
|
|
|
this.initializeAccount();
|
|
|
|
}
|
2021-08-02 03:24:53 +00:00
|
|
|
},
|
|
|
|
},
|
2019-08-14 09:48:44 +00:00
|
|
|
mounted() {
|
2020-11-24 13:04:31 +00:00
|
|
|
this.setLocale(window.chatwootConfig.selectedLocale);
|
2020-04-06 16:47:07 +00:00
|
|
|
},
|
|
|
|
methods: {
|
2020-11-24 13:04:31 +00:00
|
|
|
setLocale(locale) {
|
2020-12-12 06:38:36 +00:00
|
|
|
this.$root.$i18n.locale = locale;
|
2020-11-24 13:04:31 +00:00
|
|
|
},
|
2020-04-06 16:47:07 +00:00
|
|
|
async initializeAccount() {
|
2022-04-14 15:24:26 +00:00
|
|
|
await this.$store.dispatch('accounts/get');
|
|
|
|
const {
|
|
|
|
locale,
|
|
|
|
latest_chatwoot_version: latestChatwootVersion,
|
|
|
|
} = this.getAccount(this.currentAccountId);
|
|
|
|
const { pubsub_token: pubsubToken } = this.currentUser || {};
|
|
|
|
this.setLocale(locale);
|
|
|
|
this.latestChatwootVersion = latestChatwootVersion;
|
|
|
|
vueActionCable.init(pubsubToken);
|
2020-04-06 16:47:07 +00:00
|
|
|
},
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
@import './assets/scss/app';
|
2022-03-15 15:39:14 +00:00
|
|
|
.update-banner {
|
|
|
|
height: var(--space-larger);
|
|
|
|
align-items: center;
|
|
|
|
font-size: var(--font-size-small) !important;
|
|
|
|
}
|
2019-08-14 09:48:44 +00:00
|
|
|
</style>
|
2019-08-25 06:13:15 +00:00
|
|
|
|
|
|
|
<style src="vue-multiselect/dist/vue-multiselect.min.css"></style>
|