Files
role-user/src/app/(app)/tasks/[id]/page.tsx
T
2026-06-02 14:46:39 +08:00

115 lines
3.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import Link from "next/link";
import { notFound } from "next/navigation";
import { ArrowLeft, CalendarClock, ClipboardList, Store, UsersRound } from "lucide-react";
import { PageHeader } from "@/components/page-header";
import { StatusPill } from "@/components/status-pill";
import { TaskActionPanel } from "@/components/task-action-panel";
import { BackendError } from "@/lib/backend";
import { formatDateTime } from "@/lib/format";
import { getTaskDetail } from "@/lib/mobile-data";
import type { TaskEvent, TaskStatus } from "@/lib/types";
type TaskDetailPageProps = {
params: Promise<{ id: string }>;
};
const statusText: Record<TaskStatus, string> = {
pending: "待处理",
in_progress: "处理中",
completed: "已完成",
cancelled: "已取消"
};
const statusTone: Record<TaskStatus, "default" | "success" | "warning" | "danger"> = {
pending: "warning",
in_progress: "warning",
completed: "success",
cancelled: "danger"
};
const eventText: Record<string, string> = {
CREATED: "创建任务",
UPDATED: "更新任务",
STARTED: "开始处理",
COMPLETED: "完成任务",
CANCELLED: "取消任务",
COMMENTED: "追加备注"
};
function eventDescription(event: TaskEvent) {
const label = eventText[event.eventType] ?? event.eventType;
if (event.comment) return `${label}:${event.comment}`;
if (event.fromStatus && event.toStatus) return `${label}:${event.fromStatus} -> ${event.toStatus}`;
return label;
}
export default async function TaskDetailPage({ params }: TaskDetailPageProps) {
const { id } = await params;
let task: Awaited<ReturnType<typeof getTaskDetail>>;
try {
task = await getTaskDetail(id);
} catch (error) {
if (error instanceof BackendError && error.status === 404) {
notFound();
}
throw error;
}
return (
<div className="page-stack">
<Link className="inline-link" href="/tasks">
<ArrowLeft aria-hidden size={16} />
返回任务
</Link>
<PageHeader eyebrow={task.storeName || "任务详情"} title={task.title} description={task.description} />
<section className="detail-card">
<div className="detail-meta">
<span>
<ClipboardList aria-hidden size={16} />
当前状态
</span>
<StatusPill tone={statusTone[task.status]}>{statusText[task.status]}</StatusPill>
</div>
<div className="info-list compact">
<div>
<CalendarClock aria-hidden size={18} />
<span>截止时间</span>
<strong>{formatDateTime(task.dueAt)}</strong>
</div>
<div>
<Store aria-hidden size={18} />
<span>所属门店</span>
<strong>{task.storeName || "未指定"}</strong>
</div>
<div>
<UsersRound aria-hidden size={18} />
<span>处理人</span>
<strong>{task.assignees.map((item) => item.name).join("、") || task.assigneeName || "未指定"}</strong>
</div>
</div>
</section>
<TaskActionPanel initialStatus={task.status} taskId={task.id} />
<section className="section-block">
<div className="section-title">
<h2>处理记录</h2>
</div>
{task.events.length > 0 ? (
<div className="timeline">
{task.events.map((event) => (
<article className="timeline-item" key={event.id}>
<strong>{eventDescription(event)}</strong>
<span>{formatDateTime(event.createdAt)}</span>
</article>
))}
</div>
) : (
<p className="muted-copy">暂无处理记录。</p>
)}
</section>
</div>
);
}