diff --git a/app/frontend/packs/application-provider.js b/app/frontend/packs/application-provider.js index 9dae8dff60a..69ee7669415 100644 --- a/app/frontend/packs/application-provider.js +++ b/app/frontend/packs/application-provider.js @@ -5,6 +5,7 @@ import filter from './components/paginated_filter' import checkboxSearchFilter from './components/checkbox_search_filter' import '../styles/application-provider.scss' import cookieBanners from './cookies/cookie-banners' +import webchat from './webchat' require.context('govuk-frontend/govuk/assets') @@ -14,3 +15,4 @@ initAddFurtherConditions() checkboxSearchFilter('subject', 'Search for subject') filter() cookieBanners() +webchat() diff --git a/app/frontend/packs/webchat.js b/app/frontend/packs/webchat.js new file mode 100644 index 00000000000..e7dd978b589 --- /dev/null +++ b/app/frontend/packs/webchat.js @@ -0,0 +1,71 @@ +function Webchat () { + this.container = document.getElementById('app-web-chat') + + this.configureWidget() + this.setupElements() + this.addButtonListener() + this.addStatusChangeListener() +} + +Webchat.prototype.configureWidget = function () { + window.zESettings = { + webWidget: { + chat: { + suppress: true + } + } + } +} + +Webchat.prototype.setupElements = function () { + this.enabledContainer = document.createElement('span') + this.enabledContainer.className = 'moj-hidden' + + this.defaultContainer = document.querySelector('.app-web-chat__unavailable') + + this.button = document.createElement('a') + this.button.href = '#' + this.button.className = 'govuk-link govuk-footer__link app-web-chat__button' + this.button.innerHTML = 'Speak to an advisor now (opens in new window)' + this.enabledContainer.append(this.button) + + this.disabledContainer = document.createElement('span') + this.disabledContainer.className = 'app-web-chat__offline moj-hidden' + this.disabledContainer.innerHTML = 'Available Monday to Friday, 10am to midday (except public holidays).' + + this.container.append(this.enabledContainer) + this.container.append(this.disabledContainer) +} + +Webchat.prototype.addButtonListener = function () { + this.button.addEventListener('click', function (e) { + e.preventDefault() + + zE('webWidget', 'popout') + }, false) +} + +Webchat.prototype.addStatusChangeListener = function () { + zE('webWidget:on', 'chat:status', function (status) { + this.defaultContainer.classList.add('moj-hidden') + + if (status === 'online') { + this.enableChat() + } else { + this.disableChat() + } + }.bind(this)) +} + +Webchat.prototype.enableChat = function () { + this.disabledContainer.classList.add('moj-hidden') + this.enabledContainer.classList.remove('moj-hidden') +} + +Webchat.prototype.disableChat = function () { + this.disabledContainer.classList.remove('moj-hidden') + this.enabledContainer.classList.add('moj-hidden') +} + +const webchat = () => new Webchat() +export default webchat diff --git a/app/frontend/packs/zendesk-stub.js b/app/frontend/packs/zendesk-stub.js new file mode 100644 index 00000000000..28d67ac5797 --- /dev/null +++ b/app/frontend/packs/zendesk-stub.js @@ -0,0 +1,18 @@ +window.zendeskPopupOpen = false + +window.setZendeskStatus = function (status) { + const statusChangeEvent = new CustomEvent('setZendeskStubStatus', { detail: status }) + document.body.dispatchEvent(statusChangeEvent) +} + +window.zE = function (scope, command, callback = null) { + if (scope === 'webWidget' && command === 'popout') { + window.zendeskPopupOpen = true + } else if (scope === 'webWidget:on' && command === 'chat:status') { + document.body.addEventListener('setZendeskStubStatus', function (e) { + callback(e.detail) + }) + } else { + throw Error('Unexpected Zendesk API function call') + } +} diff --git a/app/views/layouts/_footer_meta_provider.html.erb b/app/views/layouts/_footer_meta_provider.html.erb index e038e3d52d9..769f84a260a 100644 --- a/app/views/layouts/_footer_meta_provider.html.erb +++ b/app/views/layouts/_footer_meta_provider.html.erb @@ -1,14 +1,36 @@

<%= t('layout.support.title') %>

- -

- <%= link_to t('layout.support.provider_service_guidance'), provider_interface_service_guidance_path, class: 'govuk-footer__link' %> -

+ + +

<%= t('layout.support_links.title') %>

-