@defra/flood-webchat 1.0.23 → 1.0.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.js CHANGED
@@ -1 +1 @@
1
- (()=>{"use strict";var e={n:t=>{var a=t&&t.__esModule?()=>t.default:()=>t;return e.d(a,{a}),a},d:(t,a)=>{for(var n in a)e.o(a,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:a[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{init:()=>ee});const a=require("react");var n=e.n(a);const l=require("react-dom/client"),o=require("@nice-devone/nice-cxone-chat-web-sdk"),r=(...e)=>e.filter(e=>e&&"string"==typeof e).join(" "),s=require("react-dom"),c=require("luxon"),i=require("html-react-parser");var u=e.n(i);const d=/(?:www|https?)[^\s]+/gi,m=e=>(e.match(d)&&(e=e.replace(d,e=>`<a class="govuk-link" href="${e}" target="_blank" rel="noreferrer">${e.replace(/https?:\/\//gi,"")}</a>`)),u()(e)),g=e=>({id:e.id,text:e.messageContent?.text,createdAt:new Date(e.createdAt),user:e.authorEndUserIdentity?.fullName?.trim()||null,assignee:e.authorUser?.firstName||null,direction:e.direction}),h=e=>{const t=c.DateTime.local();t.setZone("Europe/London");let a=`Floodline webchat transcript, ${t.toFormat("HH:mm:ss a, dd LLLL yyyy")}\n\n`;for(const t of e){const{text:e,direction:n,user:l,assignee:o,createdAt:r}=t,s="inbound"===n?l:`${o} (Floodline adviser)`;a+=`[${c.DateTime.fromJSDate(new Date(r)).setZone("Europe/London").toFormat("HH:mm:ss a, dd LLLL yyyy")}] ${s}: \n${e}\n\n`}return a=a.replace(/<a\b[^>]*>/i,"").replace(/<\/a>/i,""),encodeURIComponent(a)},E="webchat_settings",w="webchat_customer_id",v="webchat_thread_id",b=4e3,y={SET_CHAT_VISIBILITY:(e,t)=>({...e,isChatOpen:t}),SET_AVAILABILITY:(e,t)=>({...e,availability:t}),SET_SETTINGS:(e,t)=>(t?window.localStorage.setItem(E,JSON.stringify(t)):window.localStorage.removeItem(E),{...e,settings:t}),SET_CUSTOMER_ID:(e,t)=>(t?window.localStorage.setItem(w,t):window.localStorage.removeItem(w),{...e,customerId:t}),SET_THREAD_ID:(e,t)=>(t?window.localStorage.setItem(v,t):window.localStorage.removeItem(v),{...e,threadId:t}),SET_THREAD:(e,t)=>({...e,thread:t}),SET_MESSAGE:(e,t)=>({...e,message:g(t),messages:[...e.messages,g(t)]}),SET_MESSAGES:(e,t)=>{return{...e,messages:(a=t,a.map(e=>g(e))).reverse()};var a},SET_AGENT:(e,t)=>({...e,agent:t}),SET_AGENT_TYPING:(e,t)=>({...e,isAgentTyping:t}),SET_AGENT_STATUS:(e,t)=>({...e,agentStatus:t}),SET_UNSEEN_COUNT:(e,t)=>({...e,unseenCount:t}),SET_INSTIGATOR_ID:(e,t)=>({...e,instigatorId:t}),SET_LIVE_REGION_TEXT:(e,t)=>({...e,liveRegionText:t}),TOGGLE_IS_MOBILE:(e,t)=>({...e,isMobile:t}),TOGGLE_IS_KEYBOARD:(e,t)=>({...e,isKeyboard:t})},f={availability:null,customerId:null,threadId:null,thread:null,messages:[],unseenCount:0,instigatorId:null,agent:null,agentStatus:null,isAgentTyping:!1,isChatOpen:!1,isMobile:window.matchMedia("(max-width: 640px)").matches,isKeyboard:!1,settings:{audio:!0,scroll:!0}},p=(e,t)=>{const{type:a,payload:n}=t,l=y[a];return l?l.bind(void 0,e,n)():e},k=(0,a.createContext)(f),_=({sdk:e,availability:t,playSound:l,children:r})=>{const[s,c]=(0,a.useReducer)(p,f),i=e=>{c({type:"SET_AGENT",payload:e.detail.data.inboxAssignee}),c({type:"SET_AGENT_STATUS",payload:e.detail.data.contact.status}),c({type:"SET_UNSEEN_COUNT",payload:e.detail.data.contact.customerStatistics.unseenMessagesCount})},u=e=>{c({type:"SET_AGENT",payload:e.detail.data.inboxAssignee}),c({type:"SET_AGENT_STATUS",payload:e.detail.data.case.status})},d=()=>{c({type:"SET_AGENT_TYPING",payload:!0})},m=()=>{c({type:"SET_AGENT_TYPING",payload:!1}),c({type:"SET_LIVE_REGION_TEXT"})},g=e=>{c({type:"SET_MESSAGE",payload:e.detail.data.message}),c({type:"SET_AGENT_STATUS",payload:e.detail.data.case.status}),c({type:"SET_UNSEEN_COUNT",payload:e.detail.data.case.customerStatistics.unseenMessagesCount}),JSON.parse(window.localStorage.getItem(E)).audio&&"outbound"===e.detail.data.message.direction&&l&&l()},h=e=>{c({type:"SET_AGENT_STATUS",payload:e.detail.data.case.status})},b=e=>{c({type:"TOGGLE_IS_MOBILE",payload:e.matches})},y=()=>{c({type:"TOGGLE_IS_KEYBOARD",payload:!0})},_=()=>{c({type:"TOGGLE_IS_KEYBOARD",payload:!1})};(0,a.useEffect)(()=>(e.onChatEvent(o.ChatEvent.LIVECHAT_RECOVERED,i),e.onChatEvent(o.ChatEvent.MESSAGE_CREATED,g),e.onChatEvent(o.ChatEvent.AGENT_TYPING_STARTED,d),e.onChatEvent(o.ChatEvent.AGENT_TYPING_ENDED,m),e.onChatEvent(o.ChatEvent.ASSIGNED_AGENT_CHANGED,u),e.onChatEvent(o.ChatEvent.CONTACT_STATUS_CHANGED,h),window.matchMedia("(max-width: 640px)").addEventListener("change",b),window.addEventListener("keydown",y),window.addEventListener("pointerdown",_),()=>{window.removeEventListener("change",b),window.removeEventListener("keydown",y),window.removeEventListener("pointerdown",_)}),[e]),(0,a.useEffect)(()=>{c({type:"SET_AVAILABILITY",payload:t}),N(window.localStorage.getItem(w)),T(window.localStorage.getItem(v)),A(JSON.parse(window.localStorage.getItem(E))||s.settings)},[]),(0,a.useEffect)(()=>{"#webchat"===window.location.hash&&S(!0);const e=()=>{"#webchat"===window.location.hash?S(!0):S(!1)};return window.addEventListener("popstate",e),()=>{window.removeEventListener("popstate",e)}},[]);const S=e=>{c({type:"SET_CHAT_VISIBILITY",payload:e})},N=e=>{c({type:"SET_CUSTOMER_ID",payload:e})},T=e=>{c({type:"SET_THREAD_ID",payload:e})},C=e=>{c({type:"SET_THREAD",payload:e})},I=e=>{c({type:"SET_MESSAGES",payload:e})},A=e=>{c({type:"SET_SETTINGS",payload:e})},L=e=>{c({type:"SET_UNSEEN_COUNT",payload:e})},x=e=>{c({type:"SET_INSTIGATOR_ID",payload:e})},D=e=>{c({type:"SET_LIVE_REGION_TEXT",payload:e})},G=(0,a.useMemo)(()=>({...s,sdk:e,setSettings:A,setCustomerId:N,setThreadId:T,setThread:C,setMessages:I,setUnseenCount:L,setChatVisibility:S,setInstigatorId:x,setLiveRegionText:D,onLiveChatRecovered:i,onAssignedAgentChanged:u,onAgentTypingStarted:d,onAgentTypingEnded:m,onMessageCreated:g,onContactStatusChanged:h}));return n().createElement(k.Provider,{value:G},r)},S=()=>(0,a.useContext)(k),N=()=>{const e=window.location.href.split("#")[0];window.history.pushState({history:!0},null,`${e}#webchat`)},T=()=>{if(window.history.state?.history)return window.history.back();const e=window.location.href.split("#")[0];return window.history.replaceState(null,null,e)};function C(){const{thread:e,threadId:t,setChatVisibility:a,setUnseenCount:l,isMobile:o}=S(),r=n=>{n.preventDefault(),a(!1),T(),t&&(e?.lastMessageSeen(),l(0))},s=n().createElement("button",{className:"wc-header__back","aria-label":"Close the webchat",onClick:r},n().createElement("svg",{"aria-hidden":"true",focusable:"false",width:"20",height:"20",viewBox:"0 0 20 20"},n().createElement("path",{d:"M4.828,11L12.314,18.485L10.899,19.899L1,10L10.899,0.101L12.314,1.515L4.828,9L19,9L19,11L4.828,11Z",fill:"currentColor"}))),c=n().createElement("button",{className:"wc-header__close","aria-label":"Close the webchat",onClick:r},n().createElement("svg",{"aria-hidden":"true",focusable:"false",width:"20",height:"20",viewBox:"0 0 20 20"},n().createElement("path",{d:"M10,8.6L15.6,3L17,4.4L11.4,10L17,15.6L15.6,17L10,11.4L4.4,17L3,15.6L8.6,10L3,4.4L4.4,3L10,8.6Z",fill:"currentColor"}))),i=n().createElement("button",{className:"wc-header__hide","aria-label":"Minimise the webchat",onClick:r},n().createElement("svg",{"aria-hidden":"true",focusable:"false",width:"20",height:"20",viewBox:"0 0 20 20"},n().createElement("path",{d:"M10 14.4l-7-7L4.4 6l5.6 5.6L15.6 6 17 7.4l-7 7z",fill:"currentColor"}))),u=o&&window.history.state,d=o&&!window.history.state;let m=c;return t&&(m=i,d&&(m=i)),!t&&d&&(m=c),u&&(m=null),n().createElement("div",{className:"wc-header"},u?s:null,n().createElement("h2",{id:"wc-header",className:"wc-header__title"},"Floodline webchat"),m)}function I({onContinue:e}){return n().createElement(n().Fragment,null,n().createElement(C,null),n().createElement("div",{className:"wc-body"},n().createElement("div",{className:"wc-content"},n().createElement("h3",{id:"wc-subtitle",className:"wc-heading","aria-live":"polite"},"What you can use webchat for"),n().createElement("p",null,"Webchat lets you talk directly to a Floodline adviser."),n().createElement("p",null,"You can use webchat to get:"),n().createElement("ul",{className:"wc-list"},n().createElement("li",null,"current flood warnings and alerts in your area"),n().createElement("li",null,"information on the flood warning service"),n().createElement("li",null,"advice on what to do before, during and after a flood")),n().createElement("p",null,"There are other ways to ",n().createElement("a",{className:"govuk-link",href:"https://www.gov.uk/sign-up-for-flood-warnings",target:"_blank",rel:"noreferrer"},"sign up for flood warnings")," and ",n().createElement("a",{className:"govuk-link",href:"https://www.fws.environment-agency.gov.uk/app/olr/login",target:"_blank",rel:"noreferrer"},"manage your flood warnings account"),"."),n().createElement("p",null,"Do not use webchat to ",n().createElement("a",{className:"govuk-link",href:"https://www.gov.uk/report-flood-cause",target:"_blank",rel:"noreferrer"},"report a flood"),"."),n().createElement("button",{className:"govuk-button wc-button govuk-!-margin-top-1","data-module":"govuk-button",onClick:e},"Continue"),n().createElement("h3",{className:"wc-heading"},"Other flood information"),n().createElement("p",null,"Call Floodline for all other flood and flood warning information."),n().createElement("p",null,n().createElement("strong",null,"Floodline helpline"),n().createElement("br",null),"Telephone: 0345 988 1188",n().createElement("br",null),"Textphone: 0345 602 6340",n().createElement("br",null),"Open 24 hours a day, 7 days a week",n().createElement("br",null),n().createElement("a",{className:"govuk-link",href:"https://gov.uk/call-charges",target:"_blank",rel:"noreferrer"},"Find out more about call charges")))))}const A=require("uuid"),L=e=>{const t=async()=>e.authorize();return{connect:t,fetchCustomerId:async()=>{const e=await t();return e?.consumerIdentity.idOnExternalPlatform},fetchThread:async a=>(await t(),e.getThread(a)),fetchMessages:async(e,a)=>{await t();const n=await e.recover(a),l=[];let o=n.messages;for(;o.length;){o.map(e=>l.push(e));try{o=(await e.loadMoreMessages()).data.messages}catch(e){o=[]}}return l}}},x=({errors:e})=>{const t=Object.keys(e),a=e=>{e.preventDefault();const t=e.target.getAttribute("data-key");document.querySelector(`#wc-${t}`).focus()};return 0===t.length?null:n().createElement("div",{className:"govuk-error-summary govuk-!-static-margin-bottom-7","data-module":"govuk-error-summary",tabIndex:"-1"},n().createElement("div",{role:"alert"},n().createElement("h2",{id:"wc-error",className:"wc-error-summary__title govuk-error-summary__title"},"There is a problem"),n().createElement("div",{className:"govuk-error-summary__body"},n().createElement("ul",{className:"govuk-list govuk-error-summary__list wc-error-summary__list"},t.map(t=>n().createElement("li",{key:t},n().createElement("a",{href:"#","data-key":t,onClick:a},e[t])))))))},D=500;function G({onPreChatScreen:e}){const{sdk:t,setCustomerId:l,setThreadId:o,setThread:s,setLiveRegionText:c}=S(),{fetchCustomerId:i,fetchThread:u}=L(t),[d,m]=(0,a.useState)({}),[g,h]=(0,a.useState)(0),[E,w]=(0,a.useState)(!1),v=(0,a.useRef)(),b=(0,a.useRef)(),y=D>=g;let f=`You have ${D-g} characters remaining`;y||(f=`You have ${g-D} characters too many`),(0,a.useEffect)(()=>{Object.keys(d).length&&document.querySelector(".govuk-error-summary")?.focus()},[d]);const p=E?"Requesting...":"Request chat";return(0,a.useEffect)(()=>{E&&c(p)},[E]),n().createElement(n().Fragment,null,n().createElement(C,null),n().createElement("div",{className:"wc-body"},n().createElement("div",{className:"wc-content"},n().createElement("a",{href:"#",className:"wc-back-link govuk-back-link",onClick:e},"What you can use webchat for"),n().createElement(x,{errors:d}),n().createElement("h3",{id:"wc-subtitle",className:"wc-heading","aria-live":"polite"},"Your name and question"),n().createElement("form",null,n().createElement("div",{className:r("wc-form-group","govuk-form-group",d.name&&"govuk-form-group--error")},n().createElement("label",{className:"wc-label govuk-label",htmlFor:"wc-name"},"Your name"),d.name&&n().createElement("p",{className:"govuk-error-message"},n().createElement("span",{className:"govuk-visually-hidden"},"Error:")," ",d.name),n().createElement("input",{ref:v,className:r("wc-input","govuk-input",d.name&&"govuk-input--error"),id:"wc-name",name:"name",type:"text","data-testid":"request-chat-user-name"})),n().createElement("div",{className:"wc-form-group govuk-character-count","data-module":"govuk-character-count","data-maxlength":"500"},n().createElement("div",{className:r("govuk-form-group",d.question&&"govuk-form-group--error")},n().createElement("label",{className:"wc-label govuk-label",htmlFor:"wc-question"},"Your question"),d.question&&n().createElement("p",{className:"govuk-error-message"},n().createElement("span",{className:"govuk-visually-hidden"},"Error:"),d.question),n().createElement("textarea",{ref:b,id:"wc-question",name:"question",rows:"5","aria-describedby":"wc-question-info",onChange:e=>{h(e.target.value.length)},className:r("wc-textarea","govuk-textarea","govuk-js-character-count",!y||d.question?"govuk-textarea--error":""),"data-testid":"request-chat-user-question"}),n().createElement("div",{id:"wc-question-info",className:"wc-hint govuk-hint govuk-char-count__msg",style:{color:y?"":"#d4351c"},"aria-hidden":"true"},f),n().createElement("div",{className:"govuk-character-count__sr-status govuk-visually-hidden","aria-live":"polite"},f))),n().createElement("div",{className:"wc-inset-text govuk-inset-text"},"By selecting 'Request chat' you agree to the terms of our ",n().createElement("a",{href:"https://check-for-flooding.service.gov.uk/privacy-notice",target:"_blank",rel:"noreferrer",className:"govuk-link"},"privacy notice"),"."),n().createElement("button",{className:"wc-button govuk-button govuk-!-margin-top-1","data-module":"govuk-button",onClick:async e=>{if(e.preventDefault(),E)return;const a={};if(0===v.current.value.length&&(a.name="Enter your name"),0===b.current.value.length&&(a.question="Enter your question"),b.current.value.length>D&&(a.question="Your question must be 500 characters or less"),0===Object.keys(a).length)try{w(!0);const e=A.v4(),a=await i(),n=await u(e);t.getCustomer().setName(v.current.value),await n.startChat(b.current.value||"Begin conversation"),l(a),o(e),s(n),n.setCustomField("threadid",e)}catch(e){console.log("[Request chat Error]",e)}m(a)},"aria-disabled":E},p)))))}function q({children:e}){return n().createElement("div",{className:"wc-footer"},e)}function O({message:e,previousMessage:t}){const a="outbound"===e.direction,l=e?.direction===t?.direction;return n().createElement("li",{className:r("wc-chat__message",a?"outbound":"inbound")},n().createElement("div",{className:"wc-chat__from"},l?null:n().createElement("span",{className:r(a?"outbound":"inbound")},a?e.assignee:"You"),n().createElement("span",{className:"govuk-visually-hidden"},":")),n().createElement("div",{className:r("wc-chat__text",a?"outbound":"inbound")},m(e.text)))}const M=(e,t)=>{(0,a.useEffect)(()=>{if(e){e.style.height="0px";const t=e.scrollHeight;e.style.height=`${t}px`}},[e,t])},R=(e,t,a)=>{if("UNAVAILABLE"===e)return"Webchat is not currently available";if(!t)return"Connecting to Floodline";switch(t){case"closed":case"resolved":return a?`${a} ended the session`:"Session ended by advisor";default:return a?`You are speaking with ${a}`:"Waiting for an adviser"}};function F({onEndChatScreen:e,onSettingsScreen:t}){const{availability:l,thread:o,messages:r,agent:s,agentStatus:c,isAgentTyping:i,isChatOpen:u,settings:d,isKeyboard:m,setLiveRegionText:g}=S(),[E,w]=(0,a.useState)(""),[v,y]=(0,a.useState)(!1),f=(0,a.useRef)();M(f.current,E),(0,a.useEffect)(()=>{if(d.scroll&&0!==r.length){const e=document.querySelector(".wc-body");e.scrollTop=e.scrollHeight}},[r,i]),(0,a.useEffect)(()=>{const e=document.querySelector(".wc-form__label");0===E.length?e.classList.remove("govuk-visually-hidden"):e.classList.add("govuk-visually-hidden")},[E]);const p=[...r].reverse().find(e=>"outbound"===e.direction&&e.assignee),k=s?.nickname||s?.firstName||p?.assignee,_=R(l,c,k);(0,a.useEffect)(()=>(_&&g(`Floodline webchat - ${_}`),()=>{g()}),[_]),(0,a.useEffect)(()=>(i&&u&&g(`${k} is typing...`),()=>{g()}),[i,u]),(0,a.useEffect)(()=>{const e=r[r.length-1];return"closed"!==c&&"outbound"===e?.direction&&g(`${k} said: ${e.text}`),()=>{g()}},[r]);const N=()=>{if(0!==f.current.value.length&&"closed"!==c){try{const e=f.current.value.trim();o.sendTextMessage(e),g(`You said: ${e}`)}catch(e){console.log("[Chat Error] sendMessage",e)}w("")}},T=()=>{const e=h(r);document.querySelector("#transcript-download").setAttribute("href",`data:text/plain;charset=utf-8,${e}`)},I=a=>{if("Enter"!==a.key||a.shiftKey)" "===a.key?("end-chat"===a.target.id&&e(a),"wc-settings"===a.target.id&&t(a)):(o.keystroke(),setTimeout(()=>{o.stopTyping()},b));else switch(a.target.id){case"text-area":a.preventDefault(),N();break;case"end-chat":e(a);break;case"wc-settings":t(a);break;case"transcript-download":T()}};return n().createElement(n().Fragment,null,n().createElement(C,null),n().createElement("div",{className:"wc-status"},n().createElement("p",{className:"wc-status__availability"},_),n().createElement("a",{id:"end-chat",className:"wc-status__link",href:"#","data-module":"govuk-button",role:"button",onClick:e,onKeyDown:I},"End chat")),n().createElement("div",{className:"wc-body",tabIndex:"0"},n().createElement("ul",{className:"wc-chat"},r.length?r.map((e,t)=>n().createElement(O,{key:e.id,message:e,previousMessage:r[t-1]})):null,i?n().createElement("li",{className:"wc-chat__message outbound"},n().createElement("div",{className:"wc-chat__from"},k," is typing"),n().createElement("div",{className:"wc-chat__text outbound"},n().createElement("svg",{width:"28",height:"16",x:"0px",y:"0px",viewBox:"0 0 28 16"},n().createElement("circle",{stroke:"none",cx:"3",cy:"8",r:"3",fill:"currentColor"}),n().createElement("circle",{stroke:"none",cx:"14",cy:"8",r:"3",fill:"currentColor"}),n().createElement("circle",{stroke:"none",cx:"25",cy:"8",r:"3",fill:"currentColor"})))):null)),n().createElement(q,null,n().createElement("form",{className:"wc-form"+(v?" wc-focus-within":""),noValidate:!0,onSubmit:e=>{e.preventDefault(),N()}},n().createElement("label",{className:"govuk-label wc-form__label",htmlFor:"wc-form-textarea"},"Your message",n().createElement("span",{className:"govuk-visually-hidden"}," (enter key submits)")),n().createElement("textarea",{ref:f,rows:"1","aria-required":"true",className:"wc-form__textarea",id:"text-area",name:"message",onChange:e=>{w(e.target?.value)},onKeyDown:I,onFocus:()=>{y(m)},onBlur:()=>{y(!1)},value:E}),n().createElement("input",{type:"submit",className:"wc-form__button govuk-button",value:"Send","data-prevent-double-click":"true"})),n().createElement("div",{className:"wc-footer__settings"},n().createElement("a",{href:"#",id:"wc-settings",className:"wc-footer__settings-link","data-module":"govuk-button",onKeyDown:I,onClick:t},"Settings"),n().createElement("a",{href:"#",id:"transcript-download",className:"wc-footer__settings-link","data-module":"govuk-button",download:"floodline-webchat-transcript.txt",onKeyDown:I,onClick:T},"Save chat"))))}function U(){return n().createElement(n().Fragment,null,n().createElement(C,null),n().createElement("div",{className:"wc-body"},n().createElement("h3",{id:"wc-subtitle",className:"govuk-heading-m"},"Webchat is currently not available"),n().createElement("p",{className:"govuk-body-s"},"Try again later, or call Floodline:"),n().createElement("p",{className:"govuk-body-s"},n().createElement("strong",null,"Floodline helpline"),n().createElement("br",null),"Telephone: 0345 988 1188",n().createElement("br",null),"Textphone: 0345 602 6340",n().createElement("br",null),"Open 24 hours a day, 7 days a week",n().createElement("br",null),n().createElement("a",{className:"govuk-link",href:"https://gov.uk/call-charges"},"Find out more about call charges")),n().createElement("p",{className:"govuk-body-s"},"We're running webchat as a trial, it will not always be available.")))}function B({onChatScreen:e,onEndChatConfirm:t}){const{setCustomerId:l,setThreadId:o,setMessages:r,agentStatus:s,thread:c,threadId:i,setUnseenCount:u,isKeyboard:d}=S(),m=async e=>{e.preventDefault(),window.localStorage.setItem("tmpThreadId",i),o(),r([]),l(),c.lastMessageSeen(),u(0),"closed"!==s&&c.endChat(),t(e)};(0,a.useEffect)(()=>{d&&setTimeout(()=>{document.querySelector("#confirm-endchat").focus()},10)},[]);const g=t=>{"Enter"!==t.key&&" "!==t.key||"confirm-endchat"!==t.target.id||m(t),"Enter"!==t.key&&" "!==t.key||"resume-chat"!==t.target.id||e(t)};return n().createElement(n().Fragment,null,n().createElement(C,null),n().createElement("div",{className:"wc-body"},n().createElement("div",{className:"wc-content"},n().createElement("h3",{id:"wc-subtitle",className:"wc-heading","aria-live":"polite"},"Are you sure you want to end the chat?"),n().createElement("div",{className:"govuk-button-group"},n().createElement("a",{id:"confirm-endchat",href:"#endChat",role:"button",className:"wc-button govuk-button","data-module":"govuk-button",onClick:m,onKeyDown:g},"Yes, end chat"),n().createElement("a",{id:"resume-chat",href:"#resumeChat",role:"button",className:"wc-link govuk-link","data-module":"govuk-button",onClick:e,onKeyDown:g},"No, resume chat")))))}function Y({onCancel:e}){const{settings:t,setSettings:l}=S(),[o,r]=(0,a.useState)(t.audio),[s,c]=(0,a.useState)(t.scroll),i=t=>{t.preventDefault(),l({audio:o,scroll:s}),e(t)},u=t=>{"Enter"!==t.key&&" "!==t.key||"settings-save"!==t.target.id?"Enter"!==t.key&&" "!==t.key||"settings-cancel"!==t.target.id||e(t):i(t)};return n().createElement(n().Fragment,null,n().createElement(C,null),n().createElement("div",{className:"wc-body"},n().createElement("div",{className:"wc-content"},n().createElement("fieldset",{className:"govuk-fieldset govuk-!-margin-bottom-4"},n().createElement("legend",{className:"govuk-fieldset__legend govuk-fieldset__legend"},n().createElement("h3",{id:"wc-subtitle",className:"wc-heading"},"Change settings")),n().createElement("div",{className:"govuk-checkboxes govuk-checkboxes--small","data-module":"govuk-checkboxes"},n().createElement("div",{className:"govuk-checkboxes__item"},n().createElement("input",{id:"audio",name:"audio",type:"checkbox",value:"audio",className:"govuk-checkboxes__input",defaultChecked:o,onChange:()=>r(!o)}),n().createElement("label",{className:"wc-label govuk-label govuk-checkboxes__label",htmlFor:"audio"},"Play a sound when receiving a new message")),n().createElement("div",{className:"govuk-checkboxes__item"},n().createElement("input",{id:"scroll",name:"scroll",type:"checkbox",value:"scroll",className:"govuk-checkboxes__input",defaultChecked:s,onChange:()=>c(!s)}),n().createElement("label",{className:"wc-label govuk-label govuk-checkboxes__label",htmlFor:"scroll"},"Scroll automatically to a new message")))),n().createElement("div",{className:"govuk-button-group"},n().createElement("a",{id:"settings-save",href:"#",className:"wc-button govuk-button","data-module":"govuk-button",role:"button",onClick:i,onKeyDown:u},"Save"),n().createElement("a",{id:"settings-cancel",href:"#",className:"wc-link govuk-link","data-module":"govuk-button",role:"button",onClick:e,onKeyDown:u},"Cancel")))))}function $({onCancel:e}){const t=()=>{const e=window.localStorage.getItem("tmpThreadId");window.location.href=`https://defragroup.eu.qualtrics.com/jfe/form/SV_8dgFSJcxxIfqx5Y?Id=${e}&Source=${window.location.href}`,window.localStorage.removeItem("tmpThreadId")},a=async t=>{window.localStorage.removeItem("tmpThreadId"),e(t)},l=e=>{"Enter"!==e.key&&" "!==e.key||("feedback-close"===e.target.id&&a(e),"feedback-send"===e.target.id&&t())};return n().createElement(n().Fragment,null,n().createElement(C,null),n().createElement("div",{className:"wc-body"},n().createElement("div",{className:"wc-content"},n().createElement("h3",{id:"wc-subtitle",className:"wc-heading"},"Give feedback on Floodline webchat"),n().createElement("p",null,"We're running webchat as a trial. you can ",n().createElement("a",{id:"feedback-send",className:"govuk-link",href:"#",target:"_blank",rel:"noreferrer",onKeyDown:l,onClick:t},"give feedback")," to help us improve it."),n().createElement("p",null,n().createElement("a",{id:"feedback-close",className:"wc-link govuk-link",href:"#","data-module":"govuk-button",role:"button",onKeyDown:l,onClick:a},"Close")))))}const K=require("lodash.debounce");var V=e.n(K);const H=()=>{const{agentStatus:e,liveRegionText:t,setLiveRegionText:l}=S(),[o,r]=(0,a.useState)(),[s,c]=(0,a.useState)(),i="closed"===e||null===e,u=()=>{r(),c()},d=(0,a.useCallback)(V()(e=>{o?c(e):r(e)},2e3),[o,s]);return(0,a.useEffect)(()=>(t&&(u(),d(t)),i&&(u(),l()),()=>{u(),l()}),[t]),n().createElement(n().Fragment,null,n().createElement("div",{className:"wc-live",role:"status","aria-atomic":"true"},o),n().createElement("div",{className:"wc-live",role:"status","aria-atomic":"true"},s))},P="aria-hidden",j="data-wc-inert",W=e=>{for(const t of document.body.children)"wc-panel"!==t.id&&(e&&!t.getAttribute(P)?(t.setAttribute(P,"true"),t.setAttribute(j,"")):t.hasAttribute(j)&&(t.removeAttribute(P),t.removeAttribute(j)))},J=e=>{const[t,n]=(0,a.useState)([]),l=(0,a.useCallback)(e=>{const a=document.querySelector("#wc-panel");"Tab"===e.key&&(a&&!document.activeElement.closest("#wc-panel")&&a.focus(),e.shiftKey?(document.activeElement===t[0]||document.activeElement===document.querySelector("#wc-panel"))&&(t[t.length-1].focus(),e.preventDefault()):document.activeElement===t[t.length-1]&&(t[0].focus(),e.preventDefault()))},[t]);(0,a.useEffect)(()=>{n((()=>{const e=document.body.querySelectorAll(["#wc-panel a:not([disabled])","#wc-panel button:not([disabled])","#wc-panel select:not([disabled])","#wc-panel input:not([disabled])","#wc-panel textarea:not([disabled])",'#wc-panel *[tabindex="0"]:not([disabled])'].join(","));return Array.from(e).filter(e=>!e.closest("[hidden]")&&!e.closest('[aria-hidden="true"]'))})())},[e]),(0,a.useEffect)(()=>(W(!0),document.querySelector("#wc-panel").focus(),document.addEventListener("keydown",l),()=>{W(),document.removeEventListener("keydown",l)}),[t])};function X(){const{sdk:e,availability:t,instigatorId:l,thread:o,threadId:c,setThread:i,setThreadId:u,setChatVisibility:d,setMessages:m,setUnseenCount:g,isMobile:h,isKeyboard:E}=S(),{fetchThread:w,fetchMessages:v}=L(e),[b,y]=(0,a.useState)(c?2:0);J(b);const f=(0,a.useCallback)(e=>{"Escape"!==e.key&&"Esc"!==e.key||(c&&(o?.lastMessageSeen(),g(0)),d(!1),T())},[o,c,g,d]);(0,a.useEffect)(()=>()=>{document.getElementById(l)?.focus()},[]),(0,a.useEffect)(()=>(document.body.classList.remove("wc-u-hidden"),document.getElementsByTagName("html")[0].classList.add("wc-u-html"),document.body.classList.add("wc-u-body"),()=>{document.getElementsByTagName("html")[0].classList.remove("wc-u-html"),document.body.classList.remove("wc-u-body")}),[h]),(0,a.useEffect)(()=>(document.addEventListener("keydown",f),()=>{document.removeEventListener("keydown",f)}),[f,d]),(0,a.useEffect)(()=>{c&&(o?(o.lastMessageSeen(),g(0),y(2)):(async()=>{try{const e=await w(c);i(e);const t=await v(e,c);m(t)}catch(e){console.log("[Chat Error] fetchThread",e),u(),i(),y(0)}})())},[o,c]);const p=e=>t=>{t.preventDefault(),y(e)},k=p(0),_=p(1),N=p(2),C=p(3),A=p(4),x=p(5);let D;switch(b){case 0:default:D=n().createElement(I,{onContinue:_});break;case 1:D=n().createElement(G,{onPreChatScreen:k});break;case 2:D=n().createElement(F,{onSettingsScreen:x,onEndChatScreen:C});break;case 3:D=n().createElement(B,{onChatScreen:N,onEndChatConfirm:A});break;case 4:D=n().createElement($,{onCancel:()=>{d(!1),T()}});break;case 5:D=n().createElement(Y,{onCancel:N})}"UNAVAILABLE"===t&&(D=n().createElement(U,null));const q=n().createElement("div",{id:"wc-panel",role:"dialog",className:r("wc-panel",E&&"wc-focus-visible"),tabIndex:"-1","aria-modal":"true","aria-labelledby":"wc-header wc-subtitle"},n().createElement("div",{className:"wc-panel__inner"},D),n().createElement(H,null));return n().createElement(n().Fragment,null,(0,s.createPortal)(q,document.body))}const Z=()=>{const{threadId:e,setInstigatorId:t}=S();if(!e)return null;const a=document.getElementById("webchat-skip-link-container");return a?n().createElement(n().Fragment,null,(0,s.createPortal)(n().createElement("a",{id:"webchat-skip-link",href:"#webchat",className:"govuk-skip-link","data-module":"govuk-skip-link",onClick:e=>{e.preventDefault(),t(e.target.id),window.location.hash="#webchat"},"data-wc-skiplink":!0,"data-wc-open-btn":!0},"Skip to webchat"),a)):null};function z(){const{availability:e,isChatOpen:t,setChatVisibility:l,unseenCount:o,threadId:s,setUnseenCount:c,setInstigatorId:i,setLiveRegionText:u}=S(),d=(0,a.useRef)(),m=o>0&&!t,g=o>1?"new messages":"new message",h=e=>{e.preventDefault(),c(0),l(!t),i(e.target.id),t?T():N()},E=e=>{" "===e.key&&e.preventDefault()},w=e=>{" "===e.key&&(c(0),l(!t))};switch((0,a.useEffect)(()=>(m&&u(`Floodline webchat - ${o} ${g}`),()=>{u()}),[o,t]),(0,a.useEffect)(()=>{const a=()=>{if(!s)return;if("AVAILABLE"!==e)return;const a=d.current.parentElement.getBoundingClientRect().top+35>(window.innerHeight||document.documentElement.clientHeight),n=!t&&a;document.documentElement.classList.toggle("wc-u-scroll-padding",n),document.body.classList.toggle("wc-u-scroll-padding",n),d.current.classList.toggle("wc-availability--fixed",n)};return document.addEventListener("scroll",a),a(),()=>{document.removeEventListener("scroll",a)}},[s,t,e]),e){case"AVAILABLE":return n().createElement(n().Fragment,null,n().createElement("div",{className:r("wc-availability",t&&"wc-open"),ref:d},n().createElement("div",{className:"wc-availability__inner"},n().createElement("a",{id:"webchat-start-chat-link",className:"wc-availability__link",href:"#webchat",draggable:"false",onClick:h,onKeyUp:w,onKeyDown:E,role:"button","data-module":"govuk-button"},s?n().createElement(n().Fragment,null,"Show chat"):n().createElement(n().Fragment,null,"Start chat"),m?n().createElement("span",{className:"wc-availability__unseen"},o,n().createElement("span",{className:"govuk-visually-hidden"}," ",g)):null))),t?n().createElement(X,null):n().createElement(H,null),n().createElement(Z,null));case"EXISTING":case"UNAVAILABLE":return n().createElement("p",{className:"govuk-body"},"When it is available, a 'start chat' link will appear.");default:return n().createElement("p",{className:"govuk-body"},"Checking availability")}}const Q=async e=>{const t=new(window.AudioContext||window.webkitAudioContext);if("suspended"===t.state){const e=["touchstart","touchend","mousedown","wheel","keydown","click"],a=n=>{e.forEach(e=>{document.body.removeEventListener(e,a)}),t.resume()};e.forEach(e=>{document.body.addEventListener(e,a,!1)})}const a=await fetch(e),n=await a.arrayBuffer(),l=await t.decodeAudioData(n);return()=>{const e=t.createBufferSource();e.buffer=l,e.connect(t.destination),e.start()}};async function ee(e,t){const a=new o.ChatSdk({brandId:t.brandId,channelId:t.channelId,customerId:window.localStorage.getItem(w)||"",environment:t.environment}),r=(0,l.createRoot)(e);let s,c;try{const e=await async function(e){const t=await fetch(e);return{availability:(await t.json()).availability||"UNAVAILABLE"}}(t.availabilityEndpoint);c=await Q(t.audioUrl),s=e.availability}catch(e){s="UNAVAILABLE"}r.render(n().createElement(_,{sdk:a,availability:s,playSound:c},n().createElement(z,null)))}module.exports=t})();
1
+ (()=>{"use strict";const e={n:t=>{const a=t&&t.__esModule?()=>t.default:()=>t;return e.d(a,{a}),a},d:(t,a)=>{if(Array.isArray(a))for(var o=0;o<a.length;){var n=a[o++],s=a[o++];e.o(t,n)?0===s&&o++:0===s?Object.defineProperty(t,n,{enumerable:!0,value:a[o++]}):Object.defineProperty(t,n,{enumerable:!0,get:s})}else for(var n in a)e.o(a,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:a[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}};let t={};e.r(t),e.d(t,{init:()=>Q});const a=require("react"),o=require("react-dom/client"),n=require("@nice-devone/nice-cxone-chat-web-sdk"),s=(...e)=>e.filter(e=>e&&"string"==typeof e).join(" "),i=require("react-dom"),r=require("luxon"),d=require("html-react-parser");var l=e.n(d);const c=/(?:www|https?)[^\s]+/gi,u=e=>(e.match(c)&&(e=e.replace(c,e=>`<a class="govuk-link" href="${e}" target="_blank" rel="noreferrer">${e.replace(/https?:\/\//gi,"")}</a>`)),l()(e)),h=e=>({id:e.id,text:e.messageContent?.text,createdAt:new Date(e.createdAt),user:e.authorEndUserIdentity?.fullName?.trim()||null,assignee:e.authorUser?.firstName||null,direction:e.direction}),v=e=>{const t=r.DateTime.local();t.setZone("Europe/London");let a=`Floodline webchat transcript, ${t.toFormat("HH:mm:ss a, dd LLLL yyyy")}\n\n`;for(const t of e){const{text:e,direction:o,user:n,assignee:s,createdAt:i}=t,d="inbound"===o?n:`${s} (Floodline adviser)`;a+=`[${r.DateTime.fromJSDate(new Date(i)).setZone("Europe/London").toFormat("HH:mm:ss a, dd LLLL yyyy")}] ${d}: \n${e}\n\n`}return a=a.replace(/<a\b[^>]*>/i,"").replace(/<\/a>/i,""),encodeURIComponent(a)},g="webchat_settings",m="webchat_customer_id",E="webchat_thread_id",w={SET_CHAT_VISIBILITY:(e,t)=>({...e,isChatOpen:t}),SET_AVAILABILITY:(e,t)=>({...e,availability:t}),SET_SETTINGS:(e,t)=>(t?window.localStorage.setItem(g,JSON.stringify(t)):window.localStorage.removeItem(g),{...e,settings:t}),SET_CUSTOMER_ID:(e,t)=>(t?window.localStorage.setItem(m,t):window.localStorage.removeItem(m),{...e,customerId:t}),SET_THREAD_ID:(e,t)=>(t?window.localStorage.setItem(E,t):window.localStorage.removeItem(E),{...e,threadId:t}),SET_THREAD:(e,t)=>({...e,thread:t}),SET_MESSAGE:(e,t)=>({...e,message:h(t),messages:[...e.messages,h(t)]}),SET_MESSAGES:(e,t)=>{return{...e,messages:(a=t,a.map(e=>h(e))).reverse()};var a},SET_AGENT:(e,t)=>({...e,agent:t}),SET_AGENT_TYPING:(e,t)=>({...e,isAgentTyping:t}),SET_AGENT_STATUS:(e,t)=>({...e,agentStatus:t}),SET_UNSEEN_COUNT:(e,t)=>({...e,unseenCount:t}),SET_INSTIGATOR_ID:(e,t)=>({...e,instigatorId:t}),SET_LIVE_REGION_TEXT:(e,t)=>({...e,liveRegionText:t}),TOGGLE_IS_MOBILE:(e,t)=>({...e,isMobile:t}),TOGGLE_IS_KEYBOARD:(e,t)=>({...e,isKeyboard:t})},b={availability:null,customerId:null,threadId:null,thread:null,messages:[],unseenCount:0,instigatorId:null,agent:null,agentStatus:null,isAgentTyping:!1,isChatOpen:!1,isMobile:window.matchMedia("(max-width: 640px)").matches,isKeyboard:!1,settings:{audio:!0,scroll:!0}},y=(e,t)=>{const{type:a,payload:o}=t,n=w[a];return n?n.bind(void 0,e,o)():e},f=require("react/jsx-dev-runtime"),x=(0,a.createContext)(b),p=({sdk:e,availability:t,playSound:o,children:s})=>{const[i,r]=(0,a.useReducer)(y,b),d=e=>{r({type:"SET_AGENT",payload:e.detail.data.inboxAssignee}),r({type:"SET_AGENT_STATUS",payload:e.detail.data.contact.status}),r({type:"SET_UNSEEN_COUNT",payload:e.detail.data.contact.customerStatistics.unseenMessagesCount})},l=e=>{r({type:"SET_AGENT",payload:e.detail.data.inboxAssignee}),r({type:"SET_AGENT_STATUS",payload:e.detail.data.case.status})},c=e=>{e?.detail?.data?.user&&r({type:"SET_AGENT",payload:e.detail.data.user}),r({type:"SET_AGENT_TYPING",payload:!0})},u=()=>{r({type:"SET_AGENT_TYPING",payload:!1}),r({type:"SET_LIVE_REGION_TEXT"})},h=e=>{r({type:"SET_MESSAGE",payload:e.detail.data.message}),r({type:"SET_AGENT_STATUS",payload:e.detail.data.case.status}),r({type:"SET_UNSEEN_COUNT",payload:e.detail.data.case.customerStatistics.unseenMessagesCount}),JSON.parse(window.localStorage.getItem(g)).audio&&"outbound"===e.detail.data.message.direction&&o&&o()},v=e=>{r({type:"SET_AGENT_STATUS",payload:e.detail.data.case.status}),e.detail.data.inboxAssignee&&r({type:"SET_AGENT",payload:e.detail.data.inboxAssignee})},w=e=>{r({type:"TOGGLE_IS_MOBILE",payload:e.matches})},p=()=>{r({type:"TOGGLE_IS_KEYBOARD",payload:!0})},k=()=>{r({type:"TOGGLE_IS_KEYBOARD",payload:!1})};(0,a.useEffect)(()=>(e.onChatEvent(n.ChatEvent.LIVECHAT_RECOVERED,d),e.onChatEvent(n.ChatEvent.MESSAGE_CREATED,h),e.onChatEvent(n.ChatEvent.AGENT_TYPING_STARTED,c),e.onChatEvent(n.ChatEvent.AGENT_TYPING_ENDED,u),e.onChatEvent(n.ChatEvent.ASSIGNED_AGENT_CHANGED,l),e.onChatEvent(n.ChatEvent.CONTACT_STATUS_CHANGED,v),window.matchMedia("(max-width: 640px)").addEventListener("change",w),window.addEventListener("keydown",p),window.addEventListener("pointerdown",k),()=>{window.removeEventListener("change",w),window.removeEventListener("keydown",p),window.removeEventListener("pointerdown",k)}),[e]),(0,a.useEffect)(()=>{r({type:"SET_AVAILABILITY",payload:t}),V(window.localStorage.getItem(m)),j(window.localStorage.getItem(E)),N(JSON.parse(window.localStorage.getItem(g))||i.settings)},[]),(0,a.useEffect)(()=>{"#webchat"===window.location.hash&&D(!0);const e=()=>{"#webchat"===window.location.hash?D(!0):D(!1)};return window.addEventListener("popstate",e),()=>{window.removeEventListener("popstate",e)}},[]);const D=e=>{r({type:"SET_CHAT_VISIBILITY",payload:e})},V=e=>{r({type:"SET_CUSTOMER_ID",payload:e})},j=e=>{r({type:"SET_THREAD_ID",payload:e})},S=e=>{r({type:"SET_THREAD",payload:e})},_=e=>{r({type:"SET_MESSAGES",payload:e})},N=e=>{r({type:"SET_SETTINGS",payload:e})},T=e=>{r({type:"SET_UNSEEN_COUNT",payload:e})},C=e=>{r({type:"SET_INSTIGATOR_ID",payload:e})},I=e=>{r({type:"SET_LIVE_REGION_TEXT",payload:e})},A=(0,a.useMemo)(()=>({...i,sdk:e,setSettings:N,setCustomerId:V,setThreadId:j,setThread:S,setMessages:_,setUnseenCount:T,setChatVisibility:D,setInstigatorId:C,setLiveRegionText:I,onLiveChatRecovered:d,onAssignedAgentChanged:l,onAgentTypingStarted:c,onAgentTypingEnded:u,onMessageCreated:h,onContactStatusChanged:v}));return(0,f.jsxDEV)(x.Provider,{value:A,children:s},void 0,!1)},k=()=>(0,a.useContext)(x),D=()=>{const e=window.location.href.split("#")[0];window.history.pushState({history:!0},null,`${e}#webchat`)},V=()=>{if(window.history.state?.history)return window.history.back();const e=window.location.href.split("#")[0];return window.history.replaceState(null,null,e)};function j(){const{thread:e,threadId:t,setChatVisibility:a,setUnseenCount:o,isMobile:n}=k(),s=n=>{n.preventDefault(),a(!1),V(),t&&(e?.lastMessageSeen(),o(0))},i=(0,f.jsxDEV)("button",{className:"wc-header__back","aria-label":"Close the webchat",onClick:s,children:(0,f.jsxDEV)("svg",{"aria-hidden":"true",focusable:"false",width:"20",height:"20",viewBox:"0 0 20 20",children:(0,f.jsxDEV)("path",{d:"M4.828,11L12.314,18.485L10.899,19.899L1,10L10.899,0.101L12.314,1.515L4.828,9L19,9L19,11L4.828,11Z",fill:"currentColor"},void 0,!1)},void 0,!1)},void 0,!1),r=(0,f.jsxDEV)("button",{className:"wc-header__close","aria-label":"Close the webchat",onClick:s,children:(0,f.jsxDEV)("svg",{"aria-hidden":"true",focusable:"false",width:"20",height:"20",viewBox:"0 0 20 20",children:(0,f.jsxDEV)("path",{d:"M10,8.6L15.6,3L17,4.4L11.4,10L17,15.6L15.6,17L10,11.4L4.4,17L3,15.6L8.6,10L3,4.4L4.4,3L10,8.6Z",fill:"currentColor"},void 0,!1)},void 0,!1)},void 0,!1),d=(0,f.jsxDEV)("button",{className:"wc-header__hide","aria-label":"Minimise the webchat",onClick:s,children:(0,f.jsxDEV)("svg",{"aria-hidden":"true",focusable:"false",width:"20",height:"20",viewBox:"0 0 20 20",children:(0,f.jsxDEV)("path",{d:"M10 14.4l-7-7L4.4 6l5.6 5.6L15.6 6 17 7.4l-7 7z",fill:"currentColor"},void 0,!1)},void 0,!1)},void 0,!1),l=n&&window.history.state,c=n&&!window.history.state;let u=r;return t&&(u=d,c&&(u=d)),!t&&c&&(u=r),l&&(u=null),(0,f.jsxDEV)("div",{className:"wc-header",children:[l?i:null,(0,f.jsxDEV)("h2",{id:"wc-header",className:"wc-header__title",children:"Floodline webchat"},void 0,!1),u]},void 0,!0)}function S({onContinue:e}){return(0,f.jsxDEV)(f.Fragment,{children:[(0,f.jsxDEV)(j,{},void 0,!1),(0,f.jsxDEV)("div",{className:"wc-body",children:(0,f.jsxDEV)("div",{className:"wc-content",children:[(0,f.jsxDEV)("h3",{id:"wc-subtitle",className:"wc-heading","aria-live":"polite",children:"What you can use webchat for"},void 0,!1),(0,f.jsxDEV)("p",{children:"Webchat lets you talk directly to a Floodline adviser."},void 0,!1),(0,f.jsxDEV)("p",{children:"You can use webchat to get:"},void 0,!1),(0,f.jsxDEV)("ul",{className:"wc-list",children:[(0,f.jsxDEV)("li",{children:"current flood warnings and alerts in your area"},void 0,!1),(0,f.jsxDEV)("li",{children:"information on the flood warning service"},void 0,!1),(0,f.jsxDEV)("li",{children:"advice on what to do before, during and after a flood"},void 0,!1)]},void 0,!0),(0,f.jsxDEV)("p",{children:["There are other ways to ",(0,f.jsxDEV)("a",{className:"govuk-link",href:"https://www.gov.uk/get-flood-warnings",target:"_blank",rel:"noreferrer",children:"get flood warnings"},void 0,!1)," and ",(0,f.jsxDEV)("a",{className:"govuk-link",href:"https://get-flood-warnings.service.gov.uk/sign-in",target:"_blank",rel:"noreferrer",children:"manage your flood warnings account"},void 0,!1),"."]},void 0,!0),(0,f.jsxDEV)("p",{children:["Do not use webchat to ",(0,f.jsxDEV)("a",{className:"govuk-link",href:"https://www.gov.uk/report-flood-cause",target:"_blank",rel:"noreferrer",children:"report a flood"},void 0,!1),"."]},void 0,!0),(0,f.jsxDEV)("button",{className:"govuk-button wc-button govuk-!-margin-top-1","data-module":"govuk-button",onClick:e,children:"Continue"},void 0,!1),(0,f.jsxDEV)("h3",{className:"wc-heading",children:"Other flood information"},void 0,!1),(0,f.jsxDEV)("p",{children:"Call Floodline for all other flood and flood warning information."},void 0,!1),(0,f.jsxDEV)("p",{children:[(0,f.jsxDEV)("strong",{children:"Floodline helpline"},void 0,!1),(0,f.jsxDEV)("br",{},void 0,!1),"Telephone: 0345 988 1188",(0,f.jsxDEV)("br",{},void 0,!1),"Textphone: 0345 602 6340",(0,f.jsxDEV)("br",{},void 0,!1),"Open 24 hours a day, 7 days a week",(0,f.jsxDEV)("br",{},void 0,!1),(0,f.jsxDEV)("a",{className:"govuk-link",href:"https://gov.uk/call-charges",target:"_blank",rel:"noreferrer",children:"Find out more about call charges"},void 0,!1)]},void 0,!0)]},void 0,!0)},void 0,!1)]},void 0,!0)}const _=require("uuid"),N=e=>{const t=async()=>e.connect();return{connect:t,fetchCustomerId:async()=>(await t(),e.getCustomer().getId()),fetchThread:async a=>(await t(),e.getThread(a)),fetchMessages:async e=>{await t();const a=await e.recover(),o=[];let n=a.messages;for(;n.length;){n.map(e=>o.push(e));try{n=(await e.loadMoreMessages()).data.messages}catch(e){n=[]}}return o}}},T=({errors:e})=>{const t=Object.keys(e),a=e=>{e.preventDefault();const t=e.target.getAttribute("data-key");document.querySelector(`#wc-${t}`).focus()};return 0===t.length?null:(0,f.jsxDEV)("div",{className:"govuk-error-summary govuk-!-static-margin-bottom-7","data-module":"govuk-error-summary",tabIndex:"-1",children:(0,f.jsxDEV)("div",{role:"alert",children:[(0,f.jsxDEV)("h2",{id:"wc-error",className:"wc-error-summary__title govuk-error-summary__title",children:"There is a problem"},void 0,!1),(0,f.jsxDEV)("div",{className:"govuk-error-summary__body",children:(0,f.jsxDEV)("ul",{className:"govuk-list govuk-error-summary__list wc-error-summary__list",children:t.map(t=>(0,f.jsxDEV)("li",{children:(0,f.jsxDEV)("a",{href:"#","data-key":t,onClick:a,children:e[t]},void 0,!1)},t,!1))},void 0,!1)},void 0,!1)]},void 0,!0)},void 0,!1)},C=500;function I({onPreChatScreen:e}){const{sdk:t,setCustomerId:o,setThreadId:n,setThread:i,setLiveRegionText:r}=k(),{fetchCustomerId:d,fetchThread:l}=N(t),[c,u]=(0,a.useState)({}),[h,v]=(0,a.useState)(0),[g,m]=(0,a.useState)(!1),E=(0,a.useRef)(),w=(0,a.useRef)(),b=C>=h;let y=`You have ${C-h} characters remaining`;b||(y=`You have ${h-C} characters too many`),(0,a.useEffect)(()=>{Object.keys(c).length&&document.querySelector(".govuk-error-summary")?.focus()},[c]);const x=g?"Requesting...":"Request chat";return(0,a.useEffect)(()=>{g&&r(x)},[g]),(0,f.jsxDEV)(f.Fragment,{children:[(0,f.jsxDEV)(j,{},void 0,!1),(0,f.jsxDEV)("div",{className:"wc-body",children:(0,f.jsxDEV)("div",{className:"wc-content",children:[(0,f.jsxDEV)("a",{href:"#",className:"wc-back-link govuk-back-link",onClick:e,children:"What you can use webchat for"},void 0,!1),(0,f.jsxDEV)(T,{errors:c},void 0,!1),(0,f.jsxDEV)("h3",{id:"wc-subtitle",className:"wc-heading","aria-live":"polite",children:"Your name and question"},void 0,!1),(0,f.jsxDEV)("form",{children:[(0,f.jsxDEV)("div",{className:s("wc-form-group","govuk-form-group",c.name&&"govuk-form-group--error"),children:[(0,f.jsxDEV)("label",{className:"wc-label govuk-label",htmlFor:"wc-name",children:"Your name"},void 0,!1),c.name&&(0,f.jsxDEV)("p",{className:"govuk-error-message",children:[(0,f.jsxDEV)("span",{className:"govuk-visually-hidden",children:"Error:"},void 0,!1)," ",c.name]},void 0,!0),(0,f.jsxDEV)("input",{ref:E,className:s("wc-input","govuk-input",c.name&&"govuk-input--error"),id:"wc-name",name:"name",type:"text","data-testid":"request-chat-user-name"},void 0,!1)]},void 0,!0),(0,f.jsxDEV)("div",{className:"wc-form-group govuk-character-count","data-module":"govuk-character-count","data-maxlength":"500",children:(0,f.jsxDEV)("div",{className:s("govuk-form-group",c.question&&"govuk-form-group--error"),children:[(0,f.jsxDEV)("label",{className:"wc-label govuk-label",htmlFor:"wc-question",children:"Your question"},void 0,!1),c.question&&(0,f.jsxDEV)("p",{className:"govuk-error-message",children:[(0,f.jsxDEV)("span",{className:"govuk-visually-hidden",children:"Error:"},void 0,!1),c.question]},void 0,!0),(0,f.jsxDEV)("textarea",{ref:w,id:"wc-question",name:"question",rows:"5","aria-describedby":"wc-question-info",onChange:e=>{v(e.target.value.length)},className:s("wc-textarea","govuk-textarea","govuk-js-character-count",!b||c.question?"govuk-textarea--error":""),"data-testid":"request-chat-user-question"},void 0,!1),(0,f.jsxDEV)("div",{id:"wc-question-info",className:"wc-hint govuk-hint govuk-char-count__msg",style:{color:b?"":"#d4351c"},"aria-hidden":"true",children:y},void 0,!1),(0,f.jsxDEV)("div",{className:"govuk-character-count__sr-status govuk-visually-hidden","aria-live":"polite",children:y},void 0,!1)]},void 0,!0)},void 0,!1),(0,f.jsxDEV)("div",{className:"wc-inset-text govuk-inset-text",children:["By selecting 'Request chat' you agree to the terms of our ",(0,f.jsxDEV)("a",{href:"https://check-for-flooding.service.gov.uk/privacy-notice",target:"_blank",rel:"noreferrer",className:"govuk-link",children:"privacy notice"},void 0,!1),"."]},void 0,!0),(0,f.jsxDEV)("button",{className:"wc-button govuk-button govuk-!-margin-top-1","data-module":"govuk-button",onClick:async e=>{if(e.preventDefault(),g)return;const a={};if(0===E.current.value.length&&(a.name="Enter your name"),0===w.current.value.length&&(a.question="Enter your question"),w.current.value.length>C&&(a.question="Your question must be 500 characters or less"),0===Object.keys(a).length)try{m(!0);const e=_.v4(),a=await d(),s=await l(e);t.getCustomer().setName(E.current.value),await s.startChat(w.current.value||"Begin conversation"),o(a),n(e),i(s),s.setCustomField("threadid",e)}catch(e){console.log("[Request chat Error]",e)}u(a)},"aria-disabled":g,children:x},void 0,!1)]},void 0,!0)]},void 0,!0)},void 0,!1)]},void 0,!0)}function A({children:e}){return(0,f.jsxDEV)("div",{className:"wc-footer",children:e},void 0,!1)}function L({message:e,previousMessage:t}){const a="outbound"===e.direction,o=e?.direction===t?.direction;return(0,f.jsxDEV)("li",{className:s("wc-chat__message",a?"outbound":"inbound"),children:[(0,f.jsxDEV)("div",{className:"wc-chat__from",children:[o?null:(0,f.jsxDEV)("span",{className:s(a?"outbound":"inbound"),children:a?e.assignee:"You"},void 0,!1),(0,f.jsxDEV)("span",{className:"govuk-visually-hidden",children:":"},void 0,!1)]},void 0,!0),(0,f.jsxDEV)("div",{className:s("wc-chat__text",a?"outbound":"inbound"),children:u(e.text)},void 0,!1)]},void 0,!0)}const G=(e,t)=>{(0,a.useEffect)(()=>{if(e){e.style.height="0px";const t=e.scrollHeight;e.style.height=`${t}px`}},[e,t])},q=(e,t,a)=>{if("UNAVAILABLE"===e)return"Webchat is not currently available";if(!t)return"Connecting to Floodline";switch(t){case"closed":case"resolved":return a?`${a} ended the session`:"Session ended by advisor";default:return a?`You are speaking with ${a}`:"Waiting for an adviser"}};function O({onEndChatScreen:e,onSettingsScreen:t}){const{availability:o,thread:n,messages:s,agent:i,agentStatus:r,isAgentTyping:d,isChatOpen:l,settings:c,isKeyboard:u,setLiveRegionText:h}=k(),[g,m]=(0,a.useState)(""),[E,w]=(0,a.useState)(!1),b=(0,a.useRef)();G(b.current,g),(0,a.useEffect)(()=>{if(c.scroll&&0!==s.length){const e=document.querySelector(".wc-body");e.scrollTop=e.scrollHeight}},[s,d]),(0,a.useEffect)(()=>{const e=document.querySelector(".wc-form__label");0===g.length?e.classList.remove("govuk-visually-hidden"):e.classList.add("govuk-visually-hidden")},[g]);const y=[...s].reverse().find(e=>"outbound"===e.direction&&e.assignee),x=i?.nickname||i?.firstName||y?.assignee,p=q(o,r,x);(0,a.useEffect)(()=>(p&&h(`Floodline webchat - ${p}`),()=>{h()}),[p]),(0,a.useEffect)(()=>(d&&l&&h(`${x} is typing...`),()=>{h()}),[d,l]),(0,a.useEffect)(()=>{const e=s[s.length-1];return"closed"!==r&&"outbound"===e?.direction&&h(`${x} said: ${e.text}`),()=>{h()}},[s]);const D=()=>{if(0!==b.current.value.length&&"closed"!==r){try{const e=b.current.value.trim();n.sendTextMessage(e),h(`You said: ${e}`)}catch(e){console.log("[Chat Error] sendMessage",e)}m("")}},V=()=>{const e=v(s);document.querySelector("#transcript-download").setAttribute("href",`data:text/plain;charset=utf-8,${e}`)},S=a=>{if("Enter"!==a.key||a.shiftKey)" "===a.key?("end-chat"===a.target.id&&e(a),"wc-settings"===a.target.id&&t(a)):(n.keystroke(),setTimeout(()=>{n.stopTyping()},4e3));else switch(a.target.id){case"text-area":a.preventDefault(),D();break;case"end-chat":e(a);break;case"wc-settings":t(a);break;case"transcript-download":V()}};return(0,f.jsxDEV)(f.Fragment,{children:[(0,f.jsxDEV)(j,{},void 0,!1),(0,f.jsxDEV)("div",{className:"wc-status",children:[(0,f.jsxDEV)("p",{className:"wc-status__availability",children:p},void 0,!1),(0,f.jsxDEV)("a",{id:"end-chat",className:"wc-status__link",href:"#","data-module":"govuk-button",role:"button",onClick:e,onKeyDown:S,children:"End chat"},void 0,!1)]},void 0,!0),(0,f.jsxDEV)("div",{className:"wc-body",tabIndex:"0",children:(0,f.jsxDEV)("ul",{className:"wc-chat",children:[s.length?s.map((e,t)=>(0,f.jsxDEV)(L,{message:e,previousMessage:s[t-1]},e.id,!1)):null,d?(0,f.jsxDEV)("li",{className:"wc-chat__message outbound",children:[(0,f.jsxDEV)("div",{className:"wc-chat__from",children:[x," is typing"]},void 0,!0),(0,f.jsxDEV)("div",{className:"wc-chat__text outbound",children:(0,f.jsxDEV)("svg",{width:"28",height:"16",x:"0px",y:"0px",viewBox:"0 0 28 16",children:[(0,f.jsxDEV)("circle",{stroke:"none",cx:"3",cy:"8",r:"3",fill:"currentColor"},void 0,!1),(0,f.jsxDEV)("circle",{stroke:"none",cx:"14",cy:"8",r:"3",fill:"currentColor"},void 0,!1),(0,f.jsxDEV)("circle",{stroke:"none",cx:"25",cy:"8",r:"3",fill:"currentColor"},void 0,!1)]},void 0,!0)},void 0,!1)]},void 0,!0):null]},void 0,!0)},void 0,!1),(0,f.jsxDEV)(A,{children:[(0,f.jsxDEV)("form",{className:"wc-form"+(E?" wc-focus-within":""),noValidate:!0,onSubmit:e=>{e.preventDefault(),D()},children:[(0,f.jsxDEV)("label",{className:"govuk-label wc-form__label",htmlFor:"wc-form-textarea",children:["Your message",(0,f.jsxDEV)("span",{className:"govuk-visually-hidden",children:" (enter key submits)"},void 0,!1)]},void 0,!0),(0,f.jsxDEV)("textarea",{ref:b,rows:"1","aria-required":"true",className:"wc-form__textarea",id:"text-area",name:"message",onChange:e=>{m(e.target?.value)},onKeyDown:S,onFocus:()=>{w(u)},onBlur:()=>{w(!1)},value:g},void 0,!1),(0,f.jsxDEV)("input",{type:"submit",className:"wc-form__button govuk-button",value:"Send","data-prevent-double-click":"true"},void 0,!1)]},void 0,!0),(0,f.jsxDEV)("div",{className:"wc-footer__settings",children:[(0,f.jsxDEV)("a",{href:"#",id:"wc-settings",className:"wc-footer__settings-link","data-module":"govuk-button",onKeyDown:S,onClick:t,children:"Settings"},void 0,!1),(0,f.jsxDEV)("a",{href:"#",id:"transcript-download",className:"wc-footer__settings-link","data-module":"govuk-button",download:"floodline-webchat-transcript.txt",onKeyDown:S,onClick:V,children:"Save chat"},void 0,!1)]},void 0,!0)]},void 0,!0)]},void 0,!0)}function M(){return(0,f.jsxDEV)(f.Fragment,{children:[(0,f.jsxDEV)(j,{},void 0,!1),(0,f.jsxDEV)("div",{className:"wc-body",children:[(0,f.jsxDEV)("h3",{id:"wc-subtitle",className:"govuk-heading-m",children:"Webchat is currently not available"},void 0,!1),(0,f.jsxDEV)("p",{className:"govuk-body-s",children:"Try again later, or call Floodline:"},void 0,!1),(0,f.jsxDEV)("p",{className:"govuk-body-s",children:[(0,f.jsxDEV)("strong",{children:"Floodline helpline"},void 0,!1),(0,f.jsxDEV)("br",{},void 0,!1),"Telephone: 0345 988 1188",(0,f.jsxDEV)("br",{},void 0,!1),"Textphone: 0345 602 6340",(0,f.jsxDEV)("br",{},void 0,!1),"Open 24 hours a day, 7 days a week",(0,f.jsxDEV)("br",{},void 0,!1),(0,f.jsxDEV)("a",{className:"govuk-link",href:"https://gov.uk/call-charges",children:"Find out more about call charges"},void 0,!1)]},void 0,!0),(0,f.jsxDEV)("p",{className:"govuk-body-s",children:"We're running webchat as a trial, it will not always be available."},void 0,!1)]},void 0,!0)]},void 0,!0)}function R({onChatScreen:e,onEndChatConfirm:t}){const{setCustomerId:o,setThreadId:n,setMessages:s,agentStatus:i,thread:r,threadId:d,setUnseenCount:l,isKeyboard:c}=k(),u=async e=>{e.preventDefault(),window.localStorage.setItem("tmpThreadId",d),n(),s([]),o(),r.lastMessageSeen(),l(0),"closed"!==i&&r.endChat(),t(e)};(0,a.useEffect)(()=>{c&&setTimeout(()=>{document.querySelector("#confirm-endchat").focus()},10)},[]);const h=t=>{"Enter"!==t.key&&" "!==t.key||"confirm-endchat"!==t.target.id||u(t),"Enter"!==t.key&&" "!==t.key||"resume-chat"!==t.target.id||e(t)};return(0,f.jsxDEV)(f.Fragment,{children:[(0,f.jsxDEV)(j,{},void 0,!1),(0,f.jsxDEV)("div",{className:"wc-body",children:(0,f.jsxDEV)("div",{className:"wc-content",children:[(0,f.jsxDEV)("h3",{id:"wc-subtitle",className:"wc-heading","aria-live":"polite",children:"Are you sure you want to end the chat?"},void 0,!1),(0,f.jsxDEV)("div",{className:"govuk-button-group",children:[(0,f.jsxDEV)("a",{id:"confirm-endchat",href:"#endChat",role:"button",className:"wc-button govuk-button","data-module":"govuk-button",onClick:u,onKeyDown:h,children:"Yes, end chat"},void 0,!1),(0,f.jsxDEV)("a",{id:"resume-chat",href:"#resumeChat",role:"button",className:"wc-link govuk-link","data-module":"govuk-button",onClick:e,onKeyDown:h,children:"No, resume chat"},void 0,!1)]},void 0,!0)]},void 0,!0)},void 0,!1)]},void 0,!0)}function F({onCancel:e}){const{settings:t,setSettings:o}=k(),[n,s]=(0,a.useState)(t.audio),[i,r]=(0,a.useState)(t.scroll),d=t=>{t.preventDefault(),o({audio:n,scroll:i}),e(t)},l=t=>{"Enter"!==t.key&&" "!==t.key||"settings-save"!==t.target.id?"Enter"!==t.key&&" "!==t.key||"settings-cancel"!==t.target.id||e(t):d(t)};return(0,f.jsxDEV)(f.Fragment,{children:[(0,f.jsxDEV)(j,{},void 0,!1),(0,f.jsxDEV)("div",{className:"wc-body",children:(0,f.jsxDEV)("div",{className:"wc-content",children:[(0,f.jsxDEV)("fieldset",{className:"govuk-fieldset govuk-!-margin-bottom-4",children:[(0,f.jsxDEV)("legend",{className:"govuk-fieldset__legend govuk-fieldset__legend",children:(0,f.jsxDEV)("h3",{id:"wc-subtitle",className:"wc-heading",children:"Change settings"},void 0,!1)},void 0,!1),(0,f.jsxDEV)("div",{className:"govuk-checkboxes govuk-checkboxes--small","data-module":"govuk-checkboxes",children:[(0,f.jsxDEV)("div",{className:"govuk-checkboxes__item",children:[(0,f.jsxDEV)("input",{id:"audio",name:"audio",type:"checkbox",value:"audio",className:"govuk-checkboxes__input",defaultChecked:n,onChange:()=>s(!n)},void 0,!1),(0,f.jsxDEV)("label",{className:"wc-label govuk-label govuk-checkboxes__label",htmlFor:"audio",children:"Play a sound when receiving a new message"},void 0,!1)]},void 0,!0),(0,f.jsxDEV)("div",{className:"govuk-checkboxes__item",children:[(0,f.jsxDEV)("input",{id:"scroll",name:"scroll",type:"checkbox",value:"scroll",className:"govuk-checkboxes__input",defaultChecked:i,onChange:()=>r(!i)},void 0,!1),(0,f.jsxDEV)("label",{className:"wc-label govuk-label govuk-checkboxes__label",htmlFor:"scroll",children:"Scroll automatically to a new message"},void 0,!1)]},void 0,!0)]},void 0,!0)]},void 0,!0),(0,f.jsxDEV)("div",{className:"govuk-button-group",children:[(0,f.jsxDEV)("a",{id:"settings-save",href:"#",className:"wc-button govuk-button","data-module":"govuk-button",role:"button",onClick:d,onKeyDown:l,children:"Save"},void 0,!1),(0,f.jsxDEV)("a",{id:"settings-cancel",href:"#",className:"wc-link govuk-link","data-module":"govuk-button",role:"button",onClick:e,onKeyDown:l,children:"Cancel"},void 0,!1)]},void 0,!0)]},void 0,!0)},void 0,!1)]},void 0,!0)}function U({onCancel:e}){const t=()=>{const e=window.localStorage.getItem("tmpThreadId");window.location.href=`https://defragroup.eu.qualtrics.com/jfe/form/SV_8dgFSJcxxIfqx5Y?Id=${e}&Source=${window.location.href}`,window.localStorage.removeItem("tmpThreadId")},a=async t=>{window.localStorage.removeItem("tmpThreadId"),e(t)},o=e=>{"Enter"!==e.key&&" "!==e.key||("feedback-close"===e.target.id&&a(e),"feedback-send"===e.target.id&&t())};return(0,f.jsxDEV)(f.Fragment,{children:[(0,f.jsxDEV)(j,{},void 0,!1),(0,f.jsxDEV)("div",{className:"wc-body",children:(0,f.jsxDEV)("div",{className:"wc-content",children:[(0,f.jsxDEV)("h3",{id:"wc-subtitle",className:"wc-heading",children:"Give feedback on Floodline webchat"},void 0,!1),(0,f.jsxDEV)("p",{children:["We're running webchat as a trial. you can ",(0,f.jsxDEV)("a",{id:"feedback-send",className:"govuk-link",href:"#",target:"_blank",rel:"noreferrer",onKeyDown:o,onClick:t,children:"give feedback"},void 0,!1)," to help us improve it."]},void 0,!0),(0,f.jsxDEV)("p",{children:(0,f.jsxDEV)("a",{id:"feedback-close",className:"wc-link govuk-link",href:"#","data-module":"govuk-button",role:"button",onKeyDown:o,onClick:a,children:"Close"},void 0,!1)},void 0,!1)]},void 0,!0)},void 0,!1)]},void 0,!0)}const B=require("lodash.debounce");var Y=e.n(B);const $=()=>{const{agentStatus:e,liveRegionText:t,setLiveRegionText:o}=k(),[n,s]=(0,a.useState)(),[i,r]=(0,a.useState)(),d="closed"===e||null===e,l=()=>{s(),r()},c=(0,a.useCallback)(Y()(e=>{n?r(e):s(e)},2e3),[n,i]);return(0,a.useEffect)(()=>(t&&(l(),c(t)),d&&(l(),o()),()=>{l(),o()}),[t]),(0,f.jsxDEV)(f.Fragment,{children:[(0,f.jsxDEV)("div",{className:"wc-live",role:"status","aria-atomic":"true",children:n},void 0,!1),(0,f.jsxDEV)("div",{className:"wc-live",role:"status","aria-atomic":"true",children:i},void 0,!1)]},void 0,!0)},K="aria-hidden",H="data-wc-inert",P=e=>{for(const t of document.body.children)"wc-panel"!==t.id&&(e&&!t.getAttribute(K)?(t.setAttribute(K,"true"),t.setAttribute(H,"")):t.hasAttribute(H)&&(t.removeAttribute(K),t.removeAttribute(H)))},W=e=>{const[t,o]=(0,a.useState)([]),n=(0,a.useCallback)(e=>{const a=document.querySelector("#wc-panel");"Tab"===e.key&&(a&&!document.activeElement.closest("#wc-panel")&&a.focus(),e.shiftKey?(document.activeElement===t[0]||document.activeElement===document.querySelector("#wc-panel"))&&(t[t.length-1].focus(),e.preventDefault()):document.activeElement===t[t.length-1]&&(t[0].focus(),e.preventDefault()))},[t]);(0,a.useEffect)(()=>{o((()=>{const e=document.body.querySelectorAll(["#wc-panel a:not([disabled])","#wc-panel button:not([disabled])","#wc-panel select:not([disabled])","#wc-panel input:not([disabled])","#wc-panel textarea:not([disabled])",'#wc-panel *[tabindex="0"]:not([disabled])'].join(","));return Array.from(e).filter(e=>!e.closest("[hidden]")&&!e.closest('[aria-hidden="true"]'))})())},[e]),(0,a.useEffect)(()=>(P(!0),document.querySelector("#wc-panel").focus(),document.addEventListener("keydown",n),()=>{P(),document.removeEventListener("keydown",n)}),[t])};function J(){const{sdk:e,availability:t,instigatorId:o,thread:n,threadId:r,setThread:d,setThreadId:l,setChatVisibility:c,setMessages:u,setUnseenCount:h,isMobile:v,isKeyboard:g}=k(),{fetchThread:m,fetchMessages:E}=N(e),[w,b]=(0,a.useState)(r?2:0);W(w);const y=(0,a.useCallback)(e=>{"Escape"!==e.key&&"Esc"!==e.key||(r&&(n?.lastMessageSeen(),h(0)),c(!1),V())},[n,r,h,c]);(0,a.useEffect)(()=>()=>{document.getElementById(o)?.focus()},[]),(0,a.useEffect)(()=>(document.body.classList.remove("wc-u-hidden"),document.getElementsByTagName("html")[0].classList.add("wc-u-html"),document.body.classList.add("wc-u-body"),()=>{document.getElementsByTagName("html")[0].classList.remove("wc-u-html"),document.body.classList.remove("wc-u-body")}),[v]),(0,a.useEffect)(()=>(document.addEventListener("keydown",y),()=>{document.removeEventListener("keydown",y)}),[y,c]),(0,a.useEffect)(()=>{r&&(n?(n.lastMessageSeen(),h(0),b(2)):(async()=>{try{const e=await m(r);d(e);const t=await E(e);u(t)}catch(e){console.log("[Chat Error] fetchThread",e),l(),d(),b(0)}})())},[n,r]);const x=e=>t=>{t.preventDefault(),b(e)},p=x(0),D=x(1),j=x(2),_=x(3),T=x(4),C=x(5);let A;switch(w){case 0:default:A=(0,f.jsxDEV)(S,{onContinue:D},void 0,!1);break;case 1:A=(0,f.jsxDEV)(I,{onPreChatScreen:p},void 0,!1);break;case 2:A=(0,f.jsxDEV)(O,{onSettingsScreen:C,onEndChatScreen:_},void 0,!1);break;case 3:A=(0,f.jsxDEV)(R,{onChatScreen:j,onEndChatConfirm:T},void 0,!1);break;case 4:A=(0,f.jsxDEV)(U,{onCancel:()=>{c(!1),V()}},void 0,!1);break;case 5:A=(0,f.jsxDEV)(F,{onCancel:j},void 0,!1)}"UNAVAILABLE"===t&&(A=(0,f.jsxDEV)(M,{},void 0,!1));const L=(0,f.jsxDEV)("div",{id:"wc-panel",role:"dialog",className:s("wc-panel",g&&"wc-focus-visible"),tabIndex:"-1","aria-modal":"true","aria-labelledby":"wc-header wc-subtitle",children:[(0,f.jsxDEV)("div",{className:"wc-panel__inner",children:A},void 0,!1),(0,f.jsxDEV)($,{},void 0,!1)]},void 0,!0);return(0,f.jsxDEV)(f.Fragment,{children:(0,i.createPortal)(L,document.body)},void 0,!1)}const X=()=>{const{threadId:e,setInstigatorId:t}=k();if(!e)return null;const a=document.getElementById("webchat-skip-link-container");return a?(0,f.jsxDEV)(f.Fragment,{children:(0,i.createPortal)((0,f.jsxDEV)("a",{id:"webchat-skip-link",href:"#webchat",className:"govuk-skip-link","data-module":"govuk-skip-link",onClick:e=>{e.preventDefault(),t(e.target.id),window.location.hash="#webchat"},"data-wc-skiplink":!0,"data-wc-open-btn":!0,children:"Skip to webchat"},void 0,!1),a)},void 0,!1):null};function Z(){const{availability:e,isChatOpen:t,setChatVisibility:o,unseenCount:n,threadId:i,setUnseenCount:r,setInstigatorId:d,setLiveRegionText:l}=k(),c=(0,a.useRef)(),u=n>0&&!t,h=n>1?"new messages":"new message",v=e=>{e.preventDefault(),r(0),o(!t),d(e.target.id),t?V():D()},g=e=>{" "===e.key&&e.preventDefault()},m=e=>{" "===e.key&&(r(0),o(!t))};switch((0,a.useEffect)(()=>(u&&l(`Floodline webchat - ${n} ${h}`),()=>{l()}),[n,t]),(0,a.useEffect)(()=>{const a=()=>{if(!i)return;if("AVAILABLE"!==e)return;const a=c.current.parentElement.getBoundingClientRect().top+35>(window.innerHeight||document.documentElement.clientHeight),o=!t&&a;document.documentElement.classList.toggle("wc-u-scroll-padding",o),document.body.classList.toggle("wc-u-scroll-padding",o),c.current.classList.toggle("wc-availability--fixed",o)};return document.addEventListener("scroll",a),a(),()=>{document.removeEventListener("scroll",a)}},[i,t,e]),e){case"AVAILABLE":return(0,f.jsxDEV)(f.Fragment,{children:[(0,f.jsxDEV)("div",{className:s("wc-availability",t&&"wc-open"),ref:c,children:(0,f.jsxDEV)("div",{className:"wc-availability__inner",children:(0,f.jsxDEV)("a",{id:"webchat-start-chat-link",className:"wc-availability__link",href:"#webchat",draggable:"false",onClick:v,onKeyUp:m,onKeyDown:g,role:"button","data-module":"govuk-button",children:[i?(0,f.jsxDEV)(f.Fragment,{children:"Show chat"},void 0,!1):(0,f.jsxDEV)(f.Fragment,{children:"Start chat"},void 0,!1),u?(0,f.jsxDEV)("span",{className:"wc-availability__unseen",children:[n,(0,f.jsxDEV)("span",{className:"govuk-visually-hidden",children:[" ",h]},void 0,!0)]},void 0,!0):null]},void 0,!0)},void 0,!1)},void 0,!1),t?(0,f.jsxDEV)(J,{},void 0,!1):(0,f.jsxDEV)($,{},void 0,!1),(0,f.jsxDEV)(X,{},void 0,!1)]},void 0,!0);case"EXISTING":case"UNAVAILABLE":return(0,f.jsxDEV)("p",{className:"govuk-body",children:"When it is available, a 'start chat' link will appear."},void 0,!1);default:return(0,f.jsxDEV)("p",{className:"govuk-body",children:"Checking availability"},void 0,!1)}}const z=async e=>{const t=new(window.AudioContext||window.webkitAudioContext);if("suspended"===t.state){const e=["touchstart","touchend","mousedown","wheel","keydown","click"],a=o=>{e.forEach(e=>{document.body.removeEventListener(e,a)}),t.resume()};e.forEach(e=>{document.body.addEventListener(e,a,!1)})}const a=await fetch(e),o=await a.arrayBuffer(),n=await t.decodeAudioData(o);return()=>{const e=t.createBufferSource();e.buffer=n,e.connect(t.destination),e.start()}};async function Q(e,t){const a=new n.ChatSdk({brandId:t.brandId,channelId:t.channelId,customerId:globalThis.localStorage.getItem(m)||"",environment:t.environment,isLivechat:!0,cacheStorage:new n.CacheStorage(globalThis.localStorage),storage:globalThis.localStorage}),s=(0,o.createRoot)(e);let i,r;try{const e=await async function(e){const t=await fetch(e);return{availability:(await t.json()).availability||"UNAVAILABLE"}}(t.availabilityEndpoint);r=await z(t.audioUrl),i=e.availability}catch(e){i="UNAVAILABLE"}s.render((0,f.jsxDEV)(p,{sdk:a,availability:i,playSound:r,children:(0,f.jsxDEV)(Z,{},void 0,!1)},void 0,!1))}module.exports=t})();
package/dist/server.js CHANGED
@@ -1 +1 @@
1
- (()=>{var e={525(e,t,n){const{authenticate:o,getApiBaseUrl:a,getIsOpen:i,getActivity:s}=n(398);e.exports=async function({clientId:e,clientSecret:t,accessKey:n,accessSecret:r,maxQueueCount:c,skillEndpoint:u,hoursEndpoint:l,wellKnownUri:p="https://cxone.niceincontact.com/.well-known/cxone-configuration",authenticationUri:d="https://cxone.niceincontact.com/auth/token"}){const h="Basic "+Buffer.from(`${encodeURIComponent(e)}:${encodeURIComponent(t)}`).toString("base64"),{tenantId:m,token:y,tokenType:w}=await o({authenticationUri:d,authorisation:h,accessKey:n,accessSecret:r}),g=await a({wellKnownUri:p,tenantId:m}),[{hasCapacity:A,hasAgentsAvailable:k},f]=await Promise.all([s({baseUrl:g,tokenType:w,token:y,skillEndpoint:u,maxQueueCount:c}),i({baseUrl:g,token:y,tokenType:w,hoursEndpoint:l})]);let x="UNAVAILABLE";return f&&k&&A?x="AVAILABLE":f&&k&&!A&&(x="EXISTING"),{date:new Date,availability:x}}},398(e,t,n){const o=n(792),a=n(938),i=n(158),{isWithinHours:s}=n(411),r="application/x-www-form-urlencoded";e.exports={authenticate:async({authenticationUri:e,authorisation:t,accessKey:n,accessSecret:s})=>{const c=new URL(e),u=o.stringify({grant_type:"password",username:n,password:s}),l=await a.post(c.href,u,{signal:AbortSignal.timeout(3e3),headers:{Host:c.host,"Content-Type":r,Authorization:t}});return{token:l.data.access_token,tokenType:l.data.token_type,tenantId:i(l.data.id_token)?.tenantId}},getApiBaseUrl:async({wellKnownUri:e,tenantId:t})=>{const n=new URL(e);n.searchParams.set("tenantId",t);const{data:o}=await a.get(n.href,{headers:{Host:n.host},signal:AbortSignal.timeout(3e3)});return o.api_endpoint},getIsOpen:async({baseUrl:e,token:t,tokenType:n,hoursEndpoint:o})=>{const i=new URL(o,e),c=(await a.get(i.href,{signal:AbortSignal.timeout(3e3),headers:{Host:i.host,Authorization:`${n} ${t}`,"Content-Type":r}})).data.resultSet.hoursOfOperationProfiles[0].days;return s(c)},getActivity:async({tokenType:e,token:t,baseUrl:n,skillEndpoint:o,maxQueueCount:i})=>{const s=new URL(o,n),c=(await a.get(s.href,{signal:AbortSignal.timeout(3e3),headers:{Host:s.host,Authorization:`${e} ${t}`,"Content-Type":r}})).data.skillActivity[0];return{hasCapacity:c.queueCount<i,hasAgentsAvailable:c.agentsAvailable>=1}}}},411(e,t,n){const{DateTime:o}=n(168),a=e=>Number(e.split(":")[0]);e.exports={isWithinHours:(e,t)=>{const n=t?o.fromISO(t):o.local();n.setZone("Europe/London");const i=t?new Date(t):new Date,s=i.toLocaleDateString("en-GB",{weekday:"long"}),r=i.toLocaleDateString("en-GB").split("/"),c=e.find(e=>e.day===s),u=o.local(Number(r[2]),Number(r[1]),Number(r[0]),a(c.openTime)),l=o.local(Number(r[2]),Number(r[1]),Number(r[0]),a(c.closeTime));return n.diff(u).milliseconds>=0&&n.diff(l).milliseconds<=0}}},938(e){"use strict";e.exports=require("axios")},158(e){"use strict";e.exports=require("jwt-decode")},168(e){"use strict";e.exports=require("luxon")},792(e){"use strict";e.exports=require("node:querystring")}},t={},n=function n(o){var a=t[o];if(void 0!==a)return a.exports;var i=t[o]={exports:{}};return e[o](i,i.exports,n),i.exports}(525);module.exports=n})();
1
+ (()=>{var e={525(e,t,n){const{authenticate:o,getApiBaseUrl:a,getIsOpen:s,getActivity:i}=n(398);e.exports=async function({clientId:e,clientSecret:t,accessKey:n,accessSecret:r,maxQueueCount:c,skillEndpoint:u,hoursEndpoint:l,wellKnownUri:p="https://cxone.niceincontact.com/.well-known/cxone-configuration",authenticationUri:d="https://cxone.niceincontact.com/auth/token"}){const h="Basic "+Buffer.from(`${encodeURIComponent(e)}:${encodeURIComponent(t)}`).toString("base64"),{tenantId:m,token:w,tokenType:y}=await o({authenticationUri:d,authorisation:h,accessKey:n,accessSecret:r}),g=await a({wellKnownUri:p,tenantId:m}),[{hasCapacity:A,hasAgentsAvailable:k},f]=await Promise.all([i({baseUrl:g,tokenType:y,token:w,skillEndpoint:u,maxQueueCount:c}),s({baseUrl:g,token:w,tokenType:y,hoursEndpoint:l})]);let x="UNAVAILABLE";return f&&k&&A?x="AVAILABLE":f&&k&&!A&&(x="EXISTING"),{date:new Date,availability:x}}},398(e,t,n){const o=n(792),a=n(938),{jwtDecode:s}=n(158),{isWithinHours:i}=n(411),r="application/x-www-form-urlencoded";e.exports={authenticate:async({authenticationUri:e,authorisation:t,accessKey:n,accessSecret:i})=>{const c=new URL(e),u=o.stringify({grant_type:"password",username:n,password:i}),l=await a.post(c.href,u,{signal:AbortSignal.timeout(3e3),headers:{Host:c.host,"Content-Type":r,Authorization:t}});return{token:l.data.access_token,tokenType:l.data.token_type,tenantId:s(l.data.id_token)?.tenantId}},getApiBaseUrl:async({wellKnownUri:e,tenantId:t})=>{const n=new URL(e);n.searchParams.set("tenantId",t);const{data:o}=await a.get(n.href,{headers:{Host:n.host},signal:AbortSignal.timeout(3e3)});return o.api_endpoint},getIsOpen:async({baseUrl:e,token:t,tokenType:n,hoursEndpoint:o})=>{const s=new URL(o,e),c=(await a.get(s.href,{signal:AbortSignal.timeout(3e3),headers:{Host:s.host,Authorization:`${n} ${t}`,"Content-Type":r}})).data.resultSet.hoursOfOperationProfiles[0].days;return i(c)},getActivity:async({tokenType:e,token:t,baseUrl:n,skillEndpoint:o,maxQueueCount:s})=>{const i=new URL(o,n),c=(await a.get(i.href,{signal:AbortSignal.timeout(3e3),headers:{Host:i.host,Authorization:`${e} ${t}`,"Content-Type":r}})).data.skillActivity[0];return{hasCapacity:c.queueCount<s,hasAgentsAvailable:c.agentsAvailable>=1}}}},411(e,t,n){const{DateTime:o}=n(168),a=e=>Number(e.split(":")[0]);e.exports={isWithinHours:(e,t)=>{const n=t?o.fromISO(t):o.local();n.setZone("Europe/London");const s=t?new Date(t):new Date,i=s.toLocaleDateString("en-GB",{weekday:"long"}),r=s.toLocaleDateString("en-GB").split("/"),c=e.find(e=>e.day===i),u=o.local(Number(r[2]),Number(r[1]),Number(r[0]),a(c.openTime)),l=o.local(Number(r[2]),Number(r[1]),Number(r[0]),a(c.closeTime));return n.diff(u).milliseconds>=0&&n.diff(l).milliseconds<=0}}},938(e){"use strict";e.exports=require("axios")},158(e){"use strict";e.exports=require("jwt-decode")},168(e){"use strict";e.exports=require("luxon")},792(e){"use strict";e.exports=require("node:querystring")}};const t={};let n=function n(o){const a=t[o];if(void 0!==a)return a.exports;const s=t[o]={exports:{}};return e[o](s,s.exports,n),s.exports}(525);module.exports=n})();
package/main.scss CHANGED
@@ -1,9 +1,9 @@
1
-
2
1
  // Required GOVUK Styles
3
2
  @import "govuk-frontend/dist/govuk/core/typography";
4
3
  @import "govuk-frontend/dist/govuk/core/links";
5
4
  @import "govuk-frontend/dist/govuk/utilities/visually-hidden";
6
- @import "govuk-frontend/dist/govuk/components/button/button";
5
+ @import "govuk-frontend/dist/govuk/components/button";
6
+ @import "govuk-frontend/dist/govuk/helpers/media-queries";
7
7
 
8
8
  // (ITCSS)
9
9
  @import "./src/client/scss/settings";
@@ -14,4 +14,4 @@
14
14
  // React components
15
15
  @import "./src/client/components/availability/availability";
16
16
  @import "./src/client/components/panel/panel";
17
- @import "./src/client/components/chat/chat";
17
+ @import "./src/client/components/chat/chat";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defra/flood-webchat",
3
- "version": "1.0.23",
3
+ "version": "1.0.25",
4
4
  "description": "",
5
5
  "main": "dist/server.js",
6
6
  "browser": "dist/client.js",
@@ -31,46 +31,46 @@
31
31
  "url": "git+https://github.com/DEFRA/flood-webchat.git"
32
32
  },
33
33
  "devDependencies": {
34
- "@babel/core": "7.29.0",
35
- "@babel/preset-env": "7.29.2",
36
- "@babel/preset-react": "7.28.5",
34
+ "@babel/core": "8.0.1",
35
+ "@babel/preset-env": "8.0.2",
36
+ "@babel/preset-react": "8.0.1",
37
37
  "@testing-library/jest-dom": "6.9.1",
38
38
  "@testing-library/react": "16.3.2",
39
39
  "@testing-library/user-event": "14.6.1",
40
40
  "@types/jest": "30.0.0",
41
- "babel-jest": "30.3.0",
41
+ "babel-jest": "30.4.1",
42
42
  "babel-loader": "10.1.1",
43
43
  "core-js": "3.49.0",
44
44
  "css-loader": "7.1.4",
45
- "dotenv": "17.4.0",
45
+ "dotenv": "17.4.2",
46
46
  "husky": "9.1.7",
47
- "jest": "30.3.0",
48
- "jest-environment-jsdom": "30.3.0",
47
+ "jest": "30.4.2",
48
+ "jest-environment-jsdom": "30.4.1",
49
49
  "mini-css-extract-plugin": "2.10.2",
50
50
  "node-cache": "5.1.2",
51
- "sass": "1.98.0",
52
- "sass-loader": "16.0.7",
51
+ "sass": "1.101.3",
52
+ "sass-loader": "17.0.0",
53
53
  "standard": "17.1.2",
54
- "stylelint": "16.26.1",
55
- "stylelint-config-gds": "2.0.0",
56
- "webpack": "5.105.4",
57
- "webpack-cli": "7.0.2",
58
- "webpack-dev-server": "5.2.3",
54
+ "stylelint": "17.14.1",
55
+ "stylelint-config-gds": "3.0.0",
56
+ "webpack": "5.108.4",
57
+ "webpack-cli": "7.2.1",
58
+ "webpack-dev-server": "6.0.0",
59
59
  "webpack-merge": "6.0.1",
60
60
  "webpack-node-externals": "3.0.0"
61
61
  },
62
62
  "peerDependencies": {
63
- "govuk-frontend": "5.10.0"
63
+ "govuk-frontend": "6.4.0"
64
64
  },
65
65
  "dependencies": {
66
- "@nice-devone/nice-cxone-chat-web-sdk": "1.18.0",
67
- "axios": "1.15.0",
66
+ "@nice-devone/nice-cxone-chat-web-sdk": "3.3.0",
67
+ "axios": "1.18.1",
68
68
  "html-react-parser": "5.2.17",
69
- "jwt-decode": "3.1.2",
69
+ "jwt-decode": "4.0.0",
70
70
  "lodash.debounce": "4.0.8",
71
71
  "luxon": "3.7.2",
72
- "react": "19.2.4",
73
- "react-dom": "19.2.4",
74
- "uuid": "9.0.1"
72
+ "react": "19.2.7",
73
+ "react-dom": "19.2.7",
74
+ "uuid": "11.1.1"
75
75
  }
76
76
  }
@@ -24,7 +24,7 @@
24
24
  border-color: currentColor;
25
25
  }
26
26
 
27
- @include mq ($from: 'tablet') {
27
+ @include govuk-media-query ($from: 'tablet') {
28
28
  padding-left: 30px;
29
29
  padding-right: 30px;
30
30
  }
@@ -74,7 +74,7 @@
74
74
  padding: 0 6px;
75
75
  margin-left: 5px;
76
76
 
77
- @include mq ($from: tablet) {
77
+ @include govuk-media-query ($from: tablet) {
78
78
  top: -1px;
79
79
  padding-left: 7px;
80
80
  padding-right: 7px;
@@ -9,7 +9,7 @@
9
9
  position: relative;
10
10
  padding: 15px;
11
11
 
12
- @include mq ($from: tablet) {
12
+ @include govuk-media-query ($from: tablet) {
13
13
  padding: 10px;
14
14
  }
15
15
 
@@ -20,9 +20,9 @@
20
20
  left: 15px;
21
21
  right: 15px;
22
22
  height: 0;
23
- border-bottom: 1px solid $govuk-border-colour;
23
+ border-bottom: 1px solid govuk-functional-colour(border);
24
24
 
25
- @include mq ($from: tablet) {
25
+ @include govuk-media-query ($from: tablet) {
26
26
  left: 10px;
27
27
  right: 10px;
28
28
  }
@@ -69,7 +69,7 @@
69
69
  margin-left: auto;
70
70
  }
71
71
 
72
- @include mq ($from: tablet) {
72
+ @include govuk-media-query ($from: tablet) {
73
73
  margin-left: 10px;
74
74
  margin-right: 10px;
75
75
  }
@@ -164,7 +164,7 @@
164
164
  line-height: 20px;
165
165
  margin: 20px;
166
166
 
167
- @include mq ($from: tablet) {
167
+ @include govuk-media-query ($from: tablet) {
168
168
  margin: 18px 18px 19px;
169
169
  }
170
170
 
@@ -185,7 +185,7 @@
185
185
  align-self: flex-end;
186
186
  margin: 20px;
187
187
 
188
- @include mq ($from: tablet) {
188
+ @include govuk-media-query ($from: tablet) {
189
189
  margin: 18px 18px 19px;
190
190
  }
191
191
 
@@ -206,7 +206,7 @@
206
206
  &__button {
207
207
  margin: 10px 15px 12px 0;
208
208
 
209
- @include mq ($from: tablet) {
209
+ @include govuk-media-query ($from: tablet) {
210
210
  margin-right: 10px;
211
211
  }
212
212
 
@@ -77,7 +77,7 @@ export function Panel () {
77
77
  const fetchedThread = await fetchThread(threadId)
78
78
  setThread(fetchedThread)
79
79
 
80
- const fetchedMessages = await fetchMessages(fetchedThread, threadId)
80
+ const fetchedMessages = await fetchMessages(fetchedThread)
81
81
  setMessages(fetchedMessages)
82
82
  } catch (err) {
83
83
  console.log('[Chat Error] fetchThread', err)
@@ -13,7 +13,7 @@
13
13
  touch-action: pan-x pan-y;
14
14
  background-color: #ffffff;
15
15
 
16
- @include mq ($from: tablet) {
16
+ @include govuk-media-query ($from: tablet) {
17
17
  top: auto;
18
18
  left: auto;
19
19
  width: 400px;
@@ -44,7 +44,7 @@
44
44
  border: 0;
45
45
  outline: 0;
46
46
 
47
- @include mq ($from: tablet) {
47
+ @include govuk-media-query ($from: tablet) {
48
48
  border: 1px solid govuk-colour('black');
49
49
  }
50
50
 
@@ -69,7 +69,7 @@
69
69
  font-size: 19px;
70
70
  padding: 0 0 0 10px;
71
71
 
72
- @include mq ($from: tablet) {
72
+ @include govuk-media-query ($from: tablet) {
73
73
  padding-left: 7px;
74
74
  }
75
75
 
@@ -90,7 +90,7 @@
90
90
  cursor: pointer;
91
91
 
92
92
  &:focus {
93
- outline: 3px solid $govuk-focus-colour;
93
+ outline: 3px solid govuk-functional-colour(focus);
94
94
  }
95
95
  }
96
96
 
@@ -98,7 +98,7 @@
98
98
  margin: 0;
99
99
  display: flex;
100
100
 
101
- @include mq ($from: 'tablet') {
101
+ @include govuk-media-query ($from: 'tablet') {
102
102
  display: none
103
103
  }
104
104
  }
@@ -19,11 +19,11 @@ export function PreChat ({ onContinue }) {
19
19
  </ul>
20
20
  <p>
21
21
  There are other ways to&nbsp;
22
- <a className='govuk-link' href='https://www.gov.uk/sign-up-for-flood-warnings' target='_blank' rel='noreferrer'>
23
- sign up for flood warnings
22
+ <a className='govuk-link' href='https://www.gov.uk/get-flood-warnings' target='_blank' rel='noreferrer'>
23
+ get flood warnings
24
24
  </a>
25
25
  &nbsp;and&nbsp;
26
- <a className='govuk-link' href='https://www.fws.environment-agency.gov.uk/app/olr/login' target='_blank' rel='noreferrer'>
26
+ <a className='govuk-link' href='https://get-flood-warnings.service.gov.uk/sign-in' target='_blank' rel='noreferrer'>
27
27
  manage your flood warnings account
28
28
  </a>.
29
29
  </p>
@@ -1,6 +1,6 @@
1
1
  import React from 'react'
2
2
  import { createRoot } from 'react-dom/client'
3
- import { ChatSdk } from '@nice-devone/nice-cxone-chat-web-sdk'
3
+ import { ChatSdk, CacheStorage } from '@nice-devone/nice-cxone-chat-web-sdk'
4
4
  import { Availability } from './components/availability/availability.jsx'
5
5
  import { checkAvailability } from './lib/check-availability'
6
6
  import { AppProvider } from './store/AppProvider.jsx'
@@ -11,8 +11,11 @@ export async function init (container, options) {
11
11
  const sdk = new ChatSdk({
12
12
  brandId: options.brandId,
13
13
  channelId: options.channelId,
14
- customerId: window.localStorage.getItem(CUSTOMER_ID_STORAGE_KEY) || '',
15
- environment: options.environment
14
+ customerId: globalThis.localStorage.getItem(CUSTOMER_ID_STORAGE_KEY) || '',
15
+ environment: options.environment,
16
+ isLivechat: true,
17
+ cacheStorage: new CacheStorage(globalThis.localStorage),
18
+ storage: globalThis.localStorage
16
19
  })
17
20
 
18
21
  const root = createRoot(container)
@@ -68,7 +68,8 @@
68
68
  line-height: 1.25;
69
69
  }
70
70
 
71
- .wc-input, .wc-textarea {
71
+ .wc-input,
72
+ .wc-textarea {
72
73
  font-size: 16px;
73
74
  line-height: 1.25;
74
75
  }
@@ -87,7 +88,6 @@
87
88
  margin: 0 !important;
88
89
  padding: 0 !important;
89
90
  overflow: hidden !important;
90
- clip: rect(0 0 0 0) !important;
91
91
  -webkit-clip-path: inset(50%) !important;
92
92
  clip-path: inset(50%) !important;
93
93
  border: 0 !important;
@@ -98,4 +98,5 @@
98
98
  content: ' ';
99
99
  }
100
100
  }
101
+
101
102
  // stylelint-enable declaration-no-important
@@ -1,4 +1,4 @@
1
- // Check there is ot already similar functinality in GOV.UK Frontend
1
+ // Check there is not already similar functionality in GOV.UK Frontend
2
2
 
3
3
  @mixin defra-visually-hidden() {
4
4
  position: absolute;
@@ -7,7 +7,6 @@
7
7
  margin: 0;
8
8
  padding: 0;
9
9
  overflow: hidden;
10
- clip: rect(0 0 0 0);
11
10
  -webkit-clip-path: inset(50%);
12
11
  clip-path: inset(50%);
13
12
  border: 0;
@@ -16,8 +15,8 @@
16
15
 
17
16
  // Map specific mixins
18
17
  @mixin focus($glow: 8px, $strong: 5px, $background: 2px, $inset: 0) {
19
- position:absolute;
20
- content:'';
18
+ position: absolute;
19
+ content: '';
21
20
  left: 5px;
22
21
  right: 5px;
23
22
  top: 5px;
@@ -26,8 +25,8 @@
26
25
  0 0 0 $background #ffffff,
27
26
  inset 0 0 0 $inset govuk-colour('black'),
28
27
  0 0 0 $strong govuk-colour('black'),
29
- 0 0 0 $glow $govuk-focus-colour;
28
+ 0 0 0 $glow govuk-functional-colour(focus);
30
29
  outline: 3px solid transparent;
31
30
  pointer-events: none;
32
31
  z-index: 99;
33
- }
32
+ }
@@ -1,18 +1,18 @@
1
1
  .wc-u-html {
2
- @include mq ($until: tablet) {
2
+ @include govuk-media-query ($until: tablet) {
3
3
  height: 100vh;
4
4
  overflow: hidden;
5
5
  }
6
6
  }
7
7
 
8
8
  .wc-u-body {
9
- @include mq ($until: tablet) {
9
+ @include govuk-media-query ($until: tablet) {
10
10
  position: fixed;
11
11
  overflow: hidden;
12
- top:0;
13
- right:0;
14
- bottom:0;
15
- left:0;
12
+ top: 0;
13
+ right: 0;
14
+ bottom: 0;
15
+ left: 0;
16
16
  }
17
17
  }
18
18
 
@@ -22,4 +22,4 @@
22
22
 
23
23
  .wc-u-scroll-padding {
24
24
  scroll-padding-bottom: calc(2rem + 20px);
25
- }
25
+ }
@@ -23,7 +23,10 @@ export const AppProvider = ({ sdk, availability, playSound, children }) => {
23
23
  dispatch({ type: 'SET_AGENT_STATUS', payload: e.detail.data.case.status })
24
24
  }
25
25
 
26
- const onAgentTypingStarted = () => {
26
+ const onAgentTypingStarted = (e) => {
27
+ if (e?.detail?.data?.user) {
28
+ dispatch({ type: 'SET_AGENT', payload: e.detail.data.user })
29
+ }
27
30
  dispatch({ type: 'SET_AGENT_TYPING', payload: true })
28
31
  }
29
32
 
@@ -46,6 +49,9 @@ export const AppProvider = ({ sdk, availability, playSound, children }) => {
46
49
 
47
50
  const onContactStatusChanged = e => {
48
51
  dispatch({ type: 'SET_AGENT_STATUS', payload: e.detail.data.case.status })
52
+ if (e.detail.data.inboxAssignee) {
53
+ dispatch({ type: 'SET_AGENT', payload: e.detail.data.inboxAssignee })
54
+ }
49
55
  }
50
56
 
51
57
  const onMatchMedia = e => {
@@ -1,9 +1,9 @@
1
1
  export const useChatSdk = sdk => {
2
- const connect = async () => sdk.authorize()
2
+ const connect = async () => sdk.connect()
3
3
 
4
4
  const fetchCustomerId = async () => {
5
- const response = await connect()
6
- return response?.consumerIdentity.idOnExternalPlatform
5
+ await connect()
6
+ return sdk.getCustomer().getId()
7
7
  }
8
8
 
9
9
  const fetchThread = async threadId => {
@@ -11,10 +11,10 @@ export const useChatSdk = sdk => {
11
11
  return sdk.getThread(threadId)
12
12
  }
13
13
 
14
- const fetchMessages = async (thread, threadId) => {
14
+ const fetchMessages = async (thread) => {
15
15
  await connect()
16
16
 
17
- const recovered = await thread.recover(threadId)
17
+ const recovered = await thread.recover()
18
18
 
19
19
  const allMessages = []
20
20
  let fetchedMessages = recovered.messages
@@ -1,6 +1,6 @@
1
1
  const querystring = require('node:querystring')
2
2
  const axios = require('axios')
3
- const jwtdecode = require('jwt-decode')
3
+ const { jwtDecode } = require('jwt-decode')
4
4
  const { isWithinHours } = require('./utils.js')
5
5
 
6
6
  const contentType = 'application/x-www-form-urlencoded'
@@ -25,7 +25,7 @@ const authenticate = async ({ authenticationUri, authorisation, accessKey, acces
25
25
  return {
26
26
  token: auth.data.access_token,
27
27
  tokenType: auth.data.token_type,
28
- tenantId: jwtdecode(auth.data.id_token)?.tenantId
28
+ tenantId: jwtDecode(auth.data.id_token)?.tenantId
29
29
  }
30
30
  }
31
31