@webority/support-react 0.118.0 → 0.120.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 +92 -5
- package/dist/guidance.json +39 -1
- package/dist/support-react.js +6 -1
- package/dist/types/SupportChat.d.ts +31 -0
- package/dist/types/SupportChat.meta.d.ts +43 -0
- package/dist/types/SupportChatLauncher.d.ts +24 -0
- package/dist/types/SupportChatLauncher.meta.d.ts +51 -0
- package/dist/types/chat/client.d.ts +35 -0
- package/dist/types/chat/connection.d.ts +24 -0
- package/dist/types/chat/types.d.ts +187 -0
- package/dist/types/client.d.ts +8 -2
- package/dist/types/components/TicketDetail.d.ts +3 -1
- package/dist/types/components/chat/ChatStatusBar.d.ts +33 -0
- package/dist/types/components/chat/ChatTranscript.d.ts +33 -0
- package/dist/types/components/chat/WaitingNotice.d.ts +10 -0
- package/dist/types/components/chat/useSupportChatSession.d.ts +35 -0
- package/dist/types/index.d.ts +4 -0
- package/package.json +8 -6
package/README.md
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
# @webority/support-react
|
|
2
2
|
|
|
3
|
-
Customer support for a React portal: a ticket centre, a report-an-issue button that
|
|
4
|
-
screenshot of the page when the person asks for one, and support contact details. It talks to the Webority Support API that
|
|
3
|
+
Customer support for a React portal: a ticket centre, live chat with an AI assistant and a support agent, a report-an-issue button that
|
|
4
|
+
can attach a screenshot of the page when the person asks for one, and support contact details. It talks to the Webority Support API that
|
|
5
5
|
the product's backend hosts, and it is built on `@webority/ui-react` and `@webority/theme`, so it
|
|
6
6
|
looks like the rest of the portal with no extra CSS.
|
|
7
7
|
|
|
8
8
|
## Install
|
|
9
9
|
|
|
10
10
|
```bash
|
|
11
|
-
npm install @webority/support-react @webority/ui-react react-bootstrap bootstrap@5.3.3
|
|
11
|
+
npm install @webority/support-react @webority/chat-react @webority/ui-react react-bootstrap bootstrap@5.3.3
|
|
12
12
|
```
|
|
13
13
|
|
|
14
14
|
`@webority/ui-react`, `react`, `react-dom`, `react-bootstrap` and `bootstrap` are peer
|
|
15
15
|
dependencies: the portal already has them. Pin `@webority/support-react` to the same exact
|
|
16
|
-
version as `@webority/ui-react`.
|
|
17
|
-
|
|
16
|
+
version as `@webority/ui-react`. `@webority/chat-react` is a peer too (the chat screen reuses its
|
|
17
|
+
composer and Markdown): pin it to the same exact version. The screenshot uses `html-to-image`, which
|
|
18
|
+
installs with the package.
|
|
18
19
|
|
|
19
20
|
## Set up the provider
|
|
20
21
|
|
|
@@ -54,6 +55,23 @@ it: `createSupportClient(userClient, { base: "/api/support" })`. Every method
|
|
|
54
55
|
rejects with a `SupportApiError` carrying `code`, `status` and a `message` written for the
|
|
55
56
|
person, which the components show as-is.
|
|
56
57
|
|
|
58
|
+
The chat takes two objects built once, over the same signed-in instance:
|
|
59
|
+
|
|
60
|
+
```jsx
|
|
61
|
+
const chatClient = createSupportChatClient({ http: userClient, baseUrl: "/api/support" });
|
|
62
|
+
const connection = createSseChatConnection({
|
|
63
|
+
http: userClient,
|
|
64
|
+
baseUrl: "/api/support",
|
|
65
|
+
retryDelaysMs: [1000, 2000, 5000, 10000],
|
|
66
|
+
});
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
A host on another origin must allow the `Idempotency-Key` request header in its CORS policy, or retried messages fail.
|
|
70
|
+
|
|
71
|
+
`createSupportChatClient({ http, baseUrl = "/api/support" })` sends the chat's requests. `createSseChatConnection({ http, baseUrl = "/api/support", retryDelaysMs, stallTimeoutMs = 45000 })`
|
|
72
|
+
opens the live stream. `retryDelaysMs` is the wait in milliseconds before each reconnect; the last
|
|
73
|
+
entry repeats. `stallTimeoutMs` is how long the stream may go quiet before it is reopened.
|
|
74
|
+
|
|
57
75
|
`listTickets` returns one page, most recently updated first, in the shape
|
|
58
76
|
`{ items, page, pageSize, totalCount, totalPages }`. Every query part is optional: `status` is one
|
|
59
77
|
of `Open`, `InProgress`, `Resolved` or `Closed`, `search` matches the subject or the ticket
|
|
@@ -173,6 +191,75 @@ support config. A field the product has not set is left out, and nothing renders
|
|
|
173
191
|
<SupportContact />
|
|
174
192
|
```
|
|
175
193
|
|
|
194
|
+
### `<SupportChat />`
|
|
195
|
+
|
|
196
|
+
A live chat drawer. The AI assistant answers first. "Talk to a person" brings a support agent into
|
|
197
|
+
the same conversation, and the whole chat is kept on the customer's support ticket.
|
|
198
|
+
|
|
199
|
+
```jsx
|
|
200
|
+
<SupportProvider client={supportClient}>
|
|
201
|
+
<SupportChatLauncher onClick={() => setOpen(true)} open={open} />
|
|
202
|
+
<SupportChat
|
|
203
|
+
chatClient={chatClient}
|
|
204
|
+
connection={connection}
|
|
205
|
+
open={open}
|
|
206
|
+
onClose={() => setOpen(false)}
|
|
207
|
+
onOpenTicket={(ticket) => navigate(`/support?ticket=${ticket.id}`)}
|
|
208
|
+
/>
|
|
209
|
+
</SupportProvider>
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
Build the two clients once, outside render, as shown under set up, and keep the component inside
|
|
213
|
+
`SupportProvider`: the chat reads the support config for the message length and the time zone.
|
|
214
|
+
|
|
215
|
+
| Prop | Default | What it does |
|
|
216
|
+
|---|---|---|
|
|
217
|
+
| `chatClient` | required | The client from `createSupportChatClient`. |
|
|
218
|
+
| `connection` | required | The live stream from `createSseChatConnection`. |
|
|
219
|
+
| `open` | required | Shows the drawer. The session runs only while it is open. |
|
|
220
|
+
| `onClose` | required | Called when the drawer closes. |
|
|
221
|
+
| `appVersion` | none | Sent when the chat starts, so support knows which build the customer was on. |
|
|
222
|
+
| `onOpenTicket({ id, number })` | none | Shows a View ticket button when given. |
|
|
223
|
+
| `resolveLink(href)` | none | Decides where a link in a message goes; passed to the Markdown renderer. |
|
|
224
|
+
| `linkComponent` | none | The component that draws links in messages; passed to the Markdown renderer. |
|
|
225
|
+
| `title` | "Chat with us" | The drawer's heading. |
|
|
226
|
+
| `width` | "440px" | The drawer's width. |
|
|
227
|
+
|
|
228
|
+
The chat moves through these states:
|
|
229
|
+
|
|
230
|
+
- **Assistant answering**: the assistant's reply appears as it is written.
|
|
231
|
+
- **Waiting**: "Waiting for a person", with the number of people ahead in the queue.
|
|
232
|
+
- **With an agent**: the agent's name shows in the status.
|
|
233
|
+
- **Ended**: the reason the chat closed, with the ticket number when one was raised.
|
|
234
|
+
|
|
235
|
+
Notes: closing the drawer does not end the chat; reopening it returns the same open chat with every
|
|
236
|
+
line. A message that fails shows Try again and keeps its key, so a retry never posts twice. The chat
|
|
237
|
+
needs the `/chats` routes of the support API. The live stream is a long-lived GET that needs the
|
|
238
|
+
browser's XHR adapter (the axios default); with the fetch adapter the events arrive all at once when the request ends.
|
|
239
|
+
|
|
240
|
+
### `<SupportChatLauncher />`
|
|
241
|
+
|
|
242
|
+
The button that opens the chat. It sits in the bottom corner of the page.
|
|
243
|
+
|
|
244
|
+
```jsx
|
|
245
|
+
<SupportChatLauncher onClick={() => setOpen(true)} open={open} />
|
|
246
|
+
<SupportChatLauncher onClick={() => setOpen(true)} compact position="start" />
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
| Prop | Default | What it does |
|
|
250
|
+
|---|---|---|
|
|
251
|
+
| `onClick` | required | Called when the button is pressed. |
|
|
252
|
+
| `open` | `false` | Sets `aria-expanded`, for a launcher whose drawer is open. |
|
|
253
|
+
| `label` | "Chat with us" | The button text; with `compact` it is the tooltip and accessible name. |
|
|
254
|
+
| `position` | `"end"` | The bottom corner it sits in: `"end"` or `"start"`. |
|
|
255
|
+
| `icon` | "message-circle" | The icon's name. |
|
|
256
|
+
| `compact` | `false` | Icon only, a circle in the shared floating stack. |
|
|
257
|
+
| `className` | none | Added to the button's wrapper, to place it. |
|
|
258
|
+
| `style` | none | Merged over the wrapper's own style. |
|
|
259
|
+
|
|
260
|
+
Place it with `className` or `style`, as with `<ReportIssue />`. With `compact`, it joins the shared
|
|
261
|
+
floating stack beside `<ReportIssue />` and needs no offset.
|
|
262
|
+
|
|
176
263
|
## Hooks
|
|
177
264
|
|
|
178
265
|
`useSupportConfig()`, `useSupportTickets(query)`, `useSupportTicketCounts()` and
|
package/dist/guidance.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"format": "webority-guidance/1",
|
|
3
3
|
"package": {
|
|
4
4
|
"name": "@webority/support-react",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.120.0"
|
|
6
6
|
},
|
|
7
7
|
"components": [
|
|
8
8
|
{
|
|
@@ -40,6 +40,44 @@
|
|
|
40
40
|
]
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
|
+
{
|
|
44
|
+
"name": "SupportChat",
|
|
45
|
+
"usage": {
|
|
46
|
+
"when": [
|
|
47
|
+
"A portal offers live chat: an AI assistant answers first and the customer can ask for a person in the same conversation.",
|
|
48
|
+
"The conversation is kept on the customer's support ticket."
|
|
49
|
+
],
|
|
50
|
+
"whenNot": [
|
|
51
|
+
{
|
|
52
|
+
"text": "A one-way report or a long description of a problem.",
|
|
53
|
+
"instead": "ReportIssue"
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
"do": [],
|
|
57
|
+
"dont": [],
|
|
58
|
+
"a11y": [
|
|
59
|
+
"The chat opens as a dialog drawer, focuses the message box and closes on Escape.",
|
|
60
|
+
"Status changes (waiting, joined, ended) are announced as polite status messages.",
|
|
61
|
+
"A failed message says so and offers Try again and Discard."
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"name": "SupportChatLauncher",
|
|
67
|
+
"usage": {
|
|
68
|
+
"when": [
|
|
69
|
+
"The floating pill that opens the support chat, pinned to a bottom corner."
|
|
70
|
+
],
|
|
71
|
+
"whenNot": [],
|
|
72
|
+
"do": [],
|
|
73
|
+
"dont": [],
|
|
74
|
+
"a11y": [
|
|
75
|
+
"The button announces that it opens a dialog (aria-haspopup) and whether it is open (aria-expanded).",
|
|
76
|
+
"The default pill shows the label as its button text.",
|
|
77
|
+
"The compact circle takes the label as its accessible name and as its tooltip."
|
|
78
|
+
]
|
|
79
|
+
}
|
|
80
|
+
},
|
|
43
81
|
{
|
|
44
82
|
"name": "SupportContact",
|
|
45
83
|
"usage": {
|
package/dist/support-react.js
CHANGED
|
@@ -1 +1,6 @@
|
|
|
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};
|
|
1
|
+
import{createSseParser as e}from"@webority/ui-elements/chat-core";import{createContext as t,useCallback as n,useContext as r,useEffect as i,useId as a,useMemo as o,useRef as s,useState as c}from"react";import{AppActionIcon as l,AppAlert as u,AppAvatar as d,AppBadge as f,AppButton as p,AppCard as m,AppChip as h,AppChipGroup as g,AppConfirmDialog as _,AppCopyButton as v,AppDataTable as y,AppDescriptions as b,AppDrawer as x,AppEmptyState as S,AppFileAttachment as C,AppIcon as w,AppInput as T,AppLink as E,AppModal as D,AppSearch as O,AppSelect as k,AppSkeleton as A,AppSpinner as j,AppStatusBadge as M,AppTabs as N,AppTextarea as P,useFloatingStack as F,warnInvalidValue as I}from"@webority/ui-react";import{toBlob as L}from"html-to-image";import{createPortal as R}from"react-dom";import{IST_TIME_ZONE as ee,formatDateTime as te,formatFileSize as ne,timeZoneLabel as re}from"@webority/ui-elements/helpers";import{Fragment as z,jsx as B,jsxs as V}from"react/jsx-runtime";import{ChatComposer as H,ChatMarkdown as ie,DEFAULT_CHAT_LABELS as ae}from"@webority/chat-react";var U=`Something went wrong. Please try again.`,W=class extends Error{constructor(e,t,n){super(t),this.name=`SupportApiError`,this.code=e,this.status=n}};async function oe(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 se(e){if(e instanceof W)return e;let t=e?.response;if(!t)return new W(`network`,U);let n=await oe(t.data);return new W(typeof n?.code==`string`&&n.code?n.code:`unknown`,typeof n?.detail==`string`&&n.detail.trim()?n.detail:U,t.status)}async function G(e){try{return(await e()).data}catch(e){throw await se(e)}}function K(e,t,n){n!=null&&String(n).trim()!==``&&e.append(t,String(n))}function ce(e,t,n,r){(n??[]).forEach((n,i)=>{let a=n?.name||`${r}-${i+1}.png`;e.append(t,n,a)})}var le=20;function ue(e,t){return(e??[]).map((e,n)=>e?.name||`${t}-${n+1}.png`).join(`|`)}function de(e){return e instanceof W&&typeof e.status==`number`&&e.status>=400&&e.status<=499&&e.status!==408&&e.status!==429}function fe(e,t=`/api/support`){let n=(typeof t==`string`?t:t?.base??`/api/support`).replace(/\/+$/,``),r=e=>`${n}/tickets/${encodeURIComponent(e)}`,i=new Map,a=new Map;function o(){for(let e of i.keys()){if(i.size<=le)return;a.has(e)||i.delete(e)}}async function s(e,t){let n=i.get(e)||crypto.randomUUID();i.delete(e),i.set(e,n),a.set(e,(a.get(e)??0)+1),o();try{let r=await t(n);return i.delete(e),r}catch(t){throw de(t)&&i.delete(e),t}finally{let t=a.get(e)-1;t>0?a.set(e,t):a.delete(e)}}return{getConfig:()=>G(()=>e.get(`${n}/settings`)),listTickets:({status:t,search:r,page:i,pageSize:a}={})=>{let o=new URLSearchParams;K(o,`status`,t),K(o,`search`,r?.trim()),K(o,`page`,i),K(o,`pageSize`,a);let s=o.toString();return G(()=>e.get(`${n}/tickets${s?`?${s}`:``}`))},getTicketCounts:()=>G(()=>e.get(`${n}/tickets/counts`)),getTicket:t=>G(()=>e.get(r(t))),createTicket:({category:t,subject:r,body:i,pageUrl:a,userAgent:o,appVersion:c,files:l,screenshots:u})=>{let d=new FormData;return d.append(`category`,t??``),d.append(`subject`,r??``),d.append(`body`,i??``),K(d,`pageUrl`,a),K(d,`userAgent`,o),K(d,`appVersion`,c),ce(d,`files`,l,`file`),ce(d,`screenshots`,u,`screenshot`),s([`ticket`,t,r,i,ue(l,`file`),ue(u,`screenshot`)].join(`\0`),t=>G(()=>e.post(`${n}/tickets`,d,{headers:{"Idempotency-Key":t}})))},getSuggestions:async(t,{signal:r}={})=>{try{return await G(()=>e.get(`${n}/suggestions`,{params:{subject:t},signal:r}))}catch(e){if(e instanceof W&&e.status===404)return[];throw e}},reply:(t,{body:n,files:i,screenshots:a})=>{let o=new FormData;return o.append(`body`,n??``),ce(o,`files`,i,`file`),ce(o,`screenshots`,a,`screenshot`),s([`reply`,t,n,ue(i,`file`),ue(a,`screenshot`)].join(`\0`),n=>G(()=>e.post(`${r(t)}/replies`,o,{headers:{"Idempotency-Key":n}})))},reopen:t=>G(()=>e.post(`${r(t)}/reopen`)),cancel:t=>G(()=>e.post(`${r(t)}/cancel`)),rate:(t,{satisfaction:n,comment:i})=>{let a={satisfaction:n};return i!=null&&i.trim()!==``&&(a.comment=i.trim()),G(()=>e.post(`${r(t)}/rating`,a))},fetchAttachment:t=>G(()=>e.get(`${n}/attachments/${encodeURIComponent(t)}`,{responseType:`blob`})),confirmAction:t=>G(()=>e.post(`${n}/actions/confirm`,{token:t}))}}var pe=`Something went wrong. Please try again.`;async function me(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 he(e){if(e instanceof W)return e;let t=e?.response;if(!t)return new W(`network`,pe);let n=await me(t.data);return new W(typeof n?.code==`string`&&n.code?n.code:`unknown`,typeof n?.message==`string`&&n.message?n.message:pe,t.status)}async function q(e){try{return(await e()).data}catch(e){throw await he(e)}}function ge({http:e,baseUrl:t=`/api/support`}){let n=t.replace(/\/+$/,``),r=e=>`${n}/chats/${encodeURIComponent(e)}`;return{start:t=>{let r={};for(let e of[`pageUrl`,`userAgent`,`appVersion`]){let n=t?.[e];typeof n==`string`&&n.trim()!==``&&(r[e]=n)}return q(()=>e.post(`${n}/chats`,r))},current:()=>q(()=>e.get(`${n}/chats/current`)),get:t=>q(()=>e.get(r(t))),send:async(t,{body:n,files:i,idempotencyKey:a})=>{if(typeof a!=`string`||a.trim()===``)throw TypeError(`send needs an idempotencyKey from crypto.randomUUID().`);let o=new FormData;return o.append(`body`,n??``),(i??[]).forEach((e,t)=>{o.append(`files`,e,e?.name||`file-${t+1}.png`)}),q(()=>e.post(`${r(t)}/messages`,o,{headers:{"Idempotency-Key":a}}))},requestAgent:t=>q(()=>e.post(`${r(t)}/agent`)),typing:async t=>{await q(()=>e.post(`${r(t)}/typing`))},close:t=>q(()=>e.post(`${r(t)}/close`))}}var _e=`Something went wrong. Please try again.`;function ve(e){let t=e?.event?.target;if(!(!t||typeof t.responseText!=`string`)&&!(typeof t.status==`number`&&(t.status<200||t.status>=300)))return t.responseText}function ye(e){if(typeof e==`string`)try{return JSON.parse(e)}catch{return null}return e??null}function be(e){let t=e?.response,n=ye(t?.data),r=typeof n?.code==`string`&&n.code?n.code:`unknown`,i=typeof n?.message==`string`&&n.message?n.message:_e;return{status:t?.status,code:r,message:i}}var xe=e=>e===void 0||e===408||e===429||e>=500;function Se(){let e=``,t=null;return{push(n){e=(e+n).replace(/\r\n/g,`
|
|
2
|
+
`).replace(/\r(?!$)/g,`
|
|
3
|
+
`);let r=e.split(`
|
|
4
|
+
|
|
5
|
+
`);e=r.pop();for(let e of r)for(let n of e.split(`
|
|
6
|
+
`)){if(!n.startsWith(`id:`))continue;let e=n.slice(3);if(e.startsWith(` `)&&(e=e.slice(1)),!/^\d+$/.test(e))continue;let r=Number(e);t=t===null?r:Math.max(t,r)}},get last(){return t}}}function Ce({http:t,baseUrl:n=`/api/support`,retryDelaysMs:r,stallTimeoutMs:i=9e4}){let a=n.replace(/\/+$/,``),o=Array.isArray(r)&&r.length>0?r:[1e3];return{watch(n,r,s){let c=Number.isFinite(r)?r:null,l=!1,u=null,d=null,f=null,p=null,m=!1,h=!1,g=!1,_=null,v=0,y=e=>{Number.isFinite(e)&&(c=Math.max(c??0,e))};function b(e,t){if(!l){h=!0;try{e===`snapshot`?(y(t?.sequence),s.onSnapshot?.(t)):e===`message`?(y(t?.message?.sequence),s.onMessage?.(t)):e===`state`?s.onState?.(t):e===`typing`?s.onTyping?.(t):e===`delta`&&s.onDelta?.(t)}catch{s.onError?.(new W(`handler_failed`,_e))}}}function x(){clearTimeout(d),d=setTimeout(()=>{g=!0,u.abort()},i)}async function S(){u=new AbortController,m=!1,h=!1,g=!1,_=null;let r=0,i=Se(),o=e(({name:e,data:t})=>{if(!(l||_)){if(e===`error`){t?.code===`invalid-response`||t?.code===`stream_ended`?_=`retry`:t?.code===`chat_not_found`?(s.onError?.(t),_=`stop`):(s.onError?.(t),_=`retry`);return}b(e,t)}}),f=e=>{if(l||typeof e!=`string`||e.length<=r)return;let t=e.slice(r);r=e.length,o.push(t),i.push(t),i.last!==null&&(c=Math.max(c??0,i.last)),m=!0,x()},p=`${a}/chats/${encodeURIComponent(n)}/events${c===null?``:`?after=${c}`}`;x();let v;try{v=await t.get(p,{responseType:`text`,headers:{Accept:`text/event-stream`},signal:u.signal,timeout:0,onDownloadProgress:e=>f(ve(e))})}catch(e){if(l)return`stop`;if(g)return`retry`;let t=be(e);return xe(t.status)?`retry`:(s.onError?.({code:t.code,message:t.message}),`stop`)}finally{clearTimeout(d)}return f(v.data),clearTimeout(d),o.end(),_??`retry`}function C(e){return new Promise(t=>{p=t,f=setTimeout(t,e)})}async function w(){let e=0;for(;!l;){let t=await S();if(l||t===`stop`)return;if(m&&(e=0),v=h?0:v+1,v>=10){s.onError?.(new W(`connection_lost`,`We lost the connection to support. Check your internet and try again.`));return}let n=o[Math.min(e,o.length-1)];e+=1,await C(n)}}function T(){l=!0,u?.abort(),clearTimeout(d),clearTimeout(f),p?.()}return w(),T}}}var we=t(null);function Te(){let e=r(we);if(!e)throw Error(`Support components and hooks must be used inside <SupportProvider>.`);return e}function J(){return Te().client}function Ee(){return Te().timeZone}function De(){return Te().renderTime??null}function Oe(e,t,r=!0){let[a,o]=c({data:null,loading:r,error:null}),[l,u]=c(0),d=s(e);d.current=e;let f=s(t);i(()=>{let e=f.current!==t;if(f.current=t,!r){o({data:null,loading:!1,error:null});return}let n=!0;return o(t=>({data:e?null:t.data,loading:!0,error:null})),d.current(l>0).then(e=>n&&o({data:e,loading:!1,error:null}),e=>n&&o(t=>({...t,loading:!1,error:e}))),()=>{n=!1}},[t,r,l]);let p=n(()=>u(e=>e+1),[]),m=n(e=>o(t=>({...t,data:e})),[]);return{...a,reload:p,setData:m}}function Y(){let{loadConfig:e}=Te(),{data:t,loading:n,error:r,reload:i}=Oe(e,`config`);return{config:t,loading:n,error:r,reload:i}}function ke(e={}){let t=J(),{status:n,search:r,page:i,pageSize:a}=e,{data:o,loading:s,error:c,reload:l}=Oe(()=>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 Ae(){let e=J(),{data:t,loading:n,error:r,reload:i}=Oe(()=>e.getTicketCounts(),`ticket-counts`);return{counts:t,loading:n,error:r,reload:i}}function je(e){let t=J(),{data:r,loading:i,error:a,reload:o,setData:s}=Oe(()=>t.getTicket(e),e??``,!!e),c=n(async e=>{let t=await e();return s(t),t},[s]);return{ticket:r,loading:i,error:a,reload:o,reply:n(n=>c(()=>t.reply(e,n)),[c,t,e]),reopen:n(()=>c(()=>t.reopen(e)),[c,t,e]),cancel:n(()=>c(()=>t.cancel(e)),[c,t,e]),rate:n(n=>c(()=>t.rate(e,n)),[c,t,e])}}var Me=`We could not reach support. Check your connection and try again.`;function X(e,t){if(e instanceof W){if(e.code===`network`)return Me;if(e.code!==`unknown`)return e.message}return t}function Ne(e){return(e?.allowedContentTypes??[]).join(`,`)}function Pe(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(!Pe(e.type,a))return`${t} is a file type we cannot accept.`;if(i>0&&e.size>i)return`${t} is larger than ${ne(i)}.`}return null}var Fe=e=>e===1?`You can attach one file.`:`You can attach up to ${e} files.`;function Ie(e){return`${e.name}|${e.size}|${e.lastModified}`}function Le(e,t,n){let r=n?.maxAttachmentsPerMessage??0,i=new Set(e.map(Ie)),a=[],o=null;for(let e of t){let t=Ie(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?Fe(r):null)??Z(c,n)??(o?`${o} is already attached.`:``)}}function Re(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 ze(e,t){let[n,r]=c(e);return i(()=>{let n=setTimeout(()=>r(e),t);return()=>clearTimeout(n)},[e,t]),n}function Be({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 B(C,{id:e,label:t,optional:!0,multiple:!0,value:n,onChange:r,accept:Ne(i),maxSizeMb:s,validate:!1,error:a||void 0})}function Ve({items:e}){return e.length===0?null:B(m,{variant:`muted`,padding:`sm`,title:`These may already answer your question`,children:B(`ul`,{className:`list-unstyled mb-0 d-flex flex-column gap-2`,children:e.map(e=>V(`li`,{children:[B(`div`,{className:`fw-semibold`,children:e.title}),B(`div`,{className:`small text-body-secondary`,children:e.summary})]},e.title))})})}var He=500,Ue=3,We=5;function Ge(e,t){return t&&e.includes(t)?t:``}function Ke({id:e,config:t,defaultCategory:n,initialValues:r,onValuesChange:a,extraFiles:o=[],onSubmit:s,onBusyChange:l,children:d}){let f=t?.categories??[],[p,m]=c(()=>r?.category??Ge(f,n)),[h,g]=c(r?.subject??``),[_,v]=c(r?.body??``),[y,b]=c(r?.files??[]),[x,S]=c({}),[C,w]=c(``),E=J(),[D,O]=c(``),[A,j]=c([]),M=ze(h.trim(),He);i(()=>{a?.({category:p,subject:h,body:_,files:y})},[p,h,_,y,a]),i(()=>{O(M)},[M]),i(()=>{if(D.length<Ue){j([]);return}let e=!0,t=new AbortController;return j([]),E.getSuggestions(D,{signal:t.signal}).then(t=>{e&&j(Array.isArray(t)?t.slice(0,We):[])},()=>{e&&j([])}),()=>{e=!1,t.abort()}},[E,D]);let N=e=>{b(e),S(n=>({...n,files:Z([...o,...e],t)??void 0}))},F=e=>{let t=Re(e);t.length>0&&N([...y,...t])};function I(){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),S(e),Object.keys(e).length===0}async function L(e){if(e.preventDefault(),w(``),I()){l?.(!0);try{await s({category:p,subject:h.trim(),body:_.trim(),files:y})}catch(e){w(X(e,`Your ticket did not send. Please try again.`))}finally{l?.(!1)}}}return V(`form`,{id:e,onSubmit:L,noValidate:!0,className:`d-flex flex-column gap-3`,children:[C&&B(u,{tone:`danger`,children:C}),B(k,{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}),B(T,{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:()=>O(h.trim()),error:x.subject}),B(Ve,{items:A}),B(P,{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,B(Be,{id:`${e}-files`,files:y,onChange:N,config:t,error:x.files})]})}var qe=`supportCapture`,Je={zIndex:`var(--wui-z-fixed)`,bottom:0,insetInlineEnd:0},Ye={zIndex:`var(--wui-z-fixed)`},Xe={maxWidth:`20rem`},Ze=e=>e.dataset?.[qe]===`exclude`||e.matches?.(`.modal-backdrop`)?!1:!(e.matches?.(`.modal`)&&e.querySelector?.(`[data-support-capture="exclude"]`)),Qe=()=>new Promise(e=>requestAnimationFrame(()=>e()));async function $e(){let e=await L(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 et({file:e,failed:t,disabled:n,hintId:r,controlRef:a,onAdd:o,onRemove:s}){let[l,d]=c(null);return i(()=>{if(!e)return;let t=URL.createObjectURL(e);return d(t),()=>URL.revokeObjectURL(t)},[e]),V(`div`,{className:`d-flex flex-column gap-2`,children:[B(`span`,{className:`wui-text-sm fw-semibold`,children:`Screenshot`}),e&&l&&B(`img`,{src:l,alt:`Screenshot of the page you were on`,className:`d-block w-100 border rounded`,style:Xe}),B(`div`,{ref:a,className:`d-flex flex-wrap gap-2`,children:e?V(z,{children:[B(p,{variant:`outline`,size:`sm`,leftIcon:`refresh-cw`,onClick:o,disabled:n,"aria-describedby":r,children:`Retake`}),B(p,{variant:`ghost`,size:`sm`,leftIcon:`x`,onClick:s,disabled:n,children:`Remove screenshot`})]}):B(p,{variant:`outline`,size:`sm`,leftIcon:`camera`,onClick:o,disabled:n,"aria-describedby":r,children:`Add a screenshot`})}),B(`span`,{id:r,className:`wui-text-sm text-body-secondary`,children:`Only what is on your screen now. You can remove it before sending.`}),t&&B(u,{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 tt({label:e=`Report an issue`,floating:t=!1,compact:n=!1,defaultCategory:r=`Bug report`,appVersion:o,getTicketHref:l,onOpenTicket:d,onCreated:f,className:m,style:h}){let g=J(),{config:_,error:v}=Y(),y=`support-report-${a().replace(/[^a-zA-Z0-9-]/g,``)}`,[b,x]=c(!1),[S,C]=c(!1),[T,E]=c(null),[O,k]=c(!1),[A,j]=c(!1),[M,N]=c(null),[P,I]=c(null),L=F(`end`,t&&n),ee=s(null),te=s(!1);i(()=>{S||!te.current||(te.current=!1,ee.current?.querySelector(`button`)?.focus())},[S]);function ne(){N(null),E(null),k(!1),I(null),x(!0)}async function re(){C(!0),k(!1),await Qe(),await Qe();try{E(await $e())}catch{E(null),k(!0)}finally{te.current=!0,C(!1)}}let H=()=>{A||(x(!1),E(null),k(!1),N(null),I(null))};async function ie(e){let t=await g.createTicket({...e,pageUrl:window.location.href,userAgent:navigator.userAgent,appVersion:o,screenshots:T?[T]:[]});N(t),E(null),f?.(t)}let ae=!M&&(!!T||!!P&&(P.subject.trim()!==``||P.body.trim()!==``||P.files.length>0)),U=M&&l?l(M.id):void 0,W=M?V(`div`,{className:`d-flex justify-content-end gap-2 w-100`,children:[B(p,{variant:`secondary`,onClick:H,children:`Close`}),M&&(U||d)?B(p,{href:U,onClick:U?void 0:()=>{x(!1),N(null),d(M)},children:`View ticket`}):null]}):V(`div`,{className:`d-flex justify-content-end gap-2 w-100`,children:[B(p,{variant:`secondary`,onClick:H,disabled:A,children:`Cancel`}),B(p,{type:`submit`,form:y,loading:A,disabled:!_,children:`Submit`})]}),oe=n?B(p,{variant:`secondary`,className:`wui-floating-btn wui-floating-btn--secondary`,disabled:S,onClick:ne,"aria-haspopup":`dialog`,"aria-label":e,tooltip:e,tooltipPlacement:`start`,children:B(w,{name:`bug`,size:22})}):B(p,{leftIcon:`bug`,variant:t?`primary`:`outline`,disabled:S,onClick:ne,"aria-haspopup":`dialog`,children:e});return V(z,{children:[t&&n?L&&R(B(`span`,{className:[`wui-floating-stack-item wui-floating-stack-item--secondary`,m].filter(Boolean).join(` `),style:h,children:oe}),L):B(`span`,{"data-support-capture":`exclude`,className:[t?`position-fixed m-3`:`d-inline-block`,m].filter(Boolean).join(` `),style:t?{...Je,...h}:h,children:oe}),S&&V(`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:Ye,children:[B(`span`,{className:`spinner-border spinner-border-sm`,"aria-hidden":`true`}),`Taking a screenshot`]}),B(D,{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:ae&&!A,onClose:H,footer:W,"data-support-capture":`exclude`,children:M?B(u,{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.`}):_?B(Ke,{id:y,config:_,defaultCategory:r,initialValues:P,onValuesChange:I,extraFiles:T?[T]:[],onSubmit:ie,onBusyChange:j,children:B(et,{file:T,failed:O,disabled:A||S,hintId:`${y}-screenshot-hint`,controlRef:ee,onAdd:re,onRemove:()=>E(null)})}):B(u,{tone:v?`danger`:`info`,children:v?X(v,`We could not load the support settings.`):`Loading the form.`})})]})}function nt({open:e,onClose:t,onCreated:n,config:r,defaultCategory:i,appVersion:o}){let s=J(),l=`support-new-${a().replace(/[^a-zA-Z0-9-]/g,``)}`,[u,d]=c(!1),[f,m]=c(null),h=!!f&&(f.subject.trim()!==``||f.body.trim()!==``||f.files.length>0);async function g(e){n(await s.createTicket({...e,userAgent:typeof navigator>`u`?void 0:navigator.userAgent,appVersion:o}))}return B(D,{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:V(`div`,{className:`d-flex justify-content-end gap-2 w-100`,children:[B(p,{variant:`secondary`,onClick:t,disabled:u,children:`Cancel`}),B(p,{type:`submit`,form:l,loading:u,children:`Send ticket`})]}),children:e&&B(Ke,{id:l,config:r,defaultCategory:i,onSubmit:g,onBusyChange:d,onValuesChange:m})})}var rt={Open:`warning`,InProgress:`info`,WaitingOnCustomer:`warning`,Resolved:`success`,Closed:`neutral`,Cancelled:`neutral`};function it(e){return rt[e]??`neutral`}var at=6e4,ot=[`image/png`,`image/jpeg`,`image/gif`,`image/webp`,`application/pdf`];function st({attachment:e}){let t=J(),[n,r]=c(!1),[i,a]=c(!1);async function o(){r(!0),a(!1);let n=ot.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),at),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 s=Number.isFinite(e.sizeBytes)?ne(e.sizeBytes):`-`;return V(z,{children:[B(h,{leadingIcon:i?`x-circle`:`paperclip`,label:n?V(z,{children:[B(j,{size:`sm`,label:`Loading ${e.fileName}`}),` `,e.fileName]}):e.fileName,onClick:o,disabled:n,"aria-busy":n||void 0,title:`${e.fileName}, ${s}`}),i&&B(`span`,{role:`status`,className:`wui-text-xs text-danger align-self-center`,children:`Could not load this file. Click to try again.`})]})}function Q({iso:e,className:t}){let n=De(),r=Ee();return n?n(e):B(`time`,{dateTime:e,className:t,children:te(e,{timeZone:r})})}var ct={whiteSpace:`pre-wrap`,overflowWrap:`anywhere`};function lt({messages:e}){return B(`ol`,{className:`list-unstyled d-flex flex-column gap-3 mb-0`,"aria-label":`Conversation`,children:e.map(e=>{let t=B(Q,{iso:e.createdDateTimeUtc,className:`wui-text-xs text-body-secondary text-nowrap`});if(e.authorKind===`System`)return V(`li`,{className:`text-center wui-text-xs text-body-secondary`,"data-author":`system`,children:[B(`span`,{className:`d-block`,children:e.body}),t]},e.id);let n=e.authorKind===`Customer`,r=e.authorName||(n?`You`:`Support team`);return V(`li`,{className:`d-flex align-items-start gap-2${n?` flex-row-reverse`:``}`,"data-author":n?`customer`:`agent`,children:[B(d,{name:r,size:32,tone:n?`neutral`:`primary`}),V(m,{className:`flex-grow-1 border`,padding:`sm`,variant:n?`default`:`accent`,style:{minWidth:0},children:[V(`div`,{className:`d-flex flex-wrap align-items-center justify-content-between gap-2 mb-2`,children:[V(`span`,{className:`d-inline-flex flex-wrap align-items-center gap-2 fw-semibold wui-text-sm text-break`,children:[r,!n&&B(f,{tone:`primary`,children:`Support`})]}),t]}),B(`div`,{className:`wui-text-sm`,style:ct,children:e.body}),e.attachments?.length>0&&B(`div`,{className:`d-flex flex-wrap gap-2 mt-2`,children:e.attachments.map(e=>B(st,{attachment:e},e.id))})]})]},e.id)})})}function ut({satisfaction:e,comment:t,canRate:n=!1,commentMaxLength:r,onRate:i}){let o=a(),[s,l]=c(``),[d,f]=c(null),[h,g]=c(``);if(e)return V(u,{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?V(`span`,{className:`d-block mt-1`,children:[`Your comment: `,t]}):null]});if(!n)return null;async function _(e){g(``),f(e);try{await i({satisfaction:e,comment:s})}catch(e){g(X(e,`Your rating did not send. Please try again.`))}finally{f(null)}}return B(m,{padding:`sm`,className:`border`,title:`Did this solve your problem?`,children:V(`div`,{className:`d-flex flex-column gap-2`,children:[h&&B(u,{tone:`danger`,children:h}),B(P,{id:`${o}-comment`,label:`Anything to add?`,rows:2,maxLength:r,value:s,onChange:e=>l(e.target.value),hint:`Optional. Your comment goes to the support team.`}),V(`div`,{className:`d-flex flex-wrap gap-2`,children:[B(p,{variant:`outline`,leftIcon:`check-circle`,loading:d===`Satisfied`,disabled:d!==null,onClick:()=>_(`Satisfied`),children:`Yes, it is solved`}),B(p,{variant:`outline`,leftIcon:`x-circle`,loading:d===`Unsatisfied`,disabled:d!==null,onClick:()=>_(`Unsatisfied`),children:`No, it is not`})]})]})})}function dt({onSend:e,config:t,reopens:n=!1}){let r=a(),[i,o]=c(``),[s,d]=c([]),[f,m]=c(``),[_,v]=c(``),[y,b]=c(!1),x=e=>{let n=Le(s,e,t);d(n.files),m(n.notice)},S=e=>{let n=s.filter((t,n)=>n!==e);d(n),m(Z(n,t)??``)},C=e=>{let t=Re(e);t.length>0&&x(t)};async function w(n){n.preventDefault();let r=i.trim();if(!r){v(`Write a message before you send it.`);return}let a=Z(s,t);if(a){m(a);return}v(``),b(!0);try{await e({body:r,files:s}),o(``),d([]),m(``)}catch(e){v(X(e,`Your reply did not send. Please try again.`))}finally{b(!1)}}let T=_||f;return V(`form`,{onSubmit:w,noValidate:!0,className:`d-flex flex-column gap-2`,"aria-label":`Reply to this ticket`,children:[T&&B(u,{tone:`danger`,children:T}),B(P,{id:`${r}-body`,label:`Your reply`,rows:4,autoGrow:!0,maxLength:t?.bodyMaxLength,value:i,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}),s.length>0&&B(g,{label:`Attached files`,children:s.map((e,t)=>B(h,{leadingIcon:`paperclip`,label:e.name,removeLabel:`Remove ${e.name}`,onRemove:()=>S(t)},Ie(e)))}),V(`div`,{className:`d-flex flex-wrap align-items-center justify-content-between gap-2`,children:[B(l,{iconVariant:`bulk`,icon:`paperclip`,label:`Attach a file`,multiple:t?.maxAttachmentsPerMessage!==1,accept:Ne(t),onFiles:x}),B(p,{type:`submit`,leftIcon:`send`,loading:y,children:`Send reply`})]})]})}function ft({ticketId:e,onBack:t,onChanged:n,onOpenTicket:r}){let{config:i}=Y(),a=Ee(),o=De(),{ticket:s,loading:l,error:d,reload:f,reply:h,reopen:g,cancel:v,rate:y}=je(e),[x,S]=c(!1),[C,T]=c(!1),[E,D]=c(!1),[O,k]=c(``),j=async e=>{let t=await e();return n?.(),t};async function N(){k(``),S(!0);try{await j(g)}catch(e){k(X(e,`The ticket did not reopen. Please try again.`))}finally{S(!1)}}async function P(){k(``),D(!0);try{await j(v)}catch(e){k(X(e,`The request was not withdrawn. Please try again.`))}finally{D(!1),T(!1)}}let F=B(p,{variant:`ghost`,size:`sm`,leftIcon:`arrow-left`,onClick:t,className:`align-self-start`,children:`Back to tickets`});if(!s)return V(`section`,{className:`d-flex flex-column gap-3`,"aria-busy":l||void 0,children:[F,d?V(u,{tone:`danger`,children:[X(d,`We could not load this ticket.`),` `,B(p,{variant:`ghost`,size:`sm`,onClick:f,children:`Try again`})]}):B(A,{height:160})]});let I=it(s.status),L=[{key:`status`,label:`Status`,value:s.statusLabel?B(M,{label:s.statusLabel,tone:I}):`-`},{key:`category`,label:`Category`,value:s.category||`-`},{key:`ticket`,label:`Ticket`,value:s.number},{key:`opened`,label:`Opened`,value:B(Q,{iso:s.createdDateTimeUtc})},{key:`updated`,label:`Last update`,value:B(Q,{iso:s.updatedDateTimeUtc})}];return V(`section`,{className:`d-flex flex-column gap-3`,"aria-labelledby":`support-ticket-${s.id}`,children:[F,V(`div`,{className:`row g-3`,children:[V(`div`,{className:`col-12 col-lg-8 d-flex flex-column gap-3`,children:[V(`header`,{className:`d-flex flex-column gap-2`,children:[V(`div`,{className:`d-flex flex-wrap align-items-center gap-2`,children:[B(`h2`,{id:`support-ticket-${s.id}`,className:`h5 mb-0 text-break`,children:s.subject}),s.statusLabel&&B(M,{label:s.statusLabel,tone:I})]}),V(`ul`,{className:`list-unstyled d-flex flex-wrap gap-3 mb-0 wui-text-sm text-body-secondary`,"aria-label":`Ticket summary`,children:[s.number&&V(`li`,{className:`d-inline-flex align-items-center gap-1`,children:[B(w,{variant:`bulk`,name:`receipt-text`,size:16}),s.number]}),s.category&&V(`li`,{className:`d-inline-flex align-items-center gap-1`,children:[B(w,{variant:`bulk`,name:`folder-2`,size:16}),s.category]}),V(`li`,{className:`d-inline-flex align-items-center gap-1`,children:[B(w,{variant:`bulk`,name:`calendar-1`,size:16}),`Opened `,B(Q,{iso:s.createdDateTimeUtc})]})]}),o===null&&V(`p`,{className:`wui-text-xs text-body-secondary mb-0`,children:[`Times are shown in `,re(a),`.`]})]}),O&&B(u,{tone:`danger`,children:O}),s.mergedInto&&V(u,{tone:`info`,role:`status`,children:[`This ticket was merged into `,s.mergedInto.number,`. The conversation carries on there.`,` `,r&&V(p,{variant:`ghost`,size:`sm`,onClick:()=>r(s.mergedInto.id),children:[`Open `,s.mergedInto.number]})]}),s.canReopen&&B(u,{tone:`success`,role:`status`,children:`If you still need help, reopen the ticket or send a reply.`}),s.status===`WaitingOnCustomer`&&B(u,{tone:`warning`,role:`status`,children:`We need your answer to carry on. Reply below and the ticket goes back to our team.`}),!s.canReopen&&B(`p`,{className:`wui-text-sm text-body-secondary mb-0`,children:`Our team marks this resolved once your question is answered. Replying reopens it.`}),s.canReopen&&B(p,{variant:`secondary`,leftIcon:`history`,loading:x,onClick:N,className:`align-self-start`,children:`Reopen ticket`}),s.canCancel&&B(p,{variant:`secondary`,onClick:()=>T(!0),className:`align-self-start`,children:`Withdraw request`}),B(_,{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:E,onConfirm:P,onClose:()=>T(!1)}),B(ut,{satisfaction:s.satisfaction,comment:s.satisfactionComment,canRate:s.canRate,commentMaxLength:i?.satisfactionCommentMaxLength,onRate:e=>j(()=>y(e))}),B(lt,{messages:s.messages??[]}),s.mergedTickets?.length>0&&V(`section`,{"aria-labelledby":`support-merged-${s.id}`,className:`d-flex flex-column gap-1`,children:[B(`h3`,{id:`support-merged-${s.id}`,className:`h6 mb-0`,children:`Merged into this ticket`}),B(`ul`,{className:`list-unstyled d-flex flex-column gap-1 mb-0 wui-text-sm`,children:s.mergedTickets.map(e=>B(`li`,{children:r?V(p,{variant:`ghost`,size:`sm`,onClick:()=>r(e.id),children:[e.number,`: `,e.subject]}):`${e.number}: ${e.subject}`},e.id))})]}),!s.mergedInto&&B(dt,{config:i,reopens:s.canReopen,onSend:e=>j(()=>h(e))})]}),B(`aside`,{"aria-label":`Ticket details`,className:`col-12 col-lg-4`,children:V(m,{padding:`sm`,className:`border`,children:[B(`h3`,{className:`h6`,children:`Ticket details`}),B(b,{columns:1,items:L})]})})]})]})}var pt=`ticket`;function mt(){return typeof window>`u`?null:new URLSearchParams(window.location.search).get(pt)}function ht(e){if(typeof window>`u`)return e?`?${pt}=${encodeURIComponent(e)}`:`?`;let t=new URL(window.location.href);return e?t.searchParams.set(pt,e):t.searchParams.delete(pt),`${t.pathname}${t.search}${t.hash}`}function gt(e){if(typeof window>`u`)return;let t=ht(e);t!==`${window.location.pathname}${window.location.search}${window.location.hash}`&&window.history.replaceState(window.history.state,``,t)}var _t=[{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}],vt=[`tabs`,`select`,`none`];function yt({tickets:e,loading:t,error:n,onRetry:r,onOpen:i,status:a,onStatusChange:o,statusFilter:s=`tabs`,counts:c,search:d,onSearchChange:f,pagination:m}){I(`SupportCenter`,`statusFilter`,s,vt);let h=_t.map(({key:e,label:t,countKey:n})=>{let r=c?.[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 V(`div`,{className:`d-flex flex-column gap-3`,children:[n&&V(u,{tone:`danger`,children:[X(n,`We could not load your tickets.`),` `,B(p,{variant:`ghost`,size:`sm`,onClick:r,children:`Try again`})]}),V(`div`,{className:`d-flex flex-column flex-md-row gap-2 align-items-md-center justify-content-between`,children:[s===`none`?null:s===`select`?B(k,{label:`Status`,value:a,onChange:o,options:h}):B(N,{tabs:_t.map(({key:e,label:t,countKey:n})=>({key:e,label:t,count:c?.[n]})),value:a,onChange:o,ariaLabel:`Filter tickets by status`,className:`flex-grow-1`}),B(O,{value:d,onChange:f,placeholder:`Search tickets`,ariaLabel:`Search tickets`})]}),B(y,{columns:[{key:`subject`,label:`Subject`,render:e=>V(`div`,{className:`d-flex flex-column`,style:{minWidth:0},children:[B(E,{href:ht(e.id),animation:`none`,className:`fw-semibold text-break`,onClick:t=>g(t,e.id),children:e.subject}),V(`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?B(M,{label:e.statusLabel,tone:it(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=>B(Q,{iso:e.updatedDateTimeUtc})}],rows:e,loading:t,skeletonRows:4,ariaLabel:`Support tickets`,rowActionsLabel:`Actions`,rowActions:e=>B(l,{icon:`eye`,label:`Open ticket ${e.subject}`,href:ht(e.id),onClick:t=>g(t,e.id)}),stickyActions:!0,stackOnMobile:!0,sourceCount:c?.total??0,pagination:m,empty:B(S,{variant:`table`,icon:`message-square`,title:`No tickets yet`,text:`When you raise a ticket, it shows here with its status.`}),emptyFiltered:B(S,{variant:`table`,icon:`search`,title:`No tickets match`,text:`Try another search or status.`})})]})}var bt=300,xt=10;function St({initialTicketId:e,defaultCategory:t,appVersion:n,status:r,defaultStatus:a=`all`,onStatusChange:o,statusFilter:s=`tabs`}){let{config:l,error:d,reload:f}=Y(),[m,h]=c(a),g=r!==void 0,_=g?r:m,v=e=>{g||h(e),o?.(e)},[y,b]=c(``),x=ze(y.trim(),bt),[S,C]=c(xt),w=`${_}|${x}|${S}`,[T,E]=c({key:w,page:1}),D=T.key===w?T.page:1,O=e=>E({key:w,page:e}),k=ke({status:_===`all`?void 0:_,search:x||void 0,page:D,pageSize:S}),{counts:A,reload:j}=Ae(),[M,N]=c(()=>e||mt()),[P,F]=c(!1),I=k.totalPages;i(()=>{I>0&&D>I&&E({key:w,page:I})},[I,D,w]);let L=()=>{k.reload(),j()},R=e=>{N(e),gt(e)};if(M)return B(ft,{ticketId:M,onBack:()=>R(null),onChanged:L,onOpenTicket:R},M);let ee={page:D,totalPages:Math.max(1,k.totalPages),pageSize:S,total:k.totalCount,setPage:O,setPageSize:C};return V(`section`,{className:`d-flex flex-column gap-3 min-w-0`,"aria-labelledby":`support-center-title`,children:[V(`div`,{className:`d-flex flex-wrap align-items-center justify-content-between gap-2`,children:[B(`h2`,{id:`support-center-title`,className:`h5 mb-0`,children:`Your tickets`}),B(p,{leftIcon:`plus`,onClick:()=>F(!0),disabled:!l,children:`New ticket`})]}),d&&V(u,{tone:`warning`,children:[X(d,`We could not load the support settings.`),` `,B(p,{variant:`ghost`,size:`sm`,onClick:f,children:`Try again`})]}),B(yt,{tickets:k.tickets,loading:k.loading,error:k.error,onRetry:L,onOpen:R,status:_,onStatusChange:v,statusFilter:s,counts:A,search:y,onSearchChange:b,pagination:ee}),l&&B(nt,{open:P,onClose:()=>F(!1),config:l,defaultCategory:t,appVersion:n,onCreated:e=>{F(!1),L(),R(e.id)}})]})}function Ct(e){return e===0?`You are next in the queue.`:e===1?`1 person is ahead of you.`:`${e} people are ahead of you.`}function wt({position:e}){return V(`div`,{className:`d-flex flex-column gap-1`,children:[V(`div`,{className:`d-flex align-items-center gap-2`,children:[B(j,{size:`sm`,label:`Waiting for a person`}),B(`span`,{className:`wui-text-sm`,children:`Waiting for a person to join.`})]}),typeof e==`number`&&B(`span`,{className:`wui-text-sm text-body-secondary`,children:Ct(e)}),B(`span`,{className:`wui-text-sm text-body-secondary`,children:`If no one is free, we will reply here and by email.`})]})}var Tt={CustomerEnded:`You ended this chat.`,AgentEnded:`Our team ended this chat.`,NoAgentAvailable:`No one was free to join. We will reply to you here and by email.`,Idle:`This chat ended because it was quiet for a while.`};function Et({state:e,closeReason:t,agentName:n,ticketNumber:r,ticketId:i,waitingPosition:a,canRequestAgent:o=!1,requesting:s=!1,onRequestAgent:c,onOpenTicket:l,onRestart:u}){return V(`div`,{role:`status`,className:`d-flex flex-column gap-2 pb-3 mb-3 border-bottom`,children:[e===`Assistant`&&V(z,{children:[B(`div`,{children:B(f,{tone:`neutral`,children:`AI assistant`})}),B(`p`,{className:`wui-text-sm mb-0`,children:`You are chatting with our AI assistant.`}),o&&B(`div`,{children:B(p,{variant:`outline`,size:`sm`,leftIcon:`user`,loading:s,onClick:c,children:`Talk to a person`})})]}),e===`WaitingForAgent`&&V(z,{children:[B(`div`,{children:B(f,{tone:`info`,children:`In the queue`})}),B(wt,{position:a??null})]}),e===`WithAgent`&&V(z,{children:[B(`div`,{children:B(f,{tone:`success`,children:`Live agent`})}),B(`p`,{className:`wui-text-sm mb-0`,children:n?`${n} from our team is chatting with you.`:`A member of our team is chatting with you.`})]}),e===`Closed`&&V(z,{children:[B(`div`,{children:B(f,{tone:`neutral`,children:`Chat ended`})}),B(`p`,{className:`wui-text-sm mb-0`,children:Tt[t]??`This chat has ended.`}),r&&B(`p`,{className:`wui-text-sm mb-0`,children:`Your ticket number is ${r}.`}),V(`div`,{className:`d-flex flex-wrap gap-2`,children:[l&&i&&B(p,{variant:`outline`,size:`sm`,onClick:()=>l({id:i,number:r}),children:`View ticket`}),B(p,{size:`sm`,leftIcon:`plus`,onClick:u,children:`Start a new chat`})]})]})]})}var Dt={whiteSpace:`pre-wrap`,overflowWrap:`anywhere`},Ot={...Dt,maxWidth:`85%`};function kt(e){for(let t=e?.parentElement;t&&t!==document.body;t=t.parentElement){let{overflowY:e}=getComputedStyle(t);if((e===`auto`||e===`scroll`)&&t.scrollHeight>t.clientHeight)return t}return null}function At(e){if(!e?.parentElement)return;let t=()=>{let t=kt(e);t&&(t.scrollTop=t.scrollHeight)};t();let n=new MutationObserver(t);return n.observe(e.parentElement,{childList:!0,subtree:!0,characterData:!0}),()=>n.disconnect()}function jt({attachments:e}){return e?.length?B(`div`,{className:`d-flex flex-wrap gap-2 mt-2`,children:e.map(e=>B(st,{attachment:e},e.id))}):null}function Mt({message:e,resolveLink:t,linkComponent:n}){let r=B(Q,{iso:e.createdDateTimeUtc,className:`wui-text-xs text-body-secondary text-nowrap`});if(e.authorKind===`System`)return V(`li`,{className:`text-center wui-text-xs text-body-secondary`,"data-author":`system`,children:[B(`span`,{className:`d-block`,children:e.body}),r]});if(e.authorKind===`Customer`)return B(`li`,{className:`d-flex justify-content-end`,"data-author":`customer`,children:V(m,{padding:`sm`,variant:`muted`,style:Ot,children:[B(`span`,{className:`visually-hidden`,children:`You: `}),B(`div`,{className:`wui-text-sm`,style:Dt,children:e.body}),B(jt,{attachments:e.attachments}),B(`div`,{className:`mt-1`,children:r})]})});if(e.authorKind===`Assistant`)return V(`li`,{className:`d-flex align-items-start gap-2`,"data-author":`assistant`,children:[B(d,{name:`Assistant`,size:32,tone:`primary`}),V(`div`,{className:`flex-grow-1 wui-text-sm min-w-0`,children:[V(`div`,{className:`d-flex flex-wrap align-items-center gap-2 mb-1`,children:[B(`span`,{className:`fw-semibold`,children:`Assistant`}),B(f,{tone:`neutral`,children:`AI`})]}),B(`span`,{className:`visually-hidden`,children:`Assistant: `}),B(ie,{text:e.body,resolveLink:t,linkComponent:n}),B(jt,{attachments:e.attachments}),B(`div`,{className:`mt-1`,children:r})]})]});let i=e.authorName||`Support team`;return V(`li`,{className:`d-flex align-items-start gap-2`,"data-author":`agent`,children:[B(d,{name:i,size:32,tone:`primary`}),V(`div`,{className:`flex-grow-1 wui-text-sm min-w-0`,children:[V(`div`,{className:`d-flex flex-wrap align-items-center gap-2 mb-1`,children:[B(`span`,{className:`fw-semibold`,children:i}),B(f,{tone:`primary`,children:`Support`})]}),B(`div`,{style:Dt,children:e.body}),B(jt,{attachments:e.attachments}),B(`div`,{className:`mt-1`,children:r})]})]})}function Nt({item:e,onRetry:t,onDiscard:n}){return V(`li`,{className:`d-flex flex-column align-items-end gap-1`,"data-author":`customer`,children:[B(m,{padding:`sm`,variant:`muted`,style:Ot,children:B(`div`,{className:`wui-text-sm`,style:Dt,children:e.body})}),e.status===`sending`&&B(`span`,{className:`wui-text-xs text-body-secondary`,children:`Sending`}),e.status===`failed`&&V(u,{tone:`danger`,size:`sm`,children:[B(`div`,{children:e.error}),V(`div`,{className:`d-flex gap-2 mt-2`,children:[B(p,{size:`sm`,variant:`outline`,onClick:()=>t(e.localId),children:`Try again`}),B(p,{size:`sm`,variant:`ghost`,onClick:()=>n(e.localId),children:`Discard`})]})]})]})}function Pt({messages:e,pending:t,assistantText:n,assistantWriting:r,agentName:i,agentTyping:a,onRetry:o,onDiscard:s,resolveLink:c,linkComponent:l}){return e.length===0&&t.length===0&&!n&&!r&&!a?B(S,{icon:`sparkles`,size:`sm`,title:`How can we help?`,text:`Ask a question and our AI assistant will answer it. You can ask to talk to a person once you have sent a message.`}):V(z,{children:[V(`ol`,{className:`list-unstyled d-flex flex-column gap-3 mb-0`,"aria-label":`Conversation`,children:[e.map(e=>B(Mt,{message:e,resolveLink:c,linkComponent:l},e.id)),t.map(e=>B(Nt,{item:e,onRetry:o,onDiscard:s},e.localId)),n?V(`li`,{className:`d-flex align-items-start gap-2`,"data-author":`assistant`,"aria-busy":`true`,children:[B(d,{name:`Assistant`,size:32,tone:`primary`}),V(`div`,{className:`flex-grow-1 wui-text-sm min-w-0`,children:[B(`span`,{className:`fw-semibold`,children:`Assistant`}),B(ie,{text:n,resolveLink:c,linkComponent:l})]})]}):r&&V(`li`,{className:`d-flex align-items-start gap-2`,"data-author":`assistant`,children:[B(d,{name:`Assistant`,size:32,tone:`primary`}),V(`div`,{className:`d-flex align-items-center gap-2 wui-text-sm`,children:[B(j,{size:`sm`,label:`The assistant is writing`}),B(`span`,{children:`The assistant is writing`})]})]}),a&&B(`li`,{className:`wui-text-sm text-body-secondary`,"aria-live":`polite`,children:`${i||`Our team`} is typing`})]}),B(`div`,{ref:At})]})}var Ft=3e3,It=`This chat is no longer available.`,Lt=(e,t)=>e.sequence-t.sequence;function Rt(e,t){return e.some(e=>e.id===t.id)?e:[...e,t].sort(Lt)}function zt(e){let t=new Map;for(let n of e)t.has(n.id)||t.set(n.id,n);return[...t.values()].sort(Lt)}function Bt(e,t){if(!e)return;let n=Date.parse(e)-Date.now();if(!(n>0))return;let r=setTimeout(t,n);return()=>clearTimeout(r)}function Vt({chatClient:e,connection:t,open:r,appVersion:a}){let[o,l]=c(`idle`),[u,d]=c(``),[f,p]=c(null),[m,h]=c([]),[g,_]=c([]),[v,y]=c(``),[b,x]=c(null),[S,C]=c(null),[w,T]=c(``),[E,D]=c(!1),[,O]=c(0),k=s(null),A=s(null),j=s(0),M=n(e=>{let t=A.current;A.current=e.id;let{messages:n,...r}=e;p(r),h(zt(n??[])),t!==e.id&&_([])},[]);i(()=>Bt(b,()=>O(e=>e+1)),[b]),i(()=>Bt(S,()=>O(e=>e+1)),[S]);let N=n(()=>{let n=!0,r=()=>{},i=e=>({onSnapshot(t){t.id===e&&(M(t),y(``))},onMessage(t){t.chatId===e&&(h(e=>Rt(e,t.message)),t.message.authorKind===`Assistant`&&y(``))},onState(t){t.chatId===e&&(p(e=>e&&{...e,state:t.state,closeReason:t.closeReason,ticketId:t.ticketId,ticketNumber:t.ticketNumber,agentName:t.agentName,waitingPosition:t.state===`WaitingForAgent`?t.waitingPosition:null}),y(``))},onTyping(t){t.chatId===e&&(t.who===`Agent`?x(t.untilDateTimeUtc):t.who===`Assistant`&&C(t.untilDateTimeUtc))},onDelta(t){t.chatId===e&&y(e=>e+t.text)},onError(e){if(e.code===`chat_not_found`){p(e=>e&&{...e,state:`Closed`,closeReason:null}),T(It);return}T(typeof e.message==`string`&&e.message?e.message:`The chat connection had a problem. We are reconnecting.`)}});return l(`loading`),e.start({pageUrl:window.location.href,userAgent:navigator.userAgent,appVersion:a}).then(e=>{n&&(M(e),d(``),l(`ready`),r=t.watch(e.id,e.sequence,i(e.id)))}).catch(e=>{n&&(d(X(e,`We could not start the chat. Please try again.`)),l(`error`))}),()=>{n=!1,r()}},[e,t,M,a]);i(()=>{if(!r)return;let e=N();return k.current=()=>{e(),e=N()},()=>{k.current=null,e()}},[r,N]);let P=(t,n)=>e.get(t).then(M).catch(e=>T(X(e,n)));async function F(t){let n=f.id;try{let r=await e.send(n,{body:t.body,idempotencyKey:t.key});if(A.current!==n)return;h(e=>{let t=Rt(e,r.message);return r.reply?Rt(t,r.reply):t}),_(e=>e.filter(e=>e.localId!==t.localId)),r.reply&&y(``)}catch(e){if(A.current!==n)return;if(e?.code===`chat_closed`){_(e=>e.filter(e=>e.localId!==t.localId)),await P(n,It);return}_(n=>n.map(n=>n.localId===t.localId?{...n,status:`failed`,error:X(e,`Your message did not send. Please try again.`)}:n))}}return{phase:o,startError:u,chat:f,messages:m,pending:g,assistantText:v,agentTypingUntil:b,assistantTypingUntil:S,notice:w,requesting:E,send:e=>{let t={localId:crypto.randomUUID(),key:crypto.randomUUID(),body:e,status:`sending`,error:``};_(e=>[...e,t]),F(t)},retry:e=>{let t=g.find(t=>t.localId===e);if(!t)return;let n={...t,status:`sending`,error:``};_(t=>t.map(t=>t.localId===e?n:t)),F(n)},discard:e=>{_(t=>t.filter(t=>t.localId!==e))},requestAgent:async()=>{let t=f.id;D(!0);try{M(await e.requestAgent(t))}catch(e){let n=`We could not reach the team. Please try again.`;e?.code===`chat_not_with_assistant`?await P(t,n):T(X(e,n))}finally{D(!1)}},end:async()=>{try{M(await e.close(f.id))}catch(e){T(X(e,`We could not end the chat. Please try again.`))}},restart:()=>{A.current=null,p(null),h([]),_([]),y(``),T(``),x(null),C(null),l(`loading`),k.current?.()},retryStart:()=>{k.current?.()},notifyTyping:()=>{if(o!==`ready`||f?.state!==`WithAgent`)return;let t=Date.now();t-j.current<Ft||(j.current=t,e.typing(f.id).catch(()=>{}))}}}var Ht={composer:`Your message`,placeholder:`Type your message`},Ut=e=>!!e&&Date.now()<Date.parse(e);function Wt({chatClient:e,connection:t,open:r,onClose:a,appVersion:o,onOpenTicket:d,resolveLink:f,linkComponent:m,title:h=`Chat with us`,width:g=`440px`}){let{config:v}=Y(),y=Vt({chatClient:e,connection:t,open:r,appVersion:o}),[b,S]=c(!1),C=s(null),T=s(y.notifyTyping);i(()=>{T.current=y.notifyTyping});let E=n(()=>T.current(),[]),D=n(e=>{C.current?.removeEventListener(`input`,E),C.current=e,e?.addEventListener(`input`,E)},[E]),O=y.phase===`ready`&&y.chat!==null,k=y.chat?.state,A=O&&k!==`Closed`,M=Ut(y.assistantTypingUntil)||k===`Assistant`&&y.pending.some(e=>e.status===`sending`),N=Ut(y.agentTypingUntil),P=y.messages.some(e=>e.authorKind===`Customer`)&&!!y.chat?.assistantAvailable;i(()=>{r&&O&&C.current?.focus()},[r,O]);let F=V(`div`,{className:`drawer-header`,children:[V(`div`,{className:`drawer-title`,children:[B(`span`,{className:`drawer-title-ic`,children:B(w,{name:`message-circle`,size:18})}),h]}),V(`div`,{className:`d-flex align-items-center gap-1`,children:[A&&B(p,{variant:`ghost`,size:`sm`,onClick:()=>S(!0),children:`End chat`}),B(l,{icon:`x`,label:`Close`,onClick:a})]})]}),I;return I=y.phase===`error`?V(u,{tone:`danger`,children:[y.startError,B(`div`,{className:`mt-2`,children:B(p,{size:`sm`,variant:`outline`,onClick:y.retryStart,children:`Try again`})})]}):O?V(z,{children:[B(Et,{state:k,closeReason:y.chat.closeReason,agentName:y.chat.agentName,ticketNumber:y.chat.ticketNumber,ticketId:y.chat.ticketId,waitingPosition:y.chat.waitingPosition,canRequestAgent:P,requesting:y.requesting,onRequestAgent:y.requestAgent,onOpenTicket:d,onRestart:y.restart}),B(Pt,{messages:y.messages,pending:y.pending,assistantText:y.assistantText,assistantWriting:M,agentName:y.chat.agentName,agentTyping:N,onRetry:y.retry,onDiscard:y.discard,resolveLink:f,linkComponent:m}),y.notice&&B(u,{tone:`danger`,size:`sm`,children:y.notice})]}):B(`div`,{className:`d-flex justify-content-center py-4`,children:B(j,{label:`Starting your chat`})}),V(z,{children:[B(x,{open:r,onClose:a,sheet:!1,width:g,header:F,footer:A?V(`div`,{className:`d-flex flex-column gap-2`,children:[B(H,{onSubmit:y.send,busy:y.pending.length>0||!!y.assistantText,maxLength:v?.bodyMaxLength??4e3,inputRef:D,labels:Ht}),k===`Assistant`&&B(`p`,{className:`wui-text-xs text-body-secondary mb-0`,children:ae.disclaimer})]}):void 0,ariaLabel:h,onOpened:()=>C.current?.focus(),children:I}),B(_,{open:b,title:`End this chat?`,message:k===`Assistant`?`You can start a new chat whenever you like.`:`Our team can still see this conversation on your ticket.`,confirmLabel:`End chat`,cancelLabel:`Keep chatting`,onConfirm:()=>{S(!1),y.end()},onClose:()=>S(!1)})]})}var Gt={zIndex:`var(--wui-z-fixed)`,bottom:`var(--wui-consent-banner-block, 0px)`},Kt={end:{insetInlineEnd:0},start:{insetInlineStart:0}};function qt({onClick:e,open:t=!1,label:n=`Chat with us`,position:r=`end`,icon:i=`message-circle`,compact:a=!1,className:o,style:s}){return a?B(Jt,{onClick:e,open:t,label:n,position:r,icon:i,className:o,style:s}):B(`span`,{"data-support-capture":`exclude`,className:[`position-fixed m-3`,o].filter(Boolean).join(` `),style:{...Gt,...Kt[r],...s},children:B(p,{leftIcon:i,className:`rounded-pill`,onClick:e,"aria-haspopup":`dialog`,"aria-expanded":t,children:n})})}function Jt({onClick:e,open:t,label:n,position:r,icon:i,className:a,style:o}){let s=F(r);return s?R(B(`span`,{className:[`wui-floating-stack-item wui-floating-stack-item--primary`,a].filter(Boolean).join(` `),style:o,children:B(p,{className:`wui-floating-btn`,onClick:e,"aria-label":n,"aria-haspopup":`dialog`,"aria-expanded":t,tooltip:n,tooltipPlacement:r===`start`?`end`:`start`,children:B(w,{name:i,size:24})})}),s):null}var $=e=>typeof e==`string`&&e.trim()!==``;function Yt({className:e}){let{config:t}=Y();if(!t)return null;let n=[];return $(t.supportEmail)&&n.push({key:`email`,icon:`mail`,label:`Email`,value:V(`span`,{className:`d-inline-flex flex-wrap align-items-center gap-2`,children:[B(`a`,{href:`mailto:${t.supportEmail}`,className:`text-break`,children:t.supportEmail}),B(v,{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:V(`section`,{className:e,"aria-label":$(t.supportName)?`Contact ${t.supportName}`:`Contact support`,children:[$(t.supportName)&&B(`p`,{className:`fw-semibold mb-2`,children:t.supportName}),B(b,{items:n,layout:`list`,columns:1})]})}function Xt({client:e,timeZone:t=ee,renderTime:r,children:i}){let a=s(null),c=n((t=!1)=>{let n=a.current;if(t||!n||n.client!==e){let t=e.getConfig(),n={client:e,pending:t};return a.current=n,t.catch(()=>{a.current===n&&(a.current=null)}),t}return n.pending},[e]),l=o(()=>({client:e,loadConfig:c,timeZone:t,renderTime:r}),[e,c,t,r]);return B(we.Provider,{value:l,children:i})}export{tt as ReportIssue,W as SupportApiError,St as SupportCenter,Wt as SupportChat,qt as SupportChatLauncher,Yt as SupportContact,Xt as SupportProvider,Ce as createSseChatConnection,ge as createSupportChatClient,fe as createSupportClient,J as useSupportClient,Y as useSupportConfig,je as useSupportTicket,Ae as useSupportTicketCounts,ke as useSupportTickets};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A live chat with the support team in a drawer. An AI assistant answers first; the customer can ask
|
|
3
|
+
* for a person, who joins the same conversation. Closing the drawer leaves the chat open.
|
|
4
|
+
*
|
|
5
|
+
* @param {object} props
|
|
6
|
+
* @param {import('./chat/client.js').SupportChatClient} props.chatClient From `createSupportChatClient`.
|
|
7
|
+
* @param {import('./chat/connection.js').SupportChatConnection} props.connection From `createSseChatConnection`.
|
|
8
|
+
* @param {boolean} props.open
|
|
9
|
+
* @param {() => void} props.onClose
|
|
10
|
+
* @param {string} [props.appVersion] The product build, recorded on the chat.
|
|
11
|
+
* @param {(ticket: { id: string, number: string }) => void} [props.onOpenTicket] Shows View ticket when a chat has ended with a ticket.
|
|
12
|
+
* @param {(href: string) => string|null|undefined} [props.resolveLink] See `ChatMarkdown`.
|
|
13
|
+
* @param {import('react').ElementType} [props.linkComponent] A router link (it receives `to`).
|
|
14
|
+
* @param {string} [props.title="Chat with us"]
|
|
15
|
+
* @param {string} [props.width="440px"]
|
|
16
|
+
*/
|
|
17
|
+
export default function SupportChat({ chatClient, connection, open, onClose, appVersion, onOpenTicket, resolveLink, linkComponent, title, width, }: {
|
|
18
|
+
chatClient: import('./chat/client.js').SupportChatClient;
|
|
19
|
+
connection: import('./chat/connection.js').SupportChatConnection;
|
|
20
|
+
open: boolean;
|
|
21
|
+
onClose: () => void;
|
|
22
|
+
appVersion?: string;
|
|
23
|
+
onOpenTicket?: (ticket: {
|
|
24
|
+
id: string;
|
|
25
|
+
number: string;
|
|
26
|
+
}) => void;
|
|
27
|
+
resolveLink?: (href: string) => string | null | undefined;
|
|
28
|
+
linkComponent?: import('react').ElementType;
|
|
29
|
+
title?: string;
|
|
30
|
+
width?: string;
|
|
31
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export declare const meta: {
|
|
2
|
+
readonly name: "SupportChat";
|
|
3
|
+
readonly marker: null;
|
|
4
|
+
readonly platforms: readonly ["web"];
|
|
5
|
+
readonly acceptsChildren: false;
|
|
6
|
+
readonly props: {
|
|
7
|
+
readonly open: {
|
|
8
|
+
readonly type: "boolean";
|
|
9
|
+
readonly description: "Whether the chat drawer is open. Closing it leaves the chat open for the customer to return to.";
|
|
10
|
+
};
|
|
11
|
+
readonly title: {
|
|
12
|
+
readonly type: "string";
|
|
13
|
+
readonly default: "Chat with us";
|
|
14
|
+
readonly description: "The drawer heading.";
|
|
15
|
+
};
|
|
16
|
+
readonly width: {
|
|
17
|
+
readonly type: "string";
|
|
18
|
+
readonly default: "440px";
|
|
19
|
+
readonly description: "The drawer width; the full screen on a phone.";
|
|
20
|
+
};
|
|
21
|
+
readonly appVersion: {
|
|
22
|
+
readonly type: "string";
|
|
23
|
+
readonly description: "The product build, recorded on the chat.";
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
readonly examples: readonly [{
|
|
27
|
+
readonly id: "SupportChat";
|
|
28
|
+
readonly title: "Closed";
|
|
29
|
+
readonly props: {
|
|
30
|
+
readonly open: false;
|
|
31
|
+
};
|
|
32
|
+
}];
|
|
33
|
+
readonly usage: {
|
|
34
|
+
readonly when: readonly ["A portal offers live chat: an AI assistant answers first and the customer can ask for a person in the same conversation.", "The conversation is kept on the customer's support ticket."];
|
|
35
|
+
readonly whenNot: readonly [{
|
|
36
|
+
readonly text: "A one-way report or a long description of a problem.";
|
|
37
|
+
readonly instead: "ReportIssue";
|
|
38
|
+
}];
|
|
39
|
+
readonly do: readonly [];
|
|
40
|
+
readonly dont: readonly [];
|
|
41
|
+
readonly a11y: readonly ["The chat opens as a dialog drawer, focuses the message box and closes on Escape.", "Status changes (waiting, joined, ended) are announced as polite status messages.", "A failed message says so and offers Try again and Discard."];
|
|
42
|
+
};
|
|
43
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The floating pill that opens the support chat, pinned to a bottom corner. `compact` turns it into a
|
|
3
|
+
* 48px icon-only circle in the shared floating stack, with the label as its tooltip and accessible name.
|
|
4
|
+
*
|
|
5
|
+
* @param {object} props
|
|
6
|
+
* @param {() => void} props.onClick Opens the chat.
|
|
7
|
+
* @param {boolean} [props.open=false]
|
|
8
|
+
* @param {string} [props.label="Chat with us"]
|
|
9
|
+
* @param {"end"|"start"} [props.position="end"]
|
|
10
|
+
* @param {string} [props.icon="message-circle"]
|
|
11
|
+
* @param {boolean} [props.compact=false]
|
|
12
|
+
* @param {string} [props.className]
|
|
13
|
+
* @param {import('react').CSSProperties} [props.style] Merged over the wrapper's own style.
|
|
14
|
+
*/
|
|
15
|
+
export default function SupportChatLauncher({ onClick, open, label, position, icon, compact, className, style, }: {
|
|
16
|
+
onClick: () => void;
|
|
17
|
+
open?: boolean;
|
|
18
|
+
label?: string;
|
|
19
|
+
position?: "end" | "start";
|
|
20
|
+
icon?: string;
|
|
21
|
+
compact?: boolean;
|
|
22
|
+
className?: string;
|
|
23
|
+
style?: import('react').CSSProperties;
|
|
24
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export declare const meta: {
|
|
2
|
+
readonly name: "SupportChatLauncher";
|
|
3
|
+
readonly marker: null;
|
|
4
|
+
readonly platforms: readonly ["web"];
|
|
5
|
+
readonly acceptsChildren: false;
|
|
6
|
+
readonly props: {
|
|
7
|
+
readonly open: {
|
|
8
|
+
readonly type: "boolean";
|
|
9
|
+
readonly default: false;
|
|
10
|
+
readonly description: "Whether the chat is open. It is announced on the button.";
|
|
11
|
+
};
|
|
12
|
+
readonly label: {
|
|
13
|
+
readonly type: "string";
|
|
14
|
+
readonly default: "Chat with us";
|
|
15
|
+
readonly description: "The button text; the accessible name and tooltip in compact mode.";
|
|
16
|
+
};
|
|
17
|
+
readonly position: {
|
|
18
|
+
readonly type: "enum";
|
|
19
|
+
readonly values: readonly ["end", "start"];
|
|
20
|
+
readonly default: "end";
|
|
21
|
+
readonly description: "The bottom corner the launcher sits in.";
|
|
22
|
+
};
|
|
23
|
+
readonly icon: {
|
|
24
|
+
readonly type: "string";
|
|
25
|
+
readonly default: "message-circle";
|
|
26
|
+
readonly description: "A library icon name.";
|
|
27
|
+
};
|
|
28
|
+
readonly compact: {
|
|
29
|
+
readonly type: "boolean";
|
|
30
|
+
readonly default: false;
|
|
31
|
+
readonly description: "Shows an icon-only circle stacked in the shared floating corner container, with the label as its tooltip.";
|
|
32
|
+
};
|
|
33
|
+
readonly className: {
|
|
34
|
+
readonly type: "string";
|
|
35
|
+
readonly description: "Added to the floating wrapper.";
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
readonly omit: readonly ["style"];
|
|
39
|
+
readonly examples: readonly [{
|
|
40
|
+
readonly id: "SupportChatLauncher";
|
|
41
|
+
readonly title: "Default";
|
|
42
|
+
readonly props: {};
|
|
43
|
+
}];
|
|
44
|
+
readonly usage: {
|
|
45
|
+
readonly when: readonly ["The floating pill that opens the support chat, pinned to a bottom corner."];
|
|
46
|
+
readonly whenNot: readonly [];
|
|
47
|
+
readonly do: readonly [];
|
|
48
|
+
readonly dont: readonly [];
|
|
49
|
+
readonly a11y: readonly ["The button announces that it opens a dialog (aria-haspopup) and whether it is open (aria-expanded).", "The default pill shows the label as its button text.", "The compact circle takes the label as its accessible name and as its tooltip."];
|
|
50
|
+
};
|
|
51
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type SupportChatClient = {
|
|
2
|
+
/**
|
|
3
|
+
* Resolves to the customer's chat: a new one (201) or the open one (200). The client does not tell them apart.
|
|
4
|
+
*/
|
|
5
|
+
start: (context: object) => Promise<import("./types.js").SupportChatView>;
|
|
6
|
+
current: () => Promise<import("./types.js").SupportChatView>;
|
|
7
|
+
get: (chatId: string) => Promise<import("./types.js").SupportChatView>;
|
|
8
|
+
/**
|
|
9
|
+
* The idempotency key is created once per composed message and reused on every retry.
|
|
10
|
+
*/
|
|
11
|
+
send: (chatId: string, input: {
|
|
12
|
+
body: string;
|
|
13
|
+
files?: File[];
|
|
14
|
+
idempotencyKey: string;
|
|
15
|
+
}) => Promise<import("./types.js").SupportChatPosted>;
|
|
16
|
+
/**
|
|
17
|
+
* Resolves to the updated view.
|
|
18
|
+
*/
|
|
19
|
+
requestAgent: (chatId: string) => Promise<import("./types.js").SupportChatView>;
|
|
20
|
+
typing: (chatId: string) => Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Resolves to the updated view.
|
|
23
|
+
*/
|
|
24
|
+
close: (chatId: string) => Promise<import("./types.js").SupportChatView>;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Binds the support chat HTTP contract to the product's own authenticated client.
|
|
28
|
+
*
|
|
29
|
+
* @param {{ http: object, baseUrl?: string }} options
|
|
30
|
+
* @returns {SupportChatClient}
|
|
31
|
+
*/
|
|
32
|
+
export declare function createSupportChatClient({ http, baseUrl }: {
|
|
33
|
+
http: object;
|
|
34
|
+
baseUrl?: string;
|
|
35
|
+
}): SupportChatClient;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const MAX_RECONNECT_ATTEMPTS = 10;
|
|
2
|
+
export type SupportChatHandlers = {
|
|
3
|
+
onSnapshot: (chat: import("./types.js").SupportChatSnapshotEvent) => void;
|
|
4
|
+
onMessage: (event: import("./types.js").SupportChatMessageEvent) => void;
|
|
5
|
+
onState: (event: import("./types.js").SupportChatStateEvent) => void;
|
|
6
|
+
onTyping: (event: import("./types.js").SupportChatTypingEvent) => void;
|
|
7
|
+
onDelta: (event: import("./types.js").SupportChatDeltaEvent) => void;
|
|
8
|
+
onError: (event: import("./types.js").SupportChatErrorEvent) => void;
|
|
9
|
+
};
|
|
10
|
+
export type SupportChatConnection = {
|
|
11
|
+
watch: (chatId: string, afterSequence: number | null, handlers: SupportChatHandlers) => () => void;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* The shipped connection: the support event stream over the app's signed-in HTTP client, resumed from the last sequence.
|
|
15
|
+
*
|
|
16
|
+
* @param {{ http: object, baseUrl?: string, retryDelaysMs?: number[], stallTimeoutMs?: number }} options
|
|
17
|
+
* @returns {SupportChatConnection}
|
|
18
|
+
*/
|
|
19
|
+
export declare function createSseChatConnection({ http, baseUrl, retryDelaysMs, stallTimeoutMs }: {
|
|
20
|
+
http: object;
|
|
21
|
+
baseUrl?: string;
|
|
22
|
+
retryDelaysMs?: number[];
|
|
23
|
+
stallTimeoutMs?: number;
|
|
24
|
+
}): SupportChatConnection;
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire shapes of the live support chat. Field names are the camelCase of the backend view records in
|
|
3
|
+
* `Webority.Support/SupportChatViews.cs`; enums travel as their member names.
|
|
4
|
+
*/
|
|
5
|
+
export type SupportMessageAuthorKind = "Customer" | "Agent" | "System" | "Assistant";
|
|
6
|
+
export type SupportChatState = "Assistant" | "WaitingForAgent" | "WithAgent" | "Closed";
|
|
7
|
+
export type SupportChatCloseReason = "CustomerEnded" | "AgentEnded" | "NoAgentAvailable" | "Idle";
|
|
8
|
+
export type SupportChatMessageView = {
|
|
9
|
+
id: string;
|
|
10
|
+
sequence: number;
|
|
11
|
+
authorKind: SupportMessageAuthorKind;
|
|
12
|
+
authorName: string | null;
|
|
13
|
+
body: string;
|
|
14
|
+
attachments: {
|
|
15
|
+
id: string;
|
|
16
|
+
fileName: string;
|
|
17
|
+
contentType: string;
|
|
18
|
+
sizeBytes: number;
|
|
19
|
+
kind: string;
|
|
20
|
+
}[];
|
|
21
|
+
createdDateTimeUtc: string;
|
|
22
|
+
};
|
|
23
|
+
export type SupportChatView = {
|
|
24
|
+
id: string;
|
|
25
|
+
state: SupportChatState;
|
|
26
|
+
closeReason: SupportChatCloseReason | null;
|
|
27
|
+
sequence: number;
|
|
28
|
+
ticketId: string | null;
|
|
29
|
+
ticketNumber: string | null;
|
|
30
|
+
agentName: string | null;
|
|
31
|
+
assistantAvailable: boolean;
|
|
32
|
+
assistantAnswering: boolean;
|
|
33
|
+
customerTypingUntilDateTimeUtc: string | null;
|
|
34
|
+
agentTypingUntilDateTimeUtc: string | null;
|
|
35
|
+
waitingSinceDateTimeUtc: string | null;
|
|
36
|
+
waitingPosition: number | null;
|
|
37
|
+
messages: SupportChatMessageView[];
|
|
38
|
+
createdDateTimeUtc: string;
|
|
39
|
+
};
|
|
40
|
+
export type SupportChatPosted = {
|
|
41
|
+
message: SupportChatMessageView;
|
|
42
|
+
reply: SupportChatMessageView | null;
|
|
43
|
+
/**
|
|
44
|
+
* True when the idempotency key had already been used, so nothing new was stored.
|
|
45
|
+
*/
|
|
46
|
+
replayed: boolean;
|
|
47
|
+
};
|
|
48
|
+
export type SupportChatQueueItem = {
|
|
49
|
+
chatId: string;
|
|
50
|
+
ticketId: string;
|
|
51
|
+
ticketNumber: string;
|
|
52
|
+
queue: string;
|
|
53
|
+
reporterName: string;
|
|
54
|
+
subject: string;
|
|
55
|
+
state: SupportChatState;
|
|
56
|
+
waitingSinceDateTimeUtc: string | null;
|
|
57
|
+
sequence: number;
|
|
58
|
+
};
|
|
59
|
+
export type SupportChatSnapshotEvent = SupportChatView;
|
|
60
|
+
export type SupportChatMessageEvent = {
|
|
61
|
+
chatId: string;
|
|
62
|
+
message: SupportChatMessageView;
|
|
63
|
+
};
|
|
64
|
+
export type SupportChatStateEvent = {
|
|
65
|
+
chatId: string;
|
|
66
|
+
state: SupportChatState;
|
|
67
|
+
closeReason: SupportChatCloseReason | null;
|
|
68
|
+
ticketId: string | null;
|
|
69
|
+
ticketNumber: string | null;
|
|
70
|
+
agentName: string | null;
|
|
71
|
+
waitingPosition: number | null;
|
|
72
|
+
};
|
|
73
|
+
export type SupportChatTypingEvent = {
|
|
74
|
+
chatId: string;
|
|
75
|
+
who: "Customer" | "Agent" | "Assistant";
|
|
76
|
+
untilDateTimeUtc: string;
|
|
77
|
+
};
|
|
78
|
+
export type SupportChatDeltaEvent = {
|
|
79
|
+
chatId: string;
|
|
80
|
+
text: string;
|
|
81
|
+
};
|
|
82
|
+
export type SupportChatQueueEvent = {
|
|
83
|
+
waiting: SupportChatQueueItem[];
|
|
84
|
+
mine: SupportChatQueueItem[];
|
|
85
|
+
};
|
|
86
|
+
export type SupportChatErrorEvent = {
|
|
87
|
+
code: string;
|
|
88
|
+
message: string;
|
|
89
|
+
};
|
|
90
|
+
/** @typedef {"Customer"|"Agent"|"System"|"Assistant"} SupportMessageAuthorKind */
|
|
91
|
+
/** @typedef {"Assistant"|"WaitingForAgent"|"WithAgent"|"Closed"} SupportChatState */
|
|
92
|
+
/** @typedef {"CustomerEnded"|"AgentEnded"|"NoAgentAvailable"|"Idle"} SupportChatCloseReason */
|
|
93
|
+
/**
|
|
94
|
+
* @typedef {object} SupportChatMessageView
|
|
95
|
+
* @property {string} id
|
|
96
|
+
* @property {number} sequence
|
|
97
|
+
* @property {SupportMessageAuthorKind} authorKind
|
|
98
|
+
* @property {string|null} authorName
|
|
99
|
+
* @property {string} body
|
|
100
|
+
* @property {{ id: string, fileName: string, contentType: string, sizeBytes: number, kind: string }[]} attachments
|
|
101
|
+
* @property {string} createdDateTimeUtc
|
|
102
|
+
*/
|
|
103
|
+
/**
|
|
104
|
+
* @typedef {object} SupportChatView
|
|
105
|
+
* @property {string} id
|
|
106
|
+
* @property {SupportChatState} state
|
|
107
|
+
* @property {SupportChatCloseReason|null} closeReason
|
|
108
|
+
* @property {number} sequence
|
|
109
|
+
* @property {string|null} ticketId
|
|
110
|
+
* @property {string|null} ticketNumber
|
|
111
|
+
* @property {string|null} agentName
|
|
112
|
+
* @property {boolean} assistantAvailable
|
|
113
|
+
* @property {boolean} assistantAnswering
|
|
114
|
+
* @property {string|null} customerTypingUntilDateTimeUtc
|
|
115
|
+
* @property {string|null} agentTypingUntilDateTimeUtc
|
|
116
|
+
* @property {string|null} waitingSinceDateTimeUtc
|
|
117
|
+
* @property {number|null} waitingPosition
|
|
118
|
+
* @property {SupportChatMessageView[]} messages
|
|
119
|
+
* @property {string} createdDateTimeUtc
|
|
120
|
+
*/
|
|
121
|
+
/**
|
|
122
|
+
* The answer to posting a message: the customer's line, and the assistant's reply when it answered at once.
|
|
123
|
+
* @typedef {object} SupportChatPosted
|
|
124
|
+
* @property {SupportChatMessageView} message
|
|
125
|
+
* @property {SupportChatMessageView|null} reply
|
|
126
|
+
* @property {boolean} replayed True when the idempotency key had already been used, so nothing new was stored.
|
|
127
|
+
*/
|
|
128
|
+
/**
|
|
129
|
+
* One row of the agent queue.
|
|
130
|
+
* @typedef {object} SupportChatQueueItem
|
|
131
|
+
* @property {string} chatId
|
|
132
|
+
* @property {string} ticketId
|
|
133
|
+
* @property {string} ticketNumber
|
|
134
|
+
* @property {string} queue
|
|
135
|
+
* @property {string} reporterName
|
|
136
|
+
* @property {string} subject
|
|
137
|
+
* @property {SupportChatState} state
|
|
138
|
+
* @property {string|null} waitingSinceDateTimeUtc
|
|
139
|
+
* @property {number} sequence
|
|
140
|
+
*/
|
|
141
|
+
/**
|
|
142
|
+
* The `snapshot` event: the whole chat, sent first when the client gives no cursor.
|
|
143
|
+
* @typedef {SupportChatView} SupportChatSnapshotEvent
|
|
144
|
+
*/
|
|
145
|
+
/**
|
|
146
|
+
* The `message` event.
|
|
147
|
+
* @typedef {object} SupportChatMessageEvent
|
|
148
|
+
* @property {string} chatId
|
|
149
|
+
* @property {SupportChatMessageView} message
|
|
150
|
+
*/
|
|
151
|
+
/**
|
|
152
|
+
* The `state` event.
|
|
153
|
+
* @typedef {object} SupportChatStateEvent
|
|
154
|
+
* @property {string} chatId
|
|
155
|
+
* @property {SupportChatState} state
|
|
156
|
+
* @property {SupportChatCloseReason|null} closeReason
|
|
157
|
+
* @property {string|null} ticketId
|
|
158
|
+
* @property {string|null} ticketNumber
|
|
159
|
+
* @property {string|null} agentName
|
|
160
|
+
* @property {number|null} waitingPosition
|
|
161
|
+
*/
|
|
162
|
+
/**
|
|
163
|
+
* The `typing` event.
|
|
164
|
+
* @typedef {object} SupportChatTypingEvent
|
|
165
|
+
* @property {string} chatId
|
|
166
|
+
* @property {"Customer"|"Agent"|"Assistant"} who
|
|
167
|
+
* @property {string} untilDateTimeUtc
|
|
168
|
+
*/
|
|
169
|
+
/**
|
|
170
|
+
* The `delta` event: assistant text to append while it is written. Never stored.
|
|
171
|
+
* @typedef {object} SupportChatDeltaEvent
|
|
172
|
+
* @property {string} chatId
|
|
173
|
+
* @property {string} text
|
|
174
|
+
*/
|
|
175
|
+
/**
|
|
176
|
+
* The `queue` event, on the agent stream only: sent when either list changed.
|
|
177
|
+
* @typedef {object} SupportChatQueueEvent
|
|
178
|
+
* @property {SupportChatQueueItem[]} waiting
|
|
179
|
+
* @property {SupportChatQueueItem[]} mine
|
|
180
|
+
*/
|
|
181
|
+
/**
|
|
182
|
+
* The `error` event. The server ends the stream after it; the client reconnects.
|
|
183
|
+
* @typedef {object} SupportChatErrorEvent
|
|
184
|
+
* @property {string} code
|
|
185
|
+
* @property {string} message
|
|
186
|
+
*/
|
|
187
|
+
export {};
|
package/dist/types/client.d.ts
CHANGED
|
@@ -87,6 +87,9 @@ export type SupportClient = {
|
|
|
87
87
|
listTickets: (query?: TicketListQuery) => Promise<TicketPage>;
|
|
88
88
|
getTicketCounts: () => Promise<TicketCounts>;
|
|
89
89
|
getTicket: (id: string) => Promise<any>;
|
|
90
|
+
/**
|
|
91
|
+
* A retry of the same message reuses its key.
|
|
92
|
+
*/
|
|
90
93
|
createTicket: (input: NewTicketInput) => Promise<any>;
|
|
91
94
|
/**
|
|
92
95
|
* Known answers for a subject the person is about to raise; resolves to none when the server predates the route.
|
|
@@ -94,6 +97,9 @@ export type SupportClient = {
|
|
|
94
97
|
getSuggestions: (subject: string, options?: {
|
|
95
98
|
signal?: AbortSignal;
|
|
96
99
|
}) => Promise<SupportSuggestedArticle[]>;
|
|
100
|
+
/**
|
|
101
|
+
* A retry of the same message reuses its key.
|
|
102
|
+
*/
|
|
97
103
|
reply: (id: string, input: ReplyInput) => Promise<any>;
|
|
98
104
|
reopen: (id: string) => Promise<any>;
|
|
99
105
|
/**
|
|
@@ -173,10 +179,10 @@ export type SupportClient = {
|
|
|
173
179
|
* @property {(query?: TicketListQuery) => Promise<TicketPage>} listTickets
|
|
174
180
|
* @property {() => Promise<TicketCounts>} getTicketCounts
|
|
175
181
|
* @property {(id: string) => Promise<any>} getTicket
|
|
176
|
-
* @property {(input: NewTicketInput) => Promise<any>} createTicket
|
|
182
|
+
* @property {(input: NewTicketInput) => Promise<any>} createTicket A retry of the same message reuses its key.
|
|
177
183
|
* @property {(subject: string, options?: { signal?: AbortSignal }) => Promise<SupportSuggestedArticle[]>} getSuggestions
|
|
178
184
|
* Known answers for a subject the person is about to raise; resolves to none when the server predates the route.
|
|
179
|
-
* @property {(id: string, input: ReplyInput) => Promise<any>} reply
|
|
185
|
+
* @property {(id: string, input: ReplyInput) => Promise<any>} reply A retry of the same message reuses its key.
|
|
180
186
|
* @property {(id: string) => Promise<any>} reopen
|
|
181
187
|
* @property {(id: string) => Promise<any>} cancel Withdraws the ticket; resolves to the updated ticket.
|
|
182
188
|
* @property {(id: string, input: RatingInput) => Promise<any>} rate
|
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
* @param {string} props.ticketId
|
|
6
6
|
* @param {() => void} props.onBack Return to the ticket list.
|
|
7
7
|
* @param {() => void} [props.onChanged] The ticket changed (reply, reopen, rating), so a list can refresh.
|
|
8
|
+
* @param {(ticketId: string) => void} [props.onOpenTicket] Open another of the customer's tickets (the one this was merged into, or one merged into it).
|
|
8
9
|
*/
|
|
9
|
-
export default function TicketDetail({ ticketId, onBack, onChanged }: {
|
|
10
|
+
export default function TicketDetail({ ticketId, onBack, onChanged, onOpenTicket }: {
|
|
10
11
|
ticketId: string;
|
|
11
12
|
onBack: () => void;
|
|
12
13
|
onChanged?: () => void;
|
|
14
|
+
onOpenTicket?: (ticketId: string) => void;
|
|
13
15
|
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The line above the transcript: who the customer is talking to, what the queue position is, and
|
|
3
|
+
* how the chat ended, with the ticket it was kept on.
|
|
4
|
+
*
|
|
5
|
+
* @param {object} props
|
|
6
|
+
* @param {"Assistant"|"WaitingForAgent"|"WithAgent"|"Closed"} props.state
|
|
7
|
+
* @param {string|null} [props.closeReason]
|
|
8
|
+
* @param {string|null} [props.agentName]
|
|
9
|
+
* @param {string|null} [props.ticketNumber]
|
|
10
|
+
* @param {string|null} [props.ticketId]
|
|
11
|
+
* @param {number|null} [props.waitingPosition]
|
|
12
|
+
* @param {boolean} [props.canRequestAgent]
|
|
13
|
+
* @param {boolean} [props.requesting]
|
|
14
|
+
* @param {() => void} props.onRequestAgent
|
|
15
|
+
* @param {((ticket: { id: string, number: string }) => void)} [props.onOpenTicket]
|
|
16
|
+
* @param {() => void} props.onRestart
|
|
17
|
+
*/
|
|
18
|
+
export default function ChatStatusBar({ state, closeReason, agentName, ticketNumber, ticketId, waitingPosition, canRequestAgent, requesting, onRequestAgent, onOpenTicket, onRestart, }: {
|
|
19
|
+
state: "Assistant" | "WaitingForAgent" | "WithAgent" | "Closed";
|
|
20
|
+
closeReason?: string | null;
|
|
21
|
+
agentName?: string | null;
|
|
22
|
+
ticketNumber?: string | null;
|
|
23
|
+
ticketId?: string | null;
|
|
24
|
+
waitingPosition?: number | null;
|
|
25
|
+
canRequestAgent?: boolean;
|
|
26
|
+
requesting?: boolean;
|
|
27
|
+
onRequestAgent: () => void;
|
|
28
|
+
onOpenTicket?: ((ticket: {
|
|
29
|
+
id: string;
|
|
30
|
+
number: string;
|
|
31
|
+
}) => void);
|
|
32
|
+
onRestart: () => void;
|
|
33
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The support chat's conversation, oldest line first: customer, assistant, support team and system
|
|
3
|
+
* lines, the customer's messages still sending or failed, and the assistant's answer as it streams.
|
|
4
|
+
*
|
|
5
|
+
* @param {object} props
|
|
6
|
+
* @param {object[]} props.messages
|
|
7
|
+
* @param {{ localId: string, body: string, status: "sending"|"failed", error: string }[]} props.pending
|
|
8
|
+
* @param {string} props.assistantText
|
|
9
|
+
* @param {boolean} props.assistantWriting
|
|
10
|
+
* @param {string|null} [props.agentName]
|
|
11
|
+
* @param {boolean} props.agentTyping
|
|
12
|
+
* @param {(localId: string) => void} props.onRetry
|
|
13
|
+
* @param {(localId: string) => void} props.onDiscard
|
|
14
|
+
* @param {(href: string) => string|null|undefined} [props.resolveLink]
|
|
15
|
+
* @param {import('react').ElementType} [props.linkComponent]
|
|
16
|
+
*/
|
|
17
|
+
export default function ChatTranscript({ messages, pending, assistantText, assistantWriting, agentName, agentTyping, onRetry, onDiscard, resolveLink, linkComponent, }: {
|
|
18
|
+
messages: object[];
|
|
19
|
+
pending: {
|
|
20
|
+
localId: string;
|
|
21
|
+
body: string;
|
|
22
|
+
status: "sending" | "failed";
|
|
23
|
+
error: string;
|
|
24
|
+
}[];
|
|
25
|
+
assistantText: string;
|
|
26
|
+
assistantWriting: boolean;
|
|
27
|
+
agentName?: string | null;
|
|
28
|
+
agentTyping: boolean;
|
|
29
|
+
onRetry: (localId: string) => void;
|
|
30
|
+
onDiscard: (localId: string) => void;
|
|
31
|
+
resolveLink?: (href: string) => string | null | undefined;
|
|
32
|
+
linkComponent?: import('react').ElementType;
|
|
33
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The notice while a customer waits for a person: where they stand in the queue, when the queue
|
|
3
|
+
* position is known.
|
|
4
|
+
*
|
|
5
|
+
* @param {object} props
|
|
6
|
+
* @param {number|null} props.position Chats ahead of this one, or null when unknown.
|
|
7
|
+
*/
|
|
8
|
+
export default function WaitingNotice({ position }: {
|
|
9
|
+
position: number | null;
|
|
10
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The state of one support chat while its drawer is open: the start, the live event stream, the
|
|
3
|
+
* customer's messages that are still sending, and the actions on the chat.
|
|
4
|
+
*
|
|
5
|
+
* @param {object} options
|
|
6
|
+
* @param {import('../../chat/client.js').SupportChatClient} options.chatClient
|
|
7
|
+
* @param {import('../../chat/connection.js').SupportChatConnection} options.connection
|
|
8
|
+
* @param {boolean} options.open
|
|
9
|
+
* @param {string} [options.appVersion]
|
|
10
|
+
*/
|
|
11
|
+
export declare function useSupportChatSession({ chatClient, connection, open, appVersion }: {
|
|
12
|
+
chatClient: import('../../chat/client.js').SupportChatClient;
|
|
13
|
+
connection: import('../../chat/connection.js').SupportChatConnection;
|
|
14
|
+
open: boolean;
|
|
15
|
+
appVersion?: string;
|
|
16
|
+
}): {
|
|
17
|
+
phase: string;
|
|
18
|
+
startError: string;
|
|
19
|
+
chat: null;
|
|
20
|
+
messages: never[];
|
|
21
|
+
pending: never[];
|
|
22
|
+
assistantText: string;
|
|
23
|
+
agentTypingUntil: null;
|
|
24
|
+
assistantTypingUntil: null;
|
|
25
|
+
notice: string;
|
|
26
|
+
requesting: boolean;
|
|
27
|
+
send: (body: any) => void;
|
|
28
|
+
retry: (localId: any) => void;
|
|
29
|
+
discard: (localId: any) => void;
|
|
30
|
+
requestAgent: () => Promise<void>;
|
|
31
|
+
end: () => Promise<void>;
|
|
32
|
+
restart: () => void;
|
|
33
|
+
retryStart: () => void;
|
|
34
|
+
notifyTyping: () => void;
|
|
35
|
+
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
export { createSupportChatClient } from "./chat/client.js";
|
|
2
|
+
export { createSseChatConnection } from "./chat/connection.js";
|
|
1
3
|
export { createSupportClient, SupportApiError } from "./client.js";
|
|
2
4
|
export { useSupportClient, useSupportConfig, useSupportTicket, useSupportTicketCounts, useSupportTickets } from "./context.js";
|
|
3
5
|
export { default as ReportIssue } from "./ReportIssue.jsx";
|
|
4
6
|
export { default as SupportCenter } from "./SupportCenter.jsx";
|
|
7
|
+
export { default as SupportChat } from "./SupportChat.jsx";
|
|
8
|
+
export { default as SupportChatLauncher } from "./SupportChatLauncher.jsx";
|
|
5
9
|
export { default as SupportContact } from "./SupportContact.jsx";
|
|
6
10
|
export { default as SupportProvider } from "./SupportProvider.jsx";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webority/support-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.120.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,8 +27,9 @@
|
|
|
27
27
|
},
|
|
28
28
|
"sideEffects": false,
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@webority/
|
|
31
|
-
"@webority/ui-
|
|
30
|
+
"@webority/chat-react": "0.120.0",
|
|
31
|
+
"@webority/ui-elements": "0.120.0",
|
|
32
|
+
"@webority/ui-react": "0.120.0",
|
|
32
33
|
"bootstrap": "5.3.3",
|
|
33
34
|
"react": "^19.0.0",
|
|
34
35
|
"react-bootstrap": "^2.10.0",
|
|
@@ -42,9 +43,10 @@
|
|
|
42
43
|
"@types/react": "^19.2.17",
|
|
43
44
|
"@vitejs/plugin-react": "^6.0.1",
|
|
44
45
|
"@vitest/coverage-v8": "5.0.1",
|
|
45
|
-
"@webority/canvas-kit": "0.
|
|
46
|
-
"@webority/
|
|
47
|
-
"@webority/ui-
|
|
46
|
+
"@webority/canvas-kit": "0.120.0",
|
|
47
|
+
"@webority/chat-react": "0.120.0",
|
|
48
|
+
"@webority/ui-elements": "0.120.0",
|
|
49
|
+
"@webority/ui-react": "0.120.0",
|
|
48
50
|
"bootstrap": "5.3.3",
|
|
49
51
|
"jsdom": "30.1.1",
|
|
50
52
|
"react": "^19.2.6",
|