fix: null safety in conversation monitor page

Prevent "Cannot read properties of null (reading forEach)" when
fetchTagsAll / fetchAgentProfilesAll / fetchAgentTeamsAll return null
from the API. Add null guard in buildTagOptions and array checks for
assignee/team data before calling .map.
This commit is contained in:
Aibo117
2026-05-26 13:53:29 +08:00
parent 0f40930a41
commit 43bc9b903d
@@ -107,10 +107,11 @@ function getStatusLabel(value: string) {
}
function buildTagOptions(
nodes: TagTree[],
nodes: TagTree[] | null,
parentPath = ""
): ComboboxOption[] {
const result: ComboboxOption[] = []
if (!nodes) return result
nodes.forEach((item) => {
const currentPath = parentPath ? `${parentPath}/${item.name}` : item.name
result.push({
@@ -207,18 +208,18 @@ export default function DashboardConversationsPage() {
if (!cancelled) {
setTagOptions([
{ value: "0", label: "全部标签" },
...buildTagOptions(tagData),
...buildTagOptions(tagData || []),
])
setAssigneeOptions([
{ value: "0", label: "全部指派人" },
...assigneeData.map((item: AdminAgentProfile) => ({
...(Array.isArray(assigneeData) ? assigneeData : []).map((item: AdminAgentProfile) => ({
value: String(item.userId),
label: item.displayName || item.nickname || item.username || `#${item.userId}`,
})),
])
setAgentTeamOptions([
{ value: "0", label: "全部客服组" },
...teamData.map((item: AdminAgentTeam) => ({
...(Array.isArray(teamData) ? teamData : []).map((item: AdminAgentTeam) => ({
value: String(item.id),
label: item.name,
})),