refactor: support i18n
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
SharedMessageEditor,
|
||||
type UploadedMessageEditorImage,
|
||||
} from "@/components/chat/shared-message-editor"
|
||||
import { useI18n } from "@/i18n/provider"
|
||||
import { fetchQuickReplyListAll, type AdminQuickReply } from "@/lib/api/admin"
|
||||
|
||||
type AgentMessageEditorProps = {
|
||||
@@ -24,6 +25,7 @@ export function AgentMessageEditor({
|
||||
onUploadImage,
|
||||
onSendAttachment,
|
||||
}: AgentMessageEditorProps) {
|
||||
const t = useI18n()
|
||||
const [quickReplies, setQuickReplies] = useState<AdminQuickReply[]>([])
|
||||
const [loadingQuickReplies, setLoadingQuickReplies] = useState(true)
|
||||
const [quickReplyPickerOpen, setQuickReplyPickerOpen] = useState(false)
|
||||
@@ -38,7 +40,7 @@ export function AgentMessageEditor({
|
||||
})
|
||||
.catch((error) => {
|
||||
if (!cancelled) {
|
||||
toast.error(error instanceof Error ? error.message : "加载快捷回复失败")
|
||||
toast.error(error instanceof Error ? error.message : t("conversation.loadQuickRepliesFailed"))
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
@@ -49,7 +51,7 @@ export function AgentMessageEditor({
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [])
|
||||
}, [t])
|
||||
|
||||
return (
|
||||
<SharedMessageEditor
|
||||
|
||||
@@ -6,6 +6,7 @@ import { toast } from "sonner";
|
||||
import { ConversationTransferDialog } from "@/components/conversation-actions/transfer-dialog";
|
||||
import { ImMessageHTML } from "@/components/im-message-html";
|
||||
import { useImageLightbox } from "@/components/image-lightbox";
|
||||
import { useI18n } from "@/i18n/provider";
|
||||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
@@ -39,6 +40,7 @@ import { AgentMessageEditor } from "./agent-message-editor";
|
||||
const EMPTY_AGENT_MESSAGES: AgentMessage[] = [];
|
||||
|
||||
export function ChatPanel() {
|
||||
const t = useI18n();
|
||||
const conversation = useAgentConversationsStore(
|
||||
agentConversationSelectors.selectedConversation,
|
||||
);
|
||||
@@ -119,8 +121,8 @@ export function ChatPanel() {
|
||||
}, [getViewport]);
|
||||
|
||||
/**
|
||||
* 与 widget 消息列表一致:在单条调度链内多帧滚底直到 scrollHeight 稳定,
|
||||
* 避免多段滚底叠加导致滚动条抖动。
|
||||
* Match the widget message list: keep scrolling for a few frames until
|
||||
* scrollHeight stabilizes, which prevents stacked scroll jumps.
|
||||
*/
|
||||
const scheduleScrollToBottom = useCallback(
|
||||
(attempts = 4) => {
|
||||
@@ -170,7 +172,7 @@ export function ChatPanel() {
|
||||
return;
|
||||
}
|
||||
void markSelectedConversationRead().catch((error) => {
|
||||
toast.error(error instanceof Error ? error.message : "设置已读失败");
|
||||
toast.error(error instanceof Error ? error.message : t("conversation.markReadFailed"));
|
||||
});
|
||||
}, [
|
||||
conversation,
|
||||
@@ -178,6 +180,7 @@ export function ChatPanel() {
|
||||
isNearBottom,
|
||||
loading,
|
||||
markSelectedConversationRead,
|
||||
t,
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -282,7 +285,7 @@ export function ChatPanel() {
|
||||
await loadOlderMessages();
|
||||
} catch (error) {
|
||||
prependScrollAnchorRef.current = null;
|
||||
toast.error(error instanceof Error ? error.message : "加载历史消息失败");
|
||||
toast.error(error instanceof Error ? error.message : t("conversation.loadHistoryFailed"));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -292,7 +295,7 @@ export function ChatPanel() {
|
||||
shouldStickToBottomRef.current = true;
|
||||
await sendMessage(html);
|
||||
} catch (error) {
|
||||
toast.error(error instanceof Error ? error.message : "发送消息失败");
|
||||
toast.error(error instanceof Error ? error.message : t("conversation.sendMessageFailed"));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -300,7 +303,7 @@ export function ChatPanel() {
|
||||
if (!conversation || claiming) return;
|
||||
const session = readSession();
|
||||
if (!session?.user?.id) {
|
||||
toast.error("未登录或登录已过期");
|
||||
toast.error(t("conversation.claimRequiresSignIn"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -309,15 +312,15 @@ export function ChatPanel() {
|
||||
await assignAgentConversation(
|
||||
conversation.id,
|
||||
session.user.id,
|
||||
"认领会话",
|
||||
t("conversation.claimReason"),
|
||||
);
|
||||
|
||||
switchToMyActiveIfNeeded();
|
||||
setClaimDialogOpen(false);
|
||||
toast.success("认领成功");
|
||||
toast.success(t("conversation.claimSuccess"));
|
||||
await reloadConversationData(conversation.id);
|
||||
} catch (error) {
|
||||
toast.error(error instanceof Error ? error.message : "认领会话失败");
|
||||
toast.error(error instanceof Error ? error.message : t("conversation.claimFailed"));
|
||||
} finally {
|
||||
setClaiming(false);
|
||||
}
|
||||
@@ -332,9 +335,13 @@ export function ChatPanel() {
|
||||
return (
|
||||
<div className="mt-10 flex flex-1 items-center justify-center px-4">
|
||||
<div className="text-center text-muted-foreground">
|
||||
<p className="text-lg">暂无会话</p>
|
||||
<p className="mt-1 text-sm lg:hidden">点击左上角菜单打开列表并选择会话</p>
|
||||
<p className="mt-1 hidden text-sm lg:block">请从左侧选择会话开始聊天</p>
|
||||
<p className="text-lg">{t("conversation.empty")}</p>
|
||||
<p className="mt-1 text-sm lg:hidden">
|
||||
{t("conversation.noConversationMobile")}
|
||||
</p>
|
||||
<p className="mt-1 hidden text-sm lg:block">
|
||||
{t("conversation.selectConversationToChat")}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
@@ -355,13 +362,13 @@ export function ChatPanel() {
|
||||
disabled={messagesLoadingMore}
|
||||
onClick={() => void handleLoadOlder()}
|
||||
>
|
||||
{messagesLoadingMore ? "加载中…" : "加载更早的消息"}
|
||||
{messagesLoadingMore ? t("conversation.loading") : t("conversation.loadOlder")}
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
{loading ? (
|
||||
<div className="py-8 text-center text-sm text-muted-foreground">
|
||||
加载中...
|
||||
{t("conversation.loading")}
|
||||
</div>
|
||||
) : messages.length > 0 ? (
|
||||
messages.map((message) => (
|
||||
@@ -378,7 +385,7 @@ export function ChatPanel() {
|
||||
))
|
||||
) : (
|
||||
<div className="py-8 text-center text-sm text-muted-foreground">
|
||||
暂无消息
|
||||
{t("conversation.emptyMessages")}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
@@ -389,11 +396,11 @@ export function ChatPanel() {
|
||||
<div className="h-full overflow-auto border-t border-border/80 bg-card">
|
||||
{isClosedConversation ? (
|
||||
<div className="h-full flex justify-center items-center">
|
||||
当前会话已关闭
|
||||
{t("conversation.closedNotice")}
|
||||
</div>
|
||||
) : conversation?.status === 1 ? (
|
||||
<div className="h-full flex justify-center items-center">
|
||||
当前会话由 AI 接待中,转人工后才能由客服发送消息
|
||||
{t("conversation.aiServingNotice")}
|
||||
</div>
|
||||
) : isPendingConversation ? (
|
||||
<div className="h-full flex justify-center items-center">
|
||||
@@ -403,7 +410,7 @@ export function ChatPanel() {
|
||||
disabled={claiming}
|
||||
size="sm"
|
||||
>
|
||||
{claiming ? "认领中..." : "认领"}
|
||||
{claiming ? t("conversation.claiming") : t("conversation.claim")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -424,7 +431,7 @@ export function ChatPanel() {
|
||||
try {
|
||||
await sendAttachment(file);
|
||||
} catch (error) {
|
||||
toast.error(error instanceof Error ? error.message : "发送附件失败");
|
||||
toast.error(error instanceof Error ? error.message : t("conversation.sendAttachmentFailed"));
|
||||
}
|
||||
}}
|
||||
/>
|
||||
@@ -477,11 +484,14 @@ export function ChatPanel() {
|
||||
>
|
||||
<DialogContent className="max-w-md" showCloseButton={false}>
|
||||
<DialogHeader>
|
||||
<DialogTitle>确认认领会话</DialogTitle>
|
||||
<DialogTitle>{t("conversation.claimTitle")}</DialogTitle>
|
||||
<DialogDescription>
|
||||
{conversation
|
||||
? `确认认领“${conversation.customerName || `客户 #${conversation.customerId || conversation.id}`}”吗?认领后会话会进入我的列表。`
|
||||
: "确认认领当前会话吗?"}
|
||||
? `${t("conversation.claimConfirmPrefix")}${
|
||||
conversation.customerName ||
|
||||
`${t("conversation.customerFallbackPrefix")}${conversation.customerId || conversation.id}`
|
||||
}${t("conversation.claimConfirmSuffix")}`
|
||||
: t("conversation.claimCurrent")}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogFooter>
|
||||
@@ -491,14 +501,14 @@ export function ChatPanel() {
|
||||
disabled={claiming}
|
||||
onClick={() => setClaimDialogOpen(false)}
|
||||
>
|
||||
取消
|
||||
{t("conversation.cancel")}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
disabled={claiming}
|
||||
onClick={() => void handleClaim()}
|
||||
>
|
||||
{claiming ? "认领中..." : "确认认领"}
|
||||
{claiming ? t("conversation.claiming") : t("conversation.confirmClaim")}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
@@ -532,22 +542,25 @@ const MessageItem = memo(
|
||||
recalling,
|
||||
onRecall,
|
||||
}: MessageItemProps) {
|
||||
const t = useI18n();
|
||||
const { open: openImageLightbox } = useImageLightbox();
|
||||
const isCustomer = message.senderType === "customer";
|
||||
const isAi = message.senderType === "ai";
|
||||
const isAgentSide = message.senderType === "agent" || isAi;
|
||||
const isRecalled = Boolean(message.recalledAt) || message.sendStatus === 6;
|
||||
const senderName = isCustomer
|
||||
? message.senderName || "客户"
|
||||
? message.senderName || t("conversation.customerSender")
|
||||
: isAi
|
||||
? "AI"
|
||||
: message.senderName || "客服";
|
||||
: message.senderName || t("conversation.agentSender");
|
||||
const agentAvatarSrc =
|
||||
isAgentSide && !isAi && message.senderAvatar?.trim()
|
||||
? message.senderAvatar.trim()
|
||||
: undefined;
|
||||
const avatarFallback = isAi ? "AI" : senderName.charAt(0);
|
||||
const htmlContent = isRecalled ? "<p>该消息已撤回</p>" : buildMessageHTML(message);
|
||||
const htmlContent = isRecalled
|
||||
? `<p>${t("conversation.messageRecalledHtml")}</p>`
|
||||
: buildMessageHTML(message);
|
||||
const bubbleClassName = isAi
|
||||
? "border border-primary/15 bg-primary/5 text-foreground shadow-sm"
|
||||
: isAgentSide
|
||||
@@ -597,9 +610,13 @@ const MessageItem = memo(
|
||||
</div>
|
||||
<div className="mt-1 flex items-center gap-2 text-xs text-muted-foreground">
|
||||
<span>{formatDateTime(message.sentAt || "")}</span>
|
||||
{isRecalled ? <span>已撤回</span> : null}
|
||||
{isRecalled ? <span>{t("conversation.messageRecalled")}</span> : null}
|
||||
{message.sendStatus === 2 && !isRecalled && (
|
||||
<span>{message.customerRead ? "客户已读" : "客户未读"}</span>
|
||||
<span>
|
||||
{message.customerRead
|
||||
? t("conversation.customerRead")
|
||||
: t("conversation.customerUnread")}
|
||||
</span>
|
||||
)}
|
||||
{showRecallAction ? (
|
||||
<Button
|
||||
@@ -610,11 +627,11 @@ const MessageItem = memo(
|
||||
disabled={recalling}
|
||||
onClick={() => {
|
||||
void onRecall(message.id).catch((error) => {
|
||||
toast.error(error instanceof Error ? error.message : "撤回消息失败");
|
||||
toast.error(error instanceof Error ? error.message : t("conversation.recallFailed"));
|
||||
});
|
||||
}}
|
||||
>
|
||||
{recalling ? "撤回中..." : "撤回"}
|
||||
{recalling ? t("conversation.recalling") : t("conversation.recall")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
@@ -631,7 +648,7 @@ const MessageItem = memo(
|
||||
<Avatar className="size-8 shrink-0">
|
||||
<AvatarImage src="" />
|
||||
<AvatarFallback className={avatarClassName}>
|
||||
客
|
||||
{t("conversation.customerAvatar")}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
<div className="max-w-[70%]">
|
||||
@@ -652,7 +669,7 @@ const MessageItem = memo(
|
||||
</div>
|
||||
<div className="mt-1 flex items-center gap-2 text-xs text-muted-foreground">
|
||||
<span>{formatDateTime(message.sentAt || "")}</span>
|
||||
{isRecalled ? <span>已撤回</span> : null}
|
||||
{isRecalled ? <span>{t("conversation.messageRecalled")}</span> : null}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
|
||||
@@ -43,20 +43,31 @@ import {
|
||||
} from "@/lib/api/customer-contact";
|
||||
import {
|
||||
ContactType,
|
||||
ContactTypeLabels,
|
||||
Gender,
|
||||
GenderLabels,
|
||||
} from "@/lib/generated/enums";
|
||||
import { useAgentConversationsStore } from "@/lib/stores/agent-conversations";
|
||||
import { cn, formatDateTime } from "@/lib/utils";
|
||||
import { useI18n } from "@/i18n/provider";
|
||||
import {
|
||||
ConversationTagBadges,
|
||||
ConversationTagPicker,
|
||||
} from "./conversation-tag-picker";
|
||||
import { TicketStatusBadge } from "../../tickets/_components/ticket-status-badge";
|
||||
|
||||
function contactTypeLabel(contactType: ContactType | string) {
|
||||
return ContactTypeLabels[contactType as ContactType] ?? contactType;
|
||||
function contactTypeLabel(
|
||||
contactType: ContactType | string,
|
||||
t: (key: string, values?: Record<string, string | number>) => string
|
||||
) {
|
||||
switch (contactType) {
|
||||
case ContactType.Mobile:
|
||||
return t("conversation.contactMobile");
|
||||
case ContactType.Email:
|
||||
return t("conversation.contactEmail");
|
||||
case ContactType.Other:
|
||||
return t("conversation.contactOther");
|
||||
default:
|
||||
return String(contactType);
|
||||
}
|
||||
}
|
||||
|
||||
function ContactTypeIcon({ contactType }: { contactType: ContactType | string }) {
|
||||
@@ -113,6 +124,7 @@ function SectionHeading({
|
||||
}
|
||||
|
||||
function UnlinkedCustomerEmpty({ conversation }: { conversation: AgentConversation }) {
|
||||
const t = useI18n();
|
||||
const [linkDialogOpen, setLinkDialogOpen] = useState(false);
|
||||
const loadConversations = useAgentConversationsStore((s) => s.loadConversations);
|
||||
|
||||
@@ -120,9 +132,11 @@ function UnlinkedCustomerEmpty({ conversation }: { conversation: AgentConversati
|
||||
<div className="space-y-6 pt-2">
|
||||
<div className="flex flex-col items-center justify-center rounded-xl bg-muted/35 px-4 py-8 text-center">
|
||||
<UserRoundIcon className="mb-2 size-10 text-muted-foreground" aria-hidden />
|
||||
<p className="text-sm font-medium text-foreground">尚未关联 CRM 客户</p>
|
||||
<p className="text-sm font-medium text-foreground">
|
||||
{t("conversation.unlinkedCustomerTitle")}
|
||||
</p>
|
||||
<p className="mt-1 max-w-xs text-xs leading-relaxed text-muted-foreground">
|
||||
当前会话未绑定客户主档。绑定后可在此维护公司与联系方式。
|
||||
{t("conversation.unlinkedCustomerDescription")}
|
||||
</p>
|
||||
<Button
|
||||
type="button"
|
||||
@@ -130,7 +144,7 @@ function UnlinkedCustomerEmpty({ conversation }: { conversation: AgentConversati
|
||||
onClick={() => setLinkDialogOpen(true)}
|
||||
>
|
||||
<Link2Icon className="size-4" />
|
||||
关联或创建客户
|
||||
{t("conversation.linkOrCreateCustomer")}
|
||||
</Button>
|
||||
</div>
|
||||
<CustomerLinkOrCreateDialog
|
||||
@@ -144,6 +158,7 @@ function UnlinkedCustomerEmpty({ conversation }: { conversation: AgentConversati
|
||||
}
|
||||
|
||||
function MissingCustomerEmpty({ conversation }: { conversation: AgentConversation }) {
|
||||
const t = useI18n();
|
||||
const [linkDialogOpen, setLinkDialogOpen] = useState(false);
|
||||
const loadConversations = useAgentConversationsStore((s) => s.loadConversations);
|
||||
|
||||
@@ -151,9 +166,11 @@ function MissingCustomerEmpty({ conversation }: { conversation: AgentConversatio
|
||||
<div className="space-y-6 pt-2">
|
||||
<div className="flex flex-col items-center justify-center rounded-xl bg-muted/35 px-4 py-8 text-center">
|
||||
<UserRoundIcon className="mb-2 size-10 text-muted-foreground" aria-hidden />
|
||||
<p className="text-sm font-medium text-foreground">客户已删除或不存在</p>
|
||||
<p className="text-sm font-medium text-foreground">
|
||||
{t("conversation.missingCustomerTitle")}
|
||||
</p>
|
||||
<p className="mt-1 max-w-xs text-xs leading-relaxed text-muted-foreground">
|
||||
当前会话绑定的客户主档已不可用。你可以重新关联已有客户,或直接新建一个客户并绑定到当前会话。
|
||||
{t("conversation.missingCustomerDescription")}
|
||||
</p>
|
||||
<Button
|
||||
type="button"
|
||||
@@ -161,14 +178,14 @@ function MissingCustomerEmpty({ conversation }: { conversation: AgentConversatio
|
||||
onClick={() => setLinkDialogOpen(true)}
|
||||
>
|
||||
<Link2Icon className="size-4" />
|
||||
重新关联或创建客户
|
||||
{t("conversation.relinkOrCreateCustomer")}
|
||||
</Button>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<SectionHeading>会话归属</SectionHeading>
|
||||
<SectionHeading>{t("conversation.conversationOwner")}</SectionHeading>
|
||||
<div className="space-y-2">
|
||||
<DetailRow label="渠道ID" value={conversation.channelId ? `${conversation.channelId}` : "-"} />
|
||||
<DetailRow label="客户ID" value={conversation.customerId ? `${conversation.customerId}` : "-"} />
|
||||
<DetailRow label={t("conversation.channelId")} value={conversation.channelId ? `${conversation.channelId}` : "-"} />
|
||||
<DetailRow label={t("conversation.customerId")} value={conversation.customerId ? `${conversation.customerId}` : "-"} />
|
||||
</div>
|
||||
</div>
|
||||
<CustomerLinkOrCreateDialog
|
||||
@@ -192,6 +209,7 @@ export function ConversationInfoPanel({
|
||||
className,
|
||||
variant = "default",
|
||||
}: ConversationInfoPanelProps) {
|
||||
const t = useI18n();
|
||||
const embedded = variant === "embedded";
|
||||
|
||||
return (
|
||||
@@ -205,7 +223,9 @@ export function ConversationInfoPanel({
|
||||
)}
|
||||
>
|
||||
<div className="flex h-12.5 shrink-0 items-center border-b border-border/80 bg-card px-3">
|
||||
<h2 className="text-sm font-medium text-foreground">会话信息</h2>
|
||||
<h2 className="text-sm font-medium text-foreground">
|
||||
{t("conversation.conversationInfo")}
|
||||
</h2>
|
||||
</div>
|
||||
|
||||
<div
|
||||
@@ -217,8 +237,8 @@ export function ConversationInfoPanel({
|
||||
{!conversation ? (
|
||||
<p className="pt-4 text-sm text-muted-foreground">
|
||||
{embedded
|
||||
? "请选择会话以查看会话信息"
|
||||
: "请选择左侧会话以查看会话信息"}
|
||||
? t("conversation.selectConversationForInfo")
|
||||
: t("conversation.selectSidebarConversationForInfo")}
|
||||
</p>
|
||||
) : (
|
||||
<div className="space-y-4 py-3">
|
||||
@@ -235,6 +255,7 @@ function ConversationTagSection({
|
||||
}: {
|
||||
conversation: AgentConversation;
|
||||
}) {
|
||||
const t = useI18n();
|
||||
const setConversationTags = useAgentConversationsStore(
|
||||
(state) => state.setConversationTags,
|
||||
);
|
||||
@@ -253,7 +274,7 @@ function ConversationTagSection({
|
||||
}
|
||||
} catch (error) {
|
||||
if (!cancelled) {
|
||||
toast.error(error instanceof Error ? error.message : "加载标签失败");
|
||||
toast.error(error instanceof Error ? error.message : t("conversation.loadTagsFailed"));
|
||||
}
|
||||
} finally {
|
||||
if (!cancelled) {
|
||||
@@ -267,7 +288,7 @@ function ConversationTagSection({
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, []);
|
||||
}, [t]);
|
||||
|
||||
return (
|
||||
<section className="space-y-2 border-t pt-2">
|
||||
@@ -283,14 +304,14 @@ function ConversationTagSection({
|
||||
/>
|
||||
}
|
||||
>
|
||||
会话标签
|
||||
{t("conversation.conversationTags")}
|
||||
</SectionHeading>
|
||||
<ConversationTagBadges
|
||||
tags={conversation.tags}
|
||||
availableTags={availableTags}
|
||||
/>
|
||||
{!conversation.tags || conversation.tags.length === 0 ? (
|
||||
<p className="text-sm text-muted-foreground">暂未设置会话标签</p>
|
||||
<p className="text-sm text-muted-foreground">{t("conversation.noConversationTags")}</p>
|
||||
) : null}
|
||||
</section>
|
||||
);
|
||||
@@ -317,6 +338,7 @@ type CustomerLinkedBodyProps = {
|
||||
};
|
||||
|
||||
function CustomerLinkedBody({ conversation, customerId }: CustomerLinkedBodyProps) {
|
||||
const t = useI18n();
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [customer, setCustomer] = useState<AdminCustomer | null>(null);
|
||||
const [contacts, setContacts] = useState<AdminCustomerContact[]>([]);
|
||||
@@ -337,14 +359,14 @@ function CustomerLinkedBody({ conversation, customerId }: CustomerLinkedBodyProp
|
||||
const list = await fetchCustomerContacts(customerId);
|
||||
setContacts(Array.isArray(list) ? list : []);
|
||||
} catch (e) {
|
||||
const msg = e instanceof Error ? e.message : "加载客户信息失败";
|
||||
const msg = e instanceof Error ? e.message : t("conversation.loadCustomerFailed");
|
||||
toast.error(msg);
|
||||
setCustomer(null);
|
||||
setContacts([]);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [customerId]);
|
||||
}, [customerId, t]);
|
||||
|
||||
useEffect(() => {
|
||||
void load();
|
||||
@@ -360,7 +382,7 @@ function CustomerLinkedBody({ conversation, customerId }: CustomerLinkedBodyProp
|
||||
|
||||
if (loading && !customer) {
|
||||
return (
|
||||
<p className="pt-4 text-sm text-muted-foreground">加载客户信息…</p>
|
||||
<p className="pt-4 text-sm text-muted-foreground">{t("conversation.loadingCustomer")}</p>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -373,18 +395,20 @@ function CustomerLinkedBody({ conversation, customerId }: CustomerLinkedBodyProp
|
||||
);
|
||||
}
|
||||
|
||||
const displayName = customer.name.trim() || "未填写姓名";
|
||||
const displayName = customer.name.trim() || t("conversation.unnamedCustomer");
|
||||
const company = customer.company ?? null;
|
||||
const genderLabel =
|
||||
customer.gender === Gender.Male || customer.gender === Gender.Female
|
||||
? GenderLabels[customer.gender as Gender] ?? String(customer.gender)
|
||||
customer.gender === Gender.Male
|
||||
? t("conversation.genderMale")
|
||||
: customer.gender === Gender.Female
|
||||
? t("conversation.genderFemale")
|
||||
: null;
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{isProfileEmpty ? (
|
||||
<div className="rounded-lg bg-amber-500/10 px-3 py-2.5 text-xs leading-relaxed text-amber-950 dark:text-amber-100">
|
||||
客户主档已关联,但基础信息尚未填写。请点击「编辑」补全资料。
|
||||
{t("conversation.customerProfileEmpty")}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
@@ -415,29 +439,29 @@ function CustomerLinkedBody({ conversation, customerId }: CustomerLinkedBodyProp
|
||||
onClick={() => setCustomerEditOpen(true)}
|
||||
>
|
||||
<PencilIcon className="size-3.5" />
|
||||
编辑
|
||||
{t("conversation.edit")}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<DetailRow
|
||||
label="最近活跃"
|
||||
label={t("conversation.lastActive")}
|
||||
value={
|
||||
customer.lastActiveAt ? formatDateTime(customer.lastActiveAt) : ""
|
||||
}
|
||||
/>
|
||||
<DetailRow
|
||||
label="备注"
|
||||
label={t("conversation.remark")}
|
||||
value={customer.remark.trim() ? customer.remark : ""}
|
||||
valueClassName="whitespace-pre-wrap"
|
||||
/>
|
||||
<DetailRow
|
||||
label="创建时间"
|
||||
label={t("conversation.createdAt")}
|
||||
value={formatDateTime(customer.createdAt)}
|
||||
valueClassName="whitespace-pre-wrap"
|
||||
/>
|
||||
<DetailRow
|
||||
label="更新时间"
|
||||
label={t("conversation.updatedAt")}
|
||||
value={formatDateTime(customer.updatedAt)}
|
||||
valueClassName="whitespace-pre-wrap"
|
||||
/>
|
||||
@@ -446,16 +470,16 @@ function CustomerLinkedBody({ conversation, customerId }: CustomerLinkedBodyProp
|
||||
|
||||
<section className="space-y-2">
|
||||
{contacts.length === 0 ? (
|
||||
<p className="text-sm text-muted-foreground">暂无联系方式</p>
|
||||
<p className="text-sm text-muted-foreground">{t("conversation.noContacts")}</p>
|
||||
) : (
|
||||
<ul className="space-y-3">
|
||||
{contacts.map((row) => {
|
||||
const tags: string[] = [];
|
||||
if (row.isPrimary) {
|
||||
tags.push("主");
|
||||
tags.push(t("conversation.primaryContactBadge"));
|
||||
}
|
||||
if (row.isVerified) {
|
||||
tags.push("已验证");
|
||||
tags.push(t("conversation.verifiedContactBadge"));
|
||||
}
|
||||
return (
|
||||
<li key={row.id} className="text-sm">
|
||||
@@ -465,7 +489,7 @@ function CustomerLinkedBody({ conversation, customerId }: CustomerLinkedBodyProp
|
||||
<p className="break-all font-medium leading-snug text-foreground">
|
||||
{row.contactValue}
|
||||
<span className="ml-2 text-xs font-normal text-muted-foreground">
|
||||
{contactTypeLabel(row.contactType)}
|
||||
{contactTypeLabel(row.contactType, t)}
|
||||
</span>
|
||||
{tags.length > 0 ? (
|
||||
<span className="ml-2 text-xs text-muted-foreground">
|
||||
@@ -516,28 +540,28 @@ function CustomerLinkedBody({ conversation, customerId }: CustomerLinkedBodyProp
|
||||
onClick={() => setCompanyEditOpen(true)}
|
||||
>
|
||||
<PencilIcon className="size-3.5" />
|
||||
编辑
|
||||
{t("conversation.edit")}
|
||||
</Button>
|
||||
</div>
|
||||
<div className="space-y-2 pt-1">
|
||||
<DetailRow
|
||||
label="创建"
|
||||
label={t("conversation.createdAt")}
|
||||
value={formatDateTime(company.createdAt)}
|
||||
/>
|
||||
<DetailRow
|
||||
label="更新"
|
||||
label={t("conversation.updatedAt")}
|
||||
value={formatDateTime(company.updatedAt)}
|
||||
/>
|
||||
</div>
|
||||
<DetailRow
|
||||
label="备注"
|
||||
label={t("conversation.remark")}
|
||||
value={company.remark.trim() ? company.remark : ""}
|
||||
valueClassName="whitespace-pre-wrap"
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
公司信息加载失败或公司已删除。
|
||||
{t("conversation.companyUnavailable")}
|
||||
</p>
|
||||
)}
|
||||
</section>
|
||||
@@ -559,11 +583,11 @@ function CustomerLinkedBody({ conversation, customerId }: CustomerLinkedBodyProp
|
||||
setCustomerEditSaving(true);
|
||||
try {
|
||||
await saveCustomerProfile({ ...payload, id: customer.id });
|
||||
toast.success("已保存");
|
||||
toast.success(t("conversation.saved"));
|
||||
void load();
|
||||
setCustomerEditOpen(false);
|
||||
} catch (e) {
|
||||
toast.error(e instanceof Error ? e.message : "保存失败");
|
||||
toast.error(e instanceof Error ? e.message : t("conversation.saveFailed"));
|
||||
} finally {
|
||||
setCustomerEditSaving(false);
|
||||
}
|
||||
@@ -584,6 +608,7 @@ function CustomerLinkedBody({ conversation, customerId }: CustomerLinkedBodyProp
|
||||
}
|
||||
|
||||
function RelatedTicketsSection({ conversation }: { conversation: AgentConversation }) {
|
||||
const t = useI18n();
|
||||
const [tickets, setTickets] = useState<TicketItem[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
@@ -602,7 +627,7 @@ function RelatedTicketsSection({ conversation }: { conversation: AgentConversati
|
||||
}
|
||||
} catch (error) {
|
||||
if (!cancelled) {
|
||||
toast.error(error instanceof Error ? error.message : "加载关联工单失败");
|
||||
toast.error(error instanceof Error ? error.message : t("conversation.loadTicketsFailed"));
|
||||
}
|
||||
} finally {
|
||||
if (!cancelled) {
|
||||
@@ -614,13 +639,13 @@ function RelatedTicketsSection({ conversation }: { conversation: AgentConversati
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [conversation.id]);
|
||||
}, [conversation.id, t]);
|
||||
|
||||
return (
|
||||
<section className="space-y-2 border-t pt-2">
|
||||
<SectionHeading>关联工单</SectionHeading>
|
||||
<SectionHeading>{t("conversation.relatedTickets")}</SectionHeading>
|
||||
{loading ? (
|
||||
<p className="text-sm text-muted-foreground">加载工单中…</p>
|
||||
<p className="text-sm text-muted-foreground">{t("conversation.loadingTickets")}</p>
|
||||
) : tickets.length > 0 ? (
|
||||
<div className="space-y-2">
|
||||
{tickets.map((ticket) => (
|
||||
@@ -648,7 +673,7 @@ function RelatedTicketsSection({ conversation }: { conversation: AgentConversati
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-sm text-muted-foreground">当前会话暂无关联工单</p>
|
||||
<p className="text-sm text-muted-foreground">{t("conversation.noRelatedTickets")}</p>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
@@ -667,6 +692,7 @@ function CompanyEditDialog({
|
||||
company,
|
||||
onSaved,
|
||||
}: CompanyEditDialogProps) {
|
||||
const t = useI18n();
|
||||
const [name, setName] = useState("");
|
||||
const [code, setCode] = useState("");
|
||||
const [remark, setRemark] = useState("");
|
||||
@@ -684,7 +710,7 @@ function CompanyEditDialog({
|
||||
const handleSubmit = async () => {
|
||||
const trimmedName = name.trim();
|
||||
if (!trimmedName) {
|
||||
toast.error("公司名称不能为空");
|
||||
toast.error(t("conversation.companyNameRequired"));
|
||||
return;
|
||||
}
|
||||
setSaving(true);
|
||||
@@ -695,11 +721,11 @@ function CompanyEditDialog({
|
||||
code: code.trim(),
|
||||
remark: remark.trim(),
|
||||
});
|
||||
toast.success("已保存");
|
||||
toast.success(t("conversation.saved"));
|
||||
onSaved();
|
||||
onOpenChange(false);
|
||||
} catch (e) {
|
||||
toast.error(e instanceof Error ? e.message : "保存失败");
|
||||
toast.error(e instanceof Error ? e.message : t("conversation.saveFailed"));
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
@@ -709,23 +735,23 @@ function CompanyEditDialog({
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="sm:max-w-md" showCloseButton>
|
||||
<DialogHeader>
|
||||
<DialogTitle>编辑公司</DialogTitle>
|
||||
<DialogTitle>{t("conversation.editCompany")}</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="flex flex-col gap-4 py-1">
|
||||
<Field orientation="vertical">
|
||||
<FieldLabel htmlFor="co-name">公司名称</FieldLabel>
|
||||
<FieldLabel htmlFor="co-name">{t("conversation.companyName")}</FieldLabel>
|
||||
<FieldContent>
|
||||
<Input id="co-name" value={name} onChange={(e) => setName(e.target.value)} />
|
||||
</FieldContent>
|
||||
</Field>
|
||||
<Field orientation="vertical">
|
||||
<FieldLabel htmlFor="co-code">公司编码</FieldLabel>
|
||||
<FieldLabel htmlFor="co-code">{t("conversation.companyCode")}</FieldLabel>
|
||||
<FieldContent>
|
||||
<Input id="co-code" value={code} onChange={(e) => setCode(e.target.value)} />
|
||||
</FieldContent>
|
||||
</Field>
|
||||
<Field orientation="vertical">
|
||||
<FieldLabel htmlFor="co-remark">备注</FieldLabel>
|
||||
<FieldLabel htmlFor="co-remark">{t("conversation.remark")}</FieldLabel>
|
||||
<FieldContent>
|
||||
<Textarea
|
||||
id="co-remark"
|
||||
@@ -738,10 +764,10 @@ function CompanyEditDialog({
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button type="button" variant="outline" onClick={() => onOpenChange(false)}>
|
||||
取消
|
||||
{t("conversation.cancel")}
|
||||
</Button>
|
||||
<Button type="button" disabled={saving} onClick={() => void handleSubmit()}>
|
||||
{saving ? "保存中…" : "保存"}
|
||||
{saving ? t("conversation.saving") : t("conversation.save")}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
|
||||
@@ -4,13 +4,10 @@ import { UserIcon } from "lucide-react";
|
||||
|
||||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||
import { ScrollArea } from "@/components/ui/scroll-area";
|
||||
import { getEnumLabel } from "@/lib/enums";
|
||||
import {
|
||||
IMConversationStatus,
|
||||
IMConversationStatusLabels,
|
||||
} from "@/lib/generated/enums";
|
||||
import { IMConversationStatus } from "@/lib/generated/enums";
|
||||
import { useAgentConversationsStore } from "@/lib/stores/agent-conversations";
|
||||
import { formatDateTime } from "@/lib/utils";
|
||||
import { useI18n } from "@/i18n/provider";
|
||||
|
||||
function getStatusVariant(status: number) {
|
||||
switch (status) {
|
||||
@@ -32,6 +29,7 @@ type ConversationListProps = {
|
||||
}
|
||||
|
||||
export function ConversationList({ onAfterSelect }: ConversationListProps) {
|
||||
const t = useI18n()
|
||||
const conversations = useAgentConversationsStore((state) => state.conversations)
|
||||
const loading = useAgentConversationsStore((state) => state.conversationsLoading)
|
||||
const selectedId = useAgentConversationsStore((state) => state.selectedConversationId)
|
||||
@@ -41,7 +39,7 @@ export function ConversationList({ onAfterSelect }: ConversationListProps) {
|
||||
<ScrollArea className="overflow-auto">
|
||||
{loading ? (
|
||||
<div className="p-6 text-center text-sm text-muted-foreground">
|
||||
加载中...
|
||||
{t("conversation.loading")}
|
||||
</div>
|
||||
) : conversations.length > 0 ? (
|
||||
conversations.map((conversation) => {
|
||||
@@ -72,7 +70,10 @@ export function ConversationList({ onAfterSelect }: ConversationListProps) {
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex items-center gap-1.5">
|
||||
<span className="min-w-0 flex-1 truncate font-medium text-sm leading-4">
|
||||
{conversation.customerName || `客户 #${conversation.customerId || conversation.id}`}
|
||||
{conversation.customerName ||
|
||||
t("conversation.customerFallback", {
|
||||
id: conversation.customerId || conversation.id,
|
||||
})}
|
||||
</span>
|
||||
{conversation.agentUnreadCount > 0 ? (
|
||||
<div className="flex size-4.5 shrink-0 items-center justify-center rounded-full bg-primary text-[10px] text-primary-foreground">
|
||||
@@ -85,12 +86,12 @@ export function ConversationList({ onAfterSelect }: ConversationListProps) {
|
||||
<div className="mt-0.5 text-[11px] text-muted-foreground">
|
||||
{conversation.lastMessageAt
|
||||
? formatDateTime(conversation.lastMessageAt)
|
||||
: "暂无时间"}
|
||||
: t("conversation.noTime")}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-0.5 truncate text-xs leading-4 text-muted-foreground">
|
||||
{conversation.lastMessageSummary || "暂无最新消息"}
|
||||
{conversation.lastMessageSummary || t("conversation.noLatestMessage")}
|
||||
</div>
|
||||
<div className="mt-1 flex items-center gap-1 text-[10px] text-muted-foreground">
|
||||
<span
|
||||
@@ -98,12 +99,14 @@ export function ConversationList({ onAfterSelect }: ConversationListProps) {
|
||||
conversation.status
|
||||
)}`}
|
||||
>
|
||||
{getEnumLabel(IMConversationStatusLabels, conversation.status)}
|
||||
{getConversationStatusLabel(conversation.status, t)}
|
||||
</span>
|
||||
{conversation.status === IMConversationStatus.Pending &&
|
||||
conversation.currentTeamName ? (
|
||||
<span className="rounded-md bg-muted px-1.5 py-0.5">
|
||||
值班组:{conversation.currentTeamName}
|
||||
{t("conversation.teamOnDuty", {
|
||||
name: conversation.currentTeamName,
|
||||
})}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
@@ -113,9 +116,27 @@ export function ConversationList({ onAfterSelect }: ConversationListProps) {
|
||||
})
|
||||
) : (
|
||||
<div className="p-6 text-center text-sm text-muted-foreground">
|
||||
暂无会话
|
||||
{t("conversation.empty")}
|
||||
</div>
|
||||
)}
|
||||
</ScrollArea>
|
||||
)
|
||||
}
|
||||
|
||||
function getConversationStatusLabel(
|
||||
status: number,
|
||||
t: (key: string, values?: Record<string, string | number>) => string
|
||||
) {
|
||||
switch (status) {
|
||||
case IMConversationStatus.AIServing:
|
||||
return t("conversation.filterAiServing")
|
||||
case IMConversationStatus.Pending:
|
||||
return t("conversation.filterPending")
|
||||
case IMConversationStatus.Active:
|
||||
return t("conversation.filterActive")
|
||||
case IMConversationStatus.Closed:
|
||||
return t("conversation.filterClosed")
|
||||
default:
|
||||
return "-"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import {
|
||||
type AgentConversationTag,
|
||||
} from "@/lib/api/agent"
|
||||
import { type TagTree } from "@/lib/api/admin"
|
||||
import { useI18n } from "@/i18n/provider"
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
type TagNode = TagTree & {
|
||||
@@ -73,6 +74,7 @@ export function ConversationTagPicker({
|
||||
loading = false,
|
||||
onTagsChange,
|
||||
}: ConversationTagPickerProps) {
|
||||
const t = useI18n()
|
||||
const [pendingTagId, setPendingTagId] = useState<number | null>(null)
|
||||
|
||||
const flattenedTags = useMemo(() => flattenTagTree(availableTags), [availableTags])
|
||||
@@ -106,9 +108,9 @@ export function ConversationTagPicker({
|
||||
})
|
||||
}
|
||||
onTagsChange(nextTags)
|
||||
toast.success(exists ? "已移除会话标签" : "已添加会话标签")
|
||||
toast.success(exists ? t("conversation.tagRemoved") : t("conversation.tagAdded"))
|
||||
} catch (error) {
|
||||
toast.error(error instanceof Error ? error.message : "更新会话标签失败")
|
||||
toast.error(error instanceof Error ? error.message : t("conversation.tagUpdateFailed"))
|
||||
} finally {
|
||||
setPendingTagId(null)
|
||||
}
|
||||
@@ -123,12 +125,12 @@ export function ConversationTagPicker({
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-7 shrink-0 gap-1 px-2 text-xs"
|
||||
aria-label="编辑会话标签"
|
||||
aria-label={t("conversation.editTags")}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<TagIcon className="size-3.5 text-muted-foreground" />
|
||||
编辑
|
||||
{t("conversation.edit")}
|
||||
</PopoverTrigger>
|
||||
<PopoverContent
|
||||
align="end"
|
||||
@@ -136,14 +138,14 @@ export function ConversationTagPicker({
|
||||
onClick={(event) => event.stopPropagation()}
|
||||
>
|
||||
<Command>
|
||||
<CommandInput placeholder="搜索标签" />
|
||||
<CommandInput placeholder={t("conversation.searchTags")} />
|
||||
<CommandList>
|
||||
{loading ? <CommandEmpty>加载标签中...</CommandEmpty> : null}
|
||||
{loading ? <CommandEmpty>{t("conversation.loadingTags")}</CommandEmpty> : null}
|
||||
{!loading && flattenedTags.length === 0 ? (
|
||||
<CommandEmpty>暂无可用标签</CommandEmpty>
|
||||
<CommandEmpty>{t("conversation.emptyTags")}</CommandEmpty>
|
||||
) : null}
|
||||
{!loading ? (
|
||||
<CommandGroup heading="标签">
|
||||
<CommandGroup heading={t("conversation.tagGroup")}>
|
||||
{flattenedTags.map((tag) => {
|
||||
const checked = selectedTagIds.has(tag.id)
|
||||
const pending = pendingTagId === tag.id
|
||||
|
||||
Reference in New Issue
Block a user