2026-04-24 14:34:21 +08:00
|
|
|
"use client"
|
|
|
|
|
|
|
|
|
|
import {
|
2026-05-10 10:09:52 +08:00
|
|
|
HeadphonesIcon,
|
2026-04-24 14:34:21 +08:00
|
|
|
Maximize2Icon,
|
|
|
|
|
Minimize2Icon,
|
2026-05-10 10:30:59 +08:00
|
|
|
MoreHorizontalIcon,
|
2026-04-24 14:34:21 +08:00
|
|
|
MinusIcon,
|
|
|
|
|
RotateCwIcon,
|
|
|
|
|
XIcon,
|
|
|
|
|
} from "lucide-react"
|
2026-04-25 11:31:16 +08:00
|
|
|
import {
|
|
|
|
|
useCallback,
|
|
|
|
|
useEffect,
|
|
|
|
|
useLayoutEffect,
|
|
|
|
|
useRef,
|
|
|
|
|
useState,
|
2026-05-10 10:09:52 +08:00
|
|
|
type ComponentProps,
|
2026-04-25 11:31:16 +08:00
|
|
|
type CSSProperties,
|
|
|
|
|
} from "react"
|
2026-04-24 14:34:21 +08:00
|
|
|
import { useShallow } from "zustand/react/shallow"
|
|
|
|
|
|
2026-05-30 14:00:23 +08:00
|
|
|
import { SupportChatConnectionStatus } from "@/components/support-chat/connection-status"
|
|
|
|
|
import { getStandaloneClosedUrl } from "@/components/support-chat/close-navigation"
|
|
|
|
|
import { CustomerMessageEditor } from "@/components/support-chat/customer-message-editor"
|
2026-04-24 14:34:21 +08:00
|
|
|
import {
|
2026-05-30 14:00:23 +08:00
|
|
|
SupportChatMessageList,
|
|
|
|
|
type SupportChatMessageListHandle,
|
|
|
|
|
} from "@/components/support-chat/message-list"
|
2026-04-24 14:34:21 +08:00
|
|
|
import {
|
2026-05-30 14:00:23 +08:00
|
|
|
bindSupportHostBridge,
|
|
|
|
|
requestSupportHostClose,
|
|
|
|
|
requestSupportHostMinimize,
|
|
|
|
|
requestSupportHostToggleMaximize,
|
|
|
|
|
} from "@/lib/support-host-bridge"
|
|
|
|
|
import { useSupportChatStore } from "@/lib/stores/support-chat"
|
2026-04-25 11:26:53 +08:00
|
|
|
import { Button } from "@/components/ui/button"
|
|
|
|
|
import {
|
|
|
|
|
Dialog,
|
|
|
|
|
DialogContent,
|
|
|
|
|
DialogDescription,
|
|
|
|
|
DialogFooter,
|
|
|
|
|
DialogHeader,
|
|
|
|
|
DialogTitle,
|
|
|
|
|
} from "@/components/ui/dialog"
|
2026-05-10 10:30:59 +08:00
|
|
|
import {
|
|
|
|
|
DropdownMenu,
|
|
|
|
|
DropdownMenuContent,
|
|
|
|
|
DropdownMenuItem,
|
|
|
|
|
DropdownMenuTrigger,
|
|
|
|
|
} from "@/components/ui/dropdown-menu"
|
2026-05-10 10:09:52 +08:00
|
|
|
import { cn } from "@/lib/utils"
|
2026-05-25 12:06:15 +08:00
|
|
|
import { useI18n } from "@/i18n/provider"
|
2026-05-10 10:09:52 +08:00
|
|
|
|
|
|
|
|
const windowActionButtonClass =
|
2026-07-30 14:32:55 +08:00
|
|
|
"size-8 rounded-full border-0 bg-transparent text-muted-foreground shadow-none hover:bg-foreground/[0.06] hover:text-foreground focus-visible:ring-primary/20 dark:hover:bg-white/10"
|
2026-05-10 10:09:52 +08:00
|
|
|
|
|
|
|
|
function WindowActionButton({
|
|
|
|
|
className,
|
|
|
|
|
...props
|
|
|
|
|
}: ComponentProps<typeof Button>) {
|
|
|
|
|
return (
|
|
|
|
|
<Button
|
|
|
|
|
type="button"
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="icon"
|
|
|
|
|
className={cn(windowActionButtonClass, className)}
|
|
|
|
|
{...props}
|
|
|
|
|
/>
|
|
|
|
|
)
|
|
|
|
|
}
|
2026-04-24 14:34:21 +08:00
|
|
|
|
2026-07-30 14:32:55 +08:00
|
|
|
function getStatusDotClass(status: string) {
|
2026-05-10 10:30:59 +08:00
|
|
|
if (status === "connected") {
|
|
|
|
|
return "bg-emerald-500 shadow-[0_0_0_3px_rgba(16,185,129,0.14)]"
|
|
|
|
|
}
|
|
|
|
|
if (status === "connecting") {
|
|
|
|
|
return "bg-amber-500 shadow-[0_0_0_3px_rgba(245,158,11,0.16)]"
|
|
|
|
|
}
|
|
|
|
|
return "bg-muted-foreground shadow-[0_0_0_3px_rgba(148,163,184,0.14)]"
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-30 14:00:23 +08:00
|
|
|
function useSupportChatSystemTheme() {
|
2026-04-25 11:31:16 +08:00
|
|
|
useLayoutEffect(() => {
|
|
|
|
|
if (typeof window === "undefined") {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
const root = document.documentElement
|
|
|
|
|
const query = window.matchMedia("(prefers-color-scheme: dark)")
|
|
|
|
|
const previousDarkClass = root.classList.contains("dark")
|
|
|
|
|
const previousColorScheme = root.style.colorScheme
|
|
|
|
|
|
|
|
|
|
const syncTheme = () => {
|
|
|
|
|
const isDark = query.matches
|
|
|
|
|
root.classList.toggle("dark", isDark)
|
|
|
|
|
root.style.colorScheme = isDark ? "dark" : "light"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
syncTheme()
|
|
|
|
|
query.addEventListener("change", syncTheme)
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
query.removeEventListener("change", syncTheme)
|
|
|
|
|
root.classList.toggle("dark", previousDarkClass)
|
|
|
|
|
root.style.colorScheme = previousColorScheme
|
|
|
|
|
}
|
|
|
|
|
}, [])
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-06 09:36:15 +08:00
|
|
|
function isEmbeddedInHost() {
|
|
|
|
|
if (typeof window === "undefined") {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
return window.parent !== window
|
|
|
|
|
} catch {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-30 14:00:23 +08:00
|
|
|
export function SupportChatShell() {
|
2026-05-25 12:06:15 +08:00
|
|
|
const t = useI18n()
|
2026-05-30 14:00:23 +08:00
|
|
|
useSupportChatSystemTheme()
|
2026-04-25 11:31:16 +08:00
|
|
|
|
2026-05-30 14:00:23 +08:00
|
|
|
const messageListRef = useRef<SupportChatMessageListHandle | null>(null)
|
2026-05-06 17:37:57 +08:00
|
|
|
const [isEmbedded, setIsEmbedded] = useState(false)
|
2026-04-24 14:34:21 +08:00
|
|
|
const [isMaximized, setIsMaximized] = useState(false)
|
|
|
|
|
const [isCloseDialogOpen, setIsCloseDialogOpen] = useState(false)
|
|
|
|
|
const [isClosingConversation, setIsClosingConversation] = useState(false)
|
|
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
title,
|
|
|
|
|
subtitle,
|
|
|
|
|
themeColor,
|
|
|
|
|
conversation,
|
|
|
|
|
messages,
|
|
|
|
|
messagesHasMore,
|
|
|
|
|
messagesLoadingMore,
|
|
|
|
|
loadOlderMessages,
|
|
|
|
|
status,
|
|
|
|
|
error,
|
|
|
|
|
isOpen,
|
|
|
|
|
isVisible,
|
|
|
|
|
setIsOpen,
|
|
|
|
|
setIsVisible,
|
|
|
|
|
bootstrap,
|
|
|
|
|
handleSendMessage,
|
|
|
|
|
uploadMessageImage,
|
|
|
|
|
sendAttachment,
|
|
|
|
|
retry,
|
|
|
|
|
disconnectSocket,
|
|
|
|
|
markConversationRead,
|
|
|
|
|
closeConversation,
|
2026-05-30 14:00:23 +08:00
|
|
|
} = useSupportChatStore(
|
2026-04-24 14:34:21 +08:00
|
|
|
useShallow((state) => ({
|
|
|
|
|
title: state.title,
|
|
|
|
|
subtitle: state.subtitle,
|
|
|
|
|
themeColor: state.themeColor,
|
|
|
|
|
conversation: state.conversation,
|
|
|
|
|
messages: state.messages,
|
|
|
|
|
messagesHasMore: state.messagesHasMore,
|
|
|
|
|
messagesLoadingMore: state.messagesLoadingMore,
|
|
|
|
|
loadOlderMessages: state.loadOlderMessages,
|
|
|
|
|
status: state.status,
|
|
|
|
|
error: state.error,
|
|
|
|
|
isOpen: state.isOpen,
|
|
|
|
|
isVisible: state.isVisible,
|
|
|
|
|
setIsOpen: state.setIsOpen,
|
|
|
|
|
setIsVisible: state.setIsVisible,
|
|
|
|
|
bootstrap: state.bootstrap,
|
|
|
|
|
handleSendMessage: state.handleSendMessage,
|
|
|
|
|
uploadMessageImage: state.uploadMessageImage,
|
|
|
|
|
sendAttachment: state.sendAttachment,
|
|
|
|
|
retry: state.retry,
|
|
|
|
|
disconnectSocket: state.disconnectSocket,
|
|
|
|
|
markConversationRead: state.markConversationRead,
|
|
|
|
|
closeConversation: state.closeConversation,
|
|
|
|
|
}))
|
|
|
|
|
)
|
2026-04-24 19:17:07 +08:00
|
|
|
const safeMessages = Array.isArray(messages) ? messages : []
|
2026-04-24 14:34:21 +08:00
|
|
|
|
2026-05-06 17:37:57 +08:00
|
|
|
useEffect(() => {
|
|
|
|
|
setIsEmbedded(isEmbeddedInHost())
|
|
|
|
|
}, [])
|
|
|
|
|
|
2026-04-24 14:34:21 +08:00
|
|
|
const maybeMarkConversationRead = useCallback(() => {
|
|
|
|
|
if (!isVisible || !conversation || typeof document === "undefined") {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if (document.visibilityState !== "visible") {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
void markConversationRead().catch((readError) => {
|
2026-05-30 14:00:23 +08:00
|
|
|
console.error("Failed to mark support chat conversation read", readError)
|
2026-04-24 14:34:21 +08:00
|
|
|
})
|
2026-05-02 13:16:42 +08:00
|
|
|
}, [conversation?.id, isVisible, markConversationRead])
|
2026-04-24 14:34:21 +08:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
2026-05-30 14:00:23 +08:00
|
|
|
return bindSupportHostBridge({
|
2026-04-24 14:34:21 +08:00
|
|
|
onOpen: () => {
|
|
|
|
|
setIsOpen(true)
|
|
|
|
|
setIsVisible(true)
|
|
|
|
|
},
|
|
|
|
|
onMinimize: () => {
|
|
|
|
|
setIsVisible(false)
|
|
|
|
|
},
|
|
|
|
|
onMaximizedChange: (nextIsMaximized) => {
|
|
|
|
|
setIsMaximized(nextIsMaximized)
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}, [setIsOpen, setIsVisible])
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
bootstrap()
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
if (!isOpen) {
|
|
|
|
|
disconnectSocket()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, [isOpen, bootstrap, disconnectSocket])
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
maybeMarkConversationRead()
|
2026-04-24 19:17:07 +08:00
|
|
|
}, [maybeMarkConversationRead, safeMessages.length])
|
2026-04-24 14:34:21 +08:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const handleVisibilityChange = () => {
|
|
|
|
|
if (document.visibilityState === "visible") {
|
|
|
|
|
maybeMarkConversationRead()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const handleFocus = () => {
|
|
|
|
|
maybeMarkConversationRead()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
document.addEventListener("visibilitychange", handleVisibilityChange)
|
|
|
|
|
window.addEventListener("focus", handleFocus)
|
|
|
|
|
return () => {
|
|
|
|
|
document.removeEventListener("visibilitychange", handleVisibilityChange)
|
|
|
|
|
window.removeEventListener("focus", handleFocus)
|
|
|
|
|
}
|
|
|
|
|
}, [maybeMarkConversationRead])
|
|
|
|
|
|
|
|
|
|
async function handleSend(content: string) {
|
|
|
|
|
await handleSendMessage(content)
|
|
|
|
|
messageListRef.current?.scrollToBottom()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handleMinimize() {
|
|
|
|
|
setIsVisible(false)
|
2026-05-30 14:00:23 +08:00
|
|
|
requestSupportHostMinimize()
|
2026-04-24 14:34:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handleToggleMaximize() {
|
2026-05-30 14:00:23 +08:00
|
|
|
requestSupportHostToggleMaximize()
|
2026-04-24 14:34:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function confirmCloseConversation() {
|
|
|
|
|
if (isClosingConversation) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
setIsClosingConversation(true)
|
|
|
|
|
try {
|
|
|
|
|
if (conversation?.id) {
|
|
|
|
|
await closeConversation()
|
|
|
|
|
}
|
|
|
|
|
setIsCloseDialogOpen(false)
|
2026-05-06 09:36:15 +08:00
|
|
|
if (isEmbedded) {
|
2026-05-30 14:00:23 +08:00
|
|
|
requestSupportHostClose()
|
2026-05-06 09:36:15 +08:00
|
|
|
} else {
|
2026-05-06 19:36:32 +08:00
|
|
|
window.location.replace(getStandaloneClosedUrl())
|
2026-05-06 09:36:15 +08:00
|
|
|
}
|
2026-04-24 14:34:21 +08:00
|
|
|
} catch (closeError) {
|
2026-05-30 14:00:23 +08:00
|
|
|
window.alert(closeError instanceof Error ? closeError.message : t("supportChat.closeConversationFailed"))
|
2026-04-24 14:34:21 +08:00
|
|
|
} finally {
|
|
|
|
|
setIsClosingConversation(false)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (!isCloseDialogOpen) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
const handleKeyDown = (event: KeyboardEvent) => {
|
|
|
|
|
if (event.key === "Escape" && !isClosingConversation) {
|
|
|
|
|
setIsCloseDialogOpen(false)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
window.addEventListener("keydown", handleKeyDown)
|
|
|
|
|
return () => window.removeEventListener("keydown", handleKeyDown)
|
|
|
|
|
}, [isCloseDialogOpen, isClosingConversation])
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<main
|
2026-05-09 23:00:55 +08:00
|
|
|
className="relative flex h-[100dvh] min-h-[100dvh] overflow-hidden bg-muted text-foreground supports-not-[height:100dvh]:h-screen supports-not-[height:100dvh]:min-h-screen"
|
2026-04-25 11:26:53 +08:00
|
|
|
style={{ "--primary": themeColor } as CSSProperties}
|
2026-04-24 14:34:21 +08:00
|
|
|
>
|
2026-05-09 22:52:04 +08:00
|
|
|
<section className="flex h-full w-full flex-col overflow-hidden bg-card text-card-foreground">
|
2026-07-30 14:32:55 +08:00
|
|
|
<header className="shrink-0 border-b border-border/70 bg-card/95 px-3 py-2 shadow-[0_1px_0_rgba(15,23,42,0.02)] backdrop-blur dark:border-border/60 dark:bg-card/90 sm:px-4">
|
|
|
|
|
<div className="flex min-w-0 items-center justify-between gap-3">
|
|
|
|
|
<div className="flex min-w-0 items-center gap-2.5">
|
|
|
|
|
<div className="relative flex size-8 shrink-0 items-center justify-center rounded-full bg-primary/10 text-primary ring-1 ring-primary/15 dark:bg-primary/15 dark:ring-primary/25">
|
2026-07-30 14:32:21 +08:00
|
|
|
<HeadphonesIcon className="size-4" />
|
2026-07-30 14:32:55 +08:00
|
|
|
<span
|
|
|
|
|
className={cn(
|
|
|
|
|
"absolute -right-0.5 -bottom-0.5 size-2.5 rounded-full ring-2 ring-card",
|
|
|
|
|
getStatusDotClass(status)
|
|
|
|
|
)}
|
|
|
|
|
aria-hidden="true"
|
|
|
|
|
/>
|
2026-05-10 10:09:52 +08:00
|
|
|
</div>
|
2026-07-30 14:32:55 +08:00
|
|
|
<div className="min-w-0 space-y-0.5">
|
|
|
|
|
<div className="truncate text-sm font-semibold leading-5 text-foreground">
|
|
|
|
|
{title}
|
2026-05-10 10:09:52 +08:00
|
|
|
</div>
|
2026-07-30 14:32:55 +08:00
|
|
|
<div className="truncate text-[11px] leading-4 text-muted-foreground">
|
2026-05-10 10:09:52 +08:00
|
|
|
{subtitle}
|
|
|
|
|
</div>
|
2026-04-24 14:34:21 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-05-10 10:30:59 +08:00
|
|
|
<div className="flex shrink-0 items-center gap-0.5 sm:hidden">
|
|
|
|
|
{!isEmbedded && status !== "connected" ? (
|
|
|
|
|
<WindowActionButton
|
|
|
|
|
onClick={retry}
|
2026-05-30 14:00:23 +08:00
|
|
|
aria-label={t("supportChat.retry")}
|
|
|
|
|
title={t("supportChat.retry")}
|
2026-05-10 10:30:59 +08:00
|
|
|
>
|
|
|
|
|
<RotateCwIcon className="size-4" />
|
|
|
|
|
</WindowActionButton>
|
|
|
|
|
) : null}
|
|
|
|
|
{isEmbedded ? (
|
|
|
|
|
<DropdownMenu>
|
|
|
|
|
<DropdownMenuTrigger
|
2026-05-30 14:00:23 +08:00
|
|
|
render={<WindowActionButton aria-label={t("supportChat.moreActions")} title={t("supportChat.moreActions")} />}
|
2026-05-10 10:30:59 +08:00
|
|
|
>
|
|
|
|
|
<MoreHorizontalIcon className="size-4" />
|
|
|
|
|
</DropdownMenuTrigger>
|
|
|
|
|
<DropdownMenuContent align="end" className="w-36">
|
|
|
|
|
<DropdownMenuItem onClick={retry}>
|
|
|
|
|
<RotateCwIcon className="size-4" />
|
2026-05-30 14:00:23 +08:00
|
|
|
{t("supportChat.retry")}
|
2026-05-10 10:30:59 +08:00
|
|
|
</DropdownMenuItem>
|
|
|
|
|
<DropdownMenuItem onClick={handleMinimize}>
|
|
|
|
|
<MinusIcon className="size-4" />
|
2026-05-30 14:00:23 +08:00
|
|
|
{t("supportChat.minimize")}
|
2026-05-10 10:30:59 +08:00
|
|
|
</DropdownMenuItem>
|
|
|
|
|
<DropdownMenuItem onClick={handleToggleMaximize}>
|
|
|
|
|
{isMaximized ? (
|
|
|
|
|
<Minimize2Icon className="size-4" />
|
|
|
|
|
) : (
|
|
|
|
|
<Maximize2Icon className="size-4" />
|
|
|
|
|
)}
|
2026-05-30 14:00:23 +08:00
|
|
|
{isMaximized ? t("supportChat.restoreWindow") : t("supportChat.maximize")}
|
2026-05-10 10:30:59 +08:00
|
|
|
</DropdownMenuItem>
|
|
|
|
|
<DropdownMenuItem
|
|
|
|
|
variant="destructive"
|
|
|
|
|
onClick={() => setIsCloseDialogOpen(true)}
|
|
|
|
|
>
|
|
|
|
|
<XIcon className="size-4" />
|
2026-05-30 14:00:23 +08:00
|
|
|
{t("supportChat.closeWindow")}
|
2026-05-10 10:30:59 +08:00
|
|
|
</DropdownMenuItem>
|
|
|
|
|
</DropdownMenuContent>
|
|
|
|
|
</DropdownMenu>
|
|
|
|
|
) : (
|
|
|
|
|
<WindowActionButton
|
|
|
|
|
onClick={() => setIsCloseDialogOpen(true)}
|
2026-05-30 14:00:23 +08:00
|
|
|
aria-label={t("supportChat.closeChatWindow")}
|
|
|
|
|
title={t("supportChat.closeChatWindow")}
|
2026-05-10 10:30:59 +08:00
|
|
|
className="hover:bg-rose-50 hover:text-rose-600 dark:hover:bg-rose-950/45 dark:hover:text-rose-300"
|
|
|
|
|
>
|
|
|
|
|
<XIcon className="size-4" />
|
|
|
|
|
</WindowActionButton>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
2026-07-30 14:32:21 +08:00
|
|
|
<div className="hidden shrink-0 items-center gap-1 sm:flex">
|
2026-04-24 14:34:21 +08:00
|
|
|
{status !== "connected" ? (
|
2026-05-30 14:00:23 +08:00
|
|
|
<SupportChatConnectionStatus status={status} />
|
2026-04-24 14:34:21 +08:00
|
|
|
) : null}
|
2026-07-30 14:32:55 +08:00
|
|
|
<WindowActionButton
|
|
|
|
|
onClick={retry}
|
|
|
|
|
aria-label={t("supportChat.retry")}
|
|
|
|
|
title={t("supportChat.retry")}
|
|
|
|
|
>
|
|
|
|
|
<RotateCwIcon className="size-4" />
|
|
|
|
|
</WindowActionButton>
|
|
|
|
|
{isEmbedded ? (
|
|
|
|
|
<>
|
|
|
|
|
<WindowActionButton
|
|
|
|
|
onClick={handleMinimize}
|
|
|
|
|
aria-label={t("supportChat.minimize")}
|
|
|
|
|
title={t("supportChat.minimize")}
|
|
|
|
|
>
|
|
|
|
|
<MinusIcon className="size-4" />
|
|
|
|
|
</WindowActionButton>
|
|
|
|
|
<WindowActionButton
|
|
|
|
|
onClick={handleToggleMaximize}
|
|
|
|
|
aria-label={isMaximized ? t("supportChat.restoreWindow") : t("supportChat.maximizeWindow")}
|
|
|
|
|
title={isMaximized ? t("supportChat.restoreWindow") : t("supportChat.maximizeWindow")}
|
|
|
|
|
>
|
|
|
|
|
{isMaximized ? (
|
|
|
|
|
<Minimize2Icon className="size-4" />
|
|
|
|
|
) : (
|
|
|
|
|
<Maximize2Icon className="size-4" />
|
|
|
|
|
)}
|
|
|
|
|
</WindowActionButton>
|
|
|
|
|
</>
|
|
|
|
|
) : null}
|
|
|
|
|
<WindowActionButton
|
|
|
|
|
onClick={() => setIsCloseDialogOpen(true)}
|
|
|
|
|
aria-label={t("supportChat.closeChatWindow")}
|
|
|
|
|
title={t("supportChat.closeChatWindow")}
|
|
|
|
|
className="hover:bg-rose-50 hover:text-rose-600 dark:hover:bg-rose-950/45 dark:hover:text-rose-300"
|
|
|
|
|
>
|
|
|
|
|
<XIcon className="size-4" />
|
|
|
|
|
</WindowActionButton>
|
2026-04-24 14:34:21 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</header>
|
|
|
|
|
|
2026-05-10 10:09:52 +08:00
|
|
|
<div className="grid min-h-0 flex-1 grid-rows-[minmax(0,1fr)_auto] overflow-hidden bg-muted/60 dark:bg-muted/30">
|
2026-05-30 14:00:23 +08:00
|
|
|
<SupportChatMessageList
|
2026-04-24 14:34:21 +08:00
|
|
|
ref={messageListRef}
|
2026-04-24 19:17:07 +08:00
|
|
|
messages={safeMessages}
|
2026-04-24 14:34:21 +08:00
|
|
|
onNearBottomVisible={maybeMarkConversationRead}
|
|
|
|
|
hasMoreOlder={messagesHasMore}
|
|
|
|
|
loadingOlder={messagesLoadingMore}
|
|
|
|
|
onLoadOlder={loadOlderMessages}
|
|
|
|
|
/>
|
2026-05-10 10:09:52 +08:00
|
|
|
<div className="shrink-0 border-t border-border/80 bg-card/95 pb-[env(safe-area-inset-bottom)] shadow-[0_-10px_24px_rgba(15,23,42,0.05)] dark:bg-card/90 dark:shadow-none">
|
2026-05-09 23:00:55 +08:00
|
|
|
<CustomerMessageEditor
|
|
|
|
|
disabled={!conversation}
|
|
|
|
|
onSend={handleSend}
|
|
|
|
|
onUploadImage={uploadMessageImage}
|
|
|
|
|
onSendAttachment={sendAttachment}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2026-04-24 14:34:21 +08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{error ? (
|
2026-04-25 11:31:16 +08:00
|
|
|
<div className="border-t border-destructive/20 bg-destructive/10 px-4 py-3 text-sm text-destructive">
|
2026-04-24 14:34:21 +08:00
|
|
|
{error}
|
|
|
|
|
</div>
|
|
|
|
|
) : null}
|
|
|
|
|
</section>
|
|
|
|
|
|
2026-04-25 11:26:53 +08:00
|
|
|
<Dialog
|
|
|
|
|
open={isCloseDialogOpen}
|
|
|
|
|
onOpenChange={(open) => {
|
|
|
|
|
if (!isClosingConversation) {
|
|
|
|
|
setIsCloseDialogOpen(open)
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<DialogContent className="max-w-[320px]" showCloseButton={!isClosingConversation}>
|
|
|
|
|
<DialogHeader>
|
2026-05-30 14:00:23 +08:00
|
|
|
<DialogTitle>{t("supportChat.closeDialogTitle")}</DialogTitle>
|
2026-04-25 11:26:53 +08:00
|
|
|
<DialogDescription className="text-xs leading-5">
|
2026-05-30 14:00:23 +08:00
|
|
|
{t("supportChat.closeDialogDescription")}
|
2026-04-25 11:26:53 +08:00
|
|
|
</DialogDescription>
|
|
|
|
|
</DialogHeader>
|
|
|
|
|
<DialogFooter>
|
|
|
|
|
<Button
|
|
|
|
|
type="button"
|
|
|
|
|
variant="outline"
|
|
|
|
|
disabled={isClosingConversation}
|
|
|
|
|
onClick={() => setIsCloseDialogOpen(false)}
|
|
|
|
|
>
|
2026-05-30 14:00:23 +08:00
|
|
|
{t("supportChat.continueConversation")}
|
2026-04-25 11:26:53 +08:00
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
type="button"
|
|
|
|
|
variant="destructive"
|
|
|
|
|
disabled={isClosingConversation}
|
|
|
|
|
onClick={() => void confirmCloseConversation()}
|
|
|
|
|
>
|
2026-05-30 14:00:23 +08:00
|
|
|
{isClosingConversation ? t("supportChat.closing") : t("supportChat.confirmClose")}
|
2026-04-25 11:26:53 +08:00
|
|
|
</Button>
|
|
|
|
|
</DialogFooter>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
</Dialog>
|
2026-04-24 14:34:21 +08:00
|
|
|
</main>
|
|
|
|
|
)
|
|
|
|
|
}
|