refactor: 拆分品牌展示编辑器职责

This commit is contained in:
que01 committed 2026-10-15 14:42:20 +08:00
1 parent b23120477f
commit 6f18c67315
5 files changed
+376 -315

No files matched your search

@@ -0,0 +1,134 @@
import { Alert, Button, Col, Divider, Form, Row, Space } from "antd";
import type { FormInstance } from "antd";
import { useNavigate } from "react-router-dom";
import type { TemplateAdminSection } from "@personal-brand/api-client";
import { TemplateFieldRenderer } from "../../components/TemplateFieldRenderer.js";
import { TemplateListField } from "../../components/TemplateListField.js";
import { MutationError } from "../../components/QueryState.js";
import {
presentationFieldName,
type PresentationValues,
} from "../../lib/presentation/presentation-bindings.js";
import { fieldTargetTitle } from "./presentation-editor-helpers.js";
import type { PreviewTarget } from "./preview-selection.js";
interface PresentationFormPanelProps {
form: FormInstance<PresentationValues>;
initialValues: PresentationValues;
editableSections: TemplateAdminSection[];
relevantPageLinks: { target: string; label: string | undefined }[];
selectedTarget: PreviewTarget | undefined;
save: {
error: unknown;
isPending: boolean;
mutate: (values: PresentationValues) => void;
};
onValuesChange: (changed: PresentationValues, allValues: PresentationValues) => void;
}
export function PresentationFormPanel({
form,
initialValues,
editableSections,
relevantPageLinks,
selectedTarget,
save,
onValuesChange,
}: PresentationFormPanelProps) {
const navigate = useNavigate();
const hasEditableFields = editableSections.some((section) => section.fields.length);
return (
<Form
form={form}
layout="vertical"
initialValues={initialValues}
onValuesChange={onValuesChange}
onFinish={() => save.mutate(form.getFieldsValue(true) as PresentationValues)}
className="presentation-editor__form"
>
<div className="presentation-editor__form-body">
{editableSections.map((section, index) => (
<section key={section.key} aria-labelledby={`section-${section.key}`}>
{selectedTarget && index > 0 ? <Divider /> : null}
<h4 id={`section-${section.key}`} className="admin-subhead">
{selectedTarget ? fieldTargetTitle(section, selectedTarget.label) : section.title}
</h4>
{!selectedTarget ? (
<p className="admin-section-description admin-offset-bottom">{section.description}</p>
) : null}
<Row gutter={16}>
{section.fields.map((field) => (
<Col key={field.key} xs={24} md={24}>
{field.input === "list" ? (
<TemplateListField
field={field}
name={presentationFieldName(section.key, field.key)}
/>
) : (
<Form.Item
name={presentationFieldName(section.key, field.key)}
label={field.label}
{...(field.help ? { help: field.help } : {})}
{...(field.required
? {
rules: [{ required: true, message: `请填写${field.label}` }],
}
: {})}
>
<TemplateFieldRenderer field={field} />
</Form.Item>
)}
</Col>
))}
</Row>
</section>
))}
{relevantPageLinks.length ? (
<Alert
type="info"
showIcon
className="admin-offset-bottom-lg"
message="这个页面还有关联内容"
description={
<Space wrap>
{relevantPageLinks.map((item) => (
<Button
key={item.target}
type="link"
onClick={() => {
if (item.target.startsWith("trust:")) {
void navigate(
`/admin/trust?type=${encodeURIComponent(item.target.slice(6))}`,
);
return;
}
void navigate(
item.target === "offering" ? "/admin/services" : "/admin/workspace",
);
}}
className="admin-link-flush"
>
{item.label}
</Button>
))}
</Space>
}
/>
) : null}
{!hasEditableFields && !relevantPageLinks.length ? (
<p className="admin-section-description">这个页面没有单独的品牌文案配置。</p>
) : null}
{selectedTarget && !hasEditableFields && relevantPageLinks.length ? (
<p className="admin-section-description">此区域内容由对应的业务管理页面维护。</p>
) : null}
</div>
<div className="presentation-editor__form-actions admin-actions admin-offset-top-lg">
<MutationError error={save.error} />
<Button type="primary" htmlType="submit" loading={save.isPending}>
保存页面内容
</Button>
</div>
</Form>
);
}