feat(08-05-interaction-pattern-unification): 统一前端交互与反馈模式
这个提交包含在:
@@ -1,7 +1,7 @@
|
||||
import { resolveErrorMessage as resolveUserErrorMessage } from "../lib/resolveErrorMessage";
|
||||
import { useMemo, useState } from "react";
|
||||
import { Link, useSearchParams } from "react-router-dom";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { mapApiErrorMessage } from "../api/errorMessages";
|
||||
import { isApiError } from "../api/types";
|
||||
import {
|
||||
archiveDepartment,
|
||||
@@ -31,34 +31,34 @@ import { ConfirmDialog } from "../components/common/ConfirmDialog";
|
||||
|
||||
function mapDepartmentErrorMessage(error: unknown, fallback: string) {
|
||||
if (!isApiError(error)) {
|
||||
return error instanceof Error ? error.message : fallback;
|
||||
return resolveUserErrorMessage(error, fallback);
|
||||
}
|
||||
|
||||
if (error.code === "VALID_001") {
|
||||
if (error.details?.parentId === "not_found") {
|
||||
return `${error.code}: 上级部门不存在。`;
|
||||
return "上级部门不存在。";
|
||||
}
|
||||
if (error.details?.parentId === "archived") {
|
||||
return `${error.code}: 上级部门已归档,无法继续使用。`;
|
||||
return "上级部门已归档,无法继续使用。";
|
||||
}
|
||||
if (error.details?.parentId === "self_not_allowed") {
|
||||
return `${error.code}: 上级部门不能选择自身。`;
|
||||
return "上级部门不能选择自身。";
|
||||
}
|
||||
if (error.details?.parentId === "cycle_not_allowed") {
|
||||
return `${error.code}: 上级部门不能形成循环层级。`;
|
||||
return "上级部门不能形成循环层级。";
|
||||
}
|
||||
if (error.details?.status === "archived") {
|
||||
return `${error.code}: 已归档部门不可编辑。`;
|
||||
return "已归档部门不可编辑。";
|
||||
}
|
||||
if (error.details?.department === "has_children") {
|
||||
return `${error.code}: 当前部门存在下级节点,无法归档。`;
|
||||
return "当前部门存在下级节点,无法归档。";
|
||||
}
|
||||
if (error.details?.department === "has_active_employees") {
|
||||
return `${error.code}: 当前部门仍有在职员工,无法归档。`;
|
||||
return "当前部门仍有在职员工,无法归档。";
|
||||
}
|
||||
}
|
||||
|
||||
return `${error.code}: ${mapApiErrorMessage(error.code, error.details, error.message)}`;
|
||||
return resolveUserErrorMessage(error);
|
||||
}
|
||||
|
||||
function flattenDepartmentTree(nodes: DepartmentTreeNode[], depth = 0): Array<{ id: string; label: string }> {
|
||||
@@ -288,13 +288,7 @@ export function DepartmentsPage() {
|
||||
|
||||
{listQuery.isError ? (
|
||||
<p className="rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-600">
|
||||
{isApiError(listQuery.error)
|
||||
? `${listQuery.error.code}: ${mapApiErrorMessage(
|
||||
listQuery.error.code,
|
||||
listQuery.error.details,
|
||||
listQuery.error.message,
|
||||
)}`
|
||||
: "加载部门列表失败"}
|
||||
{resolveUserErrorMessage(listQuery.error, "加载部门列表失败")}
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
|
||||
在新工单中引用
屏蔽一个用户