feat: 支持后台配置动态咨询表单
This commit is contained in:
1 parent
aee1cff5a3
commit
54bf385f68
5 files changed
+116
-5
No files matched your search
@@ -0,0 +1,18 @@
|
|||||||
|
# 行业模板表单配置管理
|
||||||
|
|
||||||
|
## 目标
|
||||||
|
|
||||||
|
让不同品牌基于行业模板在后台配置、修改、启停咨询表单和字段;表单仍是品牌级 Runtime Workspace 配置,小程序只渲染,不出现行业分支。
|
||||||
|
|
||||||
|
## 交付边界
|
||||||
|
|
||||||
|
- 表单和字段必须按当前管理员品牌隔离。
|
||||||
|
- 禁用表单不得出现在公开 Runtime,也不得接受新的客户提交。
|
||||||
|
- 已有提交保留历史字段快照,不被表单修改破坏。
|
||||||
|
- DTO 使用运行时校验,状态变更有自动化测试。
|
||||||
|
|
||||||
|
## 验收
|
||||||
|
|
||||||
|
- API 支持表单完整查询、编辑、启用 / 禁用和安全删除约束。
|
||||||
|
- Admin 提供可用的表单配置 UI 和明确失败状态。
|
||||||
|
- Runtime、小程序和历史提交回归通过。
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# 进度
|
||||||
|
|
||||||
|
- 任务:行业模板表单配置管理
|
||||||
|
- 形态:epic
|
||||||
|
- 进度:0/3
|
||||||
|
- 当前:表单生命周期 API
|
||||||
|
- 真相文件:`SUBTASKS.csv`
|
||||||
|
|
||||||
|
## 恢复说明
|
||||||
|
|
||||||
|
继续前读取 `EPIC.md`、`SUBTASKS.csv` 和本文件,从第一个非 `DONE` 子任务继续。
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
id,title,task_type,depends_on,status,task_dir,acceptance_criteria,validation_command,notes
|
||||||
|
1,表单生命周期 API, single-full,,IN_PROGRESS,tasks/form-api,更新启停和删除约束完成并有授权测试,pnpm --filter @personal-brand/api test:integration,
|
||||||
|
2,后台表单配置界面, single-full,1,TODO,tasks/form-ui,能编辑字段和切换启用状态且保留失败输入,pnpm --filter @personal-brand/admin build,
|
||||||
|
3,跨模板回归收口, single-full,2,TODO,tasks/regression,Runtime 和小程序 fixture 全部通过,pnpm --filter @personal-brand/miniapp test:fixture && pnpm --filter @personal-brand/miniapp test:visual-fixture,
|
||||||
|
@@ -17,6 +17,7 @@ import { ApiClientError } from "@personal-brand/api-client";
|
|||||||
import type {
|
import type {
|
||||||
BrandFieldDefinition,
|
BrandFieldDefinition,
|
||||||
BrandModule,
|
BrandModule,
|
||||||
|
InquiryForm,
|
||||||
PublicWorkspace,
|
PublicWorkspace,
|
||||||
} from "@personal-brand/api-client";
|
} from "@personal-brand/api-client";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
@@ -28,6 +29,7 @@ export function WorkspacePage() {
|
|||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const [fieldOpen, setFieldOpen] = useState(false);
|
const [fieldOpen, setFieldOpen] = useState(false);
|
||||||
const [formOpen, setFormOpen] = useState(false);
|
const [formOpen, setFormOpen] = useState(false);
|
||||||
|
const [editingForm, setEditingForm] = useState<InquiryForm | null>(null);
|
||||||
const [visualTarget, setVisualTarget] = useState<string | null>(null);
|
const [visualTarget, setVisualTarget] = useState<string | null>(null);
|
||||||
const [industryTarget, setIndustryTarget] = useState<{
|
const [industryTarget, setIndustryTarget] = useState<{
|
||||||
key: "personal" | "food";
|
key: "personal" | "food";
|
||||||
@@ -140,6 +142,18 @@ export function WorkspacePage() {
|
|||||||
void queryClient.invalidateQueries({ queryKey: ["admin-inquiry-forms"] });
|
void queryClient.invalidateQueries({ queryKey: ["admin-inquiry-forms"] });
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
const updateForm = useMutation({
|
||||||
|
mutationFn: ({ id, body }: { id: string; body: Partial<InquiryForm> }) =>
|
||||||
|
client.updateAdminInquiryForm(id, body),
|
||||||
|
onSuccess: () => {
|
||||||
|
message.success("咨询表单已更新");
|
||||||
|
setFormOpen(false);
|
||||||
|
setEditingForm(null);
|
||||||
|
inquiryForm.resetFields();
|
||||||
|
void queryClient.invalidateQueries({ queryKey: ["admin-inquiry-forms"] });
|
||||||
|
void queryClient.invalidateQueries({ queryKey: ["public-runtime-workspace"] });
|
||||||
|
},
|
||||||
|
});
|
||||||
if (query.isLoading) return <Card loading />;
|
if (query.isLoading) return <Card loading />;
|
||||||
if (query.isError || !query.data) {
|
if (query.isError || !query.data) {
|
||||||
const errorStatus =
|
const errorStatus =
|
||||||
@@ -429,7 +443,14 @@ export function WorkspacePage() {
|
|||||||
<Card
|
<Card
|
||||||
title="动态咨询表单"
|
title="动态咨询表单"
|
||||||
extra={
|
extra={
|
||||||
<Button type="primary" onClick={() => setFormOpen(true)}>
|
<Button
|
||||||
|
type="primary"
|
||||||
|
onClick={() => {
|
||||||
|
setEditingForm(null);
|
||||||
|
inquiryForm.resetFields();
|
||||||
|
setFormOpen(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
新增表单
|
新增表单
|
||||||
</Button>
|
</Button>
|
||||||
}
|
}
|
||||||
@@ -447,9 +468,41 @@ export function WorkspacePage() {
|
|||||||
render: (value: unknown[]) => value?.length ?? 0,
|
render: (value: unknown[]) => value?.length ?? 0,
|
||||||
},
|
},
|
||||||
{ title: "状态", dataIndex: "isEnabled", render: (value) => (value ? "启用" : "停用") },
|
{ title: "状态", dataIndex: "isEnabled", render: (value) => (value ? "启用" : "停用") },
|
||||||
|
{
|
||||||
|
title: "操作",
|
||||||
|
render: (_: unknown, item: InquiryForm) => (
|
||||||
|
<Space>
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
onClick={() => {
|
||||||
|
setEditingForm(item);
|
||||||
|
inquiryForm.setFieldsValue({
|
||||||
|
name: item.name,
|
||||||
|
fieldsSnapshot: item.fieldsSnapshot,
|
||||||
|
});
|
||||||
|
setFormOpen(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
编辑
|
||||||
|
</Button>
|
||||||
|
<Select
|
||||||
|
size="small"
|
||||||
|
value={item.isEnabled}
|
||||||
|
options={[
|
||||||
|
{ value: true, label: "启用" },
|
||||||
|
{ value: false, label: "停用" },
|
||||||
|
]}
|
||||||
|
onChange={(isEnabled) =>
|
||||||
|
updateForm.mutate({ id: item.id, body: { isEnabled } })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
},
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
<MutationError error={createForm.error} />
|
<MutationError error={createForm.error} />
|
||||||
|
<MutationError error={updateForm.error} />
|
||||||
</Card>
|
</Card>
|
||||||
<Card title="页面模块">
|
<Card title="页面模块">
|
||||||
<Table
|
<Table
|
||||||
@@ -590,22 +643,27 @@ export function WorkspacePage() {
|
|||||||
</Modal>
|
</Modal>
|
||||||
<Modal
|
<Modal
|
||||||
open={formOpen}
|
open={formOpen}
|
||||||
title="新增动态咨询表单"
|
title={editingForm ? "编辑动态咨询表单" : "新增动态咨询表单"}
|
||||||
onCancel={() => {
|
onCancel={() => {
|
||||||
setFormOpen(false);
|
setFormOpen(false);
|
||||||
|
setEditingForm(null);
|
||||||
inquiryForm.resetFields();
|
inquiryForm.resetFields();
|
||||||
}}
|
}}
|
||||||
onOk={() => inquiryForm.submit()}
|
onOk={() => inquiryForm.submit()}
|
||||||
confirmLoading={createForm.isPending}
|
confirmLoading={createForm.isPending || updateForm.isPending}
|
||||||
>
|
>
|
||||||
<Form
|
<Form
|
||||||
form={inquiryForm}
|
form={inquiryForm}
|
||||||
layout="vertical"
|
layout="vertical"
|
||||||
onFinish={(values) =>
|
onFinish={(values) =>
|
||||||
createForm.mutate({
|
(() => {
|
||||||
|
const body = {
|
||||||
name: typeof values.name === "string" ? values.name : "",
|
name: typeof values.name === "string" ? values.name : "",
|
||||||
fieldsSnapshot: Array.isArray(values.fieldsSnapshot) ? values.fieldsSnapshot : [],
|
fieldsSnapshot: Array.isArray(values.fieldsSnapshot) ? values.fieldsSnapshot : [],
|
||||||
})
|
};
|
||||||
|
if (editingForm) updateForm.mutate({ id: editingForm.id, body });
|
||||||
|
else createForm.mutate(body);
|
||||||
|
})()
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<Form.Item name="name" label="表单名称" rules={[{ required: true }]}>
|
<Form.Item name="name" label="表单名称" rules={[{ required: true }]}>
|
||||||
|
|||||||
@@ -459,6 +459,26 @@ test("admin can create and version an inquiry form", async () => {
|
|||||||
assert.equal(created.statusCode, 201);
|
assert.equal(created.statusCode, 201);
|
||||||
const id = JSON.parse(created.body).id;
|
const id = JSON.parse(created.body).id;
|
||||||
try {
|
try {
|
||||||
|
const disabledForm = await request(`/admin/workspace/forms/${id}`, {
|
||||||
|
method: "PATCH",
|
||||||
|
headers: { authorization: `Bearer ${token}` },
|
||||||
|
payload: { isEnabled: false },
|
||||||
|
});
|
||||||
|
assert.equal(disabledForm.statusCode, 200);
|
||||||
|
assert.equal(JSON.parse(disabledForm.body).isEnabled, false);
|
||||||
|
assert.equal((await request(`/public/inquiry-forms/${id}`)).statusCode, 400);
|
||||||
|
const blockedDisabledForm = await request("/customer/inquiry-submissions", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { authorization: `Bearer ${customerToken}` },
|
||||||
|
payload: { formId: id, values: { budget: 1000 } },
|
||||||
|
});
|
||||||
|
assert.equal(blockedDisabledForm.statusCode, 400);
|
||||||
|
const enabledForm = await request(`/admin/workspace/forms/${id}`, {
|
||||||
|
method: "PATCH",
|
||||||
|
headers: { authorization: `Bearer ${token}` },
|
||||||
|
payload: { isEnabled: true },
|
||||||
|
});
|
||||||
|
assert.equal(enabledForm.statusCode, 200);
|
||||||
const updated = await request(`/admin/workspace/forms/${id}`, {
|
const updated = await request(`/admin/workspace/forms/${id}`, {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: { authorization: `Bearer ${token}` },
|
headers: { authorization: `Bearer ${token}` },
|
||||||
|
|||||||
Reference in new issue
Block a user