@webority/support-react 0.115.0 → 0.117.0
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/README.md +7 -3
- package/dist/guidance.json +1 -1
- package/dist/support-react.js +1 -1
- package/dist/types/client.d.ts +17 -0
- package/dist/types/components/AttachmentThumb.d.ts +4 -3
- package/dist/types/components/ReplyBox.d.ts +3 -1
- package/dist/types/components/SuggestedAnswers.d.ts +13 -0
- package/dist/types/lib/errors.d.ts +10 -0
- package/dist/types/lib/files.d.ts +29 -0
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -102,9 +102,13 @@ asks the server once typing pauses, and a new tab or search starts again at page
|
|
|
102
102
|
Support emails link to the support page with `?ticket=<id>`. The centre opens that ticket and
|
|
103
103
|
keeps the parameter in step as tickets open and close, so a refresh stays on the same ticket.
|
|
104
104
|
In a ticket the customer can reply with files (pasting an image into the message attaches it),
|
|
105
|
-
reopen a settled ticket, and say whether it solved their problem.
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
reopen a settled ticket, and say whether it solved their problem. The ticket's Ticket details card
|
|
106
|
+
beside the thread lists its status, category, number and times. Each attachment is a chip that
|
|
107
|
+
downloads when pressed and opens in a new tab, so a ticket fetches no file until one is asked for.
|
|
108
|
+
Files are checked against the config's type, size and count limits before anything uploads, and a
|
|
109
|
+
file that breaks a limit gets one message, in the package's words. The New ticket form shows
|
|
110
|
+
suggested answers as plain text under the subject once it has three characters and the person
|
|
111
|
+
pauses; a 404 from `GET {base}/suggestions` means none.
|
|
108
112
|
|
|
109
113
|
### `<ReportIssue />`
|
|
110
114
|
|
package/dist/guidance.json
CHANGED
package/dist/support-react.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createContext as e,useCallback as t,useContext as n,useEffect as r,useId as i,useMemo as a,useRef as o,useState as s}from"react";import{AppActionIcon as c,AppAlert as l,AppAvatar as u,AppBadge as d,AppButton as f,AppCard as p,AppConfirmDialog as m,AppCopyButton as h,AppDataTable as g,AppDescriptions as _,AppEmptyState as v,AppFileAttachment as y,AppIcon as b,AppInput as x,AppLink as S,AppModal as C,AppSearch as w,AppSelect as T,AppSkeleton as E,AppSpinner as D,AppStatusBadge as O,AppTabs as k,AppTextarea as A,useFloatingStack as j,warnInvalidValue as M}from"@webority/ui-react";import{toBlob as N}from"html-to-image";import{createPortal as ee}from"react-dom";import{Fragment as P,jsx as F,jsxs as I}from"react/jsx-runtime";var L=`Something went wrong. Please try again.`,R=class extends Error{constructor(e,t,n){super(t),this.name=`SupportApiError`,this.code=e,this.status=n}};async function z(e){if(e&&typeof Blob<`u`&&e instanceof Blob)try{return JSON.parse(await e.text())}catch{return null}if(typeof e==`string`)try{return JSON.parse(e)}catch{return null}return e??null}async function B(e){if(e instanceof R)return e;let t=e?.response;if(!t)return new R(`network`,L);let n=await z(t.data);return new R(typeof n?.code==`string`&&n.code?n.code:`unknown`,typeof n?.message==`string`&&n.message?n.message:L,t.status)}async function V(e){try{return(await e()).data}catch(e){throw await B(e)}}function H(e,t,n){n!=null&&String(n).trim()!==``&&e.append(t,String(n))}function U(e,t,n,r){(n??[]).forEach((n,i)=>{let a=n?.name||`${r}-${i+1}.png`;e.append(t,n,a)})}function te(e,t=`/api/support`){let n=(typeof t==`string`?t:t?.base??`/api/support`).replace(/\/+$/,``),r=e=>`${n}/tickets/${encodeURIComponent(e)}`;return{getConfig:()=>V(()=>e.get(`${n}/settings`)),listTickets:({status:t,search:r,page:i,pageSize:a}={})=>{let o=new URLSearchParams;H(o,`status`,t),H(o,`search`,r?.trim()),H(o,`page`,i),H(o,`pageSize`,a);let s=o.toString();return V(()=>e.get(`${n}/tickets${s?`?${s}`:``}`))},getTicketCounts:()=>V(()=>e.get(`${n}/tickets/counts`)),getTicket:t=>V(()=>e.get(r(t))),createTicket:({category:t,subject:r,body:i,pageUrl:a,userAgent:o,appVersion:s,files:c,screenshots:l})=>{let u=new FormData;return u.append(`category`,t??``),u.append(`subject`,r??``),u.append(`body`,i??``),H(u,`pageUrl`,a),H(u,`userAgent`,o),H(u,`appVersion`,s),U(u,`files`,c,`file`),U(u,`screenshots`,l,`screenshot`),V(()=>e.post(`${n}/tickets`,u))},reply:(t,{body:n,files:i,screenshots:a})=>{let o=new FormData;return o.append(`body`,n??``),U(o,`files`,i,`file`),U(o,`screenshots`,a,`screenshot`),V(()=>e.post(`${r(t)}/replies`,o))},reopen:t=>V(()=>e.post(`${r(t)}/reopen`)),cancel:t=>V(()=>e.post(`${r(t)}/cancel`)),rate:(t,{satisfaction:n,comment:i})=>{let a={satisfaction:n};return i!=null&&i.trim()!==``&&(a.comment=i.trim()),V(()=>e.post(`${r(t)}/rating`,a))},fetchAttachment:t=>V(()=>e.get(`${n}/attachments/${encodeURIComponent(t)}`,{responseType:`blob`})),confirmAction:t=>V(()=>e.post(`${n}/actions/confirm`,{token:t}))}}var W=e(null);function G(){let e=n(W);if(!e)throw Error(`Support components and hooks must be used inside <SupportProvider>.`);return e}function K(){return G().client}function ne(){return G().timeZone}function q(){return G().renderTime??null}function J(e,n,i=!0){let[a,c]=s({data:null,loading:i,error:null}),[l,u]=s(0),d=o(e);d.current=e;let f=o(n);r(()=>{let e=f.current!==n;if(f.current=n,!i){c({data:null,loading:!1,error:null});return}let t=!0;return c(t=>({data:e?null:t.data,loading:!0,error:null})),d.current(l>0).then(e=>t&&c({data:e,loading:!1,error:null}),e=>t&&c(t=>({...t,loading:!1,error:e}))),()=>{t=!1}},[n,i,l]);let p=t(()=>u(e=>e+1),[]),m=t(e=>c(t=>({...t,data:e})),[]);return{...a,reload:p,setData:m}}function Y(){let{loadConfig:e}=G(),{data:t,loading:n,error:r,reload:i}=J(e,`config`);return{config:t,loading:n,error:r,reload:i}}function X(e={}){let t=K(),{status:n,search:r,page:i,pageSize:a}=e,{data:o,loading:s,error:c,reload:l}=J(()=>t.listTickets({status:n,search:r,page:i,pageSize:a}),JSON.stringify([`tickets`,n??null,r??null,i??null,a??null]));return{tickets:o?.items??[],totalCount:o?.totalCount??0,totalPages:o?.totalPages??0,loading:s,error:c,reload:l}}function re(){let e=K(),{data:t,loading:n,error:r,reload:i}=J(()=>e.getTicketCounts(),`ticket-counts`);return{counts:t,loading:n,error:r,reload:i}}function ie(e){let n=K(),{data:r,loading:i,error:a,reload:o,setData:s}=J(()=>n.getTicket(e),e??``,!!e),c=t(async e=>{let t=await e();return s(t),t},[s]);return{ticket:r,loading:i,error:a,reload:o,reply:t(t=>c(()=>n.reply(e,t)),[c,n,e]),reopen:t(()=>c(()=>n.reopen(e)),[c,n,e]),cancel:t(()=>c(()=>n.cancel(e)),[c,n,e]),rate:t(t=>c(()=>n.rate(e,t)),[c,n,e])}}var ae=`Asia/Kolkata`,oe=330*60*1e3,se=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],ce=e=>typeof e==`number`&&Number.isFinite(e);function le(e){if(e instanceof Date)return e.getTime();if(ce(e))return e;if(typeof e!=`string`)return NaN;let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e.trim());if(t){let[e,n,r]=[Number(t[1]),Number(t[2]),Number(t[3])],i=new Date(Date.UTC(2e3,n-1,r));return i.setUTCFullYear(e),i.getUTCFullYear()===e&&i.getUTCMonth()===n-1&&i.getUTCDate()===r?i.getTime()-oe:NaN}return Date.parse(e)}function ue(e,{timeZone:t=ae}={}){let n=le(e);if(!Number.isFinite(n))return`-`;let r=Object.fromEntries(fe(t).formatToParts(n).map(e=>[e.type,e.value]));return`${r.day}-${se[Number(r.month)-1]}-${r.year}, ${r.hour}:${r.minute} ${r.dayPeriod.toUpperCase()}`}var de=new Map;function fe(e){let t=de.get(e);return t||(t=new Intl.DateTimeFormat(`en-IN`,{day:`2-digit`,month:`numeric`,year:`numeric`,hour:`numeric`,minute:`2-digit`,hour12:!0,timeZone:e}),de.set(e,t)),t}function pe(e=ae){return new Intl.DateTimeFormat(`en-IN`,{timeZone:e,timeZoneName:`short`}).formatToParts(new Date).find(e=>e.type===`timeZoneName`)?.value??e}Object.freeze({label:`Notifications`,empty:`You are all caught up.`,markAll:`Mark all read`,viewAll:`View all`,unreadPrefix:`Unread: `,today:`Today`,yesterday:`Yesterday`,allRead:`All notifications marked as read.`,noneUnread:`No unread notifications`,failed:Object.freeze({forbidden:`You do not have permission to mark these as read.`,client:`These could not be marked as read. Refresh the page and try again.`,validation:`These could not be marked as read. Refresh the page and try again.`,server:`Something went wrong on our side, so these were not marked as read. Try again in a moment.`,network:`Could not reach the server, so these were not marked as read. Check your connection and try again.`})});var me=[`KB`,`MB`,`GB`];function he(e){if(e<1024)return`${e} B`;let t=e/1024,n=0;for(;t>=1024&&n<me.length-1;)t/=1024,n+=1;return`${t.toFixed(1)} ${me[n]}`}function ge(e){return(e?.allowedContentTypes??[]).join(`,`)}function _e(e,t){if(t.length===0)return!0;let n=(e||``).toLowerCase();return t.some(e=>{let t=e.toLowerCase();return t.endsWith(`/*`)?n.startsWith(t.slice(0,-1)):n===t})}function Z(e,t){let n=e??[],r=t?.maxAttachmentsPerMessage??0,i=t?.maxAttachmentBytes??0,a=t?.allowedContentTypes??[];if(r>0&&n.length>r)return r===1?`You can attach one file.`:`You can attach up to ${r} files.`;for(let e of n){let t=e.name||`This file`;if(!_e(e.type,a))return`${t} is a file type we cannot accept.`;if(i>0&&e.size>i)return`${t} is larger than ${he(i)}.`}return null}function ve(e){let t=Array.from(e.clipboardData?.items??[]),n=Date.now();return t.filter(e=>e.kind===`file`&&e.type.startsWith(`image/`)).map(e=>e.getAsFile()).filter(Boolean).map((e,t)=>{let r=(e.type.split(`/`)[1]||`png`).replace(`jpeg`,`jpg`);return new File([e],`pasted-image-${n}-${t+1}.${r}`,{type:e.type})})}function ye({id:e,label:t=`Attachments`,files:n,onChange:r,config:i,error:a}){let o=i?.maxAttachmentBytes??0,s=o>0?Math.max(.1,Math.round(o/(1024*1024)*10)/10):0;return F(y,{id:e,label:t,optional:!0,multiple:!0,value:n,onChange:r,accept:ge(i),maxSizeMb:s,validate:!1,error:a||void 0})}function be(e,t){return t&&e.includes(t)?t:``}function xe({id:e,config:t,defaultCategory:n,initialValues:i,onValuesChange:a,extraFiles:o=[],onSubmit:c,onBusyChange:u,children:d}){let f=t?.categories??[],[p,m]=s(()=>i?.category??be(f,n)),[h,g]=s(i?.subject??``),[_,v]=s(i?.body??``),[y,b]=s(i?.files??[]),[S,C]=s({}),[w,E]=s(``);r(()=>{a?.({category:p,subject:h,body:_,files:y})},[p,h,_,y,a]);let D=e=>{b(e),C(n=>({...n,files:Z([...o,...e],t)??void 0}))},O=e=>{let t=ve(e);t.length>0&&D([...y,...t])};function k(){let e={};h.trim()||(e.subject=`Enter a subject.`),_.trim()||(e.body=`Enter what happened.`);let n=Z([...o,...y],t);return n&&(e.files=n),C(e),Object.keys(e).length===0}async function j(e){if(e.preventDefault(),E(``),k()){u?.(!0);try{await c({category:p,subject:h.trim(),body:_.trim(),files:y})}catch(e){E(e?.message||`Your ticket did not send. Please try again.`)}finally{u?.(!1)}}}return I(`form`,{id:e,onSubmit:j,noValidate:!0,className:`d-flex flex-column gap-3`,children:[w&&F(l,{tone:`danger`,children:w}),F(T,{id:`${e}-category`,label:`Category`,value:p,onChange:m,options:f.map(e=>({value:e,label:e})),placeholder:`Choose a category`,hint:`Not sure? Leave it empty and we will sort it.`,error:S.category}),F(x,{id:`${e}-subject`,label:`Subject`,required:!0,maxLength:t?.subjectMaxLength,showCount:!0,placeholder:`A short summary`,value:h,onChange:e=>g(e.target.value),error:S.subject}),F(A,{id:`${e}-body`,label:`Message`,required:!0,rows:6,maxLength:t?.bodyMaxLength,showCount:!0,placeholder:`What happened, and what did you expect to happen?`,value:_,onChange:e=>v(e.target.value),onPaste:O,hint:`You can paste an image into the message.`,error:S.body}),d,F(ye,{id:`${e}-files`,files:y,onChange:D,config:t,error:S.files})]})}var Se=`supportCapture`,Ce={zIndex:`var(--wui-z-fixed)`,bottom:0,insetInlineEnd:0},we={zIndex:`var(--wui-z-fixed)`},Te={maxWidth:`20rem`},Ee=e=>e.dataset?.[Se]===`exclude`||e.matches?.(`.modal-backdrop`)?!1:!(e.matches?.(`.modal`)&&e.querySelector?.(`[data-support-capture="exclude"]`)),De=()=>new Promise(e=>requestAnimationFrame(()=>e()));async function Oe(){let e=await N(document.body,{filter:Ee,pixelRatio:Math.min(window.devicePixelRatio||1,2),style:{overflow:`visible`,paddingRight:`0px`}});if(!e)throw Error(`The page capture came back empty.`);return new File([e],`screenshot.png`,{type:`image/png`})}function ke({file:e,failed:t,disabled:n,hintId:i,controlRef:a,onAdd:o,onRemove:c}){let[u,d]=s(null);return r(()=>{if(!e)return;let t=URL.createObjectURL(e);return d(t),()=>URL.revokeObjectURL(t)},[e]),I(`div`,{className:`d-flex flex-column gap-2`,children:[F(`span`,{className:`wui-text-sm fw-semibold`,children:`Screenshot`}),e&&u&&F(`img`,{src:u,alt:`Screenshot of the page you were on`,className:`d-block w-100 border rounded`,style:Te}),F(`div`,{ref:a,className:`d-flex flex-wrap gap-2`,children:e?I(P,{children:[F(f,{variant:`outline`,size:`sm`,leftIcon:`refresh-cw`,onClick:o,disabled:n,"aria-describedby":i,children:`Retake`}),F(f,{variant:`ghost`,size:`sm`,leftIcon:`x`,onClick:c,disabled:n,children:`Remove screenshot`})]}):F(f,{variant:`outline`,size:`sm`,leftIcon:`camera`,onClick:o,disabled:n,"aria-describedby":i,children:`Add a screenshot`})}),F(`span`,{id:i,className:`wui-text-sm text-body-secondary`,children:`Only what is on your screen now. You can remove it before sending.`}),t&&F(l,{tone:`info`,children:`We could not take a screenshot of this page. You can attach an image instead, or send the report without one.`})]})}function Ae({label:e=`Report an issue`,floating:t=!1,compact:n=!1,defaultCategory:a=`Bug report`,appVersion:c,getTicketHref:u,onOpenTicket:d,onCreated:p,className:m,style:h}){let g=K(),{config:_,error:v}=Y(),y=`support-report-${i().replace(/[^a-zA-Z0-9-]/g,``)}`,[x,S]=s(!1),[w,T]=s(!1),[E,D]=s(null),[O,k]=s(!1),[A,M]=s(!1),[N,L]=s(null),[R,z]=s(null),B=j(`end`,t&&n),V=o(null),H=o(!1);r(()=>{w||!H.current||(H.current=!1,V.current?.querySelector(`button`)?.focus())},[w]);function U(){L(null),D(null),k(!1),z(null),S(!0)}async function te(){T(!0),k(!1),await De(),await De();try{D(await Oe())}catch{D(null),k(!0)}finally{H.current=!0,T(!1)}}let W=()=>{A||(S(!1),D(null),k(!1),L(null),z(null))};async function G(e){let t=await g.createTicket({...e,pageUrl:window.location.href,userAgent:navigator.userAgent,appVersion:c,screenshots:E?[E]:[]});L(t),D(null),p?.(t)}let ne=!N&&(!!E||!!R&&(R.subject.trim()!==``||R.body.trim()!==``||R.files.length>0)),q=N&&u?u(N.id):void 0,J=N?I(`div`,{className:`d-flex justify-content-end gap-2 w-100`,children:[F(f,{variant:`secondary`,onClick:W,children:`Close`}),N&&(q||d)?F(f,{href:q,onClick:q?void 0:()=>{S(!1),L(null),d(N)},children:`View ticket`}):null]}):I(`div`,{className:`d-flex justify-content-end gap-2 w-100`,children:[F(f,{variant:`secondary`,onClick:W,disabled:A,children:`Cancel`}),F(f,{type:`submit`,form:y,loading:A,disabled:!_,children:`Submit`})]}),X=n?F(f,{variant:`secondary`,className:`wui-floating-btn wui-floating-btn--secondary`,disabled:w,onClick:U,"aria-haspopup":`dialog`,"aria-label":e,tooltip:e,tooltipPlacement:`start`,children:F(b,{name:`bug`,size:22})}):F(f,{leftIcon:`bug`,variant:t?`primary`:`outline`,disabled:w,onClick:U,"aria-haspopup":`dialog`,children:e});return I(P,{children:[t&&n?B&&ee(F(`span`,{className:[`wui-floating-stack-item wui-floating-stack-item--secondary`,m].filter(Boolean).join(` `),style:h,children:X}),B):F(`span`,{"data-support-capture":`exclude`,className:[t?`position-fixed m-3`:`d-inline-block`,m].filter(Boolean).join(` `),style:t?{...Ce,...h}:h,children:X}),w&&I(`div`,{"data-support-capture":`exclude`,role:`status`,className:`position-fixed top-0 start-50 translate-middle-x mt-3 d-flex align-items-center gap-2 px-3 py-2 bg-body border rounded-pill shadow-sm wui-text-sm`,style:we,children:[F(`span`,{className:`spinner-border spinner-border-sm`,"aria-hidden":`true`}),`Taking a screenshot`]}),F(C,{open:x,size:`lg`,title:`Report an issue`,subtitle:`Tell us what went wrong. You can add a screenshot of this page if it helps.`,headerIcon:`bug`,confirmDiscard:`Discard this report?`,dirty:ne&&!A,onClose:W,footer:J,"data-support-capture":`exclude`,children:N?F(l,{tone:`success`,role:`status`,title:`Ticket ${N.number} is with the support team`,children:`We reply by email. You can follow the ticket on your support page.`}):_?F(xe,{id:y,config:_,defaultCategory:a,initialValues:R,onValuesChange:z,extraFiles:E?[E]:[],onSubmit:G,onBusyChange:M,children:F(ke,{file:E,failed:O,disabled:A||w,hintId:`${y}-screenshot-hint`,controlRef:V,onAdd:te,onRemove:()=>D(null)})}):F(l,{tone:v?`danger`:`info`,children:v?v.message||`We could not load the support settings.`:`Loading the form.`})})]})}function je({open:e,onClose:t,onCreated:n,config:r,defaultCategory:a,appVersion:o}){let c=K(),l=`support-new-${i().replace(/[^a-zA-Z0-9-]/g,``)}`,[u,d]=s(!1),[p,m]=s(null),h=!!p&&(p.subject.trim()!==``||p.body.trim()!==``||p.files.length>0);async function g(e){n(await c.createTicket({...e,userAgent:typeof navigator>`u`?void 0:navigator.userAgent,appVersion:o}))}return F(C,{open:e,size:`lg`,title:`New ticket`,subtitle:`Tell us what you need. We reply by email and on this page.`,headerIcon:`message-square`,confirmDiscard:`Discard this ticket?`,dirty:h&&!u,onClose:()=>{u||t()},footer:I(`div`,{className:`d-flex justify-content-end gap-2 w-100`,children:[F(f,{variant:`secondary`,onClick:t,disabled:u,children:`Cancel`}),F(f,{type:`submit`,form:l,loading:u,children:`Send ticket`})]}),children:e&&F(xe,{id:l,config:r,defaultCategory:a,onSubmit:g,onBusyChange:d,onValuesChange:m})})}var Me={Open:`warning`,InProgress:`info`,WaitingOnCustomer:`warning`,Resolved:`success`,Closed:`neutral`,Cancelled:`neutral`};function Ne(e){return Me[e]??`neutral`}var Pe={width:140,maxWidth:`100%`},Fe={height:84};function Ie({attachment:e}){let t=K(),n=(e.contentType||``).startsWith(`image/`),[i,a]=s(null),[o,c]=s(!1);r(()=>{let n=!0,r=null;return a(null),c(!1),t.fetchAttachment(e.id).then(e=>{r=URL.createObjectURL(e),n?a(r):URL.revokeObjectURL(r)},()=>n&&c(!0)),()=>{n=!1,r&&URL.revokeObjectURL(r)}},[t,e.id]);let l=`Open ${e.fileName}`,u=I(`span`,{className:`d-block text-truncate px-2 py-1 wui-text-xs text-body-secondary`,children:[e.fileName,`, `,Number.isFinite(e.sizeBytes)?he(e.sizeBytes):`-`]});return o?I(`span`,{className:`d-inline-flex flex-column border rounded overflow-hidden`,style:Pe,children:[I(`span`,{className:`d-flex align-items-center justify-content-center gap-1 p-2 wui-text-xs text-body-secondary`,children:[F(b,{name:`x-circle`,size:14}),`Could not load this file.`]}),u]}):I(`a`,{className:`d-inline-flex flex-column border rounded overflow-hidden text-decoration-none`,style:Pe,href:i??void 0,target:`_blank`,rel:`noopener noreferrer`,"aria-label":l,"aria-busy":!i||void 0,children:[F(`span`,{className:`d-flex align-items-center justify-content-center bg-body-tertiary`,style:Fe,children:i?n?F(`img`,{src:i,alt:e.fileName,className:`d-block w-100 h-100 object-fit-cover`}):F(b,{name:`file-text`,size:28}):F(D,{size:`sm`,label:`Loading ${e.fileName}`})}),u]})}function Q({iso:e,className:t}){let n=q(),r=ne();return n?n(e):F(`time`,{dateTime:e,className:t,children:ue(e,{timeZone:r})})}var Le={whiteSpace:`pre-wrap`,overflowWrap:`anywhere`};function Re({messages:e}){return F(`ol`,{className:`list-unstyled d-flex flex-column gap-3 mb-0`,"aria-label":`Conversation`,children:e.map(e=>{let t=F(Q,{iso:e.createdDateTimeUtc,className:`wui-text-xs text-body-secondary text-nowrap`});if(e.authorKind===`System`)return I(`li`,{className:`text-center wui-text-xs text-body-secondary`,"data-author":`system`,children:[F(`span`,{className:`d-block`,children:e.body}),t]},e.id);let n=e.authorKind===`Customer`,r=e.authorName||(n?`You`:`Support team`);return I(`li`,{className:`d-flex align-items-start gap-2${n?` flex-row-reverse`:``}`,"data-author":n?`customer`:`agent`,children:[F(u,{name:r,size:32,tone:n?`neutral`:`primary`}),I(p,{className:`flex-grow-1 border`,padding:`sm`,variant:n?`default`:`accent`,style:{minWidth:0},children:[I(`div`,{className:`d-flex flex-wrap align-items-center justify-content-between gap-2 mb-2`,children:[I(`span`,{className:`d-inline-flex flex-wrap align-items-center gap-2 fw-semibold wui-text-sm text-break`,children:[r,!n&&F(d,{tone:`primary`,children:`Support`})]}),t]}),F(`div`,{className:`wui-text-sm`,style:Le,children:e.body}),e.attachments?.length>0&&F(`div`,{className:`d-flex flex-wrap gap-2 mt-2`,children:e.attachments.map(e=>F(Ie,{attachment:e},e.id))})]})]},e.id)})})}function ze({satisfaction:e,comment:t,canRate:n=!1,commentMaxLength:r,onRate:a}){let o=i(),[c,u]=s(``),[d,m]=s(null),[h,g]=s(``);if(e)return I(l,{tone:e===`Satisfied`?`success`:`info`,role:`status`,children:[e===`Satisfied`?`You told us this solved your problem.`:`You told us this did not solve your problem.`,t?I(`span`,{className:`d-block mt-1`,children:[`Your comment: `,t]}):null]});if(!n)return null;async function _(e){g(``),m(e);try{await a({satisfaction:e,comment:c})}catch(e){g(e?.message||`Your rating did not send. Please try again.`)}finally{m(null)}}return F(p,{padding:`sm`,className:`border`,title:`Did this solve your problem?`,children:I(`div`,{className:`d-flex flex-column gap-2`,children:[h&&F(l,{tone:`danger`,children:h}),F(A,{id:`${o}-comment`,label:`Anything to add?`,rows:2,maxLength:r,value:c,onChange:e=>u(e.target.value),hint:`Optional. Your comment goes to the support team.`}),I(`div`,{className:`d-flex flex-wrap gap-2`,children:[F(f,{variant:`outline`,leftIcon:`check-circle`,loading:d===`Satisfied`,disabled:d!==null,onClick:()=>_(`Satisfied`),children:`Yes, it is solved`}),F(f,{variant:`outline`,leftIcon:`x-circle`,loading:d===`Unsatisfied`,disabled:d!==null,onClick:()=>_(`Unsatisfied`),children:`No, it is not`})]})]})})}function Be({onSend:e,config:t,reopens:n=!1}){let r=i(),[a,o]=s(``),[c,u]=s([]),[d,p]=s(``),[m,h]=s(``),[g,_]=s(!1),v=e=>{u(e),p(Z(e,t)??``)},y=e=>{let t=ve(e);t.length>0&&v([...c,...t])};async function b(n){n.preventDefault();let r=a.trim();if(!r){h(`Write a message before you send it.`);return}let i=Z(c,t);if(i){p(i);return}h(``),_(!0);try{await e({body:r,files:c}),o(``),u([]),p(``)}catch(e){h(e?.message||`Your reply did not send. Please try again.`)}finally{_(!1)}}return I(`form`,{onSubmit:b,noValidate:!0,className:`d-flex flex-column gap-2`,"aria-label":`Reply to this ticket`,children:[m&&F(l,{tone:`danger`,children:m}),F(A,{id:`${r}-body`,label:`Your reply`,rows:4,autoGrow:!0,maxLength:t?.bodyMaxLength,value:a,onChange:e=>o(e.target.value),onPaste:y,hint:n?`Sending a reply reopens this ticket. You can paste an image into the message.`:`You can paste an image into the message.`,required:!0}),F(ye,{id:`${r}-files`,files:c,onChange:v,config:t,error:d}),F(`div`,{className:`d-flex justify-content-end`,children:F(f,{type:`submit`,leftIcon:`send`,loading:g,children:`Send reply`})})]})}function Ve({label:e,children:t}){return I(`div`,{className:`d-flex flex-column`,children:[F(`span`,{className:`wui-text-xs fw-semibold text-body-secondary`,children:e}),F(`span`,{className:`wui-text-sm`,children:t})]})}function He({ticketId:e,onBack:t,onChanged:n}){let{config:r}=Y(),i=ne(),a=q(),{ticket:o,loading:c,error:u,reload:d,reply:p,reopen:h,cancel:g,rate:_}=ie(e),[v,y]=s(!1),[b,x]=s(!1),[S,C]=s(!1),[w,T]=s(``),D=async e=>{let t=await e();return n?.(),t};async function k(){T(``),y(!0);try{await D(h)}catch(e){T(e?.message||`The ticket did not reopen. Please try again.`)}finally{y(!1)}}async function A(){T(``),C(!0);try{await D(g)}catch(e){T(e?.message||`The request was not withdrawn. Please try again.`)}finally{C(!1),x(!1)}}let j=F(f,{variant:`ghost`,size:`sm`,leftIcon:`arrow-left`,onClick:t,className:`align-self-start`,children:`Back to tickets`});return o?I(`section`,{className:`d-flex flex-column gap-3`,"aria-labelledby":`support-ticket-${o.id}`,children:[j,I(`header`,{className:`d-flex flex-column gap-2`,children:[I(`div`,{className:`d-flex flex-wrap align-items-center gap-2`,children:[F(`h2`,{id:`support-ticket-${o.id}`,className:`h5 mb-0 text-break`,children:o.subject}),o.statusLabel&&F(O,{label:o.statusLabel,tone:Ne(o.status)})]}),I(`div`,{className:`row row-cols-2 row-cols-md-4 g-3`,children:[F(Ve,{label:`Ticket`,children:o.number}),F(Ve,{label:`Category`,children:o.category||`-`}),F(Ve,{label:`Opened`,children:F(Q,{iso:o.createdDateTimeUtc})}),F(Ve,{label:`Last update`,children:F(Q,{iso:o.updatedDateTimeUtc})})]}),a===null&&I(`p`,{className:`wui-text-xs text-body-secondary mb-0`,children:[`Times are shown in `,pe(i),`.`]})]}),w&&F(l,{tone:`danger`,children:w}),o.canReopen&&F(l,{tone:`success`,role:`status`,children:`If you still need help, reopen the ticket or send a reply.`}),o.status===`WaitingOnCustomer`&&F(l,{tone:`warning`,role:`status`,children:`We need your answer to carry on. Reply below and the ticket goes back to our team.`}),!o.canReopen&&F(`p`,{className:`wui-text-sm text-body-secondary mb-0`,children:`Our team marks this resolved once your question is answered. Replying reopens it.`}),o.canReopen&&F(f,{variant:`secondary`,leftIcon:`history`,loading:v,onClick:k,className:`align-self-start`,children:`Reopen ticket`}),o.canCancel&&F(f,{variant:`secondary`,onClick:()=>x(!0),className:`align-self-start`,children:`Withdraw request`}),F(m,{open:b,title:`Withdraw this request?`,message:`Our team will stop working on this ticket. You can open a new ticket later if you still need help.`,confirmLabel:`Withdraw request`,danger:!0,loading:S,onConfirm:A,onClose:()=>x(!1)}),F(ze,{satisfaction:o.satisfaction,comment:o.satisfactionComment,canRate:o.canRate,commentMaxLength:r?.satisfactionCommentMaxLength,onRate:e=>D(()=>_(e))}),F(Re,{messages:o.messages??[]}),F(Be,{config:r,reopens:o.canReopen,onSend:e=>D(()=>p(e))})]}):I(`section`,{className:`d-flex flex-column gap-3`,"aria-busy":c||void 0,children:[j,u?I(l,{tone:`danger`,children:[u.message||`We could not load this ticket.`,` `,F(f,{variant:`ghost`,size:`sm`,onClick:d,children:`Try again`})]}):F(E,{height:160})]})}var Ue=`ticket`;function We(){return typeof window>`u`?null:new URLSearchParams(window.location.search).get(Ue)}function Ge(e){if(typeof window>`u`)return e?`?${Ue}=${encodeURIComponent(e)}`:`?`;let t=new URL(window.location.href);return e?t.searchParams.set(Ue,e):t.searchParams.delete(Ue),`${t.pathname}${t.search}${t.hash}`}function Ke(e){if(typeof window>`u`)return;let t=Ge(e);t!==`${window.location.pathname}${window.location.search}${window.location.hash}`&&window.history.replaceState(window.history.state,``,t)}var qe=[{key:`all`,label:`All`,countKey:`total`},{key:`Open`,label:`Open`,countKey:`open`},{key:`InProgress`,label:`In progress`,countKey:`inProgress`},{key:`WaitingOnCustomer`,label:`Waiting on you`,countKey:`waitingOnCustomer`},{key:`Resolved`,label:`Resolved`,countKey:`resolved`},{key:`Closed`,label:`Closed`,countKey:`closed`},{key:`Cancelled`,label:`Cancelled`,countKey:null}],Je=[`tabs`,`select`,`none`];function Ye({tickets:e,loading:t,error:n,onRetry:r,onOpen:i,status:a,onStatusChange:o,statusFilter:s=`tabs`,counts:u,search:d,onSearchChange:p,pagination:m}){M(`SupportCenter`,`statusFilter`,s,Je);let h=qe.map(({key:e,label:t,countKey:n})=>{let r=u?.[n];return{value:e,label:r==null?t:`${t} (${r})`}}),_=(e,t)=>{e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||(e.preventDefault(),i(t))};return I(`div`,{className:`d-flex flex-column gap-3`,children:[n&&I(l,{tone:`danger`,children:[n.message||`We could not load your tickets.`,` `,F(f,{variant:`ghost`,size:`sm`,onClick:r,children:`Try again`})]}),I(`div`,{className:`d-flex flex-column flex-md-row gap-2 align-items-md-center justify-content-between`,children:[s===`none`?null:s===`select`?F(T,{label:`Status`,value:a,onChange:o,options:h}):F(k,{tabs:qe.map(({key:e,label:t,countKey:n})=>({key:e,label:t,count:u?.[n]})),value:a,onChange:o,ariaLabel:`Filter tickets by status`,className:`flex-grow-1`}),F(w,{value:d,onChange:p,placeholder:`Search tickets`,ariaLabel:`Search tickets`})]}),F(g,{columns:[{key:`subject`,label:`Subject`,render:e=>I(`div`,{className:`d-flex flex-column`,style:{minWidth:0},children:[F(S,{href:Ge(e.id),animation:`none`,className:`fw-semibold text-break`,onClick:t=>_(t,e.id),children:e.subject}),I(`span`,{className:`wui-text-xs text-body-secondary`,children:[e.number,`, `,e.category,e.awaitingCustomer?`. Waiting for your reply`:``]})]})},{key:`status`,label:`Status`,render:e=>e.statusLabel?F(O,{label:e.statusLabel,tone:Ne(e.status)}):`-`},{key:`messageCount`,label:`Messages`,cellClassName:`wui-text-sm text-body-secondary`,render:e=>e.messageCount},{key:`updatedDateTimeUtc`,label:`Last update`,cellClassName:`wui-text-sm text-body-secondary text-nowrap`,render:e=>F(Q,{iso:e.updatedDateTimeUtc})}],rows:e,loading:t,skeletonRows:4,ariaLabel:`Support tickets`,rowActionsLabel:`Actions`,rowActions:e=>F(c,{icon:`eye`,label:`Open ticket ${e.subject}`,href:Ge(e.id),onClick:t=>_(t,e.id)}),stickyActions:!0,stackOnMobile:!0,sourceCount:u?.total??0,pagination:m,empty:F(v,{variant:`table`,icon:`message-square`,title:`No tickets yet`,text:`When you raise a ticket, it shows here with its status.`}),emptyFiltered:F(v,{variant:`table`,icon:`search`,title:`No tickets match`,text:`Try another search or status.`})})]})}function Xe(e,t){let[n,i]=s(e);return r(()=>{let n=setTimeout(()=>i(e),t);return()=>clearTimeout(n)},[e,t]),n}var Ze=300,Qe=10;function $e({initialTicketId:e,defaultCategory:t,appVersion:n,status:i,defaultStatus:a=`all`,onStatusChange:o,statusFilter:c=`tabs`}){let{config:u,error:d,reload:p}=Y(),[m,h]=s(a),g=i!==void 0,_=g?i:m,v=e=>{g||h(e),o?.(e)},[y,b]=s(``),x=Xe(y.trim(),Ze),[S,C]=s(Qe),w=`${_}|${x}|${S}`,[T,E]=s({key:w,page:1}),D=T.key===w?T.page:1,O=e=>E({key:w,page:e}),k=X({status:_===`all`?void 0:_,search:x||void 0,page:D,pageSize:S}),{counts:A,reload:j}=re(),[M,N]=s(()=>e||We()),[ee,P]=s(!1),L=k.totalPages;r(()=>{L>0&&D>L&&E({key:w,page:L})},[L,D,w]);let R=()=>{k.reload(),j()},z=e=>{N(e),Ke(e)};if(M)return F(He,{ticketId:M,onBack:()=>z(null),onChanged:R},M);let B={page:D,totalPages:Math.max(1,k.totalPages),pageSize:S,total:k.totalCount,setPage:O,setPageSize:C};return I(`section`,{className:`d-flex flex-column gap-3`,style:{minWidth:0},"aria-labelledby":`support-center-title`,children:[I(`div`,{className:`d-flex flex-wrap align-items-center justify-content-between gap-2`,children:[F(`h2`,{id:`support-center-title`,className:`h5 mb-0`,children:`Your tickets`}),F(f,{leftIcon:`plus`,onClick:()=>P(!0),disabled:!u,children:`New ticket`})]}),d&&I(l,{tone:`warning`,children:[d.message||`We could not load the support settings.`,` `,F(f,{variant:`ghost`,size:`sm`,onClick:p,children:`Try again`})]}),F(Ye,{tickets:k.tickets,loading:k.loading,error:k.error,onRetry:R,onOpen:z,status:_,onStatusChange:v,statusFilter:c,counts:A,search:y,onSearchChange:b,pagination:B}),u&&F(je,{open:ee,onClose:()=>P(!1),config:u,defaultCategory:t,appVersion:n,onCreated:e=>{P(!1),R(),z(e.id)}})]})}var $=e=>typeof e==`string`&&e.trim()!==``;function et({className:e}){let{config:t}=Y();if(!t)return null;let n=[];return $(t.supportEmail)&&n.push({key:`email`,icon:`mail`,label:`Email`,value:I(`span`,{className:`d-inline-flex flex-wrap align-items-center gap-2`,children:[F(`a`,{href:`mailto:${t.supportEmail}`,className:`text-break`,children:t.supportEmail}),F(h,{text:t.supportEmail,size:`sm`,label:`Copy email`,copiedLabel:`Email copied`})]})}),$(t.supportPhone)&&n.push({key:`phone`,icon:`phone`,label:`Phone`,value:t.supportPhone,href:`tel:${t.supportPhone.replace(/[^\d+]/g,``)}`}),$(t.supportHours)&&n.push({key:`hours`,icon:`clock`,label:`Hours`,value:t.supportHours}),n.length===0?null:I(`section`,{className:e,"aria-label":$(t.supportName)?`Contact ${t.supportName}`:`Contact support`,children:[$(t.supportName)&&F(`p`,{className:`fw-semibold mb-2`,children:t.supportName}),F(_,{items:n,layout:`list`,columns:1})]})}function tt({client:e,timeZone:n=ae,renderTime:r,children:i}){let s=o(null),c=t((t=!1)=>{let n=s.current;if(t||!n||n.client!==e){let t=e.getConfig(),n={client:e,pending:t};return s.current=n,t.catch(()=>{s.current===n&&(s.current=null)}),t}return n.pending},[e]),l=a(()=>({client:e,loadConfig:c,timeZone:n,renderTime:r}),[e,c,n,r]);return F(W.Provider,{value:l,children:i})}export{Ae as ReportIssue,R as SupportApiError,$e as SupportCenter,et as SupportContact,tt as SupportProvider,te as createSupportClient,K as useSupportClient,Y as useSupportConfig,ie as useSupportTicket,re as useSupportTicketCounts,X as useSupportTickets};
|
|
1
|
+
import{createContext as e,useCallback as t,useContext as n,useEffect as r,useId as i,useMemo as a,useRef as o,useState as s}from"react";import{AppActionIcon as c,AppAlert as l,AppAvatar as u,AppBadge as d,AppButton as f,AppCard as p,AppChip as m,AppChipGroup as h,AppConfirmDialog as g,AppCopyButton as _,AppDataTable as v,AppDescriptions as y,AppEmptyState as b,AppFileAttachment as x,AppIcon as S,AppInput as C,AppLink as w,AppModal as T,AppSearch as E,AppSelect as D,AppSkeleton as O,AppSpinner as k,AppStatusBadge as A,AppTabs as j,AppTextarea as M,useFloatingStack as N,warnInvalidValue as P}from"@webority/ui-react";import{toBlob as F}from"html-to-image";import{createPortal as I}from"react-dom";import{Fragment as L,jsx as R,jsxs as z}from"react/jsx-runtime";var B=`Something went wrong. Please try again.`,V=class extends Error{constructor(e,t,n){super(t),this.name=`SupportApiError`,this.code=e,this.status=n}};async function ee(e){if(e&&typeof Blob<`u`&&e instanceof Blob)try{return JSON.parse(await e.text())}catch{return null}if(typeof e==`string`)try{return JSON.parse(e)}catch{return null}return e??null}async function H(e){if(e instanceof V)return e;let t=e?.response;if(!t)return new V(`network`,B);let n=await ee(t.data);return new V(typeof n?.code==`string`&&n.code?n.code:`unknown`,typeof n?.message==`string`&&n.message?n.message:B,t.status)}async function U(e){try{return(await e()).data}catch(e){throw await H(e)}}function W(e,t,n){n!=null&&String(n).trim()!==``&&e.append(t,String(n))}function G(e,t,n,r){(n??[]).forEach((n,i)=>{let a=n?.name||`${r}-${i+1}.png`;e.append(t,n,a)})}function te(e,t=`/api/support`){let n=(typeof t==`string`?t:t?.base??`/api/support`).replace(/\/+$/,``),r=e=>`${n}/tickets/${encodeURIComponent(e)}`;return{getConfig:()=>U(()=>e.get(`${n}/settings`)),listTickets:({status:t,search:r,page:i,pageSize:a}={})=>{let o=new URLSearchParams;W(o,`status`,t),W(o,`search`,r?.trim()),W(o,`page`,i),W(o,`pageSize`,a);let s=o.toString();return U(()=>e.get(`${n}/tickets${s?`?${s}`:``}`))},getTicketCounts:()=>U(()=>e.get(`${n}/tickets/counts`)),getTicket:t=>U(()=>e.get(r(t))),createTicket:({category:t,subject:r,body:i,pageUrl:a,userAgent:o,appVersion:s,files:c,screenshots:l})=>{let u=new FormData;return u.append(`category`,t??``),u.append(`subject`,r??``),u.append(`body`,i??``),W(u,`pageUrl`,a),W(u,`userAgent`,o),W(u,`appVersion`,s),G(u,`files`,c,`file`),G(u,`screenshots`,l,`screenshot`),U(()=>e.post(`${n}/tickets`,u))},getSuggestions:async(t,{signal:r}={})=>{try{return await U(()=>e.get(`${n}/suggestions`,{params:{subject:t},signal:r}))}catch(e){if(e instanceof V&&e.status===404)return[];throw e}},reply:(t,{body:n,files:i,screenshots:a})=>{let o=new FormData;return o.append(`body`,n??``),G(o,`files`,i,`file`),G(o,`screenshots`,a,`screenshot`),U(()=>e.post(`${r(t)}/replies`,o))},reopen:t=>U(()=>e.post(`${r(t)}/reopen`)),cancel:t=>U(()=>e.post(`${r(t)}/cancel`)),rate:(t,{satisfaction:n,comment:i})=>{let a={satisfaction:n};return i!=null&&i.trim()!==``&&(a.comment=i.trim()),U(()=>e.post(`${r(t)}/rating`,a))},fetchAttachment:t=>U(()=>e.get(`${n}/attachments/${encodeURIComponent(t)}`,{responseType:`blob`})),confirmAction:t=>U(()=>e.post(`${n}/actions/confirm`,{token:t}))}}var ne=e(null);function K(){let e=n(ne);if(!e)throw Error(`Support components and hooks must be used inside <SupportProvider>.`);return e}function q(){return K().client}function re(){return K().timeZone}function ie(){return K().renderTime??null}function ae(e,n,i=!0){let[a,c]=s({data:null,loading:i,error:null}),[l,u]=s(0),d=o(e);d.current=e;let f=o(n);r(()=>{let e=f.current!==n;if(f.current=n,!i){c({data:null,loading:!1,error:null});return}let t=!0;return c(t=>({data:e?null:t.data,loading:!0,error:null})),d.current(l>0).then(e=>t&&c({data:e,loading:!1,error:null}),e=>t&&c(t=>({...t,loading:!1,error:e}))),()=>{t=!1}},[n,i,l]);let p=t(()=>u(e=>e+1),[]),m=t(e=>c(t=>({...t,data:e})),[]);return{...a,reload:p,setData:m}}function J(){let{loadConfig:e}=K(),{data:t,loading:n,error:r,reload:i}=ae(e,`config`);return{config:t,loading:n,error:r,reload:i}}function oe(e={}){let t=q(),{status:n,search:r,page:i,pageSize:a}=e,{data:o,loading:s,error:c,reload:l}=ae(()=>t.listTickets({status:n,search:r,page:i,pageSize:a}),JSON.stringify([`tickets`,n??null,r??null,i??null,a??null]));return{tickets:o?.items??[],totalCount:o?.totalCount??0,totalPages:o?.totalPages??0,loading:s,error:c,reload:l}}function se(){let e=q(),{data:t,loading:n,error:r,reload:i}=ae(()=>e.getTicketCounts(),`ticket-counts`);return{counts:t,loading:n,error:r,reload:i}}function ce(e){let n=q(),{data:r,loading:i,error:a,reload:o,setData:s}=ae(()=>n.getTicket(e),e??``,!!e),c=t(async e=>{let t=await e();return s(t),t},[s]);return{ticket:r,loading:i,error:a,reload:o,reply:t(t=>c(()=>n.reply(e,t)),[c,n,e]),reopen:t(()=>c(()=>n.reopen(e)),[c,n,e]),cancel:t(()=>c(()=>n.cancel(e)),[c,n,e]),rate:t(t=>c(()=>n.rate(e,t)),[c,n,e])}}var le=`We could not reach support. Check your connection and try again.`;function Y(e,t){if(e instanceof V){if(e.code===`network`)return le;if(e.code!==`unknown`)return e.message}return t}var ue=`Asia/Kolkata`,de=330*60*1e3,fe=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],pe=e=>typeof e==`number`&&Number.isFinite(e);function me(e){if(e instanceof Date)return e.getTime();if(pe(e))return e;if(typeof e!=`string`)return NaN;let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e.trim());if(t){let[e,n,r]=[Number(t[1]),Number(t[2]),Number(t[3])],i=new Date(Date.UTC(2e3,n-1,r));return i.setUTCFullYear(e),i.getUTCFullYear()===e&&i.getUTCMonth()===n-1&&i.getUTCDate()===r?i.getTime()-de:NaN}return Date.parse(e)}function he(e,{timeZone:t=ue}={}){let n=me(e);if(!Number.isFinite(n))return`-`;let r=Object.fromEntries(_e(t).formatToParts(n).map(e=>[e.type,e.value]));return`${r.day}-${fe[Number(r.month)-1]}-${r.year}, ${r.hour}:${r.minute} ${r.dayPeriod.toUpperCase()}`}var ge=new Map;function _e(e){let t=ge.get(e);return t||(t=new Intl.DateTimeFormat(`en-IN`,{day:`2-digit`,month:`numeric`,year:`numeric`,hour:`numeric`,minute:`2-digit`,hour12:!0,timeZone:e}),ge.set(e,t)),t}function ve(e=ue){return new Intl.DateTimeFormat(`en-IN`,{timeZone:e,timeZoneName:`short`}).formatToParts(new Date).find(e=>e.type===`timeZoneName`)?.value??e}Object.freeze({label:`Notifications`,empty:`You are all caught up.`,markAll:`Mark all read`,viewAll:`View all`,unreadPrefix:`Unread: `,today:`Today`,yesterday:`Yesterday`,allRead:`All notifications marked as read.`,noneUnread:`No unread notifications`,failed:Object.freeze({forbidden:`You do not have permission to mark these as read.`,client:`These could not be marked as read. Refresh the page and try again.`,validation:`These could not be marked as read. Refresh the page and try again.`,server:`Something went wrong on our side, so these were not marked as read. Try again in a moment.`,network:`Could not reach the server, so these were not marked as read. Check your connection and try again.`})});var ye=[`KB`,`MB`,`GB`];function be(e){if(e<1024)return`${e} B`;let t=e/1024,n=0;for(;t>=1024&&n<ye.length-1;)t/=1024,n+=1;return`${t.toFixed(1)} ${ye[n]}`}function xe(e){return(e?.allowedContentTypes??[]).join(`,`)}function Se(e,t){if(t.length===0)return!0;let n=(e||``).toLowerCase();return t.some(e=>{let t=e.toLowerCase();return t.endsWith(`/*`)?n.startsWith(t.slice(0,-1)):n===t})}function X(e,t){let n=e??[],r=t?.maxAttachmentsPerMessage??0,i=t?.maxAttachmentBytes??0,a=t?.allowedContentTypes??[];if(r>0&&n.length>r)return r===1?`You can attach one file.`:`You can attach up to ${r} files.`;for(let e of n){let t=e.name||`This file`;if(!Se(e.type,a))return`${t} is a file type we cannot accept.`;if(i>0&&e.size>i)return`${t} is larger than ${be(i)}.`}return null}var Ce=e=>e===1?`You can attach one file.`:`You can attach up to ${e} files.`;function we(e){return`${e.name}|${e.size}|${e.lastModified}`}function Te(e,t,n){let r=n?.maxAttachmentsPerMessage??0,i=new Set(e.map(we)),a=[],o=null;for(let e of t){let t=we(e);if(i.has(t)){o??=e.name;continue}i.add(t),a.push(e)}let s=r>0?Math.max(0,r-e.length):a.length,c=[...e,...a.slice(0,s)];return{files:c,notice:(a.length>s?Ce(r):null)??X(c,n)??(o?`${o} is already attached.`:``)}}function Ee(e){let t=Array.from(e.clipboardData?.items??[]),n=Date.now();return t.filter(e=>e.kind===`file`&&e.type.startsWith(`image/`)).map(e=>e.getAsFile()).filter(Boolean).map((e,t)=>{let r=(e.type.split(`/`)[1]||`png`).replace(`jpeg`,`jpg`);return new File([e],`pasted-image-${n}-${t+1}.${r}`,{type:e.type})})}function De(e,t){let[n,i]=s(e);return r(()=>{let n=setTimeout(()=>i(e),t);return()=>clearTimeout(n)},[e,t]),n}function Oe({id:e,label:t=`Attachments`,files:n,onChange:r,config:i,error:a}){let o=i?.maxAttachmentBytes??0,s=o>0?Math.max(.1,Math.round(o/(1024*1024)*10)/10):0;return R(x,{id:e,label:t,optional:!0,multiple:!0,value:n,onChange:r,accept:xe(i),maxSizeMb:s,validate:!1,error:a||void 0})}function ke({items:e}){return e.length===0?null:R(p,{variant:`muted`,padding:`sm`,title:`These may already answer your question`,children:R(`ul`,{className:`list-unstyled mb-0 d-flex flex-column gap-2`,children:e.map(e=>z(`li`,{children:[R(`div`,{className:`fw-semibold`,children:e.title}),R(`div`,{className:`small text-body-secondary`,children:e.summary})]},e.title))})})}var Ae=500,je=3,Me=5;function Ne(e,t){return t&&e.includes(t)?t:``}function Pe({id:e,config:t,defaultCategory:n,initialValues:i,onValuesChange:a,extraFiles:o=[],onSubmit:c,onBusyChange:u,children:d}){let f=t?.categories??[],[p,m]=s(()=>i?.category??Ne(f,n)),[h,g]=s(i?.subject??``),[_,v]=s(i?.body??``),[y,b]=s(i?.files??[]),[x,S]=s({}),[w,T]=s(``),E=q(),[O,k]=s(``),[A,j]=s([]),N=De(h.trim(),Ae);r(()=>{a?.({category:p,subject:h,body:_,files:y})},[p,h,_,y,a]),r(()=>{k(N)},[N]),r(()=>{if(O.length<je){j([]);return}let e=!0,t=new AbortController;return j([]),E.getSuggestions(O,{signal:t.signal}).then(t=>{e&&j(Array.isArray(t)?t.slice(0,Me):[])},()=>{e&&j([])}),()=>{e=!1,t.abort()}},[E,O]);let P=e=>{b(e),S(n=>({...n,files:X([...o,...e],t)??void 0}))},F=e=>{let t=Ee(e);t.length>0&&P([...y,...t])};function I(){let e={};h.trim()||(e.subject=`Enter a subject.`),_.trim()||(e.body=`Enter what happened.`);let n=X([...o,...y],t);return n&&(e.files=n),S(e),Object.keys(e).length===0}async function L(e){if(e.preventDefault(),T(``),I()){u?.(!0);try{await c({category:p,subject:h.trim(),body:_.trim(),files:y})}catch(e){T(Y(e,`Your ticket did not send. Please try again.`))}finally{u?.(!1)}}}return z(`form`,{id:e,onSubmit:L,noValidate:!0,className:`d-flex flex-column gap-3`,children:[w&&R(l,{tone:`danger`,children:w}),R(D,{id:`${e}-category`,label:`Category`,value:p,onChange:m,options:f.map(e=>({value:e,label:e})),placeholder:`Choose a category`,hint:`Not sure? Leave it empty and we will sort it.`,error:x.category}),R(C,{id:`${e}-subject`,label:`Subject`,required:!0,maxLength:t?.subjectMaxLength,showCount:!0,placeholder:`A short summary`,value:h,onChange:e=>g(e.target.value),onBlur:()=>k(h.trim()),error:x.subject}),R(ke,{items:A}),R(M,{id:`${e}-body`,label:`Message`,required:!0,rows:6,maxLength:t?.bodyMaxLength,showCount:!0,placeholder:`What happened, and what did you expect to happen?`,value:_,onChange:e=>v(e.target.value),onPaste:F,hint:`You can paste an image into the message.`,error:x.body}),d,R(Oe,{id:`${e}-files`,files:y,onChange:P,config:t,error:x.files})]})}var Fe=`supportCapture`,Ie={zIndex:`var(--wui-z-fixed)`,bottom:0,insetInlineEnd:0},Le={zIndex:`var(--wui-z-fixed)`},Re={maxWidth:`20rem`},ze=e=>e.dataset?.[Fe]===`exclude`||e.matches?.(`.modal-backdrop`)?!1:!(e.matches?.(`.modal`)&&e.querySelector?.(`[data-support-capture="exclude"]`)),Be=()=>new Promise(e=>requestAnimationFrame(()=>e()));async function Ve(){let e=await F(document.body,{filter:ze,pixelRatio:Math.min(window.devicePixelRatio||1,2),style:{overflow:`visible`,paddingRight:`0px`}});if(!e)throw Error(`The page capture came back empty.`);return new File([e],`screenshot.png`,{type:`image/png`})}function He({file:e,failed:t,disabled:n,hintId:i,controlRef:a,onAdd:o,onRemove:c}){let[u,d]=s(null);return r(()=>{if(!e)return;let t=URL.createObjectURL(e);return d(t),()=>URL.revokeObjectURL(t)},[e]),z(`div`,{className:`d-flex flex-column gap-2`,children:[R(`span`,{className:`wui-text-sm fw-semibold`,children:`Screenshot`}),e&&u&&R(`img`,{src:u,alt:`Screenshot of the page you were on`,className:`d-block w-100 border rounded`,style:Re}),R(`div`,{ref:a,className:`d-flex flex-wrap gap-2`,children:e?z(L,{children:[R(f,{variant:`outline`,size:`sm`,leftIcon:`refresh-cw`,onClick:o,disabled:n,"aria-describedby":i,children:`Retake`}),R(f,{variant:`ghost`,size:`sm`,leftIcon:`x`,onClick:c,disabled:n,children:`Remove screenshot`})]}):R(f,{variant:`outline`,size:`sm`,leftIcon:`camera`,onClick:o,disabled:n,"aria-describedby":i,children:`Add a screenshot`})}),R(`span`,{id:i,className:`wui-text-sm text-body-secondary`,children:`Only what is on your screen now. You can remove it before sending.`}),t&&R(l,{tone:`info`,children:`We could not take a screenshot of this page. You can attach an image instead, or send the report without one.`})]})}function Ue({label:e=`Report an issue`,floating:t=!1,compact:n=!1,defaultCategory:a=`Bug report`,appVersion:c,getTicketHref:u,onOpenTicket:d,onCreated:p,className:m,style:h}){let g=q(),{config:_,error:v}=J(),y=`support-report-${i().replace(/[^a-zA-Z0-9-]/g,``)}`,[b,x]=s(!1),[C,w]=s(!1),[E,D]=s(null),[O,k]=s(!1),[A,j]=s(!1),[M,P]=s(null),[F,B]=s(null),V=N(`end`,t&&n),ee=o(null),H=o(!1);r(()=>{C||!H.current||(H.current=!1,ee.current?.querySelector(`button`)?.focus())},[C]);function U(){P(null),D(null),k(!1),B(null),x(!0)}async function W(){w(!0),k(!1),await Be(),await Be();try{D(await Ve())}catch{D(null),k(!0)}finally{H.current=!0,w(!1)}}let G=()=>{A||(x(!1),D(null),k(!1),P(null),B(null))};async function te(e){let t=await g.createTicket({...e,pageUrl:window.location.href,userAgent:navigator.userAgent,appVersion:c,screenshots:E?[E]:[]});P(t),D(null),p?.(t)}let ne=!M&&(!!E||!!F&&(F.subject.trim()!==``||F.body.trim()!==``||F.files.length>0)),K=M&&u?u(M.id):void 0,re=M?z(`div`,{className:`d-flex justify-content-end gap-2 w-100`,children:[R(f,{variant:`secondary`,onClick:G,children:`Close`}),M&&(K||d)?R(f,{href:K,onClick:K?void 0:()=>{x(!1),P(null),d(M)},children:`View ticket`}):null]}):z(`div`,{className:`d-flex justify-content-end gap-2 w-100`,children:[R(f,{variant:`secondary`,onClick:G,disabled:A,children:`Cancel`}),R(f,{type:`submit`,form:y,loading:A,disabled:!_,children:`Submit`})]}),ie=n?R(f,{variant:`secondary`,className:`wui-floating-btn wui-floating-btn--secondary`,disabled:C,onClick:U,"aria-haspopup":`dialog`,"aria-label":e,tooltip:e,tooltipPlacement:`start`,children:R(S,{name:`bug`,size:22})}):R(f,{leftIcon:`bug`,variant:t?`primary`:`outline`,disabled:C,onClick:U,"aria-haspopup":`dialog`,children:e});return z(L,{children:[t&&n?V&&I(R(`span`,{className:[`wui-floating-stack-item wui-floating-stack-item--secondary`,m].filter(Boolean).join(` `),style:h,children:ie}),V):R(`span`,{"data-support-capture":`exclude`,className:[t?`position-fixed m-3`:`d-inline-block`,m].filter(Boolean).join(` `),style:t?{...Ie,...h}:h,children:ie}),C&&z(`div`,{"data-support-capture":`exclude`,role:`status`,className:`position-fixed top-0 start-50 translate-middle-x mt-3 d-flex align-items-center gap-2 px-3 py-2 bg-body border rounded-pill shadow-sm wui-text-sm`,style:Le,children:[R(`span`,{className:`spinner-border spinner-border-sm`,"aria-hidden":`true`}),`Taking a screenshot`]}),R(T,{open:b,size:`lg`,title:`Report an issue`,subtitle:`Tell us what went wrong. You can add a screenshot of this page if it helps.`,headerIcon:`bug`,confirmDiscard:`Discard this report?`,dirty:ne&&!A,onClose:G,footer:re,"data-support-capture":`exclude`,children:M?R(l,{tone:`success`,role:`status`,title:`Ticket ${M.number} is with the support team`,children:`We reply by email. You can follow the ticket on your support page.`}):_?R(Pe,{id:y,config:_,defaultCategory:a,initialValues:F,onValuesChange:B,extraFiles:E?[E]:[],onSubmit:te,onBusyChange:j,children:R(He,{file:E,failed:O,disabled:A||C,hintId:`${y}-screenshot-hint`,controlRef:ee,onAdd:W,onRemove:()=>D(null)})}):R(l,{tone:v?`danger`:`info`,children:v?Y(v,`We could not load the support settings.`):`Loading the form.`})})]})}function We({open:e,onClose:t,onCreated:n,config:r,defaultCategory:a,appVersion:o}){let c=q(),l=`support-new-${i().replace(/[^a-zA-Z0-9-]/g,``)}`,[u,d]=s(!1),[p,m]=s(null),h=!!p&&(p.subject.trim()!==``||p.body.trim()!==``||p.files.length>0);async function g(e){n(await c.createTicket({...e,userAgent:typeof navigator>`u`?void 0:navigator.userAgent,appVersion:o}))}return R(T,{open:e,size:`lg`,title:`New ticket`,subtitle:`Tell us what you need. We reply by email and on this page.`,headerIcon:`message-square`,confirmDiscard:`Discard this ticket?`,dirty:h&&!u,onClose:()=>{u||t()},footer:z(`div`,{className:`d-flex justify-content-end gap-2 w-100`,children:[R(f,{variant:`secondary`,onClick:t,disabled:u,children:`Cancel`}),R(f,{type:`submit`,form:l,loading:u,children:`Send ticket`})]}),children:e&&R(Pe,{id:l,config:r,defaultCategory:a,onSubmit:g,onBusyChange:d,onValuesChange:m})})}var Ge={Open:`warning`,InProgress:`info`,WaitingOnCustomer:`warning`,Resolved:`success`,Closed:`neutral`,Cancelled:`neutral`};function Ke(e){return Ge[e]??`neutral`}var qe=6e4,Je=[`image/png`,`image/jpeg`,`image/gif`,`image/webp`,`application/pdf`];function Ye({attachment:e}){let t=q(),[n,r]=s(!1),[i,a]=s(!1);async function o(){r(!0),a(!1);let n=Je.includes(e.contentType)?window.open(``,`_blank`):null;n&&(n.opener=null);try{let r=await t.fetchAttachment(e.id),i=URL.createObjectURL(r);if(setTimeout(()=>URL.revokeObjectURL(i),qe),n)n.location.href=i;else{let t=document.createElement(`a`);t.href=i,t.download=e.fileName,t.click()}}catch{n?.close(),a(!0)}finally{r(!1)}}let c=Number.isFinite(e.sizeBytes)?be(e.sizeBytes):`-`;return z(L,{children:[R(m,{leadingIcon:i?`x-circle`:`paperclip`,label:n?z(L,{children:[R(k,{size:`sm`,label:`Loading ${e.fileName}`}),` `,e.fileName]}):e.fileName,onClick:o,disabled:n,"aria-busy":n||void 0,title:`${e.fileName}, ${c}`}),i&&R(`span`,{role:`status`,className:`wui-text-xs text-danger align-self-center`,children:`Could not load this file. Click to try again.`})]})}function Z({iso:e,className:t}){let n=ie(),r=re();return n?n(e):R(`time`,{dateTime:e,className:t,children:he(e,{timeZone:r})})}var Xe={whiteSpace:`pre-wrap`,overflowWrap:`anywhere`};function Ze({messages:e}){return R(`ol`,{className:`list-unstyled d-flex flex-column gap-3 mb-0`,"aria-label":`Conversation`,children:e.map(e=>{let t=R(Z,{iso:e.createdDateTimeUtc,className:`wui-text-xs text-body-secondary text-nowrap`});if(e.authorKind===`System`)return z(`li`,{className:`text-center wui-text-xs text-body-secondary`,"data-author":`system`,children:[R(`span`,{className:`d-block`,children:e.body}),t]},e.id);let n=e.authorKind===`Customer`,r=e.authorName||(n?`You`:`Support team`);return z(`li`,{className:`d-flex align-items-start gap-2${n?` flex-row-reverse`:``}`,"data-author":n?`customer`:`agent`,children:[R(u,{name:r,size:32,tone:n?`neutral`:`primary`}),z(p,{className:`flex-grow-1 border`,padding:`sm`,variant:n?`default`:`accent`,style:{minWidth:0},children:[z(`div`,{className:`d-flex flex-wrap align-items-center justify-content-between gap-2 mb-2`,children:[z(`span`,{className:`d-inline-flex flex-wrap align-items-center gap-2 fw-semibold wui-text-sm text-break`,children:[r,!n&&R(d,{tone:`primary`,children:`Support`})]}),t]}),R(`div`,{className:`wui-text-sm`,style:Xe,children:e.body}),e.attachments?.length>0&&R(`div`,{className:`d-flex flex-wrap gap-2 mt-2`,children:e.attachments.map(e=>R(Ye,{attachment:e},e.id))})]})]},e.id)})})}function Qe({satisfaction:e,comment:t,canRate:n=!1,commentMaxLength:r,onRate:a}){let o=i(),[c,u]=s(``),[d,m]=s(null),[h,g]=s(``);if(e)return z(l,{tone:e===`Satisfied`?`success`:`info`,role:`status`,children:[e===`Satisfied`?`You told us this solved your problem.`:`You told us this did not solve your problem.`,t?z(`span`,{className:`d-block mt-1`,children:[`Your comment: `,t]}):null]});if(!n)return null;async function _(e){g(``),m(e);try{await a({satisfaction:e,comment:c})}catch(e){g(Y(e,`Your rating did not send. Please try again.`))}finally{m(null)}}return R(p,{padding:`sm`,className:`border`,title:`Did this solve your problem?`,children:z(`div`,{className:`d-flex flex-column gap-2`,children:[h&&R(l,{tone:`danger`,children:h}),R(M,{id:`${o}-comment`,label:`Anything to add?`,rows:2,maxLength:r,value:c,onChange:e=>u(e.target.value),hint:`Optional. Your comment goes to the support team.`}),z(`div`,{className:`d-flex flex-wrap gap-2`,children:[R(f,{variant:`outline`,leftIcon:`check-circle`,loading:d===`Satisfied`,disabled:d!==null,onClick:()=>_(`Satisfied`),children:`Yes, it is solved`}),R(f,{variant:`outline`,leftIcon:`x-circle`,loading:d===`Unsatisfied`,disabled:d!==null,onClick:()=>_(`Unsatisfied`),children:`No, it is not`})]})]})})}function $e({onSend:e,config:t,reopens:n=!1}){let r=i(),[a,o]=s(``),[u,d]=s([]),[p,g]=s(``),[_,v]=s(``),[y,b]=s(!1),x=e=>{let n=Te(u,e,t);d(n.files),g(n.notice)},S=e=>{let n=u.filter((t,n)=>n!==e);d(n),g(X(n,t)??``)},C=e=>{let t=Ee(e);t.length>0&&x(t)};async function w(n){n.preventDefault();let r=a.trim();if(!r){v(`Write a message before you send it.`);return}let i=X(u,t);if(i){g(i);return}v(``),b(!0);try{await e({body:r,files:u}),o(``),d([]),g(``)}catch(e){v(Y(e,`Your reply did not send. Please try again.`))}finally{b(!1)}}let T=_||p;return z(`form`,{onSubmit:w,noValidate:!0,className:`d-flex flex-column gap-2`,"aria-label":`Reply to this ticket`,children:[T&&R(l,{tone:`danger`,children:T}),R(M,{id:`${r}-body`,label:`Your reply`,rows:4,autoGrow:!0,maxLength:t?.bodyMaxLength,value:a,onChange:e=>o(e.target.value),onPaste:C,hint:n?`Sending a reply reopens this ticket. You can paste an image into the message.`:`You can paste an image into the message.`,required:!0}),u.length>0&&R(h,{label:`Attached files`,children:u.map((e,t)=>R(m,{leadingIcon:`paperclip`,label:e.name,removeLabel:`Remove ${e.name}`,onRemove:()=>S(t)},we(e)))}),z(`div`,{className:`d-flex flex-wrap align-items-center justify-content-between gap-2`,children:[R(c,{iconVariant:`bulk`,icon:`paperclip`,label:`Attach a file`,multiple:t?.maxAttachmentsPerMessage!==1,accept:xe(t),onFiles:x}),R(f,{type:`submit`,leftIcon:`send`,loading:y,children:`Send reply`})]})]})}function et({ticketId:e,onBack:t,onChanged:n}){let{config:r}=J(),i=re(),a=ie(),{ticket:o,loading:c,error:u,reload:d,reply:m,reopen:h,cancel:_,rate:v}=ce(e),[b,x]=s(!1),[C,w]=s(!1),[T,E]=s(!1),[D,k]=s(``),j=async e=>{let t=await e();return n?.(),t};async function M(){k(``),x(!0);try{await j(h)}catch(e){k(Y(e,`The ticket did not reopen. Please try again.`))}finally{x(!1)}}async function N(){k(``),E(!0);try{await j(_)}catch(e){k(Y(e,`The request was not withdrawn. Please try again.`))}finally{E(!1),w(!1)}}let P=R(f,{variant:`ghost`,size:`sm`,leftIcon:`arrow-left`,onClick:t,className:`align-self-start`,children:`Back to tickets`});if(!o)return z(`section`,{className:`d-flex flex-column gap-3`,"aria-busy":c||void 0,children:[P,u?z(l,{tone:`danger`,children:[Y(u,`We could not load this ticket.`),` `,R(f,{variant:`ghost`,size:`sm`,onClick:d,children:`Try again`})]}):R(O,{height:160})]});let F=Ke(o.status),I=[{key:`status`,label:`Status`,value:o.statusLabel?R(A,{label:o.statusLabel,tone:F}):`-`},{key:`category`,label:`Category`,value:o.category||`-`},{key:`ticket`,label:`Ticket`,value:o.number},{key:`opened`,label:`Opened`,value:R(Z,{iso:o.createdDateTimeUtc})},{key:`updated`,label:`Last update`,value:R(Z,{iso:o.updatedDateTimeUtc})}];return z(`section`,{className:`d-flex flex-column gap-3`,"aria-labelledby":`support-ticket-${o.id}`,children:[P,z(`div`,{className:`row g-3`,children:[z(`div`,{className:`col-12 col-lg-8 d-flex flex-column gap-3`,children:[z(`header`,{className:`d-flex flex-column gap-2`,children:[z(`div`,{className:`d-flex flex-wrap align-items-center gap-2`,children:[R(`h2`,{id:`support-ticket-${o.id}`,className:`h5 mb-0 text-break`,children:o.subject}),o.statusLabel&&R(A,{label:o.statusLabel,tone:F})]}),z(`ul`,{className:`list-unstyled d-flex flex-wrap gap-3 mb-0 wui-text-sm text-body-secondary`,"aria-label":`Ticket summary`,children:[o.number&&z(`li`,{className:`d-inline-flex align-items-center gap-1`,children:[R(S,{variant:`bulk`,name:`receipt-text`,size:16}),o.number]}),o.category&&z(`li`,{className:`d-inline-flex align-items-center gap-1`,children:[R(S,{variant:`bulk`,name:`folder-2`,size:16}),o.category]}),z(`li`,{className:`d-inline-flex align-items-center gap-1`,children:[R(S,{variant:`bulk`,name:`calendar-1`,size:16}),`Opened `,R(Z,{iso:o.createdDateTimeUtc})]})]}),a===null&&z(`p`,{className:`wui-text-xs text-body-secondary mb-0`,children:[`Times are shown in `,ve(i),`.`]})]}),D&&R(l,{tone:`danger`,children:D}),o.canReopen&&R(l,{tone:`success`,role:`status`,children:`If you still need help, reopen the ticket or send a reply.`}),o.status===`WaitingOnCustomer`&&R(l,{tone:`warning`,role:`status`,children:`We need your answer to carry on. Reply below and the ticket goes back to our team.`}),!o.canReopen&&R(`p`,{className:`wui-text-sm text-body-secondary mb-0`,children:`Our team marks this resolved once your question is answered. Replying reopens it.`}),o.canReopen&&R(f,{variant:`secondary`,leftIcon:`history`,loading:b,onClick:M,className:`align-self-start`,children:`Reopen ticket`}),o.canCancel&&R(f,{variant:`secondary`,onClick:()=>w(!0),className:`align-self-start`,children:`Withdraw request`}),R(g,{open:C,title:`Withdraw this request?`,message:`Our team will stop working on this ticket. You can open a new ticket later if you still need help.`,confirmLabel:`Withdraw request`,danger:!0,loading:T,onConfirm:N,onClose:()=>w(!1)}),R(Qe,{satisfaction:o.satisfaction,comment:o.satisfactionComment,canRate:o.canRate,commentMaxLength:r?.satisfactionCommentMaxLength,onRate:e=>j(()=>v(e))}),R(Ze,{messages:o.messages??[]}),R($e,{config:r,reopens:o.canReopen,onSend:e=>j(()=>m(e))})]}),R(`aside`,{"aria-label":`Ticket details`,className:`col-12 col-lg-4`,children:z(p,{padding:`sm`,className:`border`,children:[R(`h3`,{className:`h6`,children:`Ticket details`}),R(y,{columns:1,items:I})]})})]})]})}var Q=`ticket`;function tt(){return typeof window>`u`?null:new URLSearchParams(window.location.search).get(Q)}function nt(e){if(typeof window>`u`)return e?`?${Q}=${encodeURIComponent(e)}`:`?`;let t=new URL(window.location.href);return e?t.searchParams.set(Q,e):t.searchParams.delete(Q),`${t.pathname}${t.search}${t.hash}`}function rt(e){if(typeof window>`u`)return;let t=nt(e);t!==`${window.location.pathname}${window.location.search}${window.location.hash}`&&window.history.replaceState(window.history.state,``,t)}var it=[{key:`all`,label:`All`,countKey:`total`},{key:`Open`,label:`Open`,countKey:`open`},{key:`InProgress`,label:`In progress`,countKey:`inProgress`},{key:`WaitingOnCustomer`,label:`Waiting on you`,countKey:`waitingOnCustomer`},{key:`Resolved`,label:`Resolved`,countKey:`resolved`},{key:`Closed`,label:`Closed`,countKey:`closed`},{key:`Cancelled`,label:`Cancelled`,countKey:null}],at=[`tabs`,`select`,`none`];function ot({tickets:e,loading:t,error:n,onRetry:r,onOpen:i,status:a,onStatusChange:o,statusFilter:s=`tabs`,counts:u,search:d,onSearchChange:p,pagination:m}){P(`SupportCenter`,`statusFilter`,s,at);let h=it.map(({key:e,label:t,countKey:n})=>{let r=u?.[n];return{value:e,label:r==null?t:`${t} (${r})`}}),g=(e,t)=>{e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||(e.preventDefault(),i(t))};return z(`div`,{className:`d-flex flex-column gap-3`,children:[n&&z(l,{tone:`danger`,children:[Y(n,`We could not load your tickets.`),` `,R(f,{variant:`ghost`,size:`sm`,onClick:r,children:`Try again`})]}),z(`div`,{className:`d-flex flex-column flex-md-row gap-2 align-items-md-center justify-content-between`,children:[s===`none`?null:s===`select`?R(D,{label:`Status`,value:a,onChange:o,options:h}):R(j,{tabs:it.map(({key:e,label:t,countKey:n})=>({key:e,label:t,count:u?.[n]})),value:a,onChange:o,ariaLabel:`Filter tickets by status`,className:`flex-grow-1`}),R(E,{value:d,onChange:p,placeholder:`Search tickets`,ariaLabel:`Search tickets`})]}),R(v,{columns:[{key:`subject`,label:`Subject`,render:e=>z(`div`,{className:`d-flex flex-column`,style:{minWidth:0},children:[R(w,{href:nt(e.id),animation:`none`,className:`fw-semibold text-break`,onClick:t=>g(t,e.id),children:e.subject}),z(`span`,{className:`wui-text-xs text-body-secondary`,children:[e.number,`, `,e.category,e.awaitingCustomer?`. Waiting for your reply`:``]})]})},{key:`status`,label:`Status`,render:e=>e.statusLabel?R(A,{label:e.statusLabel,tone:Ke(e.status)}):`-`},{key:`messageCount`,label:`Messages`,cellClassName:`wui-text-sm text-body-secondary`,render:e=>e.messageCount},{key:`updatedDateTimeUtc`,label:`Last update`,cellClassName:`wui-text-sm text-body-secondary text-nowrap`,render:e=>R(Z,{iso:e.updatedDateTimeUtc})}],rows:e,loading:t,skeletonRows:4,ariaLabel:`Support tickets`,rowActionsLabel:`Actions`,rowActions:e=>R(c,{icon:`eye`,label:`Open ticket ${e.subject}`,href:nt(e.id),onClick:t=>g(t,e.id)}),stickyActions:!0,stackOnMobile:!0,sourceCount:u?.total??0,pagination:m,empty:R(b,{variant:`table`,icon:`message-square`,title:`No tickets yet`,text:`When you raise a ticket, it shows here with its status.`}),emptyFiltered:R(b,{variant:`table`,icon:`search`,title:`No tickets match`,text:`Try another search or status.`})})]})}var st=300,ct=10;function lt({initialTicketId:e,defaultCategory:t,appVersion:n,status:i,defaultStatus:a=`all`,onStatusChange:o,statusFilter:c=`tabs`}){let{config:u,error:d,reload:p}=J(),[m,h]=s(a),g=i!==void 0,_=g?i:m,v=e=>{g||h(e),o?.(e)},[y,b]=s(``),x=De(y.trim(),st),[S,C]=s(ct),w=`${_}|${x}|${S}`,[T,E]=s({key:w,page:1}),D=T.key===w?T.page:1,O=e=>E({key:w,page:e}),k=oe({status:_===`all`?void 0:_,search:x||void 0,page:D,pageSize:S}),{counts:A,reload:j}=se(),[M,N]=s(()=>e||tt()),[P,F]=s(!1),I=k.totalPages;r(()=>{I>0&&D>I&&E({key:w,page:I})},[I,D,w]);let L=()=>{k.reload(),j()},B=e=>{N(e),rt(e)};if(M)return R(et,{ticketId:M,onBack:()=>B(null),onChanged:L},M);let V={page:D,totalPages:Math.max(1,k.totalPages),pageSize:S,total:k.totalCount,setPage:O,setPageSize:C};return z(`section`,{className:`d-flex flex-column gap-3`,style:{minWidth:0},"aria-labelledby":`support-center-title`,children:[z(`div`,{className:`d-flex flex-wrap align-items-center justify-content-between gap-2`,children:[R(`h2`,{id:`support-center-title`,className:`h5 mb-0`,children:`Your tickets`}),R(f,{leftIcon:`plus`,onClick:()=>F(!0),disabled:!u,children:`New ticket`})]}),d&&z(l,{tone:`warning`,children:[Y(d,`We could not load the support settings.`),` `,R(f,{variant:`ghost`,size:`sm`,onClick:p,children:`Try again`})]}),R(ot,{tickets:k.tickets,loading:k.loading,error:k.error,onRetry:L,onOpen:B,status:_,onStatusChange:v,statusFilter:c,counts:A,search:y,onSearchChange:b,pagination:V}),u&&R(We,{open:P,onClose:()=>F(!1),config:u,defaultCategory:t,appVersion:n,onCreated:e=>{F(!1),L(),B(e.id)}})]})}var $=e=>typeof e==`string`&&e.trim()!==``;function ut({className:e}){let{config:t}=J();if(!t)return null;let n=[];return $(t.supportEmail)&&n.push({key:`email`,icon:`mail`,label:`Email`,value:z(`span`,{className:`d-inline-flex flex-wrap align-items-center gap-2`,children:[R(`a`,{href:`mailto:${t.supportEmail}`,className:`text-break`,children:t.supportEmail}),R(_,{text:t.supportEmail,size:`sm`,label:`Copy email`,copiedLabel:`Email copied`})]})}),$(t.supportPhone)&&n.push({key:`phone`,icon:`phone`,label:`Phone`,value:t.supportPhone,href:`tel:${t.supportPhone.replace(/[^\d+]/g,``)}`}),$(t.supportHours)&&n.push({key:`hours`,icon:`clock`,label:`Hours`,value:t.supportHours}),n.length===0?null:z(`section`,{className:e,"aria-label":$(t.supportName)?`Contact ${t.supportName}`:`Contact support`,children:[$(t.supportName)&&R(`p`,{className:`fw-semibold mb-2`,children:t.supportName}),R(y,{items:n,layout:`list`,columns:1})]})}function dt({client:e,timeZone:n=ue,renderTime:r,children:i}){let s=o(null),c=t((t=!1)=>{let n=s.current;if(t||!n||n.client!==e){let t=e.getConfig(),n={client:e,pending:t};return s.current=n,t.catch(()=>{s.current===n&&(s.current=null)}),t}return n.pending},[e]),l=a(()=>({client:e,loadConfig:c,timeZone:n,renderTime:r}),[e,c,n,r]);return R(ne.Provider,{value:l,children:i})}export{Ue as ReportIssue,V as SupportApiError,lt as SupportCenter,ut as SupportContact,dt as SupportProvider,te as createSupportClient,q as useSupportClient,J as useSupportConfig,ce as useSupportTicket,se as useSupportTicketCounts,oe as useSupportTickets};
|
package/dist/types/client.d.ts
CHANGED
|
@@ -78,12 +78,22 @@ export type TicketCounts = {
|
|
|
78
78
|
closed: number;
|
|
79
79
|
total: number;
|
|
80
80
|
};
|
|
81
|
+
export type SupportSuggestedArticle = {
|
|
82
|
+
title: string;
|
|
83
|
+
summary: string;
|
|
84
|
+
};
|
|
81
85
|
export type SupportClient = {
|
|
82
86
|
getConfig: () => Promise<any>;
|
|
83
87
|
listTickets: (query?: TicketListQuery) => Promise<TicketPage>;
|
|
84
88
|
getTicketCounts: () => Promise<TicketCounts>;
|
|
85
89
|
getTicket: (id: string) => Promise<any>;
|
|
86
90
|
createTicket: (input: NewTicketInput) => Promise<any>;
|
|
91
|
+
/**
|
|
92
|
+
* Known answers for a subject the person is about to raise; resolves to none when the server predates the route.
|
|
93
|
+
*/
|
|
94
|
+
getSuggestions: (subject: string, options?: {
|
|
95
|
+
signal?: AbortSignal;
|
|
96
|
+
}) => Promise<SupportSuggestedArticle[]>;
|
|
87
97
|
reply: (id: string, input: ReplyInput) => Promise<any>;
|
|
88
98
|
reopen: (id: string) => Promise<any>;
|
|
89
99
|
/**
|
|
@@ -152,6 +162,11 @@ export type SupportClient = {
|
|
|
152
162
|
* @property {number} closed
|
|
153
163
|
* @property {number} total
|
|
154
164
|
*/
|
|
165
|
+
/**
|
|
166
|
+
* @typedef {object} SupportSuggestedArticle A known answer to a subject, from approved resolution notes.
|
|
167
|
+
* @property {string} title
|
|
168
|
+
* @property {string} summary
|
|
169
|
+
*/
|
|
155
170
|
/**
|
|
156
171
|
* @typedef {object} SupportClient
|
|
157
172
|
* @property {() => Promise<any>} getConfig
|
|
@@ -159,6 +174,8 @@ export type SupportClient = {
|
|
|
159
174
|
* @property {() => Promise<TicketCounts>} getTicketCounts
|
|
160
175
|
* @property {(id: string) => Promise<any>} getTicket
|
|
161
176
|
* @property {(input: NewTicketInput) => Promise<any>} createTicket
|
|
177
|
+
* @property {(subject: string, options?: { signal?: AbortSignal }) => Promise<SupportSuggestedArticle[]>} getSuggestions
|
|
178
|
+
* Known answers for a subject the person is about to raise; resolves to none when the server predates the route.
|
|
162
179
|
* @property {(id: string, input: ReplyInput) => Promise<any>} reply
|
|
163
180
|
* @property {(id: string) => Promise<any>} reopen
|
|
164
181
|
* @property {(id: string) => Promise<any>} cancel Withdraws the ticket; resolves to the updated ticket.
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* One attachment on a message.
|
|
3
|
-
*
|
|
2
|
+
* One attachment on a message, as a chip. Nothing is fetched until it is pressed: the bytes need the
|
|
3
|
+
* bearer token, so the press fetches them through the support client and opens them in a new tab, or
|
|
4
|
+
* downloads them when the type is not one the browser shows inline.
|
|
4
5
|
*
|
|
5
6
|
* @param {object} props
|
|
6
7
|
* @param {{ id: string, fileName: string, contentType: string, sizeBytes: number, kind: string }} props.attachment
|
|
7
8
|
*/
|
|
8
|
-
export default function
|
|
9
|
+
export default function AttachmentChip({ attachment }: {
|
|
9
10
|
attachment: {
|
|
10
11
|
id: string;
|
|
11
12
|
fileName: string;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The customer's reply to a ticket, with attachments
|
|
2
|
+
* The customer's reply to a ticket, with attachments picked from a paperclip or pasted as images.
|
|
3
|
+
* A file already on the reply is skipped, and only as many files as the limit leaves room for are
|
|
4
|
+
* kept, with one sentence saying which.
|
|
3
5
|
*
|
|
4
6
|
* @param {object} props
|
|
5
7
|
* @param {(input: { body: string, files: File[] }) => Promise<unknown>} props.onSend Rejects with a SupportApiError on failure.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Known answers shown under the subject of a new ticket. Plain text only: titles and summaries
|
|
3
|
+
* come from the support team's notes and render as text, never as markup.
|
|
4
|
+
*
|
|
5
|
+
* @param {object} props
|
|
6
|
+
* @param {{ title: string, summary: string }[]} props.items
|
|
7
|
+
*/
|
|
8
|
+
export default function SuggestedAnswers({ items }: {
|
|
9
|
+
items: {
|
|
10
|
+
title: string;
|
|
11
|
+
summary: string;
|
|
12
|
+
}[];
|
|
13
|
+
}): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The sentence to show a person for a failed support request. A server sentence is shown only when
|
|
3
|
+
* the server sent a real code; no response gets the offline sentence; anything else (a code
|
|
4
|
+
* the client could not read, or an error thrown in the page) gets the screen's own fallback.
|
|
5
|
+
*
|
|
6
|
+
* @param {unknown} err
|
|
7
|
+
* @param {string} fallback
|
|
8
|
+
* @returns {string}
|
|
9
|
+
*/
|
|
10
|
+
export declare function supportErrorText(err: unknown, fallback: string): string;
|
|
@@ -22,6 +22,35 @@ export declare function validateAttachments(files: Blob[], config: {
|
|
|
22
22
|
maxAttachmentsPerMessage?: number;
|
|
23
23
|
allowedContentTypes?: string[];
|
|
24
24
|
} | null | undefined): string | null;
|
|
25
|
+
/**
|
|
26
|
+
* The same file picked twice has the same name, size and modified time. A pasted image is a new
|
|
27
|
+
* File each time, so pasting twice keeps both.
|
|
28
|
+
*
|
|
29
|
+
* @param {Blob & { name: string, lastModified?: number }} f
|
|
30
|
+
* @returns {string}
|
|
31
|
+
*/
|
|
32
|
+
export declare function fileIdOf(f: Blob & {
|
|
33
|
+
name: string;
|
|
34
|
+
lastModified?: number;
|
|
35
|
+
}): string;
|
|
36
|
+
/**
|
|
37
|
+
* Adds picked files to a message's files. A file already on the message, or repeated in the same
|
|
38
|
+
* pick, is skipped; the picks past the limit are left out. Returns the files to keep and the one
|
|
39
|
+
* sentence to show about what was skipped or what is wrong, or "" when nothing is.
|
|
40
|
+
*
|
|
41
|
+
* @param {File[]} current
|
|
42
|
+
* @param {File[]} picked
|
|
43
|
+
* @param {{ maxAttachmentBytes?: number, maxAttachmentsPerMessage?: number, allowedContentTypes?: string[] }|null|undefined} config
|
|
44
|
+
* @returns {{ files: File[], notice: string }}
|
|
45
|
+
*/
|
|
46
|
+
export declare function mergeAttachments(current: File[], picked: File[], config: {
|
|
47
|
+
maxAttachmentBytes?: number;
|
|
48
|
+
maxAttachmentsPerMessage?: number;
|
|
49
|
+
allowedContentTypes?: string[];
|
|
50
|
+
} | null | undefined): {
|
|
51
|
+
files: File[];
|
|
52
|
+
notice: string;
|
|
53
|
+
};
|
|
25
54
|
/**
|
|
26
55
|
* Image files from a paste event, named so they read well on the ticket.
|
|
27
56
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webority/support-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.117.0",
|
|
4
4
|
"description": "Webority customer support for React portals: ticket centre, report-an-issue with an optional page screenshot, and support contact details, built on @webority/ui-react.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"type": "module",
|
|
@@ -27,12 +27,12 @@
|
|
|
27
27
|
},
|
|
28
28
|
"sideEffects": false,
|
|
29
29
|
"peerDependencies": {
|
|
30
|
+
"@webority/ui-elements": "0.117.0",
|
|
31
|
+
"@webority/ui-react": "0.117.0",
|
|
30
32
|
"bootstrap": "5.3.3",
|
|
31
33
|
"react": "^19.0.0",
|
|
32
34
|
"react-bootstrap": "^2.10.0",
|
|
33
|
-
"react-dom": "^19.0.0"
|
|
34
|
-
"@webority/ui-elements": "0.115.0",
|
|
35
|
-
"@webority/ui-react": "0.115.0"
|
|
35
|
+
"react-dom": "^19.0.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@testing-library/dom": "10.4.2",
|
|
@@ -42,6 +42,9 @@
|
|
|
42
42
|
"@types/react": "^19.2.17",
|
|
43
43
|
"@vitejs/plugin-react": "^6.0.1",
|
|
44
44
|
"@vitest/coverage-v8": "5.0.1",
|
|
45
|
+
"@webority/canvas-kit": "0.117.0",
|
|
46
|
+
"@webority/ui-elements": "0.117.0",
|
|
47
|
+
"@webority/ui-react": "0.117.0",
|
|
45
48
|
"bootstrap": "5.3.3",
|
|
46
49
|
"jsdom": "30.1.1",
|
|
47
50
|
"react": "^19.2.6",
|
|
@@ -49,10 +52,7 @@
|
|
|
49
52
|
"react-dom": "^19.2.6",
|
|
50
53
|
"typescript": "^7.0.2",
|
|
51
54
|
"vite": "^8.0.12",
|
|
52
|
-
"vitest": "5.0.1"
|
|
53
|
-
"@webority/canvas-kit": "0.115.0",
|
|
54
|
-
"@webority/ui-elements": "0.115.0",
|
|
55
|
-
"@webority/ui-react": "0.115.0"
|
|
55
|
+
"vitest": "5.0.1"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"html-to-image": "^1.11.13"
|