feat(web): 工单页与升级面板,修掉视图竞态与标签缺失导致的崩溃
- 新增 /w/:wsId/tickets:派给我的 / 我发起的、状态过滤、列表内联快操作 - 详情抽屉按角色显示受理/开工/提交/验收/驳回/改派/取消;任务态底部可升级成工单 - 导航抽成 WorkspaceNav,带未读角标(30 秒对齐,操作后立刻刷新) - 修竞态:切视图/切 tab 连发请求时,慢的回包会把新结果盖掉(reqId 序号丢弃过期响应) - 登录支持 ?next= 站内回跳,邀请链接不再'登录完掉回首页' - e2e/tickets.mjs:双人双上下文的完整闭环,8 项断言全绿
This commit is contained in:
+14
-17
@@ -1,7 +1,8 @@
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { Link, useParams } from "react-router-dom";
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { useParams } from "react-router-dom";
|
||||
import { Layout } from "../components/Layout";
|
||||
import { TaskDetail } from "../components/TaskDetail";
|
||||
import { WorkspaceNav } from "../components/WorkspaceNav";
|
||||
import { ApiError, api } from "../lib/client";
|
||||
import { PRIORITY_LABEL, STATUS_LABEL, parseQuickAdd } from "../lib/parse";
|
||||
import type { Item, ItemStatus, Page } from "../lib/types";
|
||||
@@ -14,10 +15,10 @@ const VIEWS: { key: string; label: string; hint: string; createAs: ItemStatus }[
|
||||
{ key: "all", label: "全部", hint: "含已取消", createAs: "todo" },
|
||||
];
|
||||
|
||||
const STATUS_STYLE: Record<ItemStatus, string> = {
|
||||
const STATUS_STYLE: Record<string, string> = {
|
||||
inbox: "bg-ink-100 text-ink-700",
|
||||
todo: "bg-ink-100 text-ink-700",
|
||||
doing: "bg-accent/15 text-accent",
|
||||
doing: "bg-accent-500/15 text-accent-600",
|
||||
done: "bg-emerald-100 text-emerald-700",
|
||||
blocked: "bg-amber-100 text-amber-700",
|
||||
canceled: "bg-ink-100 text-ink-500 line-through",
|
||||
@@ -31,7 +32,7 @@ function dueLabel(iso: string | null): { text: string; overdue: boolean } | null
|
||||
}
|
||||
|
||||
export function TasksPage() {
|
||||
const { wsId } = useParams<{ wsId: string }>();
|
||||
const { wsId = "" } = useParams<{ wsId: string }>();
|
||||
const [view, setView] = useState("today");
|
||||
const [items, setItems] = useState<Item[]>([]);
|
||||
const [cursor, setCursor] = useState<string | null>(null);
|
||||
@@ -42,26 +43,32 @@ export function TasksPage() {
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [openId, setOpenId] = useState<string | null>(null);
|
||||
const [activeIdx, setActiveIdx] = useState(0);
|
||||
const reqId = useRef(0);
|
||||
|
||||
const current = VIEWS.find((v) => v.key === view);
|
||||
|
||||
const load = useCallback(
|
||||
async (nextCursor?: string | null) => {
|
||||
if (!wsId) return;
|
||||
// 换视图/改搜索词会连发多个请求,慢的那个后到会把新结果覆盖掉。
|
||||
// 每次请求记一个号,回来时不是最新号就整包丢弃。
|
||||
const mine = ++reqId.current;
|
||||
setLoading(true);
|
||||
try {
|
||||
const params = new URLSearchParams({ view, limit: "30" });
|
||||
if (query.trim()) params.set("q", query.trim());
|
||||
if (nextCursor) params.set("cursor", nextCursor);
|
||||
const page = await api.get<Page<Item>>(`/workspaces/${wsId}/items?${params}`);
|
||||
if (mine !== reqId.current) return;
|
||||
setItems((prev) => (nextCursor ? [...prev, ...page.items] : page.items));
|
||||
setCursor(page.next_cursor);
|
||||
setHasMore(page.has_more);
|
||||
setError(null);
|
||||
} catch (err) {
|
||||
if (mine !== reqId.current) return;
|
||||
setError(err instanceof ApiError ? err.message : "加载失败");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
if (mine === reqId.current) setLoading(false);
|
||||
}
|
||||
},
|
||||
[wsId, view, query],
|
||||
@@ -147,17 +154,7 @@ export function TasksPage() {
|
||||
<span className="ml-2">j/k 选择 · Enter 完成 · e 编辑 · Esc 关闭</span>
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-3 text-sm">
|
||||
<Link to={`/w/${wsId}/board`} className="text-ink-500 hover:text-ink-900">
|
||||
看板
|
||||
</Link>
|
||||
<Link to={`/w/${wsId}/members`} className="text-ink-500 hover:text-ink-900">
|
||||
成员
|
||||
</Link>
|
||||
<Link to="/" className="text-ink-500 hover:text-ink-900">
|
||||
切换工作区
|
||||
</Link>
|
||||
</div>
|
||||
<WorkspaceNav wsId={wsId} />
|
||||
</div>
|
||||
|
||||
<div className="mb-4 flex flex-wrap items-center gap-2">
|
||||
|
||||
Reference in New Issue
Block a user