feat: 让模板声明信任内容编辑语义
This commit is contained in:
1 parent
6d7fae95b3
commit
e3a4074d8e
12 files changed
+159
-13
No files matched your search
@@ -51,6 +51,17 @@ const types = [
|
||||
help: "说明回复时间、交付承诺、售后方式或合作预期。",
|
||||
},
|
||||
];
|
||||
type TrustTypeOption = {
|
||||
type: string;
|
||||
label: string;
|
||||
help?: string;
|
||||
placeholder?: string;
|
||||
};
|
||||
const fallbackTypes: TrustTypeOption[] = types.map(({ value, label, help }) => ({
|
||||
type: value,
|
||||
label,
|
||||
help,
|
||||
}));
|
||||
|
||||
export function TrustContentPage() {
|
||||
const client = createApiClient();
|
||||
@@ -58,10 +69,20 @@ export function TrustContentPage() {
|
||||
const [editing, setEditing] = useState<TrustContent | null>(null);
|
||||
const [open, setOpen] = useState(false);
|
||||
const [form] = Form.useForm<TrustContentInput>();
|
||||
const selectedType = Form.useWatch("type", form);
|
||||
const query = useQuery({
|
||||
queryKey: ["trust-content"],
|
||||
queryFn: () => client.listAdminTrustContent(),
|
||||
});
|
||||
const workspace = useQuery({
|
||||
queryKey: ["admin-workspace-trust-types"],
|
||||
queryFn: () => client.getAdminWorkspace(),
|
||||
});
|
||||
const availableTypes: TrustTypeOption[] = workspace.data?.templateContent?.trustContentTypes
|
||||
?.length
|
||||
? workspace.data.templateContent.trustContentTypes
|
||||
: fallbackTypes;
|
||||
const selectedTypeMeta = availableTypes.find((item) => item.type === selectedType);
|
||||
const save = useMutation({
|
||||
mutationFn: (values: TrustContentInput) =>
|
||||
editing
|
||||
@@ -99,7 +120,11 @@ export function TrustContentPage() {
|
||||
);
|
||||
};
|
||||
return (
|
||||
<QueryState loading={query.isLoading} error={query.error} onRetry={() => void query.refetch()}>
|
||||
<QueryState
|
||||
loading={query.isLoading || workspace.isLoading}
|
||||
error={query.error || workspace.error}
|
||||
onRetry={() => void Promise.all([query.refetch(), workspace.refetch()])}
|
||||
>
|
||||
<AdminPageHeader
|
||||
title="信任内容"
|
||||
description="用经历、案例、资历、流程和反馈,让访客知道为什么可以信任你。"
|
||||
@@ -171,7 +196,9 @@ export function TrustContentPage() {
|
||||
>
|
||||
<Form form={form} layout="vertical" onFinish={(values) => save.mutate(values)}>
|
||||
<Form.Item name="type" label="内容用途" rules={[{ required: true }]}>
|
||||
<Select options={types} />
|
||||
<Select
|
||||
options={availableTypes.map((item) => ({ value: item.type, label: item.label }))}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item name="title" label="标题" rules={[{ required: true }]}>
|
||||
<Input placeholder="例如:服务过 30+ 位独立创作者" />
|
||||
@@ -182,14 +209,16 @@ export function TrustContentPage() {
|
||||
<Form.Item
|
||||
name="content"
|
||||
label="详细内容"
|
||||
help="每行写一项,页面会按模板样式展示。不要填写 HTML 或代码。"
|
||||
help={
|
||||
selectedTypeMeta?.help ?? "每行写一项,页面会按模板样式展示。不要填写 HTML 或代码。"
|
||||
}
|
||||
rules={[{ required: true }]}
|
||||
>
|
||||
<Input.TextArea
|
||||
rows={8}
|
||||
showCount
|
||||
maxLength={2000}
|
||||
placeholder="例如:\n周一至周五 17:00 - 22:30\n周末接受团体预约"
|
||||
placeholder={selectedTypeMeta?.placeholder ?? "例如:\n第一项内容\n第二项内容"}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
|
||||
Reference in new issue
Block a user