@channelhub/widget 0.1.6 → 0.1.7
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/index.cjs +5 -5
- package/dist/index.js +279 -258
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/ChannelHubInbox.tsx +51 -16
- package/src/types.ts +1 -0
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as e, jsxs as n, Fragment as te } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef as Le, createElement as Pe, createContext as nt, useRef as ee, useState as
|
|
2
|
+
import { forwardRef as Le, createElement as Pe, createContext as nt, useRef as ee, useState as y, useMemo as Ee, useCallback as We, useEffect as Y, useImperativeHandle as yt, useContext as Ne, Component as mt } from "react";
|
|
3
3
|
import { createPortal as it } from "react-dom";
|
|
4
4
|
/**
|
|
5
5
|
* @license lucide-react v0.468.0 - ISC
|
|
@@ -54,7 +54,7 @@ const vt = Le(
|
|
|
54
54
|
...O
|
|
55
55
|
},
|
|
56
56
|
[
|
|
57
|
-
...m.map(([S,
|
|
57
|
+
...m.map(([S, W]) => Pe(S, W)),
|
|
58
58
|
...Array.isArray(C) ? C : [C]
|
|
59
59
|
]
|
|
60
60
|
)
|
|
@@ -461,40 +461,40 @@ const Pt = (t) => {
|
|
|
461
461
|
function _e({ status: t }) {
|
|
462
462
|
return t === "read" ? /* @__PURE__ */ e(Ge, { size: 11, strokeWidth: 2, style: { display: "inline", verticalAlign: "middle" } }) : t === "delivered" ? /* @__PURE__ */ e(Ge, { size: 11, strokeWidth: 2, style: { display: "inline", verticalAlign: "middle", opacity: 0.5 } }) : t === "sent" ? /* @__PURE__ */ e(ot, { size: 11, strokeWidth: 2, style: { display: "inline", verticalAlign: "middle" } }) : null;
|
|
463
463
|
}
|
|
464
|
-
const pn = Le(function({ apiUrl: i, token: r, theme: o, height: s, defaultConversationId: C, disableAttachments: m, disableNotificationSound: O, hideKeyboardHint: f, locale: S = "vi", extensions:
|
|
465
|
-
var
|
|
466
|
-
const E = ee(new Mt(i, r)), [j, A] =
|
|
467
|
-
|
|
464
|
+
const pn = Le(function({ apiUrl: i, token: r, theme: o, height: s, defaultConversationId: C, disableAttachments: m, disableNotificationSound: O, hideKeyboardHint: f, locale: S = "vi", extensions: W, onNewMessage: I, onConversationSelect: H }, R) {
|
|
465
|
+
var l, g, b, M, Z;
|
|
466
|
+
const E = ee(new Mt(i, r)), [j, A] = y([]), [F, K] = y([]), [ne, U] = y(), [w, _] = y(), k = ee(void 0), [L, se] = y(""), [z, D] = y({ provider: "all", unreadOnly: !1 }), [le, v] = y(!1), Q = ee(null), N = ee(null), [x, J] = y(null), [he, h] = y(!0), [B, P] = y(""), [q, ie] = y(() => !!(W != null && W.length)), [re, V] = y(280), [ye, ke] = y(!1), [be, fe] = y(0), G = (o == null ? void 0 : o.primaryColor) ?? "#2563eb", de = Ee(() => new Map(F.map((c) => [c.id, c])), [F]), me = ee(null), [we, Oe] = y(0), Se = We(async (c, u) => {
|
|
467
|
+
c.contactId && await E.current.patchContact(c.contactId, u), A((T) => T.map(($) => $.id === c.id ? { ...$, contactExternalId: u ?? void 0 } : $)), _((T) => T && T.id === c.id ? { ...T, contactExternalId: u ?? void 0 } : T), fe((T) => T + 1);
|
|
468
468
|
}, []), Ce = We(() => {
|
|
469
|
-
|
|
469
|
+
fe((c) => c + 1);
|
|
470
470
|
}, []), Ie = Ee(() => {
|
|
471
|
-
const
|
|
472
|
-
return ["facebook", "instagram", "telegram", "zalo", "livechat"].filter((u) =>
|
|
473
|
-
}, [F]),
|
|
471
|
+
const c = new Set(F.map((u) => u.provider));
|
|
472
|
+
return ["facebook", "instagram", "telegram", "zalo", "livechat"].filter((u) => c.has(u));
|
|
473
|
+
}, [F]), ue = Ee(() => {
|
|
474
474
|
var u;
|
|
475
|
-
const
|
|
476
|
-
for (const
|
|
477
|
-
const
|
|
478
|
-
|
|
475
|
+
const c = {};
|
|
476
|
+
for (const T of j) {
|
|
477
|
+
const $ = ((u = de.get(T.connectionId)) == null ? void 0 : u.provider) ?? "unknown";
|
|
478
|
+
c[$] = (c[$] ?? 0) + 1;
|
|
479
479
|
}
|
|
480
|
-
return
|
|
480
|
+
return c;
|
|
481
481
|
}, [j, de]);
|
|
482
|
-
function Me(
|
|
483
|
-
const u =
|
|
482
|
+
function Me(c) {
|
|
483
|
+
const u = c.clientX, T = re;
|
|
484
484
|
ke(!0), document.body.style.cursor = "col-resize", document.body.style.userSelect = "none";
|
|
485
|
-
function
|
|
486
|
-
const Re = Math.max(200, Math.min(480,
|
|
485
|
+
function $(xe) {
|
|
486
|
+
const Re = Math.max(200, Math.min(480, T + (u - xe.clientX)));
|
|
487
487
|
V(Re);
|
|
488
488
|
}
|
|
489
|
-
function
|
|
490
|
-
ke(!1), document.body.style.cursor = "", document.body.style.userSelect = "", document.removeEventListener("mousemove",
|
|
489
|
+
function ce() {
|
|
490
|
+
ke(!1), document.body.style.cursor = "", document.body.style.userSelect = "", document.removeEventListener("mousemove", $), document.removeEventListener("mouseup", ce);
|
|
491
491
|
}
|
|
492
|
-
document.addEventListener("mousemove",
|
|
492
|
+
document.addEventListener("mousemove", $), document.addEventListener("mouseup", ce);
|
|
493
493
|
}
|
|
494
|
-
const oe = We(async (
|
|
494
|
+
const oe = We(async (c) => {
|
|
495
495
|
try {
|
|
496
|
-
const u = await E.current.listConversations(
|
|
497
|
-
A((
|
|
496
|
+
const u = await E.current.listConversations(c);
|
|
497
|
+
A((T) => c ? [...T, ...u.items] : u.items), U(u.nextCursor), !c && u.items.length && _((T) => T ?? (C ? u.items.find(($) => $.id === C) ?? u.items[0] : u.items[0])), P("");
|
|
498
498
|
} catch (u) {
|
|
499
499
|
P(u instanceof Error ? u.message : "Không tải được hội thoại");
|
|
500
500
|
} finally {
|
|
@@ -502,20 +502,20 @@ const pn = Le(function({ apiUrl: i, token: r, theme: o, height: s, defaultConver
|
|
|
502
502
|
}
|
|
503
503
|
}, [C]);
|
|
504
504
|
Y(() => (E.current.listConnections().then(K).catch(() => {
|
|
505
|
-
}), oe(), E.current.connectSSE((u,
|
|
505
|
+
}), oe(), E.current.connectSSE((u, T) => {
|
|
506
506
|
if (u === "message.new" || u === "conversation.updated") {
|
|
507
507
|
if (oe(), u === "message.new") {
|
|
508
|
-
const
|
|
509
|
-
if ((
|
|
508
|
+
const $ = typeof T == "object" && T ? T : {}, ce = $.conversationId ? String($.conversationId) : "", xe = $.messageId ? String($.messageId) : "";
|
|
509
|
+
if (($.direction ? String($.direction) : "") === "inbound" && !O && Ut(), ce && ce === k.current && xe && me.current) {
|
|
510
510
|
const ft = me.current;
|
|
511
511
|
E.current.getMessage(xe).then((gt) => {
|
|
512
512
|
ft(gt);
|
|
513
513
|
}).catch(() => {
|
|
514
514
|
});
|
|
515
515
|
}
|
|
516
|
-
I == null || I(
|
|
516
|
+
I == null || I(ce || k.current || "");
|
|
517
517
|
}
|
|
518
|
-
} else u === "message.status_updated" && Oe((
|
|
518
|
+
} else u === "message.status_updated" && Oe(($) => $ + 1);
|
|
519
519
|
})), [oe, I]), Y(() => {
|
|
520
520
|
k.current = w == null ? void 0 : w.id;
|
|
521
521
|
}, [w]), Y(() => {
|
|
@@ -523,18 +523,18 @@ const pn = Le(function({ apiUrl: i, token: r, theme: o, height: s, defaultConver
|
|
|
523
523
|
});
|
|
524
524
|
}, [w == null ? void 0 : w.id]), Y(() => {
|
|
525
525
|
if (!le) return;
|
|
526
|
-
function
|
|
527
|
-
var
|
|
528
|
-
(
|
|
526
|
+
function c(u) {
|
|
527
|
+
var T, $;
|
|
528
|
+
(T = Q.current) != null && T.contains(u.target) || ($ = N.current) != null && $.contains(u.target) || v(!1);
|
|
529
529
|
}
|
|
530
|
-
return document.addEventListener("mousedown",
|
|
530
|
+
return document.addEventListener("mousedown", c), () => document.removeEventListener("mousedown", c);
|
|
531
531
|
}, [le]);
|
|
532
532
|
const ze = Ee(() => {
|
|
533
|
-
const
|
|
533
|
+
const c = L.toLowerCase().trim();
|
|
534
534
|
return j.filter((u) => {
|
|
535
535
|
var Re;
|
|
536
|
-
const
|
|
537
|
-
return
|
|
536
|
+
const T = `${u.contactName ?? ""} ${u.subject ?? ""} ${u.providerConversationKey}`.toLowerCase(), $ = ((Re = de.get(u.connectionId)) == null ? void 0 : Re.provider) ?? "unknown", ce = z.provider === "all" || $ === z.provider, xe = !z.unreadOnly || (u.unreadCount ?? 0) > 0;
|
|
537
|
+
return ce && xe && (!c || T.includes(c));
|
|
538
538
|
});
|
|
539
539
|
}, [j, de, z, L]), Te = z.provider !== "all" || z.unreadOnly, ae = S === "en" ? {
|
|
540
540
|
today: "TODAY",
|
|
@@ -557,9 +557,9 @@ const pn = Le(function({ apiUrl: i, token: r, theme: o, height: s, defaultConver
|
|
|
557
557
|
send: "Gửi",
|
|
558
558
|
all: "Tất cả"
|
|
559
559
|
};
|
|
560
|
-
yt(
|
|
561
|
-
openConversation: (
|
|
562
|
-
const u = j.find((
|
|
560
|
+
yt(R, () => ({
|
|
561
|
+
openConversation: (c) => {
|
|
562
|
+
const u = j.find((T) => T.id === c);
|
|
563
563
|
u && _(u);
|
|
564
564
|
},
|
|
565
565
|
refresh: () => void oe()
|
|
@@ -573,25 +573,25 @@ const pn = Le(function({ apiUrl: i, token: r, theme: o, height: s, defaultConver
|
|
|
573
573
|
gridTemplateColumns: q ? `minmax(260px, 300px) minmax(0, 1fr) ${re}px` : "minmax(260px, 300px) minmax(0, 1fr)",
|
|
574
574
|
transition: ye ? "none" : "grid-template-columns 220ms ease"
|
|
575
575
|
};
|
|
576
|
-
return
|
|
576
|
+
return he ? /* @__PURE__ */ n("div", { style: { ...p.state, borderRadius: (o == null ? void 0 : o.borderRadius) ?? "16px" }, children: [
|
|
577
577
|
/* @__PURE__ */ e(Fe, {}),
|
|
578
578
|
" Đang tải hộp thư…"
|
|
579
|
-
] }) :
|
|
579
|
+
] }) : B && !j.length ? /* @__PURE__ */ n("div", { style: { ...p.state, color: "#b42318", borderRadius: (o == null ? void 0 : o.borderRadius) ?? "16px" }, children: [
|
|
580
580
|
/* @__PURE__ */ e(St, { size: 16, strokeWidth: 2 }),
|
|
581
581
|
" ",
|
|
582
|
-
|
|
582
|
+
B,
|
|
583
583
|
/* @__PURE__ */ e("button", { style: p.retry, onClick: () => {
|
|
584
584
|
h(!0), oe();
|
|
585
585
|
}, children: "Thử lại" })
|
|
586
586
|
] }) : /* @__PURE__ */ e(qe.Provider, { value: i, children: /* @__PURE__ */ e(st.Provider, { value: r, children: /* @__PURE__ */ n("div", { style: He, onFocusCapture: () => {
|
|
587
|
-
const
|
|
587
|
+
const c = window.scrollY;
|
|
588
588
|
requestAnimationFrame(() => {
|
|
589
|
-
window.scrollY !==
|
|
589
|
+
window.scrollY !== c && window.scrollTo({ top: c, behavior: "instant" });
|
|
590
590
|
});
|
|
591
591
|
}, children: [
|
|
592
592
|
/* @__PURE__ */ n("aside", { style: p.sidebar, children: [
|
|
593
593
|
/* @__PURE__ */ n("div", { style: p.brand, children: [
|
|
594
|
-
/* @__PURE__ */ e("div", { style: { ...p.brandMark, background: G, overflow: "hidden", padding: 0 }, children: (
|
|
594
|
+
/* @__PURE__ */ e("div", { style: { ...p.brandMark, background: G, overflow: "hidden", padding: 0 }, children: (l = o == null ? void 0 : o.branding) != null && l.logoUrl ? /* @__PURE__ */ e("img", { src: o.branding.logoUrl, alt: "", style: { width: "100%", height: "100%", objectFit: "cover" } }) : ((g = o == null ? void 0 : o.branding) == null ? void 0 : g.mark) ?? "C" }),
|
|
595
595
|
/* @__PURE__ */ n("div", { children: [
|
|
596
596
|
/* @__PURE__ */ e("strong", { children: ((b = o == null ? void 0 : o.branding) == null ? void 0 : b.name) ?? "Hộp thư" }),
|
|
597
597
|
!((M = o == null ? void 0 : o.branding) != null && M.name) && /* @__PURE__ */ e("span", { style: p.eyebrow, children: "CHANNELHUB" })
|
|
@@ -600,18 +600,18 @@ const pn = Le(function({ apiUrl: i, token: r, theme: o, height: s, defaultConver
|
|
|
600
600
|
] }),
|
|
601
601
|
/* @__PURE__ */ n("div", { style: p.search, children: [
|
|
602
602
|
/* @__PURE__ */ e(Xe, { size: 16, strokeWidth: 2 }),
|
|
603
|
-
/* @__PURE__ */ e(Et, { "aria-label": ae.searchPlaceholder, value: L, onChange: (
|
|
604
|
-
L && /* @__PURE__ */ e("button", { style: p.clear, onClick: () =>
|
|
603
|
+
/* @__PURE__ */ e(Et, { "aria-label": ae.searchPlaceholder, value: L, onChange: (c) => se(c.target.value), placeholder: ae.searchPlaceholder }),
|
|
604
|
+
L && /* @__PURE__ */ e("button", { style: p.clear, onClick: () => se(""), "aria-label": "Xóa tìm kiếm", children: "×" })
|
|
605
605
|
] }),
|
|
606
606
|
Te && /* @__PURE__ */ n("div", { style: { display: "flex", gap: 4, flexWrap: "wrap", padding: "0 14px 8px" }, children: [
|
|
607
607
|
z.provider !== "all" && /* @__PURE__ */ n("span", { style: { display: "inline-flex", alignItems: "center", gap: 4, background: "#eef2ff", color: G, borderRadius: 6, fontSize: 11, padding: "2px 8px", fontWeight: 500 }, children: [
|
|
608
608
|
/* @__PURE__ */ e($e, { provider: z.provider }),
|
|
609
609
|
Ye(z.provider),
|
|
610
|
-
/* @__PURE__ */ e("button", { style: { border: 0, background: "none", cursor: "pointer", color: G, padding: 0, lineHeight: 1, display: "flex" }, onClick: () => D((
|
|
610
|
+
/* @__PURE__ */ e("button", { style: { border: 0, background: "none", cursor: "pointer", color: G, padding: 0, lineHeight: 1, display: "flex" }, onClick: () => D((c) => ({ ...c, provider: "all" })), "aria-label": "Xóa filter kênh", children: /* @__PURE__ */ e(je, { size: 10 }) })
|
|
611
611
|
] }),
|
|
612
612
|
z.unreadOnly && /* @__PURE__ */ n("span", { style: { display: "inline-flex", alignItems: "center", gap: 4, background: "#eef2ff", color: G, borderRadius: 6, fontSize: 11, padding: "2px 8px", fontWeight: 500 }, children: [
|
|
613
613
|
ae.unreadOnly,
|
|
614
|
-
/* @__PURE__ */ e("button", { style: { border: 0, background: "none", cursor: "pointer", color: G, padding: 0, lineHeight: 1, display: "flex" }, onClick: () => D((
|
|
614
|
+
/* @__PURE__ */ e("button", { style: { border: 0, background: "none", cursor: "pointer", color: G, padding: 0, lineHeight: 1, display: "flex" }, onClick: () => D((c) => ({ ...c, unreadOnly: !1 })), "aria-label": "Xóa filter chưa đọc", children: /* @__PURE__ */ e(je, { size: 10 }) })
|
|
615
615
|
] }),
|
|
616
616
|
/* @__PURE__ */ e("button", { style: { border: 0, background: "none", cursor: "pointer", color: d.muted, fontSize: 11, padding: "2px 4px" }, onClick: () => D({ provider: "all", unreadOnly: !1 }), children: "Xóa tất cả" })
|
|
617
617
|
] }),
|
|
@@ -627,9 +627,9 @@ const pn = Le(function({ apiUrl: i, token: r, theme: o, height: s, defaultConver
|
|
|
627
627
|
style: { ...p.iconButton, background: Te ? `${G}14` : "transparent", color: Te ? G : d.muted },
|
|
628
628
|
"aria-label": "Bộ lọc",
|
|
629
629
|
onClick: () => {
|
|
630
|
-
var
|
|
630
|
+
var c;
|
|
631
631
|
if (!le) {
|
|
632
|
-
const u = (
|
|
632
|
+
const u = (c = Q.current) == null ? void 0 : c.getBoundingClientRect();
|
|
633
633
|
u && J({ top: u.bottom + 6, left: u.left });
|
|
634
634
|
}
|
|
635
635
|
v((u) => !u);
|
|
@@ -646,27 +646,27 @@ const pn = Le(function({ apiUrl: i, token: r, theme: o, height: s, defaultConver
|
|
|
646
646
|
style: { position: "fixed", top: x.top, left: x.left, zIndex: 9999, background: d.white, border: `1px solid ${d.line}`, borderRadius: 10, padding: "12px 14px", boxShadow: "0 8px 24px rgba(23,32,51,.14)", minWidth: 210, fontFamily: (o == null ? void 0 : o.fontFamily) ?? "Inter, ui-sans-serif, system-ui, sans-serif", fontSize: 13 },
|
|
647
647
|
children: [
|
|
648
648
|
/* @__PURE__ */ e("div", { style: { fontSize: 10, fontWeight: 700, color: d.muted, letterSpacing: 1, textTransform: "uppercase", marginBottom: 8 }, children: "Kênh" }),
|
|
649
|
-
["all", ...Ie].map((
|
|
650
|
-
/* @__PURE__ */ e("input", { type: "radio", name: "provider-filter", checked: z.provider ===
|
|
651
|
-
|
|
649
|
+
["all", ...Ie].map((c) => /* @__PURE__ */ n("label", { style: { display: "flex", alignItems: "center", gap: 8, padding: "5px 6px", cursor: "pointer", borderRadius: 6, background: z.provider === c ? `${G}0f` : "transparent" }, children: [
|
|
650
|
+
/* @__PURE__ */ e("input", { type: "radio", name: "provider-filter", checked: z.provider === c, onChange: () => D((u) => ({ ...u, provider: c })), style: { accentColor: G } }),
|
|
651
|
+
c === "all" ? /* @__PURE__ */ n("span", { style: { color: d.ink }, children: [
|
|
652
652
|
ae.all,
|
|
653
653
|
" (",
|
|
654
654
|
j.length,
|
|
655
655
|
")"
|
|
656
656
|
] }) : /* @__PURE__ */ n("span", { style: { display: "flex", alignItems: "center", gap: 5, color: d.ink }, children: [
|
|
657
|
-
/* @__PURE__ */ e($e, { provider:
|
|
658
|
-
Ye(
|
|
657
|
+
/* @__PURE__ */ e($e, { provider: c }),
|
|
658
|
+
Ye(c),
|
|
659
659
|
" ",
|
|
660
660
|
/* @__PURE__ */ n("span", { style: { color: d.muted }, children: [
|
|
661
661
|
"(",
|
|
662
|
-
|
|
662
|
+
ue[c] ?? 0,
|
|
663
663
|
")"
|
|
664
664
|
] })
|
|
665
665
|
] })
|
|
666
|
-
] },
|
|
666
|
+
] }, c)),
|
|
667
667
|
/* @__PURE__ */ e("div", { style: { borderTop: `1px solid ${d.line}`, margin: "8px 0 6px" } }),
|
|
668
668
|
/* @__PURE__ */ n("label", { style: { display: "flex", alignItems: "center", gap: 8, padding: "5px 6px", cursor: "pointer", borderRadius: 6, background: z.unreadOnly ? `${G}0f` : "transparent" }, children: [
|
|
669
|
-
/* @__PURE__ */ e("input", { type: "checkbox", checked: z.unreadOnly, onChange: (
|
|
669
|
+
/* @__PURE__ */ e("input", { type: "checkbox", checked: z.unreadOnly, onChange: (c) => D((u) => ({ ...u, unreadOnly: c.target.checked })), style: { accentColor: G } }),
|
|
670
670
|
/* @__PURE__ */ e("span", { style: { color: d.ink }, children: ae.unreadOnly })
|
|
671
671
|
] })
|
|
672
672
|
]
|
|
@@ -675,12 +675,12 @@ const pn = Le(function({ apiUrl: i, token: r, theme: o, height: s, defaultConver
|
|
|
675
675
|
document.body
|
|
676
676
|
),
|
|
677
677
|
/* @__PURE__ */ n(ct, { style: p.conversationList, children: [
|
|
678
|
-
ze.map((
|
|
678
|
+
ze.map((c) => {
|
|
679
679
|
var u;
|
|
680
|
-
return /* @__PURE__ */ e(Nt, { conversation:
|
|
681
|
-
_(
|
|
680
|
+
return /* @__PURE__ */ e(Nt, { conversation: c, provider: (u = de.get(c.connectionId)) == null ? void 0 : u.provider, selected: (w == null ? void 0 : w.id) === c.id, primary: G, onSelect: () => {
|
|
681
|
+
_(c), H == null || H(c.id), E.current.markRead(c.id).then(() => oe()).catch(() => {
|
|
682
682
|
});
|
|
683
|
-
} },
|
|
683
|
+
} }, c.id);
|
|
684
684
|
}),
|
|
685
685
|
!ze.length && /* @__PURE__ */ n("div", { style: p.emptySmall, children: [
|
|
686
686
|
/* @__PURE__ */ e("div", { style: p.emptyIcon, children: /* @__PURE__ */ e(Xe, { size: 16, strokeWidth: 2 }) }),
|
|
@@ -698,18 +698,18 @@ const pn = Le(function({ apiUrl: i, token: r, theme: o, height: s, defaultConver
|
|
|
698
698
|
connection: de.get(w.connectionId),
|
|
699
699
|
client: E.current,
|
|
700
700
|
primary: G,
|
|
701
|
-
error:
|
|
702
|
-
onRegisterAppend: (
|
|
703
|
-
me.current =
|
|
701
|
+
error: B,
|
|
702
|
+
onRegisterAppend: (c) => {
|
|
703
|
+
me.current = c;
|
|
704
704
|
},
|
|
705
705
|
refreshKey: we,
|
|
706
706
|
infoOpen: q,
|
|
707
|
-
onToggleInfo: () => ie((
|
|
707
|
+
onToggleInfo: () => ie((c) => !c),
|
|
708
708
|
t: ae,
|
|
709
709
|
disableAttachments: m,
|
|
710
710
|
hideKeyboardHint: f,
|
|
711
|
-
extensions:
|
|
712
|
-
onLinkContact: (
|
|
711
|
+
extensions: W,
|
|
712
|
+
onLinkContact: (c) => Se(w, c),
|
|
713
713
|
onRefreshContactInfo: Ce
|
|
714
714
|
},
|
|
715
715
|
w.id
|
|
@@ -723,21 +723,21 @@ const pn = Le(function({ apiUrl: i, token: r, theme: o, height: s, defaultConver
|
|
|
723
723
|
onClose: () => ie(!1),
|
|
724
724
|
client: E.current,
|
|
725
725
|
onStartResize: Me,
|
|
726
|
-
extensions:
|
|
726
|
+
extensions: W,
|
|
727
727
|
extRefreshKey: be,
|
|
728
|
-
onLinkContact: (
|
|
728
|
+
onLinkContact: (c) => Se(w, c),
|
|
729
729
|
onRefreshContactInfo: Ce
|
|
730
730
|
}
|
|
731
731
|
)
|
|
732
732
|
] }) }) });
|
|
733
733
|
});
|
|
734
734
|
function Nt({ conversation: t, provider: i, selected: r, primary: o, onSelect: s }) {
|
|
735
|
-
const [C, m] =
|
|
736
|
-
let
|
|
737
|
-
r ?
|
|
735
|
+
const [C, m] = y(!1), O = t.contactName ?? t.subject ?? t.providerConversationKey, f = t.unreadCount ?? 0, S = t.lastMessageText ?? "", W = t.lastMessageDirection === "outbound" ? "Bạn: " : "", I = S.length > 60 ? S.slice(0, 60) + "…" : S, H = S ? W + I : "";
|
|
736
|
+
let R = "transparent";
|
|
737
|
+
r ? R = "#eef2ff" : C ? R = "#f7f9fc" : f > 0 && (R = "#f0f4ff");
|
|
738
738
|
const E = {
|
|
739
739
|
...p.row,
|
|
740
|
-
background:
|
|
740
|
+
background: R,
|
|
741
741
|
...r ? { boxShadow: `inset 3px 0 0 ${o}` } : f > 0 && !C ? { boxShadow: `inset 3px 0 0 ${o}` } : {}
|
|
742
742
|
};
|
|
743
743
|
return /* @__PURE__ */ n(
|
|
@@ -763,97 +763,97 @@ function Nt({ conversation: t, provider: i, selected: r, primary: o, onSelect: s
|
|
|
763
763
|
}
|
|
764
764
|
);
|
|
765
765
|
}
|
|
766
|
-
function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s, error: C, onRegisterAppend: m, refreshKey: O, infoOpen: f, onToggleInfo: S, t:
|
|
766
|
+
function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s, error: C, onRegisterAppend: m, refreshKey: O, infoOpen: f, onToggleInfo: S, t: W, disableAttachments: I, hideKeyboardHint: H, extensions: R, onLinkContact: E, onRefreshContactInfo: j }) {
|
|
767
767
|
var He;
|
|
768
|
-
const [A, F] =
|
|
768
|
+
const [A, F] = y([]), [K, ne] = y(), [U, w] = y(""), [_, k] = y(!0), [L, se] = y(!1), [z, D] = y(""), le = ee(null), v = t.contactName ?? t.subject ?? t.providerConversationKey, Q = ee(null), N = ee(null), [x, J] = y(null), [he, h] = y(!1), [B, P] = y(!1), [q, ie] = y(!1), [re, V] = y(0), ye = ee(null), ke = ee(null), be = ee(null), [fe, G] = y(!1), [de, me] = y(""), [we, Oe] = y([]), Se = ee(null), Ce = ee(null);
|
|
769
769
|
Y(() => () => {
|
|
770
770
|
x != null && x.objectUrl && URL.revokeObjectURL(x.objectUrl);
|
|
771
771
|
}, [x == null ? void 0 : x.objectUrl]), Y(() => {
|
|
772
772
|
if (!q) return;
|
|
773
|
-
function
|
|
773
|
+
function l(g) {
|
|
774
774
|
var b, M;
|
|
775
|
-
(b = ke.current) != null && b.contains(
|
|
775
|
+
(b = ke.current) != null && b.contains(g.target) || (M = ye.current) != null && M.contains(g.target) || ie(!1);
|
|
776
776
|
}
|
|
777
|
-
return document.addEventListener("mousedown",
|
|
777
|
+
return document.addEventListener("mousedown", l), () => document.removeEventListener("mousedown", l);
|
|
778
778
|
}, [q]), Y(() => {
|
|
779
779
|
o.listCannedResponses().then(Oe).catch(() => {
|
|
780
780
|
});
|
|
781
781
|
}, [o]), Y(() => {
|
|
782
|
-
if (!
|
|
783
|
-
function
|
|
782
|
+
if (!fe) return;
|
|
783
|
+
function l(g) {
|
|
784
784
|
var b, M;
|
|
785
|
-
(b = Ce.current) != null && b.contains(
|
|
785
|
+
(b = Ce.current) != null && b.contains(g.target) || (M = Se.current) != null && M.contains(g.target) || G(!1);
|
|
786
786
|
}
|
|
787
|
-
return document.addEventListener("mousedown",
|
|
788
|
-
}, [
|
|
789
|
-
const Ie = ee(!0),
|
|
790
|
-
|
|
787
|
+
return document.addEventListener("mousedown", l), () => document.removeEventListener("mousedown", l);
|
|
788
|
+
}, [fe]);
|
|
789
|
+
const Ie = ee(!0), ue = We(async (l, g) => {
|
|
790
|
+
g || (Ie.current = !l);
|
|
791
791
|
try {
|
|
792
|
-
const b = await o.listMessages(t.id,
|
|
793
|
-
F((M) =>
|
|
792
|
+
const b = await o.listMessages(t.id, l);
|
|
793
|
+
F((M) => l ? [...b.items, ...M] : b.items), ne(b.nextCursor);
|
|
794
794
|
} catch (b) {
|
|
795
795
|
D(b instanceof Error ? b.message : "Không tải được tin nhắn");
|
|
796
796
|
} finally {
|
|
797
|
-
|
|
797
|
+
g || k(!1);
|
|
798
798
|
}
|
|
799
799
|
}, [o, t.id]);
|
|
800
800
|
Y(() => {
|
|
801
|
-
k(!0),
|
|
802
|
-
}, [
|
|
803
|
-
O &&
|
|
801
|
+
k(!0), ue();
|
|
802
|
+
}, [ue]), Y(() => {
|
|
803
|
+
O && ue(void 0, !0);
|
|
804
804
|
}, [O]), Y(() => {
|
|
805
805
|
Ie.current && requestAnimationFrame(() => {
|
|
806
|
-
const
|
|
807
|
-
|
|
806
|
+
const l = le.current;
|
|
807
|
+
l && (l.scrollTop = l.scrollHeight);
|
|
808
808
|
});
|
|
809
|
-
}, [A]), Y(() => (m == null || m((
|
|
810
|
-
Ie.current = !0, F((
|
|
809
|
+
}, [A]), Y(() => (m == null || m((l) => {
|
|
810
|
+
Ie.current = !0, F((g) => g.some((b) => b.id === l.id) ? g : [...g, l]);
|
|
811
811
|
}), () => {
|
|
812
812
|
m == null || m(null);
|
|
813
813
|
}), [m]);
|
|
814
|
-
async function Me(
|
|
814
|
+
async function Me(l) {
|
|
815
815
|
var M;
|
|
816
|
-
const
|
|
817
|
-
if (!
|
|
818
|
-
|
|
819
|
-
const b = URL.createObjectURL(
|
|
820
|
-
J({ file:
|
|
816
|
+
const g = (M = l.target.files) == null ? void 0 : M[0];
|
|
817
|
+
if (!g) return;
|
|
818
|
+
l.target.value = "";
|
|
819
|
+
const b = URL.createObjectURL(g);
|
|
820
|
+
J({ file: g, uploading: !0, objectUrl: b });
|
|
821
821
|
try {
|
|
822
|
-
const Z = await o.uploadAttachment(
|
|
823
|
-
J({ file:
|
|
822
|
+
const Z = await o.uploadAttachment(g);
|
|
823
|
+
J({ file: g, uploading: !1, url: Z.url, mimeType: Z.mimeType, attachmentType: Z.attachmentType, objectUrl: b });
|
|
824
824
|
} catch {
|
|
825
825
|
URL.revokeObjectURL(b), J(null), D("Không tải lên được tệp đính kèm");
|
|
826
826
|
}
|
|
827
827
|
}
|
|
828
|
-
async function oe(
|
|
829
|
-
|
|
830
|
-
const
|
|
831
|
-
if (!(!
|
|
832
|
-
|
|
828
|
+
async function oe(l) {
|
|
829
|
+
l.preventDefault();
|
|
830
|
+
const g = U.trim(), b = x != null && x.url ? [{ url: x.url, mimeType: x.mimeType ?? "application/octet-stream", type: x.attachmentType }] : [];
|
|
831
|
+
if (!(!g && !b.length || L)) {
|
|
832
|
+
se(!0), D("");
|
|
833
833
|
try {
|
|
834
|
-
await o.sendMessage(t.id,
|
|
834
|
+
await o.sendMessage(t.id, g || void 0, b.length ? b : void 0), x != null && x.objectUrl && URL.revokeObjectURL(x.objectUrl), w(""), J(null), await ue();
|
|
835
835
|
} catch (M) {
|
|
836
836
|
D(M instanceof Error ? M.message : "Không gửi được tin nhắn");
|
|
837
837
|
} finally {
|
|
838
|
-
|
|
838
|
+
se(!1);
|
|
839
839
|
}
|
|
840
840
|
}
|
|
841
841
|
}
|
|
842
|
-
function ze(
|
|
843
|
-
const
|
|
844
|
-
if (!
|
|
845
|
-
w((
|
|
842
|
+
function ze(l) {
|
|
843
|
+
const g = be.current;
|
|
844
|
+
if (!g) {
|
|
845
|
+
w((c) => c + l), ie(!1);
|
|
846
846
|
return;
|
|
847
847
|
}
|
|
848
|
-
const b =
|
|
848
|
+
const b = g.selectionStart ?? U.length, M = g.selectionEnd ?? U.length, Z = U.slice(0, b) + l + U.slice(M);
|
|
849
849
|
w(Z), ie(!1), requestAnimationFrame(() => {
|
|
850
|
-
|
|
850
|
+
g.focus(), g.selectionStart = g.selectionEnd = b + l.length;
|
|
851
851
|
});
|
|
852
852
|
}
|
|
853
|
-
function Te(
|
|
854
|
-
w(
|
|
855
|
-
const
|
|
856
|
-
|
|
853
|
+
function Te(l) {
|
|
854
|
+
w(l), G(!1), me(""), requestAnimationFrame(() => {
|
|
855
|
+
const g = be.current;
|
|
856
|
+
g && (g.focus(), g.selectionStart = g.selectionEnd = l.length);
|
|
857
857
|
});
|
|
858
858
|
}
|
|
859
859
|
const ae = !L && (U.trim().length > 0 || (x == null ? void 0 : x.url) != null && !x.uploading);
|
|
@@ -882,39 +882,39 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
|
|
|
882
882
|
] })
|
|
883
883
|
] }),
|
|
884
884
|
/* @__PURE__ */ n(ct, { ref: le, style: p.messageArea, children: [
|
|
885
|
-
/* @__PURE__ */ e("div", { style: p.day, children:
|
|
886
|
-
K && /* @__PURE__ */ e("button", { onClick: () => void
|
|
885
|
+
/* @__PURE__ */ e("div", { style: p.day, children: W.today }),
|
|
886
|
+
K && /* @__PURE__ */ e("button", { onClick: () => void ue(K), style: p.historyButton, children: W.loadOlder }),
|
|
887
887
|
_ && /* @__PURE__ */ n("div", { style: p.messageHint, children: [
|
|
888
888
|
/* @__PURE__ */ e(Fe, {}),
|
|
889
889
|
" ",
|
|
890
|
-
|
|
890
|
+
W.loading
|
|
891
891
|
] }),
|
|
892
|
-
!_ && !A.length && /* @__PURE__ */ e("div", { style: p.messageHint, children:
|
|
893
|
-
A.map((
|
|
894
|
-
const b = (
|
|
892
|
+
!_ && !A.length && /* @__PURE__ */ e("div", { style: p.messageHint, children: W.noMessages }),
|
|
893
|
+
A.map((l, g) => {
|
|
894
|
+
const b = (R == null ? void 0 : R.flatMap((u) => u.messageEnrichments ?? [])) ?? [], M = l.direction === "inbound" && b.length > 0 && g >= A.length - 15, Z = M ? Ae(t, {
|
|
895
895
|
provider: i,
|
|
896
896
|
recentMessages: A.slice(-10),
|
|
897
897
|
linkContact: E,
|
|
898
898
|
refreshContactInfo: j,
|
|
899
|
-
sendMessage: async (
|
|
900
|
-
await o.sendMessage(t.id,
|
|
899
|
+
sendMessage: async (u, T) => {
|
|
900
|
+
await o.sendMessage(t.id, u, T), await ue(void 0, !0);
|
|
901
901
|
}
|
|
902
|
-
}) : null
|
|
902
|
+
}) : null, c = M && Z ? b.map((u, T) => {
|
|
903
|
+
var ce;
|
|
904
|
+
const $ = (ce = l.text) == null ? void 0 : ce.match(u.pattern);
|
|
905
|
+
return $ ? /* @__PURE__ */ e(Ot, { children: u.render($, Z, l) }, `${l.id}-${T}`) : null;
|
|
906
|
+
}).filter(Boolean) : [];
|
|
903
907
|
return /* @__PURE__ */ n("div", { children: [
|
|
904
|
-
/* @__PURE__ */ e(Kt, { message:
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
const R = (W = c.text) == null ? void 0 : W.match(l.pattern);
|
|
908
|
-
return R ? /* @__PURE__ */ e(Ot, { children: l.render(R, Z, c) }, `${c.id}-${u}`) : null;
|
|
909
|
-
})
|
|
910
|
-
] }, c.id);
|
|
908
|
+
/* @__PURE__ */ e(Kt, { message: l, primary: s }),
|
|
909
|
+
c.length > 0 && /* @__PURE__ */ e("div", { style: { maxWidth: "min(70%, 480px)", marginTop: -4, marginBottom: 10, display: "flex", flexDirection: "column", gap: 6 }, children: c })
|
|
910
|
+
] }, l.id);
|
|
911
911
|
})
|
|
912
912
|
] }),
|
|
913
|
-
/* @__PURE__ */ e("div", { style: { display: "flex", gap: 6, flexWrap: "wrap", padding: "6px 14px 2px", borderTop: `1px solid ${d.line}` }, children: ["Cảm ơn bạn đã liên hệ 🙏", "Mình sẽ kiểm tra ngay", "Vui lòng chờ 1-2 phút"].map((
|
|
913
|
+
/* @__PURE__ */ e("div", { style: { display: "flex", gap: 6, flexWrap: "wrap", padding: "6px 14px 2px", borderTop: `1px solid ${d.line}` }, children: ["Cảm ơn bạn đã liên hệ 🙏", "Mình sẽ kiểm tra ngay", "Vui lòng chờ 1-2 phút"].map((l) => /* @__PURE__ */ e(
|
|
914
914
|
"button",
|
|
915
915
|
{
|
|
916
916
|
type: "button",
|
|
917
|
-
onClick: () => w(
|
|
917
|
+
onClick: () => w(l),
|
|
918
918
|
style: {
|
|
919
919
|
fontSize: 11,
|
|
920
920
|
padding: "3px 10px",
|
|
@@ -925,9 +925,9 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
|
|
|
925
925
|
cursor: "pointer",
|
|
926
926
|
whiteSpace: "nowrap"
|
|
927
927
|
},
|
|
928
|
-
children:
|
|
928
|
+
children: l
|
|
929
929
|
},
|
|
930
|
-
|
|
930
|
+
l
|
|
931
931
|
)) }),
|
|
932
932
|
/* @__PURE__ */ n("form", { onSubmit: oe, style: { flex: "0 0 auto", padding: "8px 14px 12px", borderTop: `1px solid ${d.line}`, background: d.white, position: "relative" }, children: [
|
|
933
933
|
q && /* @__PURE__ */ n(
|
|
@@ -948,11 +948,11 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
|
|
|
948
948
|
fontFamily: "inherit"
|
|
949
949
|
},
|
|
950
950
|
children: [
|
|
951
|
-
/* @__PURE__ */ e("div", { style: { display: "flex", borderBottom: `1px solid ${d.line}`, background: "#f9fafb" }, children: Je.map((
|
|
951
|
+
/* @__PURE__ */ e("div", { style: { display: "flex", borderBottom: `1px solid ${d.line}`, background: "#f9fafb" }, children: Je.map((l, g) => /* @__PURE__ */ e(
|
|
952
952
|
"button",
|
|
953
953
|
{
|
|
954
954
|
type: "button",
|
|
955
|
-
onClick: () => V(
|
|
955
|
+
onClick: () => V(g),
|
|
956
956
|
style: {
|
|
957
957
|
flex: 1,
|
|
958
958
|
border: 0,
|
|
@@ -961,19 +961,19 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
|
|
|
961
961
|
fontSize: 16,
|
|
962
962
|
cursor: "pointer",
|
|
963
963
|
lineHeight: 1,
|
|
964
|
-
borderBottom: re ===
|
|
965
|
-
opacity: re ===
|
|
964
|
+
borderBottom: re === g ? `2px solid ${s}` : "2px solid transparent",
|
|
965
|
+
opacity: re === g ? 1 : 0.5,
|
|
966
966
|
transition: "opacity 100ms ease"
|
|
967
967
|
},
|
|
968
|
-
children:
|
|
968
|
+
children: l.icon
|
|
969
969
|
},
|
|
970
|
-
|
|
970
|
+
g
|
|
971
971
|
)) }),
|
|
972
|
-
/* @__PURE__ */ e("div", { style: { display: "grid", gridTemplateColumns: "repeat(8, 1fr)", gap: 2, padding: 8, maxHeight: 180, overflowY: "auto" }, children: (He = Je[re]) == null ? void 0 : He.emojis.map((
|
|
972
|
+
/* @__PURE__ */ e("div", { style: { display: "grid", gridTemplateColumns: "repeat(8, 1fr)", gap: 2, padding: 8, maxHeight: 180, overflowY: "auto" }, children: (He = Je[re]) == null ? void 0 : He.emojis.map((l, g) => /* @__PURE__ */ e(
|
|
973
973
|
"button",
|
|
974
974
|
{
|
|
975
975
|
type: "button",
|
|
976
|
-
onClick: () => ze(
|
|
976
|
+
onClick: () => ze(l),
|
|
977
977
|
style: {
|
|
978
978
|
border: 0,
|
|
979
979
|
background: "transparent",
|
|
@@ -990,14 +990,14 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
|
|
|
990
990
|
onMouseLeave: (b) => {
|
|
991
991
|
b.target.style.background = "transparent";
|
|
992
992
|
},
|
|
993
|
-
children:
|
|
993
|
+
children: l
|
|
994
994
|
},
|
|
995
|
-
|
|
995
|
+
g
|
|
996
996
|
)) })
|
|
997
997
|
]
|
|
998
998
|
}
|
|
999
999
|
),
|
|
1000
|
-
|
|
1000
|
+
fe && /* @__PURE__ */ n(
|
|
1001
1001
|
"div",
|
|
1002
1002
|
{
|
|
1003
1003
|
ref: Se,
|
|
@@ -1022,13 +1022,13 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
|
|
|
1022
1022
|
type: "text",
|
|
1023
1023
|
placeholder: "Tìm template…",
|
|
1024
1024
|
value: de,
|
|
1025
|
-
onChange: (
|
|
1025
|
+
onChange: (l) => me(l.target.value),
|
|
1026
1026
|
style: { width: "100%", boxSizing: "border-box", border: `1px solid ${d.line}`, borderRadius: 7, padding: "5px 8px", fontSize: 12, outline: "none", fontFamily: "inherit", color: d.ink }
|
|
1027
1027
|
}
|
|
1028
1028
|
) }),
|
|
1029
1029
|
/* @__PURE__ */ e("div", { style: { maxHeight: 220, overflowY: "auto" }, children: (() => {
|
|
1030
|
-
const
|
|
1031
|
-
return
|
|
1030
|
+
const l = de.trim().toLowerCase(), g = l ? we.filter((b) => b.title.toLowerCase().includes(l) || b.content.toLowerCase().includes(l) || (b.shortcut ?? "").toLowerCase().includes(l)) : we;
|
|
1031
|
+
return g.length ? g.map((b) => /* @__PURE__ */ n(
|
|
1032
1032
|
"button",
|
|
1033
1033
|
{
|
|
1034
1034
|
type: "button",
|
|
@@ -1077,18 +1077,18 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
|
|
|
1077
1077
|
ref: ke,
|
|
1078
1078
|
type: "button",
|
|
1079
1079
|
title: "Chèn emoji",
|
|
1080
|
-
onClick: () => ie((
|
|
1080
|
+
onClick: () => ie((l) => !l),
|
|
1081
1081
|
style: { ...p.toolbarBtn, background: q ? `${s}18` : "transparent", color: q ? s : "#9ca3af" },
|
|
1082
1082
|
children: /* @__PURE__ */ e($t, { size: 13, strokeWidth: 2 })
|
|
1083
1083
|
}
|
|
1084
1084
|
),
|
|
1085
1085
|
!I && /* @__PURE__ */ e("button", { type: "button", title: "Gửi ảnh / video", "aria-label": "Gửi ảnh hoặc video", style: p.toolbarBtn, onClick: () => {
|
|
1086
|
-
var
|
|
1087
|
-
return (
|
|
1086
|
+
var l;
|
|
1087
|
+
return (l = Q.current) == null ? void 0 : l.click();
|
|
1088
1088
|
}, children: /* @__PURE__ */ e(Ct, { size: 13, strokeWidth: 2 }) }),
|
|
1089
1089
|
!I && /* @__PURE__ */ e("button", { type: "button", title: "Gửi tệp đính kèm", "aria-label": "Gửi tệp đính kèm", style: p.toolbarBtn, onClick: () => {
|
|
1090
|
-
var
|
|
1091
|
-
return (
|
|
1090
|
+
var l;
|
|
1091
|
+
return (l = N.current) == null ? void 0 : l.click();
|
|
1092
1092
|
}, children: /* @__PURE__ */ e(Tt, { size: 13, strokeWidth: 2 }) }),
|
|
1093
1093
|
!I && /* @__PURE__ */ n(te, { children: [
|
|
1094
1094
|
/* @__PURE__ */ e("input", { ref: Q, type: "file", style: { display: "none" }, onChange: Me, accept: "image/*,video/mp4" }),
|
|
@@ -1101,9 +1101,9 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
|
|
|
1101
1101
|
type: "button",
|
|
1102
1102
|
title: "Template nhanh",
|
|
1103
1103
|
onClick: () => {
|
|
1104
|
-
G((
|
|
1104
|
+
G((l) => !l), me("");
|
|
1105
1105
|
},
|
|
1106
|
-
style: { ...p.toolbarBtn, background:
|
|
1106
|
+
style: { ...p.toolbarBtn, background: fe ? `${s}18` : "transparent", color: fe ? s : "#9ca3af" },
|
|
1107
1107
|
children: /* @__PURE__ */ e(Lt, { size: 13, strokeWidth: 2 })
|
|
1108
1108
|
}
|
|
1109
1109
|
),
|
|
@@ -1113,8 +1113,8 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
|
|
|
1113
1113
|
{
|
|
1114
1114
|
type: "button",
|
|
1115
1115
|
title: "In đậm",
|
|
1116
|
-
onClick: () => h((
|
|
1117
|
-
style: { ...p.toolbarBtn, fontWeight: 700, fontSize: 12, background:
|
|
1116
|
+
onClick: () => h((l) => !l),
|
|
1117
|
+
style: { ...p.toolbarBtn, fontWeight: 700, fontSize: 12, background: he ? `${s}18` : "transparent", color: he ? s : "#9ca3af", border: he ? `1px solid ${s}33` : "1px solid transparent" },
|
|
1118
1118
|
children: "B"
|
|
1119
1119
|
}
|
|
1120
1120
|
),
|
|
@@ -1123,38 +1123,59 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
|
|
|
1123
1123
|
{
|
|
1124
1124
|
type: "button",
|
|
1125
1125
|
title: "Nghiêng",
|
|
1126
|
-
onClick: () => P((
|
|
1127
|
-
style: { ...p.toolbarBtn, fontStyle: "italic", fontSize: 12, background:
|
|
1126
|
+
onClick: () => P((l) => !l),
|
|
1127
|
+
style: { ...p.toolbarBtn, fontStyle: "italic", fontSize: 12, background: B ? `${s}18` : "transparent", color: B ? s : "#9ca3af", border: B ? `1px solid ${s}33` : "1px solid transparent" },
|
|
1128
1128
|
children: "I"
|
|
1129
1129
|
}
|
|
1130
1130
|
),
|
|
1131
|
-
|
|
1131
|
+
!!(R != null && R.some((l) => {
|
|
1132
|
+
var g;
|
|
1133
|
+
return (((g = l.toolbarActions) == null ? void 0 : g.length) ?? 0) > 0;
|
|
1134
|
+
})) && /* @__PURE__ */ e("span", { style: { width: 1, height: 14, background: "#e5e7eb", margin: "0 4px" } }),
|
|
1135
|
+
R == null ? void 0 : R.flatMap((l) => l.toolbarActions ?? []).map((l, g) => /* @__PURE__ */ n(
|
|
1132
1136
|
"button",
|
|
1133
1137
|
{
|
|
1134
1138
|
type: "button",
|
|
1135
|
-
title:
|
|
1136
|
-
style:
|
|
1139
|
+
title: l.tooltip,
|
|
1140
|
+
style: l.label ? {
|
|
1141
|
+
display: "inline-flex",
|
|
1142
|
+
alignItems: "center",
|
|
1143
|
+
gap: 5,
|
|
1144
|
+
padding: "3px 9px",
|
|
1145
|
+
borderRadius: 999,
|
|
1146
|
+
border: `1px solid ${s}33`,
|
|
1147
|
+
background: `${s}0f`,
|
|
1148
|
+
color: s,
|
|
1149
|
+
fontSize: 11.5,
|
|
1150
|
+
fontWeight: 600,
|
|
1151
|
+
cursor: "pointer",
|
|
1152
|
+
lineHeight: 1.2,
|
|
1153
|
+
whiteSpace: "nowrap"
|
|
1154
|
+
} : p.toolbarBtn,
|
|
1137
1155
|
onClick: () => {
|
|
1138
1156
|
const b = (Z) => {
|
|
1139
|
-
w((
|
|
1140
|
-
`) ? `${
|
|
1141
|
-
var
|
|
1142
|
-
return (
|
|
1157
|
+
w((c) => c && !c.endsWith(" ") && !c.endsWith(`
|
|
1158
|
+
`) ? `${c} ${Z}` : `${c}${Z}`), requestAnimationFrame(() => {
|
|
1159
|
+
var c;
|
|
1160
|
+
return (c = be.current) == null ? void 0 : c.focus();
|
|
1143
1161
|
});
|
|
1144
1162
|
}, M = Ae(t, {
|
|
1145
1163
|
provider: i,
|
|
1146
1164
|
recentMessages: A.slice(-10),
|
|
1147
1165
|
linkContact: E,
|
|
1148
1166
|
refreshContactInfo: j,
|
|
1149
|
-
sendMessage: async (Z,
|
|
1150
|
-
await o.sendMessage(t.id, Z,
|
|
1167
|
+
sendMessage: async (Z, c) => {
|
|
1168
|
+
await o.sendMessage(t.id, Z, c), await ue(void 0, !0);
|
|
1151
1169
|
}
|
|
1152
1170
|
});
|
|
1153
|
-
|
|
1171
|
+
l.onClick({ ...M, insertText: b });
|
|
1154
1172
|
},
|
|
1155
|
-
children:
|
|
1173
|
+
children: [
|
|
1174
|
+
l.icon,
|
|
1175
|
+
l.label && /* @__PURE__ */ e("span", { children: l.label })
|
|
1176
|
+
]
|
|
1156
1177
|
},
|
|
1157
|
-
|
|
1178
|
+
g
|
|
1158
1179
|
))
|
|
1159
1180
|
] }),
|
|
1160
1181
|
/* @__PURE__ */ e(
|
|
@@ -1164,11 +1185,11 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
|
|
|
1164
1185
|
"aria-label": "Soạn tin nhắn",
|
|
1165
1186
|
rows: 2,
|
|
1166
1187
|
value: U,
|
|
1167
|
-
onChange: (
|
|
1168
|
-
onKeyDown: (
|
|
1169
|
-
|
|
1188
|
+
onChange: (l) => w(l.target.value),
|
|
1189
|
+
onKeyDown: (l) => {
|
|
1190
|
+
l.key === "Enter" && !l.shiftKey && (l.preventDefault(), oe(l));
|
|
1170
1191
|
},
|
|
1171
|
-
placeholder:
|
|
1192
|
+
placeholder: W.sendPlaceholder,
|
|
1172
1193
|
style: {
|
|
1173
1194
|
display: "block",
|
|
1174
1195
|
width: "100%",
|
|
@@ -1185,8 +1206,8 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
|
|
|
1185
1206
|
font: "inherit",
|
|
1186
1207
|
fontSize: 13,
|
|
1187
1208
|
lineHeight: 1.45,
|
|
1188
|
-
fontStyle:
|
|
1189
|
-
fontWeight:
|
|
1209
|
+
fontStyle: B ? "italic" : "normal",
|
|
1210
|
+
fontWeight: he ? 700 : 400
|
|
1190
1211
|
}
|
|
1191
1212
|
}
|
|
1192
1213
|
),
|
|
@@ -1223,7 +1244,7 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
|
|
|
1223
1244
|
},
|
|
1224
1245
|
children: [
|
|
1225
1246
|
L ? /* @__PURE__ */ e(lt, { size: 12, style: { animation: "channelhub-spin .7s linear infinite" } }) : /* @__PURE__ */ e(Bt, { size: 12, strokeWidth: 2 }),
|
|
1226
|
-
|
|
1247
|
+
W.send
|
|
1227
1248
|
]
|
|
1228
1249
|
}
|
|
1229
1250
|
)
|
|
@@ -1236,7 +1257,7 @@ function Ft({ conversation: t, provider: i, connection: r, client: o, primary: s
|
|
|
1236
1257
|
}
|
|
1237
1258
|
function Kt({ message: t, primary: i }) {
|
|
1238
1259
|
var K, ne, U, w, _;
|
|
1239
|
-
const r = Ne(qe), o = Ne(st), s = (k) => k.startsWith("/v1/media/proxy") ? `${r}${k}&tok=${encodeURIComponent(o)}` : k, C = t.direction === "outbound", m = ((K = t.attachments) == null ? void 0 : K.filter((k) => k.type === "image")) ?? [], O = ((ne = t.attachments) == null ? void 0 : ne.filter((k) => k.type === "sticker")) ?? [], f = ((U = t.attachments) == null ? void 0 : U.filter((k) => k.type === "video")) ?? [], S = ((w = t.attachments) == null ? void 0 : w.filter((k) => k.type === "audio")) ?? [],
|
|
1260
|
+
const r = Ne(qe), o = Ne(st), s = (k) => k.startsWith("/v1/media/proxy") ? `${r}${k}&tok=${encodeURIComponent(o)}` : k, C = t.direction === "outbound", m = ((K = t.attachments) == null ? void 0 : K.filter((k) => k.type === "image")) ?? [], O = ((ne = t.attachments) == null ? void 0 : ne.filter((k) => k.type === "sticker")) ?? [], f = ((U = t.attachments) == null ? void 0 : U.filter((k) => k.type === "video")) ?? [], S = ((w = t.attachments) == null ? void 0 : w.filter((k) => k.type === "audio")) ?? [], W = ((_ = t.attachments) == null ? void 0 : _.filter((k) => k.type === "file")) ?? [], [I, H] = y(null), R = C ? "flex-end" : "flex-start", E = /* @__PURE__ */ n("time", { style: { display: "block", marginTop: 4, fontSize: 10, opacity: 0.65, textAlign: "right", letterSpacing: 0.2, userSelect: "none" }, children: [
|
|
1240
1261
|
Ke(t.occurredAt, !0),
|
|
1241
1262
|
C && /* @__PURE__ */ n(te, { children: [
|
|
1242
1263
|
" ",
|
|
@@ -1248,8 +1269,8 @@ function Kt({ message: t, primary: i }) {
|
|
|
1248
1269
|
" ",
|
|
1249
1270
|
/* @__PURE__ */ e(_e, { status: t.status })
|
|
1250
1271
|
] })
|
|
1251
|
-
] }) }), A = C ? { ...p.bubbleOut, background: i, color: "#fff", border: "1px solid transparent" } : p.bubbleIn, F = !t.text && S.length === 0 &&
|
|
1252
|
-
return /* @__PURE__ */ n("div", { style: { ...p.messageLine, justifyContent:
|
|
1272
|
+
] }) }), A = C ? { ...p.bubbleOut, background: i, color: "#fff", border: "1px solid transparent" } : p.bubbleIn, F = !t.text && S.length === 0 && W.length === 0;
|
|
1273
|
+
return /* @__PURE__ */ n("div", { style: { ...p.messageLine, justifyContent: R, flexDirection: "column", alignItems: R }, children: [
|
|
1253
1274
|
O.map((k, L) => /* @__PURE__ */ n("div", { style: { position: "relative", marginBottom: 2 }, children: [
|
|
1254
1275
|
/* @__PURE__ */ e("img", { src: s(k.url), alt: "sticker", style: { display: "block", maxWidth: 128, maxHeight: 128, objectFit: "contain" } }),
|
|
1255
1276
|
F && m.length === 0 && f.length === 0 && L === O.length - 1 && j
|
|
@@ -1263,14 +1284,14 @@ function Kt({ message: t, primary: i }) {
|
|
|
1263
1284
|
/* @__PURE__ */ e("div", { style: { position: "absolute", inset: 0, display: "flex", alignItems: "center", justifyContent: "center", borderRadius: 12, background: "rgba(0,0,0,.25)" }, children: /* @__PURE__ */ e("div", { style: { width: 40, height: 40, borderRadius: "50%", background: "rgba(255,255,255,.9)", display: "flex", alignItems: "center", justifyContent: "center" }, children: /* @__PURE__ */ e(Rt, { size: 16, fill: "#172033", color: "#172033", style: { marginLeft: 2 } }) }) }),
|
|
1264
1285
|
F && L === f.length - 1 && j
|
|
1265
1286
|
] }, L)),
|
|
1266
|
-
(S.length > 0 ||
|
|
1287
|
+
(S.length > 0 || W.length > 0 || t.text || !m.length && !f.length && !O.length && !t.text) && /* @__PURE__ */ n("div", { style: A, children: [
|
|
1267
1288
|
S.map((k, L) => /* @__PURE__ */ e("audio", { src: s(k.url), controls: !0, style: { display: "block", width: "100%", marginBottom: 4 } }, L)),
|
|
1268
|
-
|
|
1289
|
+
W.map((k, L) => /* @__PURE__ */ n("a", { href: s(k.url), target: "_blank", rel: "noreferrer", style: { display: "block", fontSize: 12, color: C ? "#fff" : "#2563eb", textDecoration: "underline", marginBottom: 4 }, children: [
|
|
1269
1290
|
"📎 ",
|
|
1270
1291
|
Pt(k.mimeType)
|
|
1271
1292
|
] }, L)),
|
|
1272
1293
|
t.text && /* @__PURE__ */ e("p", { style: { margin: 0, whiteSpace: "pre-wrap", wordBreak: "break-word" }, children: t.text }),
|
|
1273
|
-
!S.length && !
|
|
1294
|
+
!S.length && !W.length && !t.text && /* @__PURE__ */ e("p", { style: { margin: 0, opacity: 0.5 }, children: "[attachment]" }),
|
|
1274
1295
|
E
|
|
1275
1296
|
] }),
|
|
1276
1297
|
I && it(
|
|
@@ -1294,7 +1315,7 @@ function qt({
|
|
|
1294
1315
|
onLinkContact: f,
|
|
1295
1316
|
onRefreshContactInfo: S
|
|
1296
1317
|
}) {
|
|
1297
|
-
const
|
|
1318
|
+
const W = t.contactName ?? t.subject ?? t.providerConversationKey, I = i == null ? void 0 : i.provider, H = !!(m != null && m.some((v) => v.contactInfoRows)), [R, E] = y({ channel: !0, stats: !1, extra: !0 }), j = (v) => E((Q) => ({ ...Q, [v]: !Q[v] })), [A, F] = y(""), [K, ne] = y(!1), [U, w] = y(!1), [_, k] = y(""), [L, se] = y([]), [z, D] = y(!1);
|
|
1298
1319
|
Y(() => {
|
|
1299
1320
|
F(""), w(!1), k(""), s.getNote(t.id).then((v) => {
|
|
1300
1321
|
v && F(v.content);
|
|
@@ -1316,7 +1337,7 @@ function qt({
|
|
|
1316
1337
|
).then((N) => {
|
|
1317
1338
|
if (v) return;
|
|
1318
1339
|
const x = N.filter((J) => J.status === "fulfilled").flatMap((J) => J.value);
|
|
1319
|
-
|
|
1340
|
+
se(x), D(!1);
|
|
1320
1341
|
}), () => {
|
|
1321
1342
|
v = !0;
|
|
1322
1343
|
};
|
|
@@ -1358,21 +1379,21 @@ function qt({
|
|
|
1358
1379
|
dt,
|
|
1359
1380
|
{
|
|
1360
1381
|
src: t.contactPictureUrl,
|
|
1361
|
-
fallback: ut(
|
|
1382
|
+
fallback: ut(W),
|
|
1362
1383
|
style: { ...p.avatar, width: 48, height: 48, fontSize: 16 }
|
|
1363
1384
|
}
|
|
1364
1385
|
),
|
|
1365
1386
|
/* @__PURE__ */ e("span", { style: { ...p.providerBadge, width: 20, height: 20 }, children: /* @__PURE__ */ e($e, { provider: I }) })
|
|
1366
1387
|
] }),
|
|
1367
|
-
/* @__PURE__ */ e("strong", { style: { marginTop: 10, fontSize: 15, color: d.ink, textAlign: "center" }, children:
|
|
1388
|
+
/* @__PURE__ */ e("strong", { style: { marginTop: 10, fontSize: 15, color: d.ink, textAlign: "center" }, children: W }),
|
|
1368
1389
|
/* @__PURE__ */ e("span", { style: { fontSize: 11, color: d.muted, fontFamily: "monospace", textAlign: "center" }, children: t.providerConversationKey })
|
|
1369
1390
|
] }),
|
|
1370
|
-
/* @__PURE__ */ n(Ue, { label: "KÊNH", sectionKey: "channel", expanded:
|
|
1371
|
-
/* @__PURE__ */ e(
|
|
1391
|
+
/* @__PURE__ */ n(Ue, { label: "KÊNH", sectionKey: "channel", expanded: R.channel, onToggle: () => j("channel"), children: [
|
|
1392
|
+
/* @__PURE__ */ e(pe, { label: "Nền tảng", children: /* @__PURE__ */ n("span", { style: { display: "flex", alignItems: "center", gap: 5 }, children: [
|
|
1372
1393
|
/* @__PURE__ */ e($e, { provider: I }),
|
|
1373
1394
|
/* @__PURE__ */ e("span", { children: ht(I) })
|
|
1374
1395
|
] }) }),
|
|
1375
|
-
/* @__PURE__ */ n(
|
|
1396
|
+
/* @__PURE__ */ n(pe, { label: "ID hội thoại", children: [
|
|
1376
1397
|
/* @__PURE__ */ n("span", { style: { fontFamily: "monospace", fontSize: 11 }, children: [
|
|
1377
1398
|
t.id.slice(0, 8),
|
|
1378
1399
|
"…"
|
|
@@ -1380,26 +1401,26 @@ function qt({
|
|
|
1380
1401
|
/* @__PURE__ */ e(Vt, { value: t.id })
|
|
1381
1402
|
] })
|
|
1382
1403
|
] }),
|
|
1383
|
-
/* @__PURE__ */ n(Ue, { label: "THỐNG KÊ", sectionKey: "stats", expanded:
|
|
1384
|
-
/* @__PURE__ */ e(
|
|
1385
|
-
(t.unreadCount ?? 0) > 0 && /* @__PURE__ */ e(
|
|
1404
|
+
/* @__PURE__ */ n(Ue, { label: "THỐNG KÊ", sectionKey: "stats", expanded: R.stats, onToggle: () => j("stats"), children: [
|
|
1405
|
+
/* @__PURE__ */ e(pe, { label: "Tin nhắn", value: String(t.messageCount ?? 0) }),
|
|
1406
|
+
(t.unreadCount ?? 0) > 0 && /* @__PURE__ */ e(pe, { label: "Chưa đọc", value: String(t.unreadCount), valueColor: "#ef4444" }),
|
|
1386
1407
|
/* @__PURE__ */ e(
|
|
1387
|
-
|
|
1408
|
+
pe,
|
|
1388
1409
|
{
|
|
1389
1410
|
label: "Gần nhất",
|
|
1390
1411
|
value: t.lastMessageAt ? new Date(t.lastMessageAt).toLocaleDateString("vi-VN", { day: "2-digit", month: "2-digit", year: "numeric" }) : "—"
|
|
1391
1412
|
}
|
|
1392
1413
|
),
|
|
1393
|
-
/* @__PURE__ */ e(
|
|
1414
|
+
/* @__PURE__ */ e(pe, { label: "Lần đầu", value: "—" })
|
|
1394
1415
|
] }),
|
|
1395
|
-
/* @__PURE__ */ n(Ue, { label: "THÔNG TIN BỔ SUNG", sectionKey: "extra", expanded:
|
|
1416
|
+
/* @__PURE__ */ n(Ue, { label: "THÔNG TIN BỔ SUNG", sectionKey: "extra", expanded: R.extra, onToggle: () => j("extra"), children: [
|
|
1396
1417
|
!H && /* @__PURE__ */ n(te, { children: [
|
|
1397
|
-
/* @__PURE__ */ e(
|
|
1398
|
-
/* @__PURE__ */ e(
|
|
1399
|
-
/* @__PURE__ */ e(
|
|
1418
|
+
/* @__PURE__ */ e(pe, { label: "Điện thoại", value: "— chưa có", valueMuted: !0 }),
|
|
1419
|
+
/* @__PURE__ */ e(pe, { label: "Email", value: "— chưa có", valueMuted: !0 }),
|
|
1420
|
+
/* @__PURE__ */ e(pe, { label: "Nhãn", value: "— chưa có", valueMuted: !0 })
|
|
1400
1421
|
] }),
|
|
1401
1422
|
z && L.length === 0 && /* @__PURE__ */ e("div", { style: { fontSize: 12, color: d.muted, padding: "6px 0" }, children: "Đang tải hồ sơ CRM…" }),
|
|
1402
|
-
L.map((v) => /* @__PURE__ */ e(
|
|
1423
|
+
L.map((v) => /* @__PURE__ */ e(pe, { label: v.label, children: /* @__PURE__ */ n("span", { style: { display: "inline-flex", alignItems: "center", gap: 6, flexWrap: "wrap", justifyContent: "flex-end" }, children: [
|
|
1403
1424
|
v.onClick ? /* @__PURE__ */ e(
|
|
1404
1425
|
"button",
|
|
1405
1426
|
{
|
|
@@ -1448,8 +1469,8 @@ function qt({
|
|
|
1448
1469
|
provider: I,
|
|
1449
1470
|
linkContact: f,
|
|
1450
1471
|
refreshContactInfo: S,
|
|
1451
|
-
sendMessage: async (J,
|
|
1452
|
-
await s.sendMessage(t.id, J,
|
|
1472
|
+
sendMessage: async (J, he) => {
|
|
1473
|
+
await s.sendMessage(t.id, J, he);
|
|
1453
1474
|
}
|
|
1454
1475
|
});
|
|
1455
1476
|
v.onClick(x);
|
|
@@ -1462,8 +1483,8 @@ function qt({
|
|
|
1462
1483
|
Q
|
|
1463
1484
|
);
|
|
1464
1485
|
}),
|
|
1465
|
-
/* @__PURE__ */ n("div", { style: { border:
|
|
1466
|
-
/* @__PURE__ */ e("div", { style: { display: "flex", alignItems: "center", gap: 6, padding: "7px 10px", borderBottom: "1px solid #fde68a", fontSize: 11, fontWeight: 600, color: "#92400e" }, children: "Ghi chú nội bộ" }),
|
|
1486
|
+
/* @__PURE__ */ n("div", { style: { border: `1px solid ${d.line}`, borderRadius: 10, background: "#fff", overflow: "hidden" }, children: [
|
|
1487
|
+
/* @__PURE__ */ e("div", { style: { display: "flex", alignItems: "center", gap: 6, padding: "7px 10px", borderBottom: "1px solid #fde68a", background: "#fffbeb", fontSize: 11, fontWeight: 600, color: "#92400e" }, children: "Ghi chú nội bộ" }),
|
|
1467
1488
|
/* @__PURE__ */ e(
|
|
1468
1489
|
"textarea",
|
|
1469
1490
|
{
|
|
@@ -1514,14 +1535,14 @@ function Ue({ label: t, children: i, sectionKey: r, expanded: o, onToggle: s })
|
|
|
1514
1535
|
m && i
|
|
1515
1536
|
] });
|
|
1516
1537
|
}
|
|
1517
|
-
function
|
|
1518
|
-
return /* @__PURE__ */ n("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "
|
|
1519
|
-
/* @__PURE__ */ e("span", { style: { color: d.muted, flexShrink: 0 }, children: t }),
|
|
1520
|
-
/* @__PURE__ */ e("span", { style: { color: o ?? (s ? d.muted : d.ink), textAlign: "right", minWidth: 0,
|
|
1538
|
+
function pe({ label: t, value: i, children: r, valueColor: o, valueMuted: s }) {
|
|
1539
|
+
return /* @__PURE__ */ n("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "flex-start", padding: "5px 16px", fontSize: 12, gap: 10 }, children: [
|
|
1540
|
+
/* @__PURE__ */ e("span", { style: { color: d.muted, flexShrink: 0, lineHeight: 1.4 }, children: t }),
|
|
1541
|
+
/* @__PURE__ */ e("span", { style: { color: o ?? (s ? d.muted : d.ink), textAlign: "right", minWidth: 0, display: "flex", alignItems: "center", justifyContent: "flex-end", flexWrap: "wrap", gap: 4, lineHeight: 1.4 }, children: r ?? i })
|
|
1521
1542
|
] });
|
|
1522
1543
|
}
|
|
1523
1544
|
function Vt({ value: t }) {
|
|
1524
|
-
const [i, r] =
|
|
1545
|
+
const [i, r] = y(!1);
|
|
1525
1546
|
return /* @__PURE__ */ e(
|
|
1526
1547
|
"button",
|
|
1527
1548
|
{
|
|
@@ -1582,13 +1603,13 @@ const p = {
|
|
|
1582
1603
|
clear: { border: 0, background: "none", color: d.muted, cursor: "pointer", fontSize: 18 },
|
|
1583
1604
|
listHeader: { display: "flex", alignItems: "center", padding: "10px 18px", borderTop: `1px solid ${d.line}`, borderBottom: `1px solid ${d.line}`, color: d.muted, fontSize: 11, fontWeight: 700, letterSpacing: 0.4, textTransform: "uppercase" },
|
|
1584
1605
|
conversationList: { overflowY: "auto", flex: 1, minHeight: 0 },
|
|
1585
|
-
row: { display: "flex", width: "100%", gap: 11, padding: "
|
|
1586
|
-
avatarWrap: { position: "relative", flex: "0 0 auto", width:
|
|
1587
|
-
avatar: { flex: "0 0 auto", width:
|
|
1606
|
+
row: { display: "flex", width: "100%", gap: 11, padding: "16px 14px", border: 0, borderBottom: `1px solid ${d.line}`, background: "transparent", textAlign: "left", cursor: "pointer", transition: "background 120ms ease" },
|
|
1607
|
+
avatarWrap: { position: "relative", flex: "0 0 auto", width: 44, height: 44 },
|
|
1608
|
+
avatar: { flex: "0 0 auto", width: 44, height: 44, display: "grid", placeItems: "center", borderRadius: "50%", objectFit: "cover", fontSize: 14, fontWeight: 800 },
|
|
1588
1609
|
providerBadge: { position: "absolute", left: -3, bottom: -3, display: "grid", placeItems: "center", width: 17, height: 17, border: "2px solid #fff", borderRadius: "50%", background: "#fff", color: "#64748b" },
|
|
1589
1610
|
rowBody: { minWidth: 0, flex: 1 },
|
|
1590
|
-
rowTop: { display: "flex", justifyContent: "space-between", alignItems: "center", gap: 8, fontSize:
|
|
1591
|
-
rowBottom: { display: "flex", marginTop: 4, fontSize:
|
|
1611
|
+
rowTop: { display: "flex", justifyContent: "space-between", alignItems: "center", gap: 8, fontSize: 14 },
|
|
1612
|
+
rowBottom: { display: "flex", marginTop: 4, fontSize: 12, minWidth: 0, overflow: "hidden", lineHeight: 1.4 },
|
|
1592
1613
|
unreadBadge: { display: "inline-grid", placeItems: "center", minWidth: 18, height: 18, borderRadius: 999, background: "#ef4444", color: "#fff", fontSize: 10, fontWeight: 800, padding: "0 5px" },
|
|
1593
1614
|
loadMore: { width: "100%", border: 0, background: "transparent", color: "#4c72ca", padding: 14, cursor: "pointer", fontSize: 12 },
|
|
1594
1615
|
emptySmall: { display: "grid", justifyItems: "center", gap: 7, padding: "56px 24px", color: d.muted, fontSize: 12, textAlign: "center" },
|
|
@@ -1995,7 +2016,7 @@ function nn() {
|
|
|
1995
2016
|
t.textContent = "@keyframes ch-spin{to{transform:rotate(360deg)}}", document.head.appendChild(t);
|
|
1996
2017
|
}
|
|
1997
2018
|
function un({ apiUrl: t, token: i, onConnectionChange: r }) {
|
|
1998
|
-
const o = t.replace(/\/$/, ""), [s, C] =
|
|
2019
|
+
const o = t.replace(/\/$/, ""), [s, C] = y([]), [m, O] = y(!0), [f, S] = y({ name: "list" }), [W, I] = y(null), [H, R] = y(!1), [E, j] = y(""), [A, F] = y(""), [K, ne] = y(""), [U, w] = y(""), [_, k] = y(!1), [L, se] = y(!1), z = ee(null);
|
|
1999
2020
|
nn();
|
|
2000
2021
|
const D = We(async () => {
|
|
2001
2022
|
try {
|
|
@@ -2003,8 +2024,8 @@ function un({ apiUrl: t, token: i, onConnectionChange: r }) {
|
|
|
2003
2024
|
headers: { authorization: `Bearer ${i}` }
|
|
2004
2025
|
});
|
|
2005
2026
|
if (!h.ok) throw new Error("Không tải được kênh");
|
|
2006
|
-
const
|
|
2007
|
-
C(
|
|
2027
|
+
const B = await h.json();
|
|
2028
|
+
C(B), r == null || r(B);
|
|
2008
2029
|
} catch (h) {
|
|
2009
2030
|
I(h instanceof Error ? h.message : "Lỗi tải dữ liệu");
|
|
2010
2031
|
} finally {
|
|
@@ -2014,14 +2035,14 @@ function un({ apiUrl: t, token: i, onConnectionChange: r }) {
|
|
|
2014
2035
|
Y(() => {
|
|
2015
2036
|
D();
|
|
2016
2037
|
}, [D]), Y(() => {
|
|
2017
|
-
if (!
|
|
2038
|
+
if (!W) return;
|
|
2018
2039
|
const h = setTimeout(() => I(null), 5e3);
|
|
2019
2040
|
return () => clearTimeout(h);
|
|
2020
|
-
}, [
|
|
2041
|
+
}, [W]), Y(() => () => {
|
|
2021
2042
|
z.current && window.removeEventListener("message", z.current);
|
|
2022
2043
|
}, []);
|
|
2023
|
-
async function le(h,
|
|
2024
|
-
if (confirm(`Bạn chắc chắn muốn ngắt kết nối "${
|
|
2044
|
+
async function le(h, B) {
|
|
2045
|
+
if (confirm(`Bạn chắc chắn muốn ngắt kết nối "${B}"?
|
|
2025
2046
|
|
|
2026
2047
|
Hành động này không thể hoàn tác.`))
|
|
2027
2048
|
try {
|
|
@@ -2043,19 +2064,19 @@ Hành động này không thể hoàn tác.`))
|
|
|
2043
2064
|
I("Token không đúng định dạng");
|
|
2044
2065
|
return;
|
|
2045
2066
|
}
|
|
2046
|
-
|
|
2067
|
+
R(!0), I(null);
|
|
2047
2068
|
try {
|
|
2048
2069
|
const h = await fetch(`${o}/v1/connect/telegram/start`, {
|
|
2049
2070
|
method: "POST",
|
|
2050
2071
|
headers: { authorization: `Bearer ${i}`, "content-type": "application/json" },
|
|
2051
2072
|
body: JSON.stringify({ botToken: E.trim(), displayName: A.trim() || void 0 })
|
|
2052
|
-
}),
|
|
2053
|
-
if (!h.ok || !
|
|
2073
|
+
}), B = await h.json();
|
|
2074
|
+
if (!h.ok || !B.connectionId) throw new Error(B.message ?? "Không thể kết nối Telegram");
|
|
2054
2075
|
j(""), F(""), await D(), S({ name: "list" });
|
|
2055
2076
|
} catch (h) {
|
|
2056
2077
|
I(h instanceof Error ? h.message : "Lỗi kết nối");
|
|
2057
2078
|
} finally {
|
|
2058
|
-
|
|
2079
|
+
R(!1);
|
|
2059
2080
|
}
|
|
2060
2081
|
}
|
|
2061
2082
|
async function Q() {
|
|
@@ -2063,14 +2084,14 @@ Hành động này không thể hoàn tác.`))
|
|
|
2063
2084
|
I("Vui lòng nhập tên widget");
|
|
2064
2085
|
return;
|
|
2065
2086
|
}
|
|
2066
|
-
|
|
2087
|
+
R(!0), I(null);
|
|
2067
2088
|
try {
|
|
2068
|
-
const h = U.split(/[\n,]+/).map((q) => q.trim()).filter(Boolean),
|
|
2089
|
+
const h = U.split(/[\n,]+/).map((q) => q.trim()).filter(Boolean), B = await fetch(`${o}/v1/connect/livechat/start`, {
|
|
2069
2090
|
method: "POST",
|
|
2070
2091
|
headers: { authorization: `Bearer ${i}`, "content-type": "application/json" },
|
|
2071
2092
|
body: JSON.stringify({ displayName: K.trim(), allowedDomains: h.length ? h : void 0 })
|
|
2072
|
-
}), P = await
|
|
2073
|
-
if (!
|
|
2093
|
+
}), P = await B.json();
|
|
2094
|
+
if (!B.ok || !P.connectionId || !P.embedScript) throw new Error(P.message ?? "Không thể tạo widget");
|
|
2074
2095
|
ne(""), w(""), await D(), S({
|
|
2075
2096
|
name: "livechat-result",
|
|
2076
2097
|
connectionId: P.connectionId,
|
|
@@ -2081,16 +2102,16 @@ Hành động này không thể hoàn tác.`))
|
|
|
2081
2102
|
} catch (h) {
|
|
2082
2103
|
I(h instanceof Error ? h.message : "Lỗi tạo widget");
|
|
2083
2104
|
} finally {
|
|
2084
|
-
|
|
2105
|
+
R(!1);
|
|
2085
2106
|
}
|
|
2086
2107
|
}
|
|
2087
2108
|
async function N(h) {
|
|
2088
2109
|
I(null);
|
|
2089
2110
|
try {
|
|
2090
|
-
const
|
|
2111
|
+
const B = `${o}/static/oauth-popup.html`, P = await fetch(`${o}/v1/connect/${h}/start`, {
|
|
2091
2112
|
method: "POST",
|
|
2092
2113
|
headers: { authorization: `Bearer ${i}`, "content-type": "application/json" },
|
|
2093
|
-
body: JSON.stringify({ callbackUrl:
|
|
2114
|
+
body: JSON.stringify({ callbackUrl: B })
|
|
2094
2115
|
}), q = await P.json();
|
|
2095
2116
|
if (!P.ok || !q.authorizationUrl) throw new Error(q.message ?? "Không thể bắt đầu kết nối");
|
|
2096
2117
|
const ie = window.open(q.authorizationUrl, "channelhub-oauth", "width=600,height=700,scrollbars=yes,resizable=yes");
|
|
@@ -2111,13 +2132,13 @@ Hành động này không thể hoàn tác.`))
|
|
|
2111
2132
|
}
|
|
2112
2133
|
};
|
|
2113
2134
|
z.current = re, window.addEventListener("message", re);
|
|
2114
|
-
} catch (
|
|
2115
|
-
I(
|
|
2135
|
+
} catch (B) {
|
|
2136
|
+
I(B instanceof Error ? B.message : "Lỗi kết nối"), S({ name: "list" });
|
|
2116
2137
|
}
|
|
2117
2138
|
}
|
|
2118
|
-
function x(h,
|
|
2139
|
+
function x(h, B) {
|
|
2119
2140
|
navigator.clipboard.writeText(h).then(() => {
|
|
2120
|
-
|
|
2141
|
+
B === "script" ? (k(!0), setTimeout(() => k(!1), 2e3)) : (se(!0), setTimeout(() => se(!1), 2e3));
|
|
2121
2142
|
});
|
|
2122
2143
|
}
|
|
2123
2144
|
function J() {
|
|
@@ -2129,10 +2150,10 @@ Hành động này không thể hoàn tác.`))
|
|
|
2129
2150
|
}
|
|
2130
2151
|
z.current && (window.removeEventListener("message", z.current), z.current = null), S({ name: "add" });
|
|
2131
2152
|
}
|
|
2132
|
-
async function
|
|
2153
|
+
async function he(h) {
|
|
2133
2154
|
if (f.name !== "oauth-select") return;
|
|
2134
|
-
const { provider:
|
|
2135
|
-
|
|
2155
|
+
const { provider: B, sessionId: P, popup: q } = f;
|
|
2156
|
+
R(!0), I(null);
|
|
2136
2157
|
const ie = {
|
|
2137
2158
|
facebook: `${o}/v1/connect/facebook/select-page`,
|
|
2138
2159
|
instagram: `${o}/v1/connect/instagram/select-account`,
|
|
@@ -2143,10 +2164,10 @@ Hành động này không thể hoàn tác.`))
|
|
|
2143
2164
|
zalo: "oaId"
|
|
2144
2165
|
};
|
|
2145
2166
|
try {
|
|
2146
|
-
const V = await fetch(ie[
|
|
2167
|
+
const V = await fetch(ie[B] ?? `${o}/v1/connect/${B}/select-page`, {
|
|
2147
2168
|
method: "POST",
|
|
2148
2169
|
headers: { authorization: `Bearer ${i}`, "content-type": "application/json" },
|
|
2149
|
-
body: JSON.stringify({ sessionId: P, [re[
|
|
2170
|
+
body: JSON.stringify({ sessionId: P, [re[B] ?? "pageId"]: h })
|
|
2150
2171
|
}), ye = await V.json();
|
|
2151
2172
|
if (!V.ok || !ye.connectionId) throw new Error(ye.message ?? "Không thể kết nối");
|
|
2152
2173
|
if (q)
|
|
@@ -2158,11 +2179,11 @@ Hành động này không thể hoàn tác.`))
|
|
|
2158
2179
|
} catch (V) {
|
|
2159
2180
|
I(V instanceof Error ? V.message : "Lỗi kết nối");
|
|
2160
2181
|
} finally {
|
|
2161
|
-
|
|
2182
|
+
R(!1);
|
|
2162
2183
|
}
|
|
2163
2184
|
}
|
|
2164
2185
|
return /* @__PURE__ */ n("div", { style: a.root, children: [
|
|
2165
|
-
|
|
2186
|
+
W && /* @__PURE__ */ e("div", { style: a.errorBanner, children: W }),
|
|
2166
2187
|
f.name === "list" && /* @__PURE__ */ n(te, { children: [
|
|
2167
2188
|
/* @__PURE__ */ n("div", { style: a.header, children: [
|
|
2168
2189
|
/* @__PURE__ */ e("div", { style: a.headerLeft, children: /* @__PURE__ */ n("div", { children: [
|
|
@@ -2461,7 +2482,7 @@ https://www.myshop.com`,
|
|
|
2461
2482
|
"button",
|
|
2462
2483
|
{
|
|
2463
2484
|
disabled: H,
|
|
2464
|
-
onClick: () => void
|
|
2485
|
+
onClick: () => void he(h.id),
|
|
2465
2486
|
style: {
|
|
2466
2487
|
display: "flex",
|
|
2467
2488
|
alignItems: "center",
|
|
@@ -2501,7 +2522,7 @@ function rn(t) {
|
|
|
2501
2522
|
return null;
|
|
2502
2523
|
}
|
|
2503
2524
|
function on({ conn: t, apiUrl: i, size: r = 40 }) {
|
|
2504
|
-
const [o, s] =
|
|
2525
|
+
const [o, s] = y(!1), C = rn(t), m = Math.round(r * 0.28);
|
|
2505
2526
|
return C && !o ? /* @__PURE__ */ e(
|
|
2506
2527
|
"img",
|
|
2507
2528
|
{
|
|
@@ -2514,7 +2535,7 @@ function on({ conn: t, apiUrl: i, size: r = 40 }) {
|
|
|
2514
2535
|
) : /* @__PURE__ */ e(ge, { provider: t.provider, apiUrl: i, size: r });
|
|
2515
2536
|
}
|
|
2516
2537
|
function an({ conn: t, apiUrl: i, onDisconnect: r }) {
|
|
2517
|
-
const [o, s] =
|
|
2538
|
+
const [o, s] = y(!1);
|
|
2518
2539
|
return /* @__PURE__ */ n("div", { style: a.channelItem, children: [
|
|
2519
2540
|
/* @__PURE__ */ e(on, { conn: t, apiUrl: i, size: 40 }),
|
|
2520
2541
|
/* @__PURE__ */ n("div", { style: a.channelInfo, children: [
|
|
@@ -2547,7 +2568,7 @@ const ln = [
|
|
|
2547
2568
|
{ id: "livechat", name: "Live Chat", desc: "Website widget", type: "livechat" }
|
|
2548
2569
|
];
|
|
2549
2570
|
function dn({ provider: t, apiUrl: i, onClick: r }) {
|
|
2550
|
-
const [o, s] =
|
|
2571
|
+
const [o, s] = y(!1);
|
|
2551
2572
|
return /* @__PURE__ */ n(
|
|
2552
2573
|
"div",
|
|
2553
2574
|
{
|
|
@@ -2581,7 +2602,7 @@ function De({ done: t, active: i, label: r }) {
|
|
|
2581
2602
|
r
|
|
2582
2603
|
] });
|
|
2583
2604
|
}
|
|
2584
|
-
console.log("[ChannelHub] widget v0.1.
|
|
2605
|
+
console.log("[ChannelHub] widget v0.1.7 loaded");
|
|
2585
2606
|
export {
|
|
2586
2607
|
un as ChannelHubChannels,
|
|
2587
2608
|
Mt as ChannelHubClient,
|