89 lines
3.1 KiB
TypeScript
89 lines
3.1 KiB
TypeScript
import Link from "next/link";
|
|
import type { Route } from "next";
|
|
|
|
import { EmptyState } from "@/components/empty-state";
|
|
import { FilterNav } from "@/components/filter-nav";
|
|
import { PageHeader } from "@/components/page-header";
|
|
import { StatusPill } from "@/components/status-pill";
|
|
import { formatDateTime } from "@/lib/format";
|
|
import { getTasks } from "@/lib/mobile-data";
|
|
import type { TaskStatus } from "@/lib/types";
|
|
|
|
const statusText: Record<TaskStatus, string> = {
|
|
pending: "待处理",
|
|
in_progress: "处理中",
|
|
completed: "已完成",
|
|
cancelled: "已取消"
|
|
};
|
|
|
|
const statusTone: Record<TaskStatus, "success" | "warning" | "danger"> = {
|
|
pending: "warning",
|
|
in_progress: "warning",
|
|
completed: "success",
|
|
cancelled: "danger"
|
|
};
|
|
|
|
type TasksPageProps = {
|
|
searchParams: Promise<{ status?: string | string[] }>;
|
|
};
|
|
|
|
function firstSearchValue(value: string | string[] | undefined) {
|
|
return Array.isArray(value) ? value[0] : value;
|
|
}
|
|
|
|
function normalizeStatus(value: string | string[] | undefined): TaskStatus | "all" {
|
|
const status = firstSearchValue(value);
|
|
if (status === "pending" || status === "in_progress" || status === "completed" || status === "cancelled") {
|
|
return status;
|
|
}
|
|
|
|
return "all";
|
|
}
|
|
|
|
function emptyCopy(status: TaskStatus | "all") {
|
|
if (status === "pending") return "当前没有待处理任务。";
|
|
if (status === "in_progress") return "当前没有处理中的任务。";
|
|
if (status === "completed") return "当前没有已完成任务。";
|
|
if (status === "cancelled") return "当前没有已取消任务。";
|
|
return "当前没有分配给你的任务。";
|
|
}
|
|
|
|
export default async function TasksPage({ searchParams }: TasksPageProps) {
|
|
const status = normalizeStatus((await searchParams).status);
|
|
const tasks = await getTasks(status === "all" ? {} : { status });
|
|
|
|
return (
|
|
<div className="page-stack">
|
|
<PageHeader title="任务" description="查看个人和门店分配给你的事项。" />
|
|
<FilterNav
|
|
label="任务筛选"
|
|
options={[
|
|
{ label: "全部", href: "/tasks" as Route, active: status === "all" },
|
|
{ label: "待处理", href: "/tasks?status=pending" as Route, active: status === "pending" },
|
|
{ label: "处理中", href: "/tasks?status=in_progress" as Route, active: status === "in_progress" },
|
|
{ label: "已完成", href: "/tasks?status=completed" as Route, active: status === "completed" }
|
|
]}
|
|
/>
|
|
{tasks.length > 0 ? (
|
|
<section className="list-stack">
|
|
{tasks.map((task) => {
|
|
const href = `/tasks/${task.id}` as Route;
|
|
|
|
return (
|
|
<Link className="list-card" href={href} key={task.id}>
|
|
<div>
|
|
<h2>{task.title}</h2>
|
|
<p>{task.description || `截止:${formatDateTime(task.dueAt)}`}</p>
|
|
</div>
|
|
<StatusPill tone={statusTone[task.status]}>{statusText[task.status]}</StatusPill>
|
|
</Link>
|
|
);
|
|
})}
|
|
</section>
|
|
) : (
|
|
<EmptyState title="暂无任务" description={emptyCopy(status)} />
|
|
)}
|
|
</div>
|
|
);
|
|
}
|