Trang chi tiết
Trang chi tiết hiện một bản ghi gồm tóm tắt ở đầu trang, tiến trình duyệt, thông tin và lịch sử. Trang chỉ hiện những nút mà người đang đăng nhập được bấm ở trạng thái hiện tại.
Đây là nơi ra quyết định. Người duyệt mở một đề xuất, đọc số tiền và lý do rồi bấm Duyệt hoặc Từ chối. Người tạo mở cùng trang nhưng thấy nút Huỷ đề xuất. Ví dụ lấy từ trang chi tiết của template Duyệt mua sắm (templates/purchase-requests/).
// Trang chi tiết: PageContainer (breadcrumb, tag, tóm tắt, số chính) + Steps tiến trình + Info + Timeline + nút quyết định cố định ở chân.
// Không dùng PageContainer onBack (làm sập trang trên runtime này) — dùng breadcrumb.
import { useState } from "react";
import { ModalForm, PageContainer, ProCard, ProDescriptions, ProFormTextArea } from "@ant-design/pro-components";
import { Alert, App, Button, Col, Flex, Row, Space, Steps, Tag, Timeline, Typography } from "antd";
import { CheckOutlined, CloseOutlined } from "@ant-design/icons";
export default function Page() {
const { message } = App.useApp();
const [status, setStatus] = useState<"pending" | "approved" | "rejected">("pending");
const [note, setNote] = useState<string | null>(null);
const events = [
{ color: "blue", text: <><b>Trần Thị Lan</b> tạo đề xuất</>, at: "12:52 10/11/2026" },
...(status !== "pending" ? [{ color: status === "approved" ? "green" : "red", text: <><b>Nguyễn Thu Hà</b> {status === "approved" ? "duyệt" : "từ chối"}{note ? <> — <i>“{note}”</i></> : null}</>, at: "vừa xong" }] : []),
];
const decide = (to: "approved" | "rejected") => async (v: { note?: string }) => {
setStatus(to); setNote(v.note ?? null);
message.success(to === "approved" ? "Đã duyệt" : "Đã từ chối");
return true;
};
return (
<PageContainer
header={{
title: "Gia hạn Microsoft 365 Business (12 tháng, 10 user)",
breadcrumb: { items: [{ title: <a>Đề xuất</a> }, { title: "#9" }] },
tags: <Tag color={status === "pending" ? "processing" : status === "approved" ? "success" : "error"}>{status === "pending" ? "Chờ duyệt" : status === "approved" ? "Đã duyệt" : "Từ chối"}</Tag>,
}}
content={
<ProDescriptions column={{ xs: 1, sm: 2, lg: 3 }}>
<ProDescriptions.Item label="Người tạo">Trần Thị Lan · Hành chính</ProDescriptions.Item>
<ProDescriptions.Item label="Hạng mục">Phần mềm</ProDescriptions.Item>
<ProDescriptions.Item label="Cần trước">13/11/2026</ProDescriptions.Item>
</ProDescriptions>
}
extraContent={
<Space orientation="vertical" size={0} style={{ textAlign: "right" }}>
<Typography.Text type="secondary">Số tiền đề xuất</Typography.Text>
<Typography.Text strong style={{ fontSize: 28 }}>18.600.000 ₫</Typography.Text>
</Space>
}
footer={status === "pending" ? [
<ModalForm key="r" title="Từ chối đề xuất" width={480} trigger={<Button danger icon={<CloseOutlined />}>Từ chối</Button>} onFinish={decide("rejected")} modalProps={{ okText: "Từ chối", okButtonProps: { danger: true } }}>
<ProFormTextArea name="note" label="Lý do từ chối" rules={[{ required: true, whitespace: true, message: "Cần ghi lý do" }]} />
</ModalForm>,
<ModalForm key="a" title="Duyệt đề xuất" width={480} trigger={<Button type="primary" icon={<CheckOutlined />}>Duyệt</Button>} onFinish={decide("approved")} modalProps={{ okText: "Duyệt" }}>
<ProFormTextArea name="note" label="Ghi chú (tuỳ chọn)" />
</ModalForm>,
] : undefined}
>
<Flex vertical gap={16}>
<ProCard title="Tiến trình" headerBordered>
<Steps current={status === "pending" ? 1 : 2} status={status === "rejected" ? "error" : status === "approved" ? "finish" : "process"}
items={[{ title: "Gửi đề xuất", content: "Trần Thị Lan · 12:52 10/11" }, { title: status === "pending" ? "Quản lý duyệt" : status === "approved" ? "Đã duyệt" : "Từ chối", content: status === "pending" ? "Cần trước 13/11" : "Nguyễn Thu Hà" }]} />
</ProCard>
{status === "rejected" && <Alert type="error" showIcon title="Bị từ chối bởi Nguyễn Thu Hà" description={`Lý do: ${note}`} />}
<Row gutter={[16, 16]}>
<Col xs={24} lg={15}>
<ProCard title="Thông tin" headerBordered style={{ height: "100%" }}>
<Typography.Paragraph>Bản hiện tại hết hạn cuối tháng, cần gia hạn để không gián đoạn email.</Typography.Paragraph>
</ProCard>
</Col>
<Col xs={24} lg={9}>
<ProCard title="Lịch sử" headerBordered style={{ height: "100%" }}>
<Timeline items={events.map((e) => ({ color: e.color, children: <><div>{e.text}</div><Typography.Text type="secondary" style={{ fontSize: 12 }}>{e.at}</Typography.Text></> }))} />
</ProCard>
</Col>
</Row>
</Flex>
</PageContainer>
);
}
Làm màn hình "Trang chi tiết + duyệt" cho app của tôi theo mẫu manh.run UI playbook (framework_docs("pro")): Trang chi tiết: PageContainer (breadcrumb, tag, tóm tắt, số chính) + Steps tiến trình + Info + Timeline + nút quyết định cố định ở chân. Dữ liệu lấy từ API của app qua useApiClient(); nhãn và trường theo spec của tôi.Cây file
Trang và các API của nó nằm cùng thư mục [id:int]. Mỗi thao tác đổi trạng thái là một API riêng.
app/requests/[id:int]/
├── page.tsx /requests/12 trang chi tiết
├── get.ts GET /requests/12 api.requests.detail(id)
├── patch.ts PATCH /requests/12 api.requests.update(id, body)
├── approve/post.ts POST …/approve api.requests.approve(id, { note })
├── reject/post.ts POST …/reject api.requests.reject(id, { note })
└── cancel/post.ts POST …/cancel api.requests.cancel(id, {})Bố cục trang
Trang theo bố cục profile/advanced của Ant Design Pro:
PageContainer
├── header tiêu đề · Tag trạng thái · nút chuyển trạng thái (extra)
├── content 3–4 thông tin chính (ProDescriptions)
├── extraContent con số quan trọng nhất (số tiền)
├── ProCard "Tiến trình" → Steps
├── Alert kết quả: đã duyệt / bị từ chối + ghi chú
├── Row gutter={[16, 16]}
│ ├── Col lg={15} ProCard "Thông tin" → ProDescriptions
│ └── Col lg={9} ActivityLog "Lịch sử"Tải bản ghi và trường hợp không tìm thấy
Tải bản ghi bằng useRequest với refreshDeps: [id]. Không tìm thấy hoặc không có quyền xem thì hiện Result ngay trong PageContainer, kèm nút về danh sách.
const { id } = useParams();
const api = useApiClient();
const { data: r, loading, error, refresh, mutate } =
useRequest(async () => (await api.requests.detail(id!)) as RequestDetail, { refreshDeps: [id] });
const breadcrumb = { items: [{ title: <a onClick={() => nav("/requests")}>Đề xuất</a> }, { title: `#${id}` }] };
if (loading && !r) return <PageContainer header={{ breadcrumb }} loading />;
if (error || !r) return (
<PageContainer header={{ breadcrumb }}>
<ProCard>
<Result status="404" title="Không tìm thấy đề xuất"
subTitle="Đề xuất không tồn tại hoặc bạn không có quyền xem."
extra={<Button type="primary" onClick={() => nav("/requests")}>Về danh sách</Button>} />
</ProCard>
</PageContainer>
);Đầu trang: trạng thái, tóm tắt, số chính
Đặt trạng thái ở tags, thông tin chính ở content, số tiền ở extraContent. Người duyệt đọc đủ thông tin để quyết định mà không phải cuộn trang.
<PageContainer
header={{
title: r.title, breadcrumb,
tags: <Tag color={STATUS_COLOR[r.status]}>{STATUS_ENUM[r.status].text}</Tag>,
extra: actions,
}}
content={
<ProDescriptions column={{ xs: 1, sm: 2, lg: 4 }} dataSource={r}>
<ProDescriptions.Item label="Người tạo">{r.creatorName}</ProDescriptions.Item>
<ProDescriptions.Item label="Hạng mục">{CATEGORY[r.category]}</ProDescriptions.Item>
<ProDescriptions.Item label="Cần trước">
<Typography.Text type={isLate(r) ? "danger" : undefined}>{vnDate(r.neededBy)}</Typography.Text>
</ProDescriptions.Item>
<ProDescriptions.Item label="Mã">#{r.id}</ProDescriptions.Item>
</ProDescriptions>
}
extraContent={<Statistic title="Số tiền đề xuất" value={vnd(r.amount)} />}
>
{/* tiến trình, thông tin, lịch sử */}
</PageContainer>Tiến trình bằng Steps
Tính các bước dựa vào trạng thái. Bước đang chờ là quyết định sắp phải đưa ra. Đề xuất bị từ chối thì đặt status="error".
const decided = r.status === "approved" || r.status === "rejected";
const steps = [
{ title: "Gửi đề xuất", content: `${r.creatorName} · ${vnDateTime(r.createdAt)}` },
r.status === "cancelled" ? { title: "Đã huỷ", content: "Người tạo huỷ trước khi duyệt" }
: decided ? { title: r.status === "approved" ? "Đã duyệt" : "Từ chối", content: `${r.deciderName} · ${vnDateTime(r.decidedAt)}` }
: { title: "Quản lý duyệt", content: r.neededBy ? `Cần trước ${vnDate(r.neededBy)}` : "Đang chờ" },
];
<ProCard title="Tiến trình" headerBordered>
<Steps
current={r.status === "pending" ? 1 : 2}
status={r.status === "rejected" ? "error" : r.status === "cancelled" ? "wait" : r.status === "approved" ? "finish" : "process"}
items={steps}
/>
</ProCard>
{r.status === "rejected" && (
<Alert type="error" showIcon title={`${r.deciderName} đã từ chối`} description={`Lý do: ${r.decisionNote}`} />
)}Thông tin và lịch sử
Phần thông tin dùng ProDescriptions hai cột. Phần lịch sử dùng ActivityLog từ manh/shell: mỗi mục ghi ai, làm gì, ghi chú và lúc nào, bước chuyển trạng thái hiện dạng “Chờ duyệt → Đã duyệt”.
<Row gutter={[16, 16]}>
<Col xs={24} lg={15}>
<ProCard title="Thông tin" headerBordered style={{ height: "100%" }}>
<ProDescriptions column={{ xs: 1, sm: 2 }} dataSource={r}>
<ProDescriptions.Item label="Ngày tạo">{vnDateTime(r.createdAt)}</ProDescriptions.Item>
<ProDescriptions.Item label="Người duyệt">{r.deciderName ?? "—"}</ProDescriptions.Item>
<ProDescriptions.Item label="Ghi chú duyệt" span={2}>{r.decisionNote || "—"}</ProDescriptions.Item>
</ProDescriptions>
</ProCard>
</Col>
<Col xs={24} lg={9}>
<ActivityLog title="Lịch sử" items={r.events} statusLabels={RequestStatus} />
</Col>
</Row>Mỗi mục của items có dạng { id, at, actorName, body?, fromStatus?, toStatus? }. Truyền thêm add thì ActivityLog có ô để ghi chú mới.
Có sẵn mảng columns của danh sách thì dùng lại: <ProDescriptions columns={columns as ProDescriptionsItemProps<Req>[]} dataSource={r} />. valueEnum và valueType sẽ hiện giống hệt trong bảng. Cột chỉ để lọc thì thêm hideInDescriptions.
Nút chuyển trạng thái bằng FlowActions
Vòng đời đề xuất khai báo một lần bằng defineFlow trong app/shared/request.ts. FlowActions từ manh/shell đọc bảng đó và chỉ hiện những bước mà vai trò hiện tại được làm ở trạng thái hiện tại. Người tạo thấy Huỷ đề xuất, người duyệt thấy Duyệt và Từ chối, đề xuất đã xử lý thì không còn nút nào.
const move = (to: string, row: RequestDetail, v?: { note?: string }) =>
to === "approved" ? api.requests.approve(row.id, v ?? {})
: to === "rejected" ? api.requests.reject(row.id, { note: v?.note })
: api.requests.cancel(row.id, {});
const actions = (
<FlowActions flow={RequestFlow} record={r} labels={RequestStatus} move={move} onDone={refresh}
ask={{ rejected: [{ title: "Lý do từ chối", dataIndex: "note", valueType: "textarea",
formItemProps: { rules: [{ required: true, whitespace: true, message: "Từ chối cần ghi lý do" }] } }] }} />
);askmở form nhỏ trước khi chuyển. Ở đây từ chối bắt buộc ghi lý do.- Bước huỷ hay từ chối có hỏi lại trước khi làm. Xong bước nào thì hiện thông báo và gọi
onDone, lỗi thì hiện câu báo lỗi của server. - Nút khác ngoài vòng đời, như Sửa, gọi API qua
useActiontừapp/hooks:const save = useAction((v) => api.requests.update(r.id, v), { ok: "Đã lưu", reload: refresh }).
Kiểm lại ở server
Ẩn nút chỉ giúp người dùng khỏi bấm nhầm. Handler vẫn phải kiểm vai trò và trạng thái:
import { z } from "@hono/zod-openapi";
import { decide } from "../../repository";
export const access = ["manager"]; // không phải quản lý → 403
export const schema = { body: z.object({ note: z.string().max(1000).optional() }) };
export default (c, { user, param, body }) => decide(user, param.id, "rejected", body.note);Trong decide, từ chối mà thiếu lý do thì trả 400; đề xuất không còn ở trạng thái chờ thì trả 409 “Đề xuất đã được xử lý”. Mỗi quyết định ghi thêm một dòng lịch sử, nên ActivityLog luôn đầy đủ.
Giao diện và server dùng chung bảng bước chuyển trong app/shared/request.ts. decide gọi RequestFlow.assert(user, row.status, "rejected"): bước chuyển không hợp lệ trả 409, sai vai trò trả 403. FlowActions lấy các bước từ RequestFlow.next(r.status, role). Điều kiện chỉ người tạo mới được làm, như huỷ đề xuất của chính mình, thì repository vẫn phải tự kiểm. Xem Làm một tính năng CRUD.
Cần biết
- Không dùng
onBacktrênPageContainervì trang sẽ sập. Dùngheader.breadcrumb. - Chia cột Thông tin / Lịch sử bằng
Row gutter+Col, không dùngProCard gutter. - Khi hai người duyệt cùng lúc, người bấm sau nhận lỗi 409. Hiện nguyên câu báo lỗi và tải lại bản ghi để thấy ai đã quyết định.
- Muốn sửa ngay trên trang, dùng
ProDescriptions editable={{ onSave }}và đặteditable: falsecho cột không được sửa.
Bước tiếp theo
- Form —
DrawerFormdùng cho nút Sửa. - Đăng nhập và phân quyền —
accessvà người dùng trong handler. - Trang và layout — đường dẫn động
[id:int].