feat: 完成模板区域与咨询字段编辑闭环
This commit is contained in:
1 parent
c5db30f817
commit
66dbba5748
6 files changed
+211
-24
No files matched your search
@@ -34,6 +34,7 @@ import { ImageUrlField } from "../../components/ImageUrlField.js";
|
||||
import { TemplateListField } from "../../components/TemplateListField.js";
|
||||
import { MutationError } from "../../components/QueryState.js";
|
||||
import { TemplatePreview } from "./TemplatePreview.js";
|
||||
import { InquiryPreviewEditor } from "./InquiryPreviewEditor.js";
|
||||
import { resolvePreviewSelection, type PreviewSelection } from "./preview-selection.js";
|
||||
import {
|
||||
applyBrandPreviewValues,
|
||||
@@ -135,6 +136,17 @@ function renderField(field: TemplateAdminField) {
|
||||
);
|
||||
}
|
||||
|
||||
function previewTargetSource(
|
||||
section: TemplateAdminSection,
|
||||
targetKey: string,
|
||||
): "brand" | "offering" | "trust" | "inquiry" {
|
||||
const fields = section.fields.filter((field) => field.previewTarget === targetKey);
|
||||
if (fields.some((field) => field.binding.startsWith("offering."))) return "offering";
|
||||
if (fields.some((field) => field.binding.startsWith("trust."))) return "trust";
|
||||
if (fields.some((field) => field.binding.startsWith("brand."))) return "brand";
|
||||
return section.target;
|
||||
}
|
||||
|
||||
export function PresentationEditor({
|
||||
templateContent,
|
||||
previewWorkspace,
|
||||
@@ -157,6 +169,9 @@ export function PresentationEditor({
|
||||
}>();
|
||||
const [previewConfig, setPreviewConfig] = useState(config ?? {});
|
||||
const [previewBrandValues, setPreviewBrandValues] = useState<Record<string, unknown>>({});
|
||||
const [inquiryDraft, setInquiryDraft] =
|
||||
useState<RuntimeWorkspace["inquiryForms"][number]["fields"]>();
|
||||
const inquiryRuntime = previewWorkspace?.inquiryForms.find((item) => item.target === "brand");
|
||||
const sections = useMemo(() => {
|
||||
const declaredTemplateFields = (templateContent?.templateFields ?? []).map((field) => ({
|
||||
...field,
|
||||
@@ -220,10 +235,20 @@ export function PresentationEditor({
|
||||
(section.previewTargets ?? []).map((target) => ({
|
||||
...target,
|
||||
page: section.page,
|
||||
source: section.target,
|
||||
source: previewTargetSource(section, target.key),
|
||||
})),
|
||||
)
|
||||
.concat(
|
||||
selectedPage === "inquiry" && inquiryRuntime
|
||||
? inquiryRuntime.fields.map((field) => ({
|
||||
key: `inquiry-field:${field.key}`,
|
||||
label: field.label,
|
||||
page: "inquiry",
|
||||
source: "inquiry" as const,
|
||||
}))
|
||||
: [],
|
||||
),
|
||||
[templateContent, selectedPage, recordSections],
|
||||
[templateContent, selectedPage, recordSections, inquiryRuntime],
|
||||
);
|
||||
const activeTarget = selection?.targetKey;
|
||||
const selectedTarget = visibleTargets.find((target) => target.key === activeTarget);
|
||||
@@ -253,7 +278,9 @@ export function PresentationEditor({
|
||||
? trustQuery.data?.find((item) => item.id === selection?.recordId)
|
||||
: undefined;
|
||||
const editableSections = filterSectionsForPreviewTarget(
|
||||
visibleSections.filter((section) => section.target === "brand" || section.target === "inquiry"),
|
||||
visibleSections.filter((section) =>
|
||||
section.fields.some((field) => field.binding.startsWith("brand.")),
|
||||
),
|
||||
selectedTarget?.key,
|
||||
);
|
||||
const recordSection = useMemo(
|
||||
@@ -403,6 +430,9 @@ export function PresentationEditor({
|
||||
if (!previewWorkspace) return undefined;
|
||||
const next: RuntimeWorkspace = {
|
||||
...previewWorkspace,
|
||||
inquiryForms: previewWorkspace.inquiryForms.map((item) =>
|
||||
item.key === inquiryRuntime?.key && inquiryDraft ? { ...item, fields: inquiryDraft } : item,
|
||||
),
|
||||
brand: projectBrandAliases(
|
||||
{
|
||||
...previewWorkspace.brand,
|
||||
@@ -484,6 +514,8 @@ export function PresentationEditor({
|
||||
selectedRecord,
|
||||
recordSection,
|
||||
templateContent,
|
||||
inquiryDraft,
|
||||
inquiryRuntime,
|
||||
]);
|
||||
const selectedDetailOfferingId =
|
||||
detailOfferingId && draftWorkspace?.offerings.some((item) => item.id === detailOfferingId)
|
||||
@@ -589,7 +621,16 @@ export function PresentationEditor({
|
||||
<Typography.Title level={5}>
|
||||
{selectedTarget?.label ?? pageTitle(selectedPage ?? "home")}
|
||||
</Typography.Title>
|
||||
{selectedRecordSource && selection?.recordId && selectedSection ? (
|
||||
{activeTarget?.startsWith("inquiry-field:") && inquiryRuntime ? (
|
||||
<InquiryPreviewEditor
|
||||
runtime={
|
||||
draftWorkspace?.inquiryForms.find((item) => item.key === inquiryRuntime.key) ??
|
||||
inquiryRuntime
|
||||
}
|
||||
fieldKey={activeTarget.slice("inquiry-field:".length)}
|
||||
onDraft={setInquiryDraft}
|
||||
/>
|
||||
) : selectedRecordSource && selection?.recordId && selectedSection ? (
|
||||
selectedRecord ? (
|
||||
<RecordEditor
|
||||
key={`${selectedRecordSource}:${selectedRecord.id}:${selectedSection.key}`}
|
||||
@@ -660,7 +701,7 @@ export function PresentationEditor({
|
||||
initialValues={initialValues}
|
||||
onValuesChange={handleValuesChange}
|
||||
onFinish={(values) => save.mutate(values)}
|
||||
style={{ minHeight: 540, display: "flex", flexDirection: "column" }}
|
||||
style={{ minHeight: 0, display: "flex", flexDirection: "column" }}
|
||||
>
|
||||
<div style={{ flex: 1 }}>
|
||||
{editableSections.map((section, index) => (
|
||||
@@ -678,11 +719,7 @@ export function PresentationEditor({
|
||||
) : null}
|
||||
<Row gutter={16}>
|
||||
{section.fields.map((field) => (
|
||||
<Col
|
||||
key={field.key}
|
||||
xs={24}
|
||||
md={field.input === "textarea" || field.input === "list" ? 24 : 12}
|
||||
>
|
||||
<Col key={field.key} xs={24} md={24}>
|
||||
{field.input === "list" ? (
|
||||
<TemplateListField
|
||||
field={field}
|
||||
@@ -841,17 +878,13 @@ function RecordEditor({
|
||||
initialValues={initialValues}
|
||||
onValuesChange={(_, values) => onDraft(values)}
|
||||
onFinish={(values) => save.mutate(values)}
|
||||
style={{ minHeight: 540, display: "flex", flexDirection: "column" }}
|
||||
style={{ minHeight: 0, display: "flex", flexDirection: "column" }}
|
||||
>
|
||||
<Typography.Paragraph type="secondary">{section.description}</Typography.Paragraph>
|
||||
<div style={{ flex: 1 }}>
|
||||
<Row gutter={16}>
|
||||
{section.fields.map((field) => (
|
||||
<Col
|
||||
key={field.key}
|
||||
xs={24}
|
||||
md={field.input === "textarea" || field.input === "list" ? 24 : 12}
|
||||
>
|
||||
<Col key={field.key} xs={24} md={24}>
|
||||
{field.input === "list" ? (
|
||||
<TemplateListField
|
||||
field={field}
|
||||
|
||||
Reference in new issue
Block a user