Skip to content

Instantly share code, notes, and snippets.

@dimasch
Last active August 17, 2021 07:49
Show Gist options
  • Save dimasch/bc136fee60e5af8eeb1eb34f0e491ead to your computer and use it in GitHub Desktop.
Save dimasch/bc136fee60e5af8eeb1eb34f0e491ead to your computer and use it in GitHub Desktop.
The Zendesk integration for Vue Storefront
import Zendesk from '@dansmaculotte/vue-zendesk'
import { Logger } from '@vue-storefront/core/lib/logger'
import { once, isServer } from '@vue-storefront/core/helpers'
import { StorefrontModule } from '@vue-storefront/core/lib/modules';
import Vue from 'vue';
const zendeskStore = {
namespaced: true,
state: {
key: null
}
}
export const ZendeskModule: StorefrontModule = function ({ store, router, appConfig }) {
if (appConfig.zendesk.key && !isServer) {
once('__VUE_EXTEND_ZENDESK__', () => {
Vue.use(Zendesk, {
key: appConfig.zendesk.key || '',
disabled: true,
hideOnLoad: true,
settings: {
webWidget: {
color: {
theme: '#78a300'
}
}
}
})
})
} else {
Logger.warn(
'Zendesk extension is not working. Ensure Zendesk account ID is defined in config',
'Zendesk'
)()
}
store.registerModule('zendesk', zendeskStore)
if (appConfig.zendesk.key && !isServer) {
Vue.$zendesk.show()
// or we can improve a time for display via subscribe on any VSF events:
/*
Vue.prototype.$bus.$on('any-custom-event-name', event => {
Vue.$zendesk.show()
});
*/
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment