refactor: 拆分后台咨询记录模块
This commit is contained in:
1 parent
8033cabff9
commit
bff6e4e9d6
2 files changed
+98
-1
No files matched your search
@@ -0,0 +1,96 @@
|
||||
import { Badge, Button, Card, Select, Space, Table, Tag, message } from "antd";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import type { AdminBooking } from "@personal-brand/api-client";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
import { useState } from "react";
|
||||
|
||||
const statuses = ["received", "contacting", "confirmed", "completed", "cancelled"] as const;
|
||||
const labels: Record<string, string> = {
|
||||
received: "待处理",
|
||||
contacting: "沟通中",
|
||||
confirmed: "已确认",
|
||||
completed: "已完成",
|
||||
cancelled: "已取消",
|
||||
};
|
||||
|
||||
export function InquiriesPage() {
|
||||
const client = createApiClient();
|
||||
const queryClient = useQueryClient();
|
||||
const [status, setStatus] = useState<string>();
|
||||
const query = useQuery({
|
||||
queryKey: ["admin-bookings", status],
|
||||
queryFn: () => client.listAdminBookings(status ? { status: status as never } : {}),
|
||||
});
|
||||
const update = useMutation({
|
||||
mutationFn: ({ id, value }: { id: string; value: never }) =>
|
||||
client.updateAdminBookingStatus(id, value),
|
||||
onSuccess: () => {
|
||||
message.success("咨询状态已更新");
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-bookings"] });
|
||||
},
|
||||
});
|
||||
const read = useMutation({
|
||||
mutationFn: (id: string) => client.markAdminBookingRead(id),
|
||||
onSuccess: () => void queryClient.invalidateQueries({ queryKey: ["admin-bookings"] }),
|
||||
});
|
||||
return (
|
||||
<Card
|
||||
title="咨询记录"
|
||||
extra={
|
||||
<Space>
|
||||
<Select
|
||||
allowClear
|
||||
placeholder="全部状态"
|
||||
style={{ width: 130 }}
|
||||
value={status}
|
||||
onChange={setStatus}
|
||||
options={statuses.map((value) => ({ value, label: labels[value] }))}
|
||||
/>
|
||||
<Badge
|
||||
count={
|
||||
query.data?.filter((item) => !(item as AdminBooking & { isRead?: boolean }).isRead)
|
||||
.length ?? 0
|
||||
}
|
||||
showZero
|
||||
/>
|
||||
</Space>
|
||||
}
|
||||
>
|
||||
<Table
|
||||
rowKey="id"
|
||||
loading={query.isLoading}
|
||||
dataSource={query.data ?? []}
|
||||
columns={[
|
||||
{ title: "编号", dataIndex: "bookingNo" },
|
||||
{ title: "联系人", dataIndex: "customerName" },
|
||||
{
|
||||
title: "提交时间",
|
||||
dataIndex: "createdAt",
|
||||
render: (value: string) => new Date(value).toLocaleString("zh-CN"),
|
||||
},
|
||||
{
|
||||
title: "状态",
|
||||
dataIndex: "status",
|
||||
render: (value: string) => <Tag>{labels[value] ?? value}</Tag>,
|
||||
},
|
||||
{
|
||||
title: "操作",
|
||||
render: (_: unknown, item: AdminBooking) => (
|
||||
<Space>
|
||||
<Select
|
||||
size="small"
|
||||
value={item.status}
|
||||
onChange={(value) => update.mutate({ id: item.id, value: value as never })}
|
||||
options={statuses.map((value) => ({ value, label: labels[value] }))}
|
||||
/>
|
||||
<Button size="small" onClick={() => read.mutate(item.id)}>
|
||||
标记已读
|
||||
</Button>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user