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( function buildTagOptions(
nodes: TagTree[], nodes: TagTree[] | null,
parentPath = "" parentPath = ""
): ComboboxOption[] { ): ComboboxOption[] {
const result: ComboboxOption[] = [] const result: ComboboxOption[] = []
if (!nodes) return result
nodes.forEach((item) => { nodes.forEach((item) => {
const currentPath = parentPath ? `${parentPath}/${item.name}` : item.name const currentPath = parentPath ? `${parentPath}/${item.name}` : item.name
result.push({ result.push({
@@ -207,18 +208,18 @@ export default function DashboardConversationsPage() {
if (!cancelled) { if (!cancelled) {
setTagOptions([ setTagOptions([
{ value: "0", label: "全部标签" }, { value: "0", label: "全部标签" },
...buildTagOptions(tagData), ...buildTagOptions(tagData || []),
]) ])
setAssigneeOptions([ setAssigneeOptions([
{ value: "0", label: "全部指派人" }, { value: "0", label: "全部指派人" },
...assigneeData.map((item: AdminAgentProfile) => ({ ...(Array.isArray(assigneeData) ? assigneeData : []).map((item: AdminAgentProfile) => ({
value: String(item.userId), value: String(item.userId),
label: item.displayName || item.nickname || item.username || `#${item.userId}`, label: item.displayName || item.nickname || item.username || `#${item.userId}`,
})), })),
]) ])
setAgentTeamOptions([ setAgentTeamOptions([
{ value: "0", label: "全部客服组" }, { value: "0", label: "全部客服组" },
...teamData.map((item: AdminAgentTeam) => ({ ...(Array.isArray(teamData) ? teamData : []).map((item: AdminAgentTeam) => ({
value: String(item.id), value: String(item.id),
label: item.name, label: item.name,
})), })),