@burdenoff/microfe-support 2026.529.1 → 2026.530.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/support/components/tickets/MessageComposer.js +92 -86
- package/dist/support/components/tickets/MessageComposer.js.map +1 -1
- package/dist/support/pages/CreateTicketPage.js +106 -104
- package/dist/support/pages/CreateTicketPage.js.map +1 -1
- package/dist/support/utils/attachments.js +49 -0
- package/dist/support/utils/attachments.js.map +1 -0
- package/package.json +1 -1
|
@@ -1,124 +1,130 @@
|
|
|
1
1
|
import { tWithFallback as e } from "../../utils/i18n.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { SUPPORT_ATTACHMENT_ACCEPT as t, partitionAttachments as n, rejectedAttachmentsMessage as r } from "../../utils/attachments.js";
|
|
3
|
+
import { useEffect as i, useRef as a, useState as o } from "react";
|
|
4
|
+
import { Loader2 as s, Lock as c, Paperclip as l, Send as u } from "lucide-react";
|
|
5
|
+
import { Fragment as d, jsx as f, jsxs as p } from "react/jsx-runtime";
|
|
6
|
+
import { useI18n as m } from "@burdenoff/fe-libs/shared/providers/shell/I18nProvider";
|
|
6
7
|
//#region src/support/components/tickets/MessageComposer.tsx
|
|
7
|
-
var
|
|
8
|
-
let { t:
|
|
9
|
-
|
|
10
|
-
let e =
|
|
8
|
+
var h = [], g = ({ ticketId: g, onSendMessage: _, placeholder: v = "Type your message...", disabled: y = !1, allowInternalNotes: b = !1, cannedResponses: x = h, cannedResponsesLoading: S = !1 }) => {
|
|
9
|
+
let { t: C } = m(), [w, T] = o(""), [E, D] = o(!1), [O, k] = o(!1), [A, j] = o([]), [M, N] = o(null), P = a(null), F = a(null);
|
|
10
|
+
i(() => {
|
|
11
|
+
let e = P.current;
|
|
11
12
|
e && (e.style.height = "auto", e.style.height = `${e.scrollHeight}px`);
|
|
12
|
-
}, [
|
|
13
|
-
let
|
|
14
|
-
if (e.preventDefault(), !(!
|
|
15
|
-
|
|
13
|
+
}, [w]);
|
|
14
|
+
let I = async (e) => {
|
|
15
|
+
if (e.preventDefault(), !(!w.trim() && A.length === 0 || O)) {
|
|
16
|
+
k(!0);
|
|
16
17
|
try {
|
|
17
|
-
let e = await
|
|
18
|
-
e?.preserveMessage ||
|
|
18
|
+
let e = await _(w.trim(), E, A);
|
|
19
|
+
e?.preserveMessage || T(""), D(!1), e?.preserveAttachedFiles || (j([]), N(null));
|
|
19
20
|
} catch (e) {
|
|
20
21
|
console.error("Failed to send message:", e);
|
|
21
22
|
} finally {
|
|
22
|
-
|
|
23
|
+
k(!1);
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
|
-
},
|
|
26
|
-
e.key === "Enter" && !e.shiftKey && (e.preventDefault(),
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
},
|
|
30
|
-
let t = Array.from(e.target.files || []);
|
|
31
|
-
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
},
|
|
35
|
-
let t =
|
|
36
|
-
t && (
|
|
26
|
+
}, L = (e) => {
|
|
27
|
+
e.key === "Enter" && !e.shiftKey && (e.preventDefault(), I(e));
|
|
28
|
+
}, R = () => {
|
|
29
|
+
F.current?.click();
|
|
30
|
+
}, z = (e) => {
|
|
31
|
+
let { accepted: t, rejected: i } = n(Array.from(e.target.files || []));
|
|
32
|
+
t.length > 0 && j((e) => [...e, ...t]), N(i.length > 0 ? r(i) : null), e.target.value = "";
|
|
33
|
+
}, B = (e) => {
|
|
34
|
+
j((t) => t.filter((t, n) => n !== e)), N(null);
|
|
35
|
+
}, V = (e) => {
|
|
36
|
+
let t = x.find((t) => t.id === e);
|
|
37
|
+
t && (T((e) => {
|
|
37
38
|
let n = e.trimEnd();
|
|
38
39
|
return n ? `${n}\n\n${t.content}` : t.content;
|
|
39
|
-
}), requestAnimationFrame(() =>
|
|
40
|
+
}), requestAnimationFrame(() => P.current?.focus()));
|
|
40
41
|
};
|
|
41
|
-
return /* @__PURE__ */
|
|
42
|
+
return /* @__PURE__ */ f("div", {
|
|
42
43
|
"data-tour": "support-ticket-message-composer",
|
|
43
44
|
className: "shrink-0 border-t border-border bg-background",
|
|
44
|
-
children: /* @__PURE__ */
|
|
45
|
-
onSubmit:
|
|
45
|
+
children: /* @__PURE__ */ p("form", {
|
|
46
|
+
onSubmit: I,
|
|
46
47
|
className: "p-4",
|
|
47
48
|
children: [
|
|
48
|
-
|
|
49
|
+
b && /* @__PURE__ */ f("div", {
|
|
49
50
|
className: "flex items-center gap-2 mb-3",
|
|
50
|
-
children: /* @__PURE__ */
|
|
51
|
+
children: /* @__PURE__ */ p("label", {
|
|
51
52
|
className: "flex items-center gap-2 cursor-pointer",
|
|
52
|
-
children: [/* @__PURE__ */
|
|
53
|
+
children: [/* @__PURE__ */ f("input", {
|
|
53
54
|
type: "checkbox",
|
|
54
55
|
"aria-label": "Internal note",
|
|
55
|
-
checked:
|
|
56
|
-
onChange: (e) =>
|
|
56
|
+
checked: E,
|
|
57
|
+
onChange: (e) => D(e.target.checked),
|
|
57
58
|
className: "rounded border-border",
|
|
58
|
-
disabled:
|
|
59
|
-
}), /* @__PURE__ */
|
|
59
|
+
disabled: y
|
|
60
|
+
}), /* @__PURE__ */ p("span", {
|
|
60
61
|
className: "text-sm flex items-center gap-1 text-muted-foreground",
|
|
61
|
-
children: [/* @__PURE__ */
|
|
62
|
+
children: [/* @__PURE__ */ f(c, { size: 14 }), e(C, "support.messageComposer.internalNote", "Internal Note (not visible to customer)")]
|
|
62
63
|
})]
|
|
63
64
|
})
|
|
64
65
|
}),
|
|
65
|
-
|
|
66
|
+
b && /* @__PURE__ */ p("div", {
|
|
66
67
|
className: "mb-3 flex flex-col gap-1 sm:max-w-sm",
|
|
67
|
-
children: [/* @__PURE__ */
|
|
68
|
+
children: [/* @__PURE__ */ f("label", {
|
|
68
69
|
htmlFor: "support-canned-response",
|
|
69
70
|
className: "text-sm font-medium text-foreground",
|
|
70
|
-
children: e(
|
|
71
|
-
}), /* @__PURE__ */
|
|
71
|
+
children: e(C, "support.messageComposer.cannedResponses", "Canned responses")
|
|
72
|
+
}), /* @__PURE__ */ p("select", {
|
|
72
73
|
id: "support-canned-response",
|
|
73
74
|
value: "",
|
|
74
|
-
onChange: (e) =>
|
|
75
|
-
disabled:
|
|
75
|
+
onChange: (e) => V(e.target.value),
|
|
76
|
+
disabled: y || O || S || x.length === 0,
|
|
76
77
|
className: "rounded-lg border border-border bg-background px-3 py-2 text-sm text-foreground transition-colors focus:border-primary focus:outline-none focus:ring-2 focus:ring-primary/20 disabled:cursor-not-allowed disabled:opacity-50",
|
|
77
|
-
children: [/* @__PURE__ */
|
|
78
|
+
children: [/* @__PURE__ */ f("option", {
|
|
78
79
|
value: "",
|
|
79
|
-
children:
|
|
80
|
-
}),
|
|
80
|
+
children: S ? e(C, "support.messageComposer.loadingCannedResponses", "Loading saved replies...") : x.length > 0 ? e(C, "support.messageComposer.selectCannedResponse", "Insert a saved reply") : e(C, "support.messageComposer.noCannedResponses", "No saved replies available")
|
|
81
|
+
}), x.map((e) => /* @__PURE__ */ f("option", {
|
|
81
82
|
value: e.id,
|
|
82
83
|
children: e.shortcut ? `${e.title} (${e.shortcut})` : e.title
|
|
83
84
|
}, e.id))]
|
|
84
85
|
})]
|
|
85
86
|
}),
|
|
86
|
-
/* @__PURE__ */
|
|
87
|
+
/* @__PURE__ */ p("div", {
|
|
87
88
|
className: "relative",
|
|
88
89
|
children: [
|
|
89
|
-
/* @__PURE__ */
|
|
90
|
-
ref:
|
|
91
|
-
"aria-label": e(
|
|
92
|
-
value:
|
|
93
|
-
onChange: (e) =>
|
|
94
|
-
onKeyDown:
|
|
95
|
-
placeholder: e(
|
|
96
|
-
disabled:
|
|
90
|
+
/* @__PURE__ */ f("textarea", {
|
|
91
|
+
ref: P,
|
|
92
|
+
"aria-label": e(C, "support.messageComposer.placeholder", v),
|
|
93
|
+
value: w,
|
|
94
|
+
onChange: (e) => T(e.target.value),
|
|
95
|
+
onKeyDown: L,
|
|
96
|
+
placeholder: e(C, "support.messageComposer.placeholder", v),
|
|
97
|
+
disabled: y || O,
|
|
97
98
|
rows: 1,
|
|
98
|
-
className: `auto-resize w-full px-4 py-3 rounded-lg border resize-none transition-colors ${
|
|
99
|
+
className: `auto-resize w-full px-4 py-3 rounded-lg border resize-none transition-colors ${E ? "border-status-warning-bg bg-status-warning-bg-subtle" : "border-border bg-background"} text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary`
|
|
99
100
|
}),
|
|
100
|
-
/* @__PURE__ */
|
|
101
|
-
ref:
|
|
101
|
+
/* @__PURE__ */ f("input", {
|
|
102
|
+
ref: F,
|
|
102
103
|
type: "file",
|
|
103
104
|
multiple: !0,
|
|
104
105
|
"aria-label": "Attach files",
|
|
105
|
-
onChange:
|
|
106
|
+
onChange: z,
|
|
106
107
|
className: "hidden",
|
|
107
|
-
accept:
|
|
108
|
+
accept: t
|
|
108
109
|
}),
|
|
109
|
-
|
|
110
|
+
M && /* @__PURE__ */ f("p", {
|
|
111
|
+
role: "alert",
|
|
112
|
+
className: "mt-2 text-sm text-status-error-text",
|
|
113
|
+
children: M
|
|
114
|
+
}),
|
|
115
|
+
A.length > 0 && /* @__PURE__ */ f("div", {
|
|
110
116
|
className: "flex flex-wrap gap-2 mt-2",
|
|
111
|
-
children:
|
|
117
|
+
children: A.map((e, t) => /* @__PURE__ */ p("div", {
|
|
112
118
|
className: "flex items-center gap-2 px-3 py-1 rounded-lg bg-muted text-sm",
|
|
113
119
|
children: [
|
|
114
|
-
/* @__PURE__ */ l
|
|
115
|
-
/* @__PURE__ */
|
|
120
|
+
/* @__PURE__ */ f(l, { size: 14 }),
|
|
121
|
+
/* @__PURE__ */ f("span", {
|
|
116
122
|
className: "max-w-[200px] truncate",
|
|
117
123
|
children: e.name
|
|
118
124
|
}),
|
|
119
|
-
/* @__PURE__ */
|
|
125
|
+
/* @__PURE__ */ f("button", {
|
|
120
126
|
type: "button",
|
|
121
|
-
onClick: () =>
|
|
127
|
+
onClick: () => B(t),
|
|
122
128
|
className: "flex min-h-11 min-w-11 items-center justify-center rounded text-muted-foreground transition-colors hover:text-foreground",
|
|
123
129
|
"aria-label": `Remove attachment ${e.name}`,
|
|
124
130
|
children: "×"
|
|
@@ -126,37 +132,37 @@ var f = [], p = ({ ticketId: p, onSendMessage: m, placeholder: h = "Type your me
|
|
|
126
132
|
]
|
|
127
133
|
}, `${e.name}-${t}`))
|
|
128
134
|
}),
|
|
129
|
-
/* @__PURE__ */
|
|
135
|
+
/* @__PURE__ */ p("div", {
|
|
130
136
|
className: "flex items-center justify-between mt-3",
|
|
131
|
-
children: [/* @__PURE__ */
|
|
137
|
+
children: [/* @__PURE__ */ p("button", {
|
|
132
138
|
type: "button",
|
|
133
|
-
onClick:
|
|
139
|
+
onClick: R,
|
|
134
140
|
className: "min-h-11 inline-flex items-center gap-2 px-3 py-2 rounded-lg transition-colors text-muted-foreground hover:bg-muted",
|
|
135
|
-
disabled:
|
|
141
|
+
disabled: y || O,
|
|
136
142
|
children: [
|
|
137
|
-
/* @__PURE__ */ l
|
|
138
|
-
/* @__PURE__ */
|
|
143
|
+
/* @__PURE__ */ f(l, { size: 18 }),
|
|
144
|
+
/* @__PURE__ */ f("span", {
|
|
139
145
|
className: "text-sm",
|
|
140
|
-
children: e(
|
|
146
|
+
children: e(C, "support.messageComposer.attachFiles", "Attach files")
|
|
141
147
|
}),
|
|
142
|
-
|
|
148
|
+
A.length > 0 && /* @__PURE__ */ f("span", {
|
|
143
149
|
className: "text-xs bg-primary text-primary-foreground rounded-full px-2 py-0.5",
|
|
144
|
-
children:
|
|
150
|
+
children: A.length
|
|
145
151
|
})
|
|
146
152
|
]
|
|
147
|
-
}), /* @__PURE__ */
|
|
153
|
+
}), /* @__PURE__ */ p("div", {
|
|
148
154
|
className: "flex items-center gap-2",
|
|
149
|
-
children: [/* @__PURE__ */
|
|
155
|
+
children: [/* @__PURE__ */ f("span", {
|
|
150
156
|
className: "text-xs text-muted-foreground hidden sm:inline",
|
|
151
|
-
children: e(
|
|
152
|
-
}), /* @__PURE__ */
|
|
157
|
+
children: e(C, "support.messageComposer.hint", "Markdown supported. Press Enter to send, Shift+Enter for new line")
|
|
158
|
+
}), /* @__PURE__ */ f("button", {
|
|
153
159
|
type: "submit",
|
|
154
|
-
disabled: !
|
|
155
|
-
className: `min-h-11 inline-flex items-center gap-2 px-4 py-2 rounded-lg font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed ${
|
|
156
|
-
children:
|
|
160
|
+
disabled: !w.trim() && A.length === 0 || y || O,
|
|
161
|
+
className: `min-h-11 inline-flex items-center gap-2 px-4 py-2 rounded-lg font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed ${E ? "bg-status-warning-bg hover:bg-status-warning-bg/90 text-on-accent" : "bg-primary hover:bg-primary/90 text-primary-foreground"}`,
|
|
162
|
+
children: O ? /* @__PURE__ */ p(d, { children: [/* @__PURE__ */ f(s, {
|
|
157
163
|
size: 18,
|
|
158
164
|
className: "animate-spin"
|
|
159
|
-
}), e(
|
|
165
|
+
}), e(C, "support.messageComposer.sending", "Sending...")] }) : /* @__PURE__ */ p(d, { children: [/* @__PURE__ */ f(u, { size: 18 }), e(C, "support.messageComposer.send", "Send")] })
|
|
160
166
|
})]
|
|
161
167
|
})]
|
|
162
168
|
})
|
|
@@ -167,6 +173,6 @@ var f = [], p = ({ ticketId: p, onSendMessage: m, placeholder: h = "Type your me
|
|
|
167
173
|
});
|
|
168
174
|
};
|
|
169
175
|
//#endregion
|
|
170
|
-
export {
|
|
176
|
+
export { g as MessageComposer };
|
|
171
177
|
|
|
172
178
|
//# sourceMappingURL=MessageComposer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageComposer.js","names":[],"sources":["../../../../src/support/components/tickets/MessageComposer.tsx"],"sourcesContent":["import { useState, useRef, useEffect, type FC } from 'react';\nimport { Send, Paperclip, Lock, Loader2 } from 'lucide-react';\nimport { useI18n } from '@burdenoff/fe-libs/shared/providers/shell/I18nProvider';\nimport { tWithFallback } from '../../utils/i18n';\n\nexport interface MessageComposerSendResult {\n preserveAttachedFiles?: boolean;\n preserveMessage?: boolean;\n}\n\ninterface MessageComposerProps {\n ticketId: string;\n onSendMessage: (\n content: string,\n isInternal: boolean,\n files: File[]\n ) => Promise<MessageComposerSendResult | void>;\n placeholder?: string;\n disabled?: boolean;\n allowInternalNotes?: boolean;\n cannedResponses?: readonly CannedResponseOption[];\n cannedResponsesLoading?: boolean;\n}\n\nexport interface CannedResponseOption {\n id: string;\n title: string;\n content: string;\n shortcut?: string | null;\n}\n\nconst EMPTY_CANNED_RESPONSES: readonly CannedResponseOption[] = [];\n\nexport const MessageComposer: FC<MessageComposerProps> = ({\n ticketId: _ticketId,\n onSendMessage,\n placeholder = 'Type your message...',\n disabled = false,\n allowInternalNotes = false,\n cannedResponses = EMPTY_CANNED_RESPONSES,\n cannedResponsesLoading = false,\n}) => {\n const { t } = useI18n();\n const [message, setMessage] = useState('');\n const [isInternal, setIsInternal] = useState(false);\n const [isSending, setIsSending] = useState(false);\n const [attachedFiles, setAttachedFiles] = useState<File[]>([]);\n const textareaRef = useRef<HTMLTextAreaElement>(null);\n const fileInputRef = useRef<HTMLInputElement>(null);\n\n // Auto-resize textarea as content changes\n useEffect(() => {\n const textarea = textareaRef.current;\n if (textarea) {\n // Reset height to auto to get the correct scrollHeight\n textarea.style.height = 'auto';\n // Set height to scrollHeight (content height) but respect CSS max-height\n textarea.style.height = `${textarea.scrollHeight}px`;\n }\n }, [message]);\n\n const handleSubmit = async (e: React.FormEvent) => {\n e.preventDefault();\n if ((!message.trim() && attachedFiles.length === 0) || isSending) return;\n\n setIsSending(true);\n try {\n const result = await onSendMessage(message.trim(), isInternal, attachedFiles);\n if (!result?.preserveMessage) {\n setMessage('');\n }\n setIsInternal(false);\n if (!result?.preserveAttachedFiles) {\n setAttachedFiles([]);\n }\n } catch (error) {\n console.error('Failed to send message:', error);\n } finally {\n setIsSending(false);\n }\n };\n\n const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {\n if (e.key === 'Enter' && !e.shiftKey) {\n e.preventDefault();\n handleSubmit(e);\n }\n };\n\n const handleAttachFiles = () => {\n fileInputRef.current?.click();\n };\n\n const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n const files = Array.from(e.target.files || []);\n setAttachedFiles((prev) => [...prev, ...files]);\n // Reset input so the same file can be selected again\n e.target.value = '';\n };\n\n const handleRemoveFile = (index: number) => {\n setAttachedFiles((prev) => prev.filter((_, i) => i !== index));\n };\n\n const handleInsertCannedResponse = (responseId: string) => {\n const selectedResponse = cannedResponses.find((response) => response.id === responseId);\n if (!selectedResponse) return;\n\n setMessage((currentMessage) => {\n const trimmedMessage = currentMessage.trimEnd();\n return trimmedMessage\n ? `${trimmedMessage}\\n\\n${selectedResponse.content}`\n : selectedResponse.content;\n });\n\n requestAnimationFrame(() => textareaRef.current?.focus());\n };\n\n return (\n <div\n data-tour=\"support-ticket-message-composer\"\n className=\"shrink-0 border-t border-border bg-background\"\n >\n <form onSubmit={handleSubmit} className=\"p-4\">\n {/* Internal note toggle */}\n {allowInternalNotes && (\n <div className=\"flex items-center gap-2 mb-3\">\n <label className=\"flex items-center gap-2 cursor-pointer\">\n <input\n type=\"checkbox\"\n aria-label=\"Internal note\"\n checked={isInternal}\n onChange={(e) => setIsInternal(e.target.checked)}\n className=\"rounded border-border\"\n disabled={disabled}\n />\n <span className=\"text-sm flex items-center gap-1 text-muted-foreground\">\n <Lock size={14} />\n {tWithFallback(\n t,\n 'support.messageComposer.internalNote',\n 'Internal Note (not visible to customer)'\n )}\n </span>\n </label>\n </div>\n )}\n\n {allowInternalNotes && (\n <div className=\"mb-3 flex flex-col gap-1 sm:max-w-sm\">\n <label\n htmlFor=\"support-canned-response\"\n className=\"text-sm font-medium text-foreground\"\n >\n {tWithFallback(t, 'support.messageComposer.cannedResponses', 'Canned responses')}\n </label>\n <select\n id=\"support-canned-response\"\n value=\"\"\n onChange={(event) => handleInsertCannedResponse(event.target.value)}\n disabled={\n disabled || isSending || cannedResponsesLoading || cannedResponses.length === 0\n }\n className=\"rounded-lg border border-border bg-background px-3 py-2 text-sm text-foreground transition-colors focus:border-primary focus:outline-none focus:ring-2 focus:ring-primary/20 disabled:cursor-not-allowed disabled:opacity-50\"\n >\n <option value=\"\">\n {cannedResponsesLoading\n ? tWithFallback(\n t,\n 'support.messageComposer.loadingCannedResponses',\n 'Loading saved replies...'\n )\n : cannedResponses.length > 0\n ? tWithFallback(\n t,\n 'support.messageComposer.selectCannedResponse',\n 'Insert a saved reply'\n )\n : tWithFallback(\n t,\n 'support.messageComposer.noCannedResponses',\n 'No saved replies available'\n )}\n </option>\n {cannedResponses.map((response) => (\n <option key={response.id} value={response.id}>\n {response.shortcut ? `${response.title} (${response.shortcut})` : response.title}\n </option>\n ))}\n </select>\n </div>\n )}\n\n {/* Message input */}\n <div className=\"relative\">\n <textarea\n ref={textareaRef}\n aria-label={tWithFallback(t, 'support.messageComposer.placeholder', placeholder)}\n value={message}\n onChange={(e) => setMessage(e.target.value)}\n onKeyDown={handleKeyDown}\n placeholder={tWithFallback(t, 'support.messageComposer.placeholder', placeholder)}\n disabled={disabled || isSending}\n rows={1}\n className={`auto-resize w-full px-4 py-3 rounded-lg border resize-none transition-colors ${\n isInternal\n ? 'border-status-warning-bg bg-status-warning-bg-subtle'\n : 'border-border bg-background'\n } text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary`}\n />\n\n {/* Hidden file input */}\n <input\n ref={fileInputRef}\n type=\"file\"\n multiple\n aria-label=\"Attach files\"\n onChange={handleFileChange}\n className=\"hidden\"\n accept=\"image/*,.pdf,.doc,.docx,.txt\"\n />\n\n {/* Attached files display */}\n {attachedFiles.length > 0 && (\n <div className=\"flex flex-wrap gap-2 mt-2\">\n {attachedFiles.map((file, index) => (\n <div\n key={`${file.name}-${index}`}\n className=\"flex items-center gap-2 px-3 py-1 rounded-lg bg-muted text-sm\"\n >\n <Paperclip size={14} />\n <span className=\"max-w-[200px] truncate\">{file.name}</span>\n <button\n type=\"button\"\n onClick={() => handleRemoveFile(index)}\n className=\"flex min-h-11 min-w-11 items-center justify-center rounded text-muted-foreground transition-colors hover:text-foreground\"\n aria-label={`Remove attachment ${file.name}`}\n >\n ×\n </button>\n </div>\n ))}\n </div>\n )}\n\n {/* Actions */}\n <div className=\"flex items-center justify-between mt-3\">\n <button\n type=\"button\"\n onClick={handleAttachFiles}\n className=\"min-h-11 inline-flex items-center gap-2 px-3 py-2 rounded-lg transition-colors text-muted-foreground hover:bg-muted\"\n disabled={disabled || isSending}\n >\n <Paperclip size={18} />\n <span className=\"text-sm\">\n {tWithFallback(t, 'support.messageComposer.attachFiles', 'Attach files')}\n </span>\n {attachedFiles.length > 0 && (\n <span className=\"text-xs bg-primary text-primary-foreground rounded-full px-2 py-0.5\">\n {attachedFiles.length}\n </span>\n )}\n </button>\n\n <div className=\"flex items-center gap-2\">\n <span className=\"text-xs text-muted-foreground hidden sm:inline\">\n {tWithFallback(\n t,\n 'support.messageComposer.hint',\n 'Markdown supported. Press Enter to send, Shift+Enter for new line'\n )}\n </span>\n <button\n type=\"submit\"\n disabled={(!message.trim() && attachedFiles.length === 0) || disabled || isSending}\n className={`min-h-11 inline-flex items-center gap-2 px-4 py-2 rounded-lg font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed ${\n isInternal\n ? 'bg-status-warning-bg hover:bg-status-warning-bg/90 text-on-accent'\n : 'bg-primary hover:bg-primary/90 text-primary-foreground'\n }`}\n >\n {isSending ? (\n <>\n <Loader2 size={18} className=\"animate-spin\" />\n {tWithFallback(t, 'support.messageComposer.sending', 'Sending...')}\n </>\n ) : (\n <>\n <Send size={18} />\n {tWithFallback(t, 'support.messageComposer.send', 'Send')}\n </>\n )}\n </button>\n </div>\n </div>\n </div>\n </form>\n </div>\n );\n};\n"],"mappings":";;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D;SACI,CAAA,EACP,kBAAC,UAAD;SACE,MAAK;SACL,UAAW,CAAC,EAAQ,MAAM,IAAI,EAAc,WAAW,KAAM,KAAY;SACzE,WAAW,8IACT,IACI,sEACA;mBAGL,IACC,kBAAA,GAAA,EAAA,UAAA,CACE,kBAAC,GAAD;UAAS,MAAM;UAAI,WAAU;UAAiB,CAAA,EAC7C,EAAc,GAAG,mCAAmC,aAAa,CACjE,EAAA,CAAA,GAEH,kBAAA,GAAA,EAAA,UAAA,CACE,kBAAC,GAAD,EAAM,MAAM,IAAM,CAAA,EACjB,EAAc,GAAG,gCAAgC,OAAO,CACxD,EAAA,CAAA;SAEE,CAAA,CACL;UACF;;MACF;;IACD;;EACH,CAAA"}
|
|
1
|
+
{"version":3,"file":"MessageComposer.js","names":[],"sources":["../../../../src/support/components/tickets/MessageComposer.tsx"],"sourcesContent":["import { useState, useRef, useEffect, type FC } from 'react';\nimport { Send, Paperclip, Lock, Loader2 } from 'lucide-react';\nimport { useI18n } from '@burdenoff/fe-libs/shared/providers/shell/I18nProvider';\nimport { tWithFallback } from '../../utils/i18n';\nimport {\n SUPPORT_ATTACHMENT_ACCEPT,\n partitionAttachments,\n rejectedAttachmentsMessage,\n} from '../../utils/attachments';\n\nexport interface MessageComposerSendResult {\n preserveAttachedFiles?: boolean;\n preserveMessage?: boolean;\n}\n\ninterface MessageComposerProps {\n ticketId: string;\n onSendMessage: (\n content: string,\n isInternal: boolean,\n files: File[]\n ) => Promise<MessageComposerSendResult | void>;\n placeholder?: string;\n disabled?: boolean;\n allowInternalNotes?: boolean;\n cannedResponses?: readonly CannedResponseOption[];\n cannedResponsesLoading?: boolean;\n}\n\nexport interface CannedResponseOption {\n id: string;\n title: string;\n content: string;\n shortcut?: string | null;\n}\n\nconst EMPTY_CANNED_RESPONSES: readonly CannedResponseOption[] = [];\n\nexport const MessageComposer: FC<MessageComposerProps> = ({\n ticketId: _ticketId,\n onSendMessage,\n placeholder = 'Type your message...',\n disabled = false,\n allowInternalNotes = false,\n cannedResponses = EMPTY_CANNED_RESPONSES,\n cannedResponsesLoading = false,\n}) => {\n const { t } = useI18n();\n const [message, setMessage] = useState('');\n const [isInternal, setIsInternal] = useState(false);\n const [isSending, setIsSending] = useState(false);\n const [attachedFiles, setAttachedFiles] = useState<File[]>([]);\n const [fileError, setFileError] = useState<string | null>(null);\n const textareaRef = useRef<HTMLTextAreaElement>(null);\n const fileInputRef = useRef<HTMLInputElement>(null);\n\n // Auto-resize textarea as content changes\n useEffect(() => {\n const textarea = textareaRef.current;\n if (textarea) {\n // Reset height to auto to get the correct scrollHeight\n textarea.style.height = 'auto';\n // Set height to scrollHeight (content height) but respect CSS max-height\n textarea.style.height = `${textarea.scrollHeight}px`;\n }\n }, [message]);\n\n const handleSubmit = async (e: React.FormEvent) => {\n e.preventDefault();\n if ((!message.trim() && attachedFiles.length === 0) || isSending) return;\n\n setIsSending(true);\n try {\n const result = await onSendMessage(message.trim(), isInternal, attachedFiles);\n if (!result?.preserveMessage) {\n setMessage('');\n }\n setIsInternal(false);\n if (!result?.preserveAttachedFiles) {\n setAttachedFiles([]);\n setFileError(null);\n }\n } catch (error) {\n console.error('Failed to send message:', error);\n } finally {\n setIsSending(false);\n }\n };\n\n const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {\n if (e.key === 'Enter' && !e.shiftKey) {\n e.preventDefault();\n handleSubmit(e);\n }\n };\n\n const handleAttachFiles = () => {\n fileInputRef.current?.click();\n };\n\n const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n const files = Array.from(e.target.files || []);\n const { accepted, rejected } = partitionAttachments(files);\n if (accepted.length > 0) {\n setAttachedFiles((prev) => [...prev, ...accepted]);\n }\n setFileError(rejected.length > 0 ? rejectedAttachmentsMessage(rejected) : null);\n // Reset input so the same file can be selected again\n e.target.value = '';\n };\n\n const handleRemoveFile = (index: number) => {\n setAttachedFiles((prev) => prev.filter((_, i) => i !== index));\n // Clear any stale rejection error once the user removes attachments, so a\n // prior \"unsupported type\" warning doesn't linger with no files visible.\n setFileError(null);\n };\n\n const handleInsertCannedResponse = (responseId: string) => {\n const selectedResponse = cannedResponses.find((response) => response.id === responseId);\n if (!selectedResponse) return;\n\n setMessage((currentMessage) => {\n const trimmedMessage = currentMessage.trimEnd();\n return trimmedMessage\n ? `${trimmedMessage}\\n\\n${selectedResponse.content}`\n : selectedResponse.content;\n });\n\n requestAnimationFrame(() => textareaRef.current?.focus());\n };\n\n return (\n <div\n data-tour=\"support-ticket-message-composer\"\n className=\"shrink-0 border-t border-border bg-background\"\n >\n <form onSubmit={handleSubmit} className=\"p-4\">\n {/* Internal note toggle */}\n {allowInternalNotes && (\n <div className=\"flex items-center gap-2 mb-3\">\n <label className=\"flex items-center gap-2 cursor-pointer\">\n <input\n type=\"checkbox\"\n aria-label=\"Internal note\"\n checked={isInternal}\n onChange={(e) => setIsInternal(e.target.checked)}\n className=\"rounded border-border\"\n disabled={disabled}\n />\n <span className=\"text-sm flex items-center gap-1 text-muted-foreground\">\n <Lock size={14} />\n {tWithFallback(\n t,\n 'support.messageComposer.internalNote',\n 'Internal Note (not visible to customer)'\n )}\n </span>\n </label>\n </div>\n )}\n\n {allowInternalNotes && (\n <div className=\"mb-3 flex flex-col gap-1 sm:max-w-sm\">\n <label\n htmlFor=\"support-canned-response\"\n className=\"text-sm font-medium text-foreground\"\n >\n {tWithFallback(t, 'support.messageComposer.cannedResponses', 'Canned responses')}\n </label>\n <select\n id=\"support-canned-response\"\n value=\"\"\n onChange={(event) => handleInsertCannedResponse(event.target.value)}\n disabled={\n disabled || isSending || cannedResponsesLoading || cannedResponses.length === 0\n }\n className=\"rounded-lg border border-border bg-background px-3 py-2 text-sm text-foreground transition-colors focus:border-primary focus:outline-none focus:ring-2 focus:ring-primary/20 disabled:cursor-not-allowed disabled:opacity-50\"\n >\n <option value=\"\">\n {cannedResponsesLoading\n ? tWithFallback(\n t,\n 'support.messageComposer.loadingCannedResponses',\n 'Loading saved replies...'\n )\n : cannedResponses.length > 0\n ? tWithFallback(\n t,\n 'support.messageComposer.selectCannedResponse',\n 'Insert a saved reply'\n )\n : tWithFallback(\n t,\n 'support.messageComposer.noCannedResponses',\n 'No saved replies available'\n )}\n </option>\n {cannedResponses.map((response) => (\n <option key={response.id} value={response.id}>\n {response.shortcut ? `${response.title} (${response.shortcut})` : response.title}\n </option>\n ))}\n </select>\n </div>\n )}\n\n {/* Message input */}\n <div className=\"relative\">\n <textarea\n ref={textareaRef}\n aria-label={tWithFallback(t, 'support.messageComposer.placeholder', placeholder)}\n value={message}\n onChange={(e) => setMessage(e.target.value)}\n onKeyDown={handleKeyDown}\n placeholder={tWithFallback(t, 'support.messageComposer.placeholder', placeholder)}\n disabled={disabled || isSending}\n rows={1}\n className={`auto-resize w-full px-4 py-3 rounded-lg border resize-none transition-colors ${\n isInternal\n ? 'border-status-warning-bg bg-status-warning-bg-subtle'\n : 'border-border bg-background'\n } text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary`}\n />\n\n {/* Hidden file input */}\n <input\n ref={fileInputRef}\n type=\"file\"\n multiple\n aria-label=\"Attach files\"\n onChange={handleFileChange}\n className=\"hidden\"\n accept={SUPPORT_ATTACHMENT_ACCEPT}\n />\n\n {/* Unsupported file type error */}\n {fileError && (\n <p role=\"alert\" className=\"mt-2 text-sm text-status-error-text\">\n {fileError}\n </p>\n )}\n\n {/* Attached files display */}\n {attachedFiles.length > 0 && (\n <div className=\"flex flex-wrap gap-2 mt-2\">\n {attachedFiles.map((file, index) => (\n <div\n key={`${file.name}-${index}`}\n className=\"flex items-center gap-2 px-3 py-1 rounded-lg bg-muted text-sm\"\n >\n <Paperclip size={14} />\n <span className=\"max-w-[200px] truncate\">{file.name}</span>\n <button\n type=\"button\"\n onClick={() => handleRemoveFile(index)}\n className=\"flex min-h-11 min-w-11 items-center justify-center rounded text-muted-foreground transition-colors hover:text-foreground\"\n aria-label={`Remove attachment ${file.name}`}\n >\n ×\n </button>\n </div>\n ))}\n </div>\n )}\n\n {/* Actions */}\n <div className=\"flex items-center justify-between mt-3\">\n <button\n type=\"button\"\n onClick={handleAttachFiles}\n className=\"min-h-11 inline-flex items-center gap-2 px-3 py-2 rounded-lg transition-colors text-muted-foreground hover:bg-muted\"\n disabled={disabled || isSending}\n >\n <Paperclip size={18} />\n <span className=\"text-sm\">\n {tWithFallback(t, 'support.messageComposer.attachFiles', 'Attach files')}\n </span>\n {attachedFiles.length > 0 && (\n <span className=\"text-xs bg-primary text-primary-foreground rounded-full px-2 py-0.5\">\n {attachedFiles.length}\n </span>\n )}\n </button>\n\n <div className=\"flex items-center gap-2\">\n <span className=\"text-xs text-muted-foreground hidden sm:inline\">\n {tWithFallback(\n t,\n 'support.messageComposer.hint',\n 'Markdown supported. Press Enter to send, Shift+Enter for new line'\n )}\n </span>\n <button\n type=\"submit\"\n disabled={(!message.trim() && attachedFiles.length === 0) || disabled || isSending}\n className={`min-h-11 inline-flex items-center gap-2 px-4 py-2 rounded-lg font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed ${\n isInternal\n ? 'bg-status-warning-bg hover:bg-status-warning-bg/90 text-on-accent'\n : 'bg-primary hover:bg-primary/90 text-primary-foreground'\n }`}\n >\n {isSending ? (\n <>\n <Loader2 size={18} className=\"animate-spin\" />\n {tWithFallback(t, 'support.messageComposer.sending', 'Sending...')}\n </>\n ) : (\n <>\n <Send size={18} />\n {tWithFallback(t, 'support.messageComposer.send', 'Send')}\n </>\n )}\n </button>\n </div>\n </div>\n </div>\n </form>\n </div>\n );\n};\n"],"mappings":";;;;;;;AAoCA,IAAM,IAA0D,EAAE,EAErD,KAA6C,EACxD,UAAU,GACV,kBACA,iBAAc,wBACd,cAAW,IACX,wBAAqB,IACrB,qBAAkB,GAClB,4BAAyB,SACrB;CACJ,IAAM,EAAE,SAAM,GAAS,EACjB,CAAC,GAAS,KAAc,EAAS,GAAG,EACpC,CAAC,GAAY,KAAiB,EAAS,GAAM,EAC7C,CAAC,G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,CAAA,EACP,kBAAC,UAAD;SACE,MAAK;SACL,UAAW,CAAC,EAAQ,MAAM,IAAI,EAAc,WAAW,KAAM,KAAY;SACzE,WAAW,8IACT,IACI,sEACA;mBAGL,IACC,kBAAA,GAAA,EAAA,UAAA,CACE,kBAAC,GAAD;UAAS,MAAM;UAAI,WAAU;UAAiB,CAAA,EAC7C,EAAc,GAAG,mCAAmC,aAAa,CACjE,EAAA,CAAA,GAEH,kBAAA,GAAA,EAAA,UAAA,CACE,kBAAC,GAAD,EAAM,MAAM,IAAM,CAAA,EACjB,EAAc,GAAG,gCAAgC,OAAO,CACxD,EAAA,CAAA;SAEE,CAAA,CACL;UACF;;MACF;;IACD;;EACH,CAAA"}
|
|
@@ -8,265 +8,267 @@ import { useTicketOperations as s } from "../hooks/useTicketOperations.js";
|
|
|
8
8
|
import { useNotification as c } from "../hooks/useNotification.js";
|
|
9
9
|
import { NotificationToast as l } from "../components/NotificationToast.js";
|
|
10
10
|
import { extractErrorMessage as u } from "../utils/errors.js";
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
11
|
+
import { SUPPORT_ATTACHMENT_ACCEPT as d, partitionAttachments as f, rejectedAttachmentsMessage as p } from "../utils/attachments.js";
|
|
12
|
+
import { uploadSupportAttachmentFiles as m } from "../utils/supportFiles.js";
|
|
13
|
+
import { ATTACHMENTS_FAILED_PARAM as h } from "../constants.js";
|
|
14
|
+
import { useEffect as g, useRef as _, useState as v } from "react";
|
|
15
|
+
import { ArrowLeft as y, Loader2 as b, Paperclip as x, Plus as S } from "lucide-react";
|
|
16
|
+
import { useNavigate as C } from "react-router-dom";
|
|
17
|
+
import { Fragment as w, jsx as T, jsxs as E } from "react/jsx-runtime";
|
|
17
18
|
//#region src/support/pages/CreateTicketPage.tsx
|
|
18
|
-
var
|
|
19
|
-
function
|
|
20
|
-
let
|
|
19
|
+
var D = 5, O = 10;
|
|
20
|
+
function k() {
|
|
21
|
+
let k = C(), { basePath: A = "" } = e(), { createTicket: j, createTicketLoading: M, updateTicket: N } = s(), { data: P, loading: F } = i({ variables: {
|
|
21
22
|
filter: { isActive: !0 },
|
|
22
23
|
limit: 100,
|
|
23
24
|
offset: 0
|
|
24
|
-
} }),
|
|
25
|
+
} }), I = [...P?.ticketCategories?.nodes ?? []].sort((e, t) => e.displayOrder - t.displayOrder), [L, R] = v({
|
|
25
26
|
subject: "",
|
|
26
27
|
description: "",
|
|
27
28
|
priority: a.Normal,
|
|
28
29
|
categoryId: void 0
|
|
29
|
-
}), [
|
|
30
|
-
|
|
30
|
+
}), [z, B] = v([]), [V, H] = v(null), { notification: U, notify: W } = c(), G = _(null), K = () => {
|
|
31
|
+
G.current &&= (clearTimeout(G.current), null);
|
|
31
32
|
};
|
|
32
|
-
|
|
33
|
-
let
|
|
34
|
-
if (e.preventDefault(),
|
|
35
|
-
|
|
33
|
+
g(() => K, []);
|
|
34
|
+
let q = async (e) => {
|
|
35
|
+
if (e.preventDefault(), L.subject.trim().length < D) {
|
|
36
|
+
W("error", `Subject must be at least ${D} characters long.`);
|
|
36
37
|
return;
|
|
37
38
|
}
|
|
38
|
-
if ((
|
|
39
|
-
|
|
39
|
+
if ((L.description ?? "").trim().length < O) {
|
|
40
|
+
W("error", `Description must be at least ${O} characters long.`);
|
|
40
41
|
return;
|
|
41
42
|
}
|
|
42
43
|
try {
|
|
43
|
-
let e = await
|
|
44
|
-
...
|
|
45
|
-
priority:
|
|
46
|
-
categoryId:
|
|
44
|
+
let e = await j({
|
|
45
|
+
...L,
|
|
46
|
+
priority: L.priority ?? void 0,
|
|
47
|
+
categoryId: L.categoryId ?? void 0
|
|
47
48
|
});
|
|
48
49
|
if (!e) return;
|
|
49
|
-
if (
|
|
50
|
-
let t = await
|
|
50
|
+
if (z.length > 0) try {
|
|
51
|
+
let t = await m({
|
|
51
52
|
ticketId: e.id,
|
|
52
|
-
files:
|
|
53
|
+
files: z,
|
|
53
54
|
onFileProgress: (e, t) => {
|
|
54
|
-
t < 100 &&
|
|
55
|
+
t < 100 && H(e);
|
|
55
56
|
}
|
|
56
57
|
});
|
|
57
|
-
await
|
|
58
|
+
await N(e.id, { metadata: { initialAttachmentIds: t.files.map((e) => e.id) } }), H(null), B([]);
|
|
58
59
|
} catch (n) {
|
|
59
|
-
|
|
60
|
-
let r = new URLSearchParams({ [
|
|
61
|
-
|
|
60
|
+
H(null), console.error("[support] create ticket: attachments failed", n);
|
|
61
|
+
let r = new URLSearchParams({ [h]: "1" });
|
|
62
|
+
k(t(A, `tickets/${e.id}?${r.toString()}`));
|
|
62
63
|
return;
|
|
63
64
|
}
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
W("success", "Ticket created successfully!"), K(), G.current = setTimeout(() => {
|
|
66
|
+
k(t(A, `tickets/${e.id}`)), G.current = null;
|
|
66
67
|
}, 1e3);
|
|
67
68
|
} catch (e) {
|
|
68
|
-
|
|
69
|
+
W("error", u(e, "Failed to create ticket. Please try again."), 5e3);
|
|
69
70
|
}
|
|
70
|
-
},
|
|
71
|
-
let t = Array.from(e.target.files || []);
|
|
72
|
-
|
|
73
|
-
},
|
|
74
|
-
|
|
71
|
+
}, J = (e) => {
|
|
72
|
+
let { accepted: t, rejected: n } = f(Array.from(e.target.files || []));
|
|
73
|
+
t.length > 0 && B((e) => [...e, ...t]), n.length > 0 && W("error", p(n), 6e3), e.target.value = "";
|
|
74
|
+
}, Y = (e) => {
|
|
75
|
+
B((t) => t.filter((t, n) => n !== e));
|
|
75
76
|
};
|
|
76
|
-
return /* @__PURE__ */
|
|
77
|
+
return /* @__PURE__ */ E(o, {
|
|
77
78
|
showHeader: !1,
|
|
78
79
|
children: [
|
|
79
|
-
/* @__PURE__ */
|
|
80
|
-
/* @__PURE__ */
|
|
80
|
+
/* @__PURE__ */ T(l, { notification: U }),
|
|
81
|
+
/* @__PURE__ */ E("div", {
|
|
81
82
|
className: "flex items-center gap-4 mb-6",
|
|
82
|
-
children: [/* @__PURE__ */
|
|
83
|
+
children: [/* @__PURE__ */ T(n, {
|
|
83
84
|
variant: "ghost",
|
|
84
85
|
size: "sm",
|
|
85
|
-
onClick: () =>
|
|
86
|
+
onClick: () => k(".."),
|
|
86
87
|
className: "p-2",
|
|
87
|
-
children: /* @__PURE__ */
|
|
88
|
-
}), /* @__PURE__ */
|
|
88
|
+
children: /* @__PURE__ */ T(y, { size: 20 })
|
|
89
|
+
}), /* @__PURE__ */ E("div", { children: [/* @__PURE__ */ T("h1", {
|
|
89
90
|
className: "text-2xl font-bold text-foreground",
|
|
90
91
|
children: "Create New Ticket"
|
|
91
|
-
}), /* @__PURE__ */
|
|
92
|
+
}), /* @__PURE__ */ T("p", {
|
|
92
93
|
className: "text-sm text-muted-foreground",
|
|
93
94
|
children: "Submit a new support request"
|
|
94
95
|
})] })]
|
|
95
96
|
}),
|
|
96
|
-
/* @__PURE__ */
|
|
97
|
+
/* @__PURE__ */ T("div", {
|
|
97
98
|
className: "max-w-2xl",
|
|
98
|
-
children: /* @__PURE__ */
|
|
99
|
-
onSubmit:
|
|
99
|
+
children: /* @__PURE__ */ E("form", {
|
|
100
|
+
onSubmit: q,
|
|
100
101
|
className: "space-y-6",
|
|
101
|
-
children: [/* @__PURE__ */
|
|
102
|
+
children: [/* @__PURE__ */ E("div", {
|
|
102
103
|
className: "p-6 rounded-xl border bg-card space-y-6",
|
|
103
104
|
children: [
|
|
104
|
-
/* @__PURE__ */
|
|
105
|
+
/* @__PURE__ */ E("div", { children: [/* @__PURE__ */ E("label", {
|
|
105
106
|
htmlFor: "support-ticket-subject",
|
|
106
107
|
className: "mb-2 block text-sm font-medium text-foreground",
|
|
107
|
-
children: ["Subject ", /* @__PURE__ */
|
|
108
|
+
children: ["Subject ", /* @__PURE__ */ T("span", {
|
|
108
109
|
className: "text-destructive",
|
|
109
110
|
children: "*"
|
|
110
111
|
})]
|
|
111
|
-
}), /* @__PURE__ */
|
|
112
|
+
}), /* @__PURE__ */ T(r, {
|
|
112
113
|
id: "support-ticket-subject",
|
|
113
114
|
"data-tour": "support-ticket-subject",
|
|
114
115
|
type: "text",
|
|
115
116
|
required: !0,
|
|
116
|
-
value:
|
|
117
|
-
onChange: (e) =>
|
|
118
|
-
...
|
|
117
|
+
value: L.subject,
|
|
118
|
+
onChange: (e) => R({
|
|
119
|
+
...L,
|
|
119
120
|
subject: e.target.value
|
|
120
121
|
}),
|
|
121
122
|
placeholder: "Brief description of your issue"
|
|
122
123
|
})] }),
|
|
123
|
-
/* @__PURE__ */
|
|
124
|
-
/* @__PURE__ */
|
|
124
|
+
/* @__PURE__ */ E("div", { children: [
|
|
125
|
+
/* @__PURE__ */ E("label", {
|
|
125
126
|
htmlFor: "support-ticket-description",
|
|
126
127
|
className: "mb-2 block text-sm font-medium text-foreground",
|
|
127
|
-
children: ["Description ", /* @__PURE__ */
|
|
128
|
+
children: ["Description ", /* @__PURE__ */ T("span", {
|
|
128
129
|
className: "text-destructive",
|
|
129
130
|
children: "*"
|
|
130
131
|
})]
|
|
131
132
|
}),
|
|
132
|
-
/* @__PURE__ */
|
|
133
|
+
/* @__PURE__ */ T("textarea", {
|
|
133
134
|
id: "support-ticket-description",
|
|
134
135
|
"data-tour": "support-ticket-description",
|
|
135
136
|
"aria-label": "Description",
|
|
136
137
|
required: !0,
|
|
137
138
|
rows: 6,
|
|
138
|
-
value:
|
|
139
|
-
onChange: (e) =>
|
|
140
|
-
...
|
|
139
|
+
value: L.description || "",
|
|
140
|
+
onChange: (e) => R({
|
|
141
|
+
...L,
|
|
141
142
|
description: e.target.value
|
|
142
143
|
}),
|
|
143
144
|
className: "w-full px-4 py-3 rounded-lg border bg-background text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary transition-colors",
|
|
144
145
|
placeholder: "Provide detailed information about your issue"
|
|
145
146
|
}),
|
|
146
|
-
/* @__PURE__ */
|
|
147
|
+
/* @__PURE__ */ T("p", {
|
|
147
148
|
className: "mt-2 text-xs text-muted-foreground",
|
|
148
149
|
children: "Markdown is supported, including fenced code blocks."
|
|
149
150
|
})
|
|
150
151
|
] }),
|
|
151
|
-
/* @__PURE__ */
|
|
152
|
+
/* @__PURE__ */ E("div", { children: [/* @__PURE__ */ T("label", {
|
|
152
153
|
htmlFor: "support-ticket-priority",
|
|
153
154
|
className: "mb-2 block text-sm font-medium text-foreground",
|
|
154
155
|
children: "Priority"
|
|
155
|
-
}), /* @__PURE__ */
|
|
156
|
+
}), /* @__PURE__ */ E("select", {
|
|
156
157
|
id: "support-ticket-priority",
|
|
157
158
|
"data-tour": "support-ticket-priority",
|
|
158
|
-
value:
|
|
159
|
-
onChange: (e) =>
|
|
160
|
-
...
|
|
159
|
+
value: L.priority || "NORMAL",
|
|
160
|
+
onChange: (e) => R({
|
|
161
|
+
...L,
|
|
161
162
|
priority: e.target.value
|
|
162
163
|
}),
|
|
163
164
|
className: "w-full px-4 py-3 rounded-lg border bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary transition-colors",
|
|
164
165
|
children: [
|
|
165
|
-
/* @__PURE__ */
|
|
166
|
+
/* @__PURE__ */ T("option", {
|
|
166
167
|
value: "LOW",
|
|
167
168
|
children: "Low - General question or minor issue"
|
|
168
169
|
}),
|
|
169
|
-
/* @__PURE__ */
|
|
170
|
+
/* @__PURE__ */ T("option", {
|
|
170
171
|
value: "NORMAL",
|
|
171
172
|
children: "Normal - Standard support request"
|
|
172
173
|
}),
|
|
173
|
-
/* @__PURE__ */
|
|
174
|
+
/* @__PURE__ */ T("option", {
|
|
174
175
|
value: "HIGH",
|
|
175
176
|
children: "High - Significant impact on work"
|
|
176
177
|
}),
|
|
177
|
-
/* @__PURE__ */
|
|
178
|
+
/* @__PURE__ */ T("option", {
|
|
178
179
|
value: "CRITICAL",
|
|
179
180
|
children: "Critical - Complete blocker, urgent"
|
|
180
181
|
})
|
|
181
182
|
]
|
|
182
183
|
})] }),
|
|
183
|
-
/* @__PURE__ */
|
|
184
|
+
/* @__PURE__ */ E("div", { children: [/* @__PURE__ */ T("label", {
|
|
184
185
|
htmlFor: "support-ticket-category",
|
|
185
186
|
className: "mb-2 block text-sm font-medium text-foreground",
|
|
186
187
|
children: "Category"
|
|
187
|
-
}), /* @__PURE__ */
|
|
188
|
+
}), /* @__PURE__ */ E("select", {
|
|
188
189
|
id: "support-ticket-category",
|
|
189
190
|
"data-tour": "support-ticket-category",
|
|
190
|
-
value:
|
|
191
|
-
onChange: (e) =>
|
|
192
|
-
...
|
|
191
|
+
value: L.categoryId || "",
|
|
192
|
+
onChange: (e) => R({
|
|
193
|
+
...L,
|
|
193
194
|
categoryId: e.target.value || void 0
|
|
194
195
|
}),
|
|
195
196
|
className: "w-full px-4 py-3 rounded-lg border bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary transition-colors",
|
|
196
|
-
children: [/* @__PURE__ */
|
|
197
|
+
children: [/* @__PURE__ */ T("option", {
|
|
197
198
|
value: "",
|
|
198
|
-
children:
|
|
199
|
-
}),
|
|
199
|
+
children: F ? "Loading categories..." : "Select a category"
|
|
200
|
+
}), I.map((e) => /* @__PURE__ */ T("option", {
|
|
200
201
|
value: e.id,
|
|
201
202
|
children: e.name
|
|
202
203
|
}, e.id))]
|
|
203
204
|
})] }),
|
|
204
|
-
/* @__PURE__ */
|
|
205
|
-
/* @__PURE__ */
|
|
205
|
+
/* @__PURE__ */ E("div", { children: [
|
|
206
|
+
/* @__PURE__ */ T("span", {
|
|
206
207
|
id: "create-ticket-attachments-heading",
|
|
207
208
|
className: "mb-2 block text-sm font-medium text-foreground",
|
|
208
209
|
children: "Attachments"
|
|
209
210
|
}),
|
|
210
|
-
/* @__PURE__ */
|
|
211
|
+
/* @__PURE__ */ E("label", {
|
|
211
212
|
"data-tour": "support-ticket-attachments",
|
|
212
213
|
className: "flex cursor-pointer items-center justify-center gap-2 rounded-lg border border-dashed border-border bg-muted/20 p-4 text-sm text-muted-foreground transition-colors hover:bg-muted/40",
|
|
213
214
|
children: [
|
|
214
|
-
/* @__PURE__ */
|
|
215
|
-
/* @__PURE__ */
|
|
216
|
-
/* @__PURE__ */
|
|
215
|
+
/* @__PURE__ */ T(x, { size: 16 }),
|
|
216
|
+
/* @__PURE__ */ T("span", { children: "Attach files, screenshots, logs, or documents" }),
|
|
217
|
+
/* @__PURE__ */ T("input", {
|
|
217
218
|
type: "file",
|
|
218
219
|
multiple: !0,
|
|
219
220
|
"aria-labelledby": "create-ticket-attachments-heading",
|
|
220
221
|
className: "hidden",
|
|
221
|
-
|
|
222
|
+
accept: d,
|
|
223
|
+
onChange: J
|
|
222
224
|
})
|
|
223
225
|
]
|
|
224
226
|
}),
|
|
225
|
-
|
|
227
|
+
z.length > 0 && /* @__PURE__ */ T("div", {
|
|
226
228
|
className: "mt-3 flex flex-wrap gap-2",
|
|
227
|
-
children:
|
|
229
|
+
children: z.map((e, t) => /* @__PURE__ */ E("div", {
|
|
228
230
|
className: "flex items-center gap-2 rounded-lg border bg-background px-3 py-2 text-sm",
|
|
229
231
|
children: [
|
|
230
|
-
/* @__PURE__ */
|
|
231
|
-
/* @__PURE__ */
|
|
232
|
+
/* @__PURE__ */ T(x, { size: 14 }),
|
|
233
|
+
/* @__PURE__ */ T("span", {
|
|
232
234
|
className: "max-w-[240px] truncate",
|
|
233
235
|
children: e.name
|
|
234
236
|
}),
|
|
235
|
-
/* @__PURE__ */
|
|
237
|
+
/* @__PURE__ */ T("button", {
|
|
236
238
|
type: "button",
|
|
237
239
|
className: "flex min-h-11 min-w-11 items-center justify-center rounded text-muted-foreground hover:text-foreground",
|
|
238
|
-
onClick: () =>
|
|
240
|
+
onClick: () => Y(t),
|
|
239
241
|
"aria-label": `Remove attachment ${e.name}`,
|
|
240
242
|
children: "×"
|
|
241
243
|
})
|
|
242
244
|
]
|
|
243
245
|
}, `${e.name}-${t}`))
|
|
244
246
|
}),
|
|
245
|
-
|
|
247
|
+
V && /* @__PURE__ */ E("p", {
|
|
246
248
|
className: "mt-2 text-xs text-muted-foreground",
|
|
247
249
|
children: [
|
|
248
250
|
"Uploading ",
|
|
249
|
-
|
|
251
|
+
V,
|
|
250
252
|
"..."
|
|
251
253
|
]
|
|
252
254
|
})
|
|
253
255
|
] })
|
|
254
256
|
]
|
|
255
|
-
}), /* @__PURE__ */
|
|
257
|
+
}), /* @__PURE__ */ E("div", {
|
|
256
258
|
className: "flex flex-col gap-3 sm:flex-row",
|
|
257
|
-
children: [/* @__PURE__ */
|
|
259
|
+
children: [/* @__PURE__ */ T(n, {
|
|
258
260
|
type: "submit",
|
|
259
261
|
"data-tour": "support-ticket-submit",
|
|
260
|
-
disabled:
|
|
262
|
+
disabled: M || !L.subject || !L.description,
|
|
261
263
|
className: "flex-1",
|
|
262
|
-
children:
|
|
264
|
+
children: M ? /* @__PURE__ */ E(w, { children: [/* @__PURE__ */ T(b, {
|
|
263
265
|
size: 18,
|
|
264
266
|
className: "animate-spin"
|
|
265
|
-
}), "Creating…"] }) : /* @__PURE__ */
|
|
266
|
-
}), /* @__PURE__ */
|
|
267
|
+
}), "Creating…"] }) : /* @__PURE__ */ E(w, { children: [/* @__PURE__ */ T(S, { size: 18 }), "Create Ticket"] })
|
|
268
|
+
}), /* @__PURE__ */ T(n, {
|
|
267
269
|
type: "button",
|
|
268
270
|
variant: "outline",
|
|
269
|
-
onClick: () =>
|
|
271
|
+
onClick: () => k(".."),
|
|
270
272
|
children: "Cancel"
|
|
271
273
|
})]
|
|
272
274
|
})]
|
|
@@ -276,6 +278,6 @@ function E() {
|
|
|
276
278
|
});
|
|
277
279
|
}
|
|
278
280
|
//#endregion
|
|
279
|
-
export {
|
|
281
|
+
export { k as CreateTicketPage };
|
|
280
282
|
|
|
281
283
|
//# sourceMappingURL=CreateTicketPage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CreateTicketPage.js","names":[],"sources":["../../../src/support/pages/CreateTicketPage.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\nimport { useNavigate } from 'react-router-dom';\nimport { ArrowLeft, Loader2, Plus, Paperclip } from 'lucide-react';\nimport { Button, Input } from '../components/ui';\nimport { useTicketOperations } from '../hooks/useTicketOperations';\nimport { useGetTicketCategoriesQuery } from '../../generated/global-operations';\nimport { useNotification } from '../hooks/useNotification';\nimport { PageLayout } from '../components/PageLayout';\nimport { NotificationToast } from '../components/NotificationToast';\nimport { useSupport } from '../providers/SupportProvider';\nimport { joinPath } from '../utils';\nimport { extractErrorMessage } from '../utils/errors';\nimport { uploadSupportAttachmentFiles } from '../utils/supportFiles';\nimport { ATTACHMENTS_FAILED_PARAM } from '../constants';\nimport { SupportTicketPriority, type CreateSupportTicketInput } from '../../generated/global-types';\n\n/**\n * Client-side minimum lengths. Keep these in lockstep with the server-side\n * validators in global-support-svc/src/modules/support/utils/validation.ts —\n * when the server tightens or loosens these, update them here too. These are\n * best-effort UX hints only; the server's validation error is authoritative\n * and surfaces through `extractErrorMessage` on the catch path.\n */\nconst MIN_SUBJECT_LENGTH = 5;\nconst MIN_DESCRIPTION_LENGTH = 10;\n\nexport function CreateTicketPage() {\n const navigate = useNavigate();\n const { basePath = '' } = useSupport();\n const { createTicket, createTicketLoading, updateTicket } = useTicketOperations();\n const { data: categoriesData, loading: categoriesLoading } = useGetTicketCategoriesQuery({\n variables: {\n filter: { isActive: true },\n limit: 100,\n offset: 0,\n },\n });\n const activeCategories = [...(categoriesData?.ticketCategories?.nodes ?? [])].sort(\n (first, second) => first.displayOrder - second.displayOrder\n );\n const [formData, setFormData] = useState<CreateSupportTicketInput>({\n subject: '',\n description: '',\n priority: SupportTicketPriority.Normal,\n categoryId: undefined,\n });\n const [attachedFiles, setAttachedFiles] = useState<File[]>([]);\n const [uploadingFileName, setUploadingFileName] = useState<string | null>(null);\n const { notification, notify: showNotification } = useNotification();\n\n // Track the post-success navigate timer so unmounting mid-flight (Cancel\n // / back button / fast subsequent create) doesn't fire a delayed navigate.\n const navigateTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const clearNavigateTimeout = (): void => {\n if (navigateTimeoutRef.current) {\n clearTimeout(navigateTimeoutRef.current);\n navigateTimeoutRef.current = null;\n }\n };\n\n useEffect(() => clearNavigateTimeout, []);\n\n const handleSubmit = async (e: React.FormEvent) => {\n e.preventDefault();\n\n if (formData.subject.trim().length < MIN_SUBJECT_LENGTH) {\n showNotification('error', `Subject must be at least ${MIN_SUBJECT_LENGTH} characters long.`);\n return;\n }\n if ((formData.description ?? '').trim().length < MIN_DESCRIPTION_LENGTH) {\n showNotification(\n 'error',\n `Description must be at least ${MIN_DESCRIPTION_LENGTH} characters long.`\n );\n return;\n }\n\n try {\n const ticket = await createTicket({\n ...formData,\n priority: formData.priority ?? undefined,\n categoryId: formData.categoryId ?? undefined,\n });\n if (!ticket) {\n return;\n }\n\n if (attachedFiles.length > 0) {\n try {\n const uploadResult = await uploadSupportAttachmentFiles({\n ticketId: ticket.id,\n files: attachedFiles,\n onFileProgress: (fileName, progress) => {\n if (progress < 100) {\n setUploadingFileName(fileName);\n }\n },\n });\n\n await updateTicket(ticket.id, {\n metadata: {\n initialAttachmentIds: uploadResult.files.map((file) => file.id),\n },\n });\n setUploadingFileName(null);\n setAttachedFiles([]);\n } catch (uploadError) {\n setUploadingFileName(null);\n // Carry only a code-level flag in the URL — never the raw backend\n // error. Query strings persist in browser history, referer, proxy\n // logs, and analytics; a verbose server error (e.g. an S3 key, a\n // tenant id, a stack line) landing there is an information leak.\n // The destination page composes the user-facing message entirely\n // client-side via useAttachmentsFailedToast.\n console.error('[support] create ticket: attachments failed', uploadError);\n const nextParams = new URLSearchParams({\n [ATTACHMENTS_FAILED_PARAM]: '1',\n });\n navigate(joinPath(basePath, `tickets/${ticket.id}?${nextParams.toString()}`));\n return;\n }\n }\n\n showNotification('success', 'Ticket created successfully!');\n clearNavigateTimeout();\n navigateTimeoutRef.current = setTimeout(() => {\n navigate(joinPath(basePath, `tickets/${ticket.id}`));\n navigateTimeoutRef.current = null;\n }, 1000);\n } catch (error) {\n // Prefer the server error message when available — client-side\n // validation (`MIN_SUBJECT_LENGTH` etc.) is best-effort; the server\n // is authoritative and its message is what should reach the user\n // if we reached the `createTicket` call and it rejected.\n const message = extractErrorMessage(error, 'Failed to create ticket. Please try again.');\n showNotification('error', message, 5000);\n }\n };\n\n const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n const files = Array.from(event.target.files || []);\n setAttachedFiles((current) => [...current, ...files]);\n event.target.value = '';\n };\n\n const removeAttachedFile = (fileIndex: number) => {\n setAttachedFiles((current) => current.filter((_, index) => index !== fileIndex));\n };\n\n return (\n <PageLayout showHeader={false}>\n <NotificationToast notification={notification} />\n\n {/* Header */}\n <div className=\"flex items-center gap-4 mb-6\">\n <Button variant=\"ghost\" size=\"sm\" onClick={() => navigate('..')} className=\"p-2\">\n <ArrowLeft size={20} />\n </Button>\n <div>\n <h1 className=\"text-2xl font-bold text-foreground\">Create New Ticket</h1>\n <p className=\"text-sm text-muted-foreground\">Submit a new support request</p>\n </div>\n </div>\n\n {/* Form */}\n <div className=\"max-w-2xl\">\n <form onSubmit={handleSubmit} className=\"space-y-6\">\n <div className=\"p-6 rounded-xl border bg-card space-y-6\">\n <div>\n <label\n htmlFor=\"support-ticket-subject\"\n className=\"mb-2 block text-sm font-medium text-foreground\"\n >\n Subject <span className=\"text-destructive\">*</span>\n </label>\n <Input\n id=\"support-ticket-subject\"\n data-tour=\"support-ticket-subject\"\n type=\"text\"\n required\n value={formData.subject}\n onChange={(e: React.ChangeEvent<HTMLInputElement>) =>\n setFormData({ ...formData, subject: e.target.value })\n }\n placeholder=\"Brief description of your issue\"\n />\n </div>\n\n <div>\n <label\n htmlFor=\"support-ticket-description\"\n className=\"mb-2 block text-sm font-medium text-foreground\"\n >\n Description <span className=\"text-destructive\">*</span>\n </label>\n <textarea\n id=\"support-ticket-description\"\n data-tour=\"support-ticket-description\"\n aria-label=\"Description\"\n required\n rows={6}\n value={formData.description || ''}\n onChange={(e) => setFormData({ ...formData, description: e.target.value })}\n className=\"w-full px-4 py-3 rounded-lg border bg-background text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary transition-colors\"\n placeholder=\"Provide detailed information about your issue\"\n />\n <p className=\"mt-2 text-xs text-muted-foreground\">\n Markdown is supported, including fenced code blocks.\n </p>\n </div>\n\n <div>\n <label\n htmlFor=\"support-ticket-priority\"\n className=\"mb-2 block text-sm font-medium text-foreground\"\n >\n Priority\n </label>\n <select\n id=\"support-ticket-priority\"\n data-tour=\"support-ticket-priority\"\n value={formData.priority || 'NORMAL'}\n onChange={(e) =>\n setFormData({ ...formData, priority: e.target.value as SupportTicketPriority })\n }\n className=\"w-full px-4 py-3 rounded-lg border bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary transition-colors\"\n >\n <option value=\"LOW\">Low - General question or minor issue</option>\n <option value=\"NORMAL\">Normal - Standard support request</option>\n <option value=\"HIGH\">High - Significant impact on work</option>\n <option value=\"CRITICAL\">Critical - Complete blocker, urgent</option>\n </select>\n </div>\n\n <div>\n <label\n htmlFor=\"support-ticket-category\"\n className=\"mb-2 block text-sm font-medium text-foreground\"\n >\n Category\n </label>\n <select\n id=\"support-ticket-category\"\n data-tour=\"support-ticket-category\"\n value={formData.categoryId || ''}\n onChange={(e) =>\n setFormData({\n ...formData,\n categoryId: e.target.value || undefined,\n })\n }\n className=\"w-full px-4 py-3 rounded-lg border bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary transition-colors\"\n >\n <option value=\"\">\n {categoriesLoading ? 'Loading categories...' : 'Select a category'}\n </option>\n {activeCategories.map((category) => (\n <option key={category.id} value={category.id}>\n {category.name}\n </option>\n ))}\n </select>\n </div>\n\n <div>\n <span\n id=\"create-ticket-attachments-heading\"\n className=\"mb-2 block text-sm font-medium text-foreground\"\n >\n Attachments\n </span>\n <label\n data-tour=\"support-ticket-attachments\"\n className=\"flex cursor-pointer items-center justify-center gap-2 rounded-lg border border-dashed border-border bg-muted/20 p-4 text-sm text-muted-foreground transition-colors hover:bg-muted/40\"\n >\n <Paperclip size={16} />\n <span>Attach files, screenshots, logs, or documents</span>\n <input\n type=\"file\"\n multiple\n aria-labelledby=\"create-ticket-attachments-heading\"\n className=\"hidden\"\n onChange={handleFileChange}\n />\n </label>\n\n {attachedFiles.length > 0 && (\n <div className=\"mt-3 flex flex-wrap gap-2\">\n {attachedFiles.map((file, index) => (\n <div\n key={`${file.name}-${index}`}\n className=\"flex items-center gap-2 rounded-lg border bg-background px-3 py-2 text-sm\"\n >\n <Paperclip size={14} />\n <span className=\"max-w-[240px] truncate\">{file.name}</span>\n <button\n type=\"button\"\n className=\"flex min-h-11 min-w-11 items-center justify-center rounded text-muted-foreground hover:text-foreground\"\n onClick={() => removeAttachedFile(index)}\n aria-label={`Remove attachment ${file.name}`}\n >\n ×\n </button>\n </div>\n ))}\n </div>\n )}\n\n {uploadingFileName && (\n <p className=\"mt-2 text-xs text-muted-foreground\">\n Uploading {uploadingFileName}...\n </p>\n )}\n </div>\n </div>\n\n <div className=\"flex flex-col gap-3 sm:flex-row\">\n <Button\n type=\"submit\"\n data-tour=\"support-ticket-submit\"\n disabled={createTicketLoading || !formData.subject || !formData.description}\n className=\"flex-1\"\n >\n {createTicketLoading ? (\n <>\n <Loader2 size={18} className=\"animate-spin\" />\n Creating…\n </>\n ) : (\n <>\n <Plus size={18} />\n Create Ticket\n </>\n )}\n </Button>\n <Button type=\"button\" variant=\"outline\" onClick={() => navigate('..')}>\n Cancel\n </Button>\n </div>\n </form>\n </div>\n </PageLayout>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAuBA,IAAM,IAAqB,GACrB,IAAyB;AAE/B,SAAgB,IAAmB;CACjC,IAAM,IAAW,GAAa,EACxB,EAAE,cAAW,OAAO,GAAY,EAChC,EAAE,iBAAc,wBAAqB,oBAAiB,GAAqB,EAC3E,EAAE,MAAM,GAAgB,SAAS,MAAsB,EAA4B,EACvF,W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kD;UACrC;UAAkB;UAC3B;;QAEF,EAAA,CAAA;OACF;SAEN,kBAAC,OAAD;MAAK,WAAU;gBAAf,CACE,kBAAC,GAAD;OACE,MAAK;OACL,aAAU;OACV,UAAU,KAAuB,CAAC,EAAS,WAAW,CAAC,EAAS;OAChE,WAAU;iBAET,IACC,kBAAA,GAAA,EAAA,UAAA,CACE,kBAAC,GAAD;QAAS,MAAM;QAAI,WAAU;QAAiB,CAAA,EAAA,YAE7C,EAAA,CAAA,GAEH,kBAAA,GAAA,EAAA,UAAA,CACE,kBAAC,GAAD,EAAM,MAAM,IAAM,CAAA,EAAA,gBAEjB,EAAA,CAAA;OAEE,CAAA,EACT,kBAAC,GAAD;OAAQ,MAAK;OAAS,SAAQ;OAAU,eAAe,EAAS,KAAK;iBAAE;OAE9D,CAAA,CACL;QACD;;IACH,CAAA;GACK"}
|
|
1
|
+
{"version":3,"file":"CreateTicketPage.js","names":[],"sources":["../../../src/support/pages/CreateTicketPage.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\nimport { useNavigate } from 'react-router-dom';\nimport { ArrowLeft, Loader2, Plus, Paperclip } from 'lucide-react';\nimport { Button, Input } from '../components/ui';\nimport { useTicketOperations } from '../hooks/useTicketOperations';\nimport { useGetTicketCategoriesQuery } from '../../generated/global-operations';\nimport { useNotification } from '../hooks/useNotification';\nimport { PageLayout } from '../components/PageLayout';\nimport { NotificationToast } from '../components/NotificationToast';\nimport { useSupport } from '../providers/SupportProvider';\nimport { joinPath } from '../utils';\nimport { extractErrorMessage } from '../utils/errors';\nimport {\n SUPPORT_ATTACHMENT_ACCEPT,\n partitionAttachments,\n rejectedAttachmentsMessage,\n} from '../utils/attachments';\nimport { uploadSupportAttachmentFiles } from '../utils/supportFiles';\nimport { ATTACHMENTS_FAILED_PARAM } from '../constants';\nimport { SupportTicketPriority, type CreateSupportTicketInput } from '../../generated/global-types';\n\n/**\n * Client-side minimum lengths. Keep these in lockstep with the server-side\n * validators in global-support-svc/src/modules/support/utils/validation.ts —\n * when the server tightens or loosens these, update them here too. These are\n * best-effort UX hints only; the server's validation error is authoritative\n * and surfaces through `extractErrorMessage` on the catch path.\n */\nconst MIN_SUBJECT_LENGTH = 5;\nconst MIN_DESCRIPTION_LENGTH = 10;\n\nexport function CreateTicketPage() {\n const navigate = useNavigate();\n const { basePath = '' } = useSupport();\n const { createTicket, createTicketLoading, updateTicket } = useTicketOperations();\n const { data: categoriesData, loading: categoriesLoading } = useGetTicketCategoriesQuery({\n variables: {\n filter: { isActive: true },\n limit: 100,\n offset: 0,\n },\n });\n const activeCategories = [...(categoriesData?.ticketCategories?.nodes ?? [])].sort(\n (first, second) => first.displayOrder - second.displayOrder\n );\n const [formData, setFormData] = useState<CreateSupportTicketInput>({\n subject: '',\n description: '',\n priority: SupportTicketPriority.Normal,\n categoryId: undefined,\n });\n const [attachedFiles, setAttachedFiles] = useState<File[]>([]);\n const [uploadingFileName, setUploadingFileName] = useState<string | null>(null);\n const { notification, notify: showNotification } = useNotification();\n\n // Track the post-success navigate timer so unmounting mid-flight (Cancel\n // / back button / fast subsequent create) doesn't fire a delayed navigate.\n const navigateTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const clearNavigateTimeout = (): void => {\n if (navigateTimeoutRef.current) {\n clearTimeout(navigateTimeoutRef.current);\n navigateTimeoutRef.current = null;\n }\n };\n\n useEffect(() => clearNavigateTimeout, []);\n\n const handleSubmit = async (e: React.FormEvent) => {\n e.preventDefault();\n\n if (formData.subject.trim().length < MIN_SUBJECT_LENGTH) {\n showNotification('error', `Subject must be at least ${MIN_SUBJECT_LENGTH} characters long.`);\n return;\n }\n if ((formData.description ?? '').trim().length < MIN_DESCRIPTION_LENGTH) {\n showNotification(\n 'error',\n `Description must be at least ${MIN_DESCRIPTION_LENGTH} characters long.`\n );\n return;\n }\n\n try {\n const ticket = await createTicket({\n ...formData,\n priority: formData.priority ?? undefined,\n categoryId: formData.categoryId ?? undefined,\n });\n if (!ticket) {\n return;\n }\n\n if (attachedFiles.length > 0) {\n try {\n const uploadResult = await uploadSupportAttachmentFiles({\n ticketId: ticket.id,\n files: attachedFiles,\n onFileProgress: (fileName, progress) => {\n if (progress < 100) {\n setUploadingFileName(fileName);\n }\n },\n });\n\n await updateTicket(ticket.id, {\n metadata: {\n initialAttachmentIds: uploadResult.files.map((file) => file.id),\n },\n });\n setUploadingFileName(null);\n setAttachedFiles([]);\n } catch (uploadError) {\n setUploadingFileName(null);\n // Carry only a code-level flag in the URL — never the raw backend\n // error. Query strings persist in browser history, referer, proxy\n // logs, and analytics; a verbose server error (e.g. an S3 key, a\n // tenant id, a stack line) landing there is an information leak.\n // The destination page composes the user-facing message entirely\n // client-side via useAttachmentsFailedToast.\n console.error('[support] create ticket: attachments failed', uploadError);\n const nextParams = new URLSearchParams({\n [ATTACHMENTS_FAILED_PARAM]: '1',\n });\n navigate(joinPath(basePath, `tickets/${ticket.id}?${nextParams.toString()}`));\n return;\n }\n }\n\n showNotification('success', 'Ticket created successfully!');\n clearNavigateTimeout();\n navigateTimeoutRef.current = setTimeout(() => {\n navigate(joinPath(basePath, `tickets/${ticket.id}`));\n navigateTimeoutRef.current = null;\n }, 1000);\n } catch (error) {\n // Prefer the server error message when available — client-side\n // validation (`MIN_SUBJECT_LENGTH` etc.) is best-effort; the server\n // is authoritative and its message is what should reach the user\n // if we reached the `createTicket` call and it rejected.\n const message = extractErrorMessage(error, 'Failed to create ticket. Please try again.');\n showNotification('error', message, 5000);\n }\n };\n\n const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n const files = Array.from(event.target.files || []);\n const { accepted, rejected } = partitionAttachments(files);\n if (accepted.length > 0) {\n setAttachedFiles((current) => [...current, ...accepted]);\n }\n if (rejected.length > 0) {\n showNotification('error', rejectedAttachmentsMessage(rejected), 6000);\n }\n event.target.value = '';\n };\n\n const removeAttachedFile = (fileIndex: number) => {\n setAttachedFiles((current) => current.filter((_, index) => index !== fileIndex));\n };\n\n return (\n <PageLayout showHeader={false}>\n <NotificationToast notification={notification} />\n\n {/* Header */}\n <div className=\"flex items-center gap-4 mb-6\">\n <Button variant=\"ghost\" size=\"sm\" onClick={() => navigate('..')} className=\"p-2\">\n <ArrowLeft size={20} />\n </Button>\n <div>\n <h1 className=\"text-2xl font-bold text-foreground\">Create New Ticket</h1>\n <p className=\"text-sm text-muted-foreground\">Submit a new support request</p>\n </div>\n </div>\n\n {/* Form */}\n <div className=\"max-w-2xl\">\n <form onSubmit={handleSubmit} className=\"space-y-6\">\n <div className=\"p-6 rounded-xl border bg-card space-y-6\">\n <div>\n <label\n htmlFor=\"support-ticket-subject\"\n className=\"mb-2 block text-sm font-medium text-foreground\"\n >\n Subject <span className=\"text-destructive\">*</span>\n </label>\n <Input\n id=\"support-ticket-subject\"\n data-tour=\"support-ticket-subject\"\n type=\"text\"\n required\n value={formData.subject}\n onChange={(e: React.ChangeEvent<HTMLInputElement>) =>\n setFormData({ ...formData, subject: e.target.value })\n }\n placeholder=\"Brief description of your issue\"\n />\n </div>\n\n <div>\n <label\n htmlFor=\"support-ticket-description\"\n className=\"mb-2 block text-sm font-medium text-foreground\"\n >\n Description <span className=\"text-destructive\">*</span>\n </label>\n <textarea\n id=\"support-ticket-description\"\n data-tour=\"support-ticket-description\"\n aria-label=\"Description\"\n required\n rows={6}\n value={formData.description || ''}\n onChange={(e) => setFormData({ ...formData, description: e.target.value })}\n className=\"w-full px-4 py-3 rounded-lg border bg-background text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary transition-colors\"\n placeholder=\"Provide detailed information about your issue\"\n />\n <p className=\"mt-2 text-xs text-muted-foreground\">\n Markdown is supported, including fenced code blocks.\n </p>\n </div>\n\n <div>\n <label\n htmlFor=\"support-ticket-priority\"\n className=\"mb-2 block text-sm font-medium text-foreground\"\n >\n Priority\n </label>\n <select\n id=\"support-ticket-priority\"\n data-tour=\"support-ticket-priority\"\n value={formData.priority || 'NORMAL'}\n onChange={(e) =>\n setFormData({ ...formData, priority: e.target.value as SupportTicketPriority })\n }\n className=\"w-full px-4 py-3 rounded-lg border bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary transition-colors\"\n >\n <option value=\"LOW\">Low - General question or minor issue</option>\n <option value=\"NORMAL\">Normal - Standard support request</option>\n <option value=\"HIGH\">High - Significant impact on work</option>\n <option value=\"CRITICAL\">Critical - Complete blocker, urgent</option>\n </select>\n </div>\n\n <div>\n <label\n htmlFor=\"support-ticket-category\"\n className=\"mb-2 block text-sm font-medium text-foreground\"\n >\n Category\n </label>\n <select\n id=\"support-ticket-category\"\n data-tour=\"support-ticket-category\"\n value={formData.categoryId || ''}\n onChange={(e) =>\n setFormData({\n ...formData,\n categoryId: e.target.value || undefined,\n })\n }\n className=\"w-full px-4 py-3 rounded-lg border bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary transition-colors\"\n >\n <option value=\"\">\n {categoriesLoading ? 'Loading categories...' : 'Select a category'}\n </option>\n {activeCategories.map((category) => (\n <option key={category.id} value={category.id}>\n {category.name}\n </option>\n ))}\n </select>\n </div>\n\n <div>\n <span\n id=\"create-ticket-attachments-heading\"\n className=\"mb-2 block text-sm font-medium text-foreground\"\n >\n Attachments\n </span>\n <label\n data-tour=\"support-ticket-attachments\"\n className=\"flex cursor-pointer items-center justify-center gap-2 rounded-lg border border-dashed border-border bg-muted/20 p-4 text-sm text-muted-foreground transition-colors hover:bg-muted/40\"\n >\n <Paperclip size={16} />\n <span>Attach files, screenshots, logs, or documents</span>\n <input\n type=\"file\"\n multiple\n aria-labelledby=\"create-ticket-attachments-heading\"\n className=\"hidden\"\n accept={SUPPORT_ATTACHMENT_ACCEPT}\n onChange={handleFileChange}\n />\n </label>\n\n {attachedFiles.length > 0 && (\n <div className=\"mt-3 flex flex-wrap gap-2\">\n {attachedFiles.map((file, index) => (\n <div\n key={`${file.name}-${index}`}\n className=\"flex items-center gap-2 rounded-lg border bg-background px-3 py-2 text-sm\"\n >\n <Paperclip size={14} />\n <span className=\"max-w-[240px] truncate\">{file.name}</span>\n <button\n type=\"button\"\n className=\"flex min-h-11 min-w-11 items-center justify-center rounded text-muted-foreground hover:text-foreground\"\n onClick={() => removeAttachedFile(index)}\n aria-label={`Remove attachment ${file.name}`}\n >\n ×\n </button>\n </div>\n ))}\n </div>\n )}\n\n {uploadingFileName && (\n <p className=\"mt-2 text-xs text-muted-foreground\">\n Uploading {uploadingFileName}...\n </p>\n )}\n </div>\n </div>\n\n <div className=\"flex flex-col gap-3 sm:flex-row\">\n <Button\n type=\"submit\"\n data-tour=\"support-ticket-submit\"\n disabled={createTicketLoading || !formData.subject || !formData.description}\n className=\"flex-1\"\n >\n {createTicketLoading ? (\n <>\n <Loader2 size={18} className=\"animate-spin\" />\n Creating…\n </>\n ) : (\n <>\n <Plus size={18} />\n Create Ticket\n </>\n )}\n </Button>\n <Button type=\"button\" variant=\"outline\" onClick={() => navigate('..')}>\n Cancel\n </Button>\n </div>\n </form>\n </div>\n </PageLayout>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA4BA,IAAM,IAAqB,GACrB,IAAyB;AAE/B,SAAgB,IAAmB;CACjC,IAAM,IAAW,GAAa,EACxB,EAAE,cAAW,OAAO,GAAY,EAChC,EAAE,iBAAc,wBAAqB,oBAAiB,GAAqB,EAC3E,EAAE,MAAM,GAAgB,SAAS,MAAsB,EAA4B,EACvF,WAAW;EACT,QAAQ,EAAE,UAAU,IAAM;EAC1B,OAAO;EACP,QAAQ;EACT,EACF,CAAC,EACI,IAAmB,CAAC,GAAI,GAAgB,kBAAkB,SAAS,EAAE,CAAE,CAAC,MAC3E,GAAO,MAAW,EAAM,eAAe,EAAO,aAChD,EACK,CAAC,GAAU,KAAe,EAAmC;EACjE,SAAS;EACT,aAAa;EACb,UAAU,EAAsB;EAChC,YAAY,KAAA;EACb,CAAC,EACI,CAAC,GAAe,KAAoB,EAAiB,EAAE,CAAC,EACxD,CAAC,GAAmB,KAAwB,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AC,GAAD;QAAS,MAAM;QAAI,WAAU;QAAiB,CAAA,EAAA,YAE7C,EAAA,CAAA,GAEH,kBAAA,GAAA,EAAA,UAAA,CACE,kBAAC,GAAD,EAAM,MAAM,IAAM,CAAA,EAAA,gBAEjB,EAAA,CAAA;OAEE,CAAA,EACT,kBAAC,GAAD;OAAQ,MAAK;OAAS,SAAQ;OAAU,eAAe,EAAS,KAAK;iBAAE;OAE9D,CAAA,CACL;QACD;;IACH,CAAA;GACK"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
//#region src/support/utils/attachments.ts
|
|
2
|
+
var e = {
|
|
3
|
+
png: "image/png",
|
|
4
|
+
jpg: "image/jpeg",
|
|
5
|
+
jpeg: "image/jpeg",
|
|
6
|
+
webp: "image/webp",
|
|
7
|
+
pdf: "application/pdf",
|
|
8
|
+
txt: "text/plain",
|
|
9
|
+
doc: "application/msword",
|
|
10
|
+
docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
|
11
|
+
}, t = Object.keys(e), n = new Set(Object.values(e)), r = [...new Set(Object.values(e)), ...Object.keys(e).map((e) => `.${e}`)].join(","), i = t.join(", ").toUpperCase(), a = 5 * 1024 * 1024 * 1024;
|
|
12
|
+
function o(e) {
|
|
13
|
+
let t = e.lastIndexOf(".");
|
|
14
|
+
return t >= 0 ? e.slice(t + 1).toLowerCase() : "";
|
|
15
|
+
}
|
|
16
|
+
function s(e) {
|
|
17
|
+
let r = t.includes(o(e.name)), i = !e.type || n.has(e.type);
|
|
18
|
+
return r && i;
|
|
19
|
+
}
|
|
20
|
+
function c(e) {
|
|
21
|
+
return s(e) && e.size <= 5368709120;
|
|
22
|
+
}
|
|
23
|
+
function l(e) {
|
|
24
|
+
let t = [], n = [];
|
|
25
|
+
for (let r of e) c(r) ? t.push(r) : n.push(r);
|
|
26
|
+
return {
|
|
27
|
+
accepted: t,
|
|
28
|
+
rejected: n
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function u(e) {
|
|
32
|
+
return e >= 1024 * 1024 * 1024 ? `${Math.round(e / (1024 * 1024 * 1024))} GB` : e >= 1024 * 1024 ? `${Math.round(e / (1024 * 1024))} MB` : `${Math.round(e / 1024)} KB`;
|
|
33
|
+
}
|
|
34
|
+
function d(e) {
|
|
35
|
+
let t = e.filter((e) => s(e) && e.size > 5368709120), n = e.filter((e) => !s(e)), r = [];
|
|
36
|
+
if (n.length > 0) {
|
|
37
|
+
let e = n.map((e) => e.name).join(", ");
|
|
38
|
+
r.push(`Unsupported file type: ${e}. Allowed types: ${i}.`);
|
|
39
|
+
}
|
|
40
|
+
if (t.length > 0) {
|
|
41
|
+
let e = t.map((e) => e.name).join(", ");
|
|
42
|
+
r.push(`File too large: ${e}. Maximum size is ${u(a)}.`);
|
|
43
|
+
}
|
|
44
|
+
return r.join(" ");
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
export { r as SUPPORT_ATTACHMENT_ACCEPT, l as partitionAttachments, d as rejectedAttachmentsMessage };
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=attachments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachments.js","names":[],"sources":["../../../src/support/utils/attachments.ts"],"sourcesContent":["/**\n * Support attachment allowlist — kept in sync with the backend\n * (`global-support-svc` SUPPORT_ALLOWED_EXTENSIONS / SUPPORT_ALLOWED_MIME_TYPES,\n * default set in `support-attachment.service.ts`). The file picker `accept`\n * and client-side validation here mirror that set so a file the backend would\n * reject is never offered or silently sent (which surfaced as the opaque\n * \"Attachment file extension is not allowed\" error).\n */\n/**\n * Single source of truth: allowed extension -> MIME type. Both the `accept`\n * string and the extension/MIME allowlists are derived from this map, so the\n * picker and the validator can never drift out of sync.\n */\nconst EXT_TO_MIME: Record<string, string> = {\n png: 'image/png',\n jpg: 'image/jpeg',\n jpeg: 'image/jpeg',\n webp: 'image/webp',\n pdf: 'application/pdf',\n txt: 'text/plain',\n doc: 'application/msword',\n docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',\n};\n\nexport const SUPPORT_ALLOWED_EXTENSIONS = Object.keys(EXT_TO_MIME) as readonly string[];\n\nconst SUPPORT_ALLOWED_MIME_TYPES = new Set(Object.values(EXT_TO_MIME));\n\n/**\n * `accept` value for <input type=\"file\">. Derived from EXT_TO_MIME so it always\n * matches the validator. Includes both MIME types and extension hints so the\n * native picker filters correctly across browsers/OSes.\n */\nexport const SUPPORT_ATTACHMENT_ACCEPT = [\n ...new Set(Object.values(EXT_TO_MIME)),\n ...Object.keys(EXT_TO_MIME).map((ext) => `.${ext}`),\n].join(',');\n\n/** Human-readable allowed-types label for error messages. */\nexport const SUPPORT_ALLOWED_TYPES_LABEL = SUPPORT_ALLOWED_EXTENSIONS.join(', ').toUpperCase();\n\n/**\n * Max attachment size, mirroring the backend cap\n * (`global-support-svc` SUPPORT_MAX_FILE_SIZE_BYTES, default 5 GiB; the service\n * throws \"Attachment exceeds the maximum support upload size\" past this). We\n * reject oversized files here too so the user gets immediate feedback instead\n * of waiting through a long upload only to be rejected server-side.\n */\nexport const SUPPORT_MAX_ATTACHMENT_BYTES = 5 * 1024 * 1024 * 1024; // 5 GiB\n\nfunction getFileExtension(fileName: string): string {\n const dotIndex = fileName.lastIndexOf('.');\n return dotIndex >= 0 ? fileName.slice(dotIndex + 1).toLowerCase() : '';\n}\n\nfunction isAllowedType(file: File): boolean {\n const extOk = SUPPORT_ALLOWED_EXTENSIONS.includes(getFileExtension(file.name));\n // Defense-in-depth only — NOT a security boundary. Most browsers derive\n // `file.type` from the extension, so a renamed `payload.exe` -> `payload.png`\n // will usually still report `image/png` and pass. This MIME check mainly\n // catches mismatches from drag-and-drop or less common browsers; the backend\n // (content/magic-byte validation in global-support-svc) is authoritative.\n // When `file.type` is empty (unknown type), fall back to extension-only.\n const mimeOk = !file.type || SUPPORT_ALLOWED_MIME_TYPES.has(file.type);\n return extOk && mimeOk;\n}\n\nexport function isAllowedAttachment(file: File): boolean {\n return isAllowedType(file) && file.size <= SUPPORT_MAX_ATTACHMENT_BYTES;\n}\n\n/**\n * Split a selection into allowed/rejected. Drag-drop and \"All files\" picker\n * overrides bypass the `accept` attribute, so callers must validate here too.\n */\nexport function partitionAttachments(files: File[]): { accepted: File[]; rejected: File[] } {\n const accepted: File[] = [];\n const rejected: File[] = [];\n for (const file of files) {\n if (isAllowedAttachment(file)) {\n accepted.push(file);\n } else {\n rejected.push(file);\n }\n }\n return { accepted, rejected };\n}\n\nfunction formatBytes(bytes: number): string {\n if (bytes >= 1024 * 1024 * 1024) return `${Math.round(bytes / (1024 * 1024 * 1024))} GB`;\n if (bytes >= 1024 * 1024) return `${Math.round(bytes / (1024 * 1024))} MB`;\n return `${Math.round(bytes / 1024)} KB`;\n}\n\nexport function rejectedAttachmentsMessage(rejected: File[]): string {\n const oversized = rejected.filter(\n (file) => isAllowedType(file) && file.size > SUPPORT_MAX_ATTACHMENT_BYTES\n );\n const wrongType = rejected.filter((file) => !isAllowedType(file));\n const parts: string[] = [];\n if (wrongType.length > 0) {\n const names = wrongType.map((file) => file.name).join(', ');\n parts.push(`Unsupported file type: ${names}. Allowed types: ${SUPPORT_ALLOWED_TYPES_LABEL}.`);\n }\n if (oversized.length > 0) {\n const names = oversized.map((file) => file.name).join(', ');\n parts.push(\n `File too large: ${names}. Maximum size is ${formatBytes(SUPPORT_MAX_ATTACHMENT_BYTES)}.`\n );\n }\n return parts.join(' ');\n}\n"],"mappings":";AAaA,IAAM,IAAsC;CAC1C,KAAK;CACL,KAAK;CACL,MAAM;CACN,MAAM;CACN,KAAK;CACL,KAAK;CACL,KAAK;CACL,MAAM;CACP,EAEY,IAA6B,OAAO,KAAK,EAAY,EAE5D,IAA6B,IAAI,IAAI,OAAO,OAAO,EAAY,CAAC,EAOzD,IAA4B,CACvC,GAAG,IAAI,IAAI,OAAO,OAAO,EAAY,CAAC,EACtC,GAAG,OAAO,KAAK,EAAY,CAAC,KAAK,MAAQ,IAAI,IAAM,CACpD,CAAC,KAAK,I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