175 lines
7.5 KiB
TypeScript
175 lines
7.5 KiB
TypeScript
import { Button, Card, Col, Form, Input, Row, Select, Space, Tag, Typography, message } from "antd";
|
||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||
import type { BrandProfile } from "@personal-brand/api-client";
|
||
import { createApiClient } from "../../lib/api.js";
|
||
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
||
import { ImageUrlField } from "../../components/ImageUrlField.js";
|
||
import { MutationError, QueryState } from "../../components/QueryState.js";
|
||
import { PresentationEditor } from "./PresentationEditor.js";
|
||
|
||
export function BrandPage() {
|
||
const client = createApiClient();
|
||
const queryClient = useQueryClient();
|
||
const [form] = Form.useForm<BrandProfile>();
|
||
const brand = useQuery({ queryKey: ["admin-brand"], queryFn: () => client.getAdminBrand() });
|
||
const workspace = useQuery({
|
||
queryKey: ["admin-workspace"],
|
||
queryFn: () => client.getAdminWorkspace(),
|
||
});
|
||
const previewWorkspace = useQuery({
|
||
queryKey: ["admin-preview-workspace"],
|
||
queryFn: () => client.getAdminPreviewWorkspace(),
|
||
});
|
||
const template = useQuery({
|
||
queryKey: ["template", brand.data?.templateKey],
|
||
queryFn: () => client.getPublicTemplate(brand.data!.templateKey),
|
||
enabled: Boolean(brand.data?.templateKey),
|
||
});
|
||
const save = useMutation({
|
||
mutationFn: (values: Partial<BrandProfile>) => client.updateAdminBrand(values),
|
||
onSuccess: () => {
|
||
message.success("品牌表达已保存");
|
||
void queryClient.invalidateQueries({ queryKey: ["admin-brand"] });
|
||
},
|
||
});
|
||
return (
|
||
<QueryState loading={brand.isLoading} error={brand.error} onRetry={() => void brand.refetch()}>
|
||
{!brand.data ? null : (
|
||
<>
|
||
<AdminPageHeader
|
||
title="品牌资料"
|
||
description="先让访客理解你是谁、服务谁,以及为什么值得信任。"
|
||
extra={<Tag color="blue">{template.data?.name ?? "当前模板"}</Tag>}
|
||
/>
|
||
<Row gutter={[24, 24]} align="top">
|
||
<Col xs={24} xl={16}>
|
||
<Form
|
||
form={form}
|
||
layout="vertical"
|
||
initialValues={brand.data}
|
||
onFinish={(values) => save.mutate(values)}
|
||
>
|
||
<Card
|
||
title="我是谁"
|
||
extra={<Typography.Text type="secondary">公开展示</Typography.Text>}
|
||
>
|
||
<Form.Item
|
||
name="name"
|
||
label="品牌名称"
|
||
help="可以是个人姓名、工作室名称或品牌名。"
|
||
rules={[{ required: true, message: "请输入品牌名称" }]}
|
||
>
|
||
<Input size="large" placeholder="例如:林然|品牌顾问" />
|
||
</Form.Item>
|
||
<Form.Item
|
||
name="tagline"
|
||
label="一句话定位"
|
||
help="用一句话说明你为谁提供什么价值。"
|
||
rules={[{ required: true, message: "请输入一句话定位" }]}
|
||
>
|
||
<Input size="large" placeholder="例如:帮助独立创作者建立可信的个人品牌" />
|
||
</Form.Item>
|
||
<Form.Item name="description" label="品牌简介" help="介绍背景、方法和合作风格。">
|
||
<Input.TextArea
|
||
rows={5}
|
||
showCount
|
||
maxLength={500}
|
||
placeholder="让第一次认识你的人快速建立基本信任。"
|
||
/>
|
||
</Form.Item>
|
||
</Card>
|
||
<Card title="如何联系与合作" style={{ marginTop: 24 }}>
|
||
<Row gutter={16}>
|
||
<Col xs={24} md={12}>
|
||
<Form.Item name="hours" label="可联系时间">
|
||
<Input placeholder="例如:工作日 10:00–18:00" />
|
||
</Form.Item>
|
||
</Col>
|
||
<Col xs={24} md={12}>
|
||
<Form.Item name="address" label="所在位置">
|
||
<Input placeholder="城市或服务范围" />
|
||
</Form.Item>
|
||
</Col>
|
||
<Col xs={24} md={12}>
|
||
<Form.Item name="contactPhone" label="联系电话">
|
||
<Input />
|
||
</Form.Item>
|
||
</Col>
|
||
<Col xs={24} md={12}>
|
||
<Form.Item name="contactWechat" label="微信号">
|
||
<Input />
|
||
</Form.Item>
|
||
</Col>
|
||
</Row>
|
||
<Form.Item
|
||
name="deliveryNote"
|
||
label="合作预期"
|
||
help="说明响应时间、合作方式或重要边界。"
|
||
>
|
||
<Input.TextArea rows={3} placeholder="例如:收到咨询后 1 个工作日内回复。" />
|
||
</Form.Item>
|
||
</Card>
|
||
<Card title="模板与品牌视觉" style={{ marginTop: 24 }}>
|
||
<Form.Item
|
||
name="templateKey"
|
||
label="业务表达模板"
|
||
help="模板只改变业务表达,不改变个人品牌主线。"
|
||
>
|
||
<Select
|
||
disabled
|
||
options={[
|
||
{ value: "personal", label: "个人品牌" },
|
||
{ value: "food", label: "餐饮模板" },
|
||
]}
|
||
/>
|
||
</Form.Item>
|
||
<Row gutter={16}>
|
||
<Col xs={24} md={12}>
|
||
<Form.Item
|
||
name="avatarUrl"
|
||
label="头像图片地址"
|
||
help="粘贴一张可公开访问的图片地址。"
|
||
>
|
||
<ImageUrlField />
|
||
</Form.Item>
|
||
</Col>
|
||
<Col xs={24} md={12}>
|
||
<Form.Item name="coverUrl" label="品牌封面图片地址" help="建议使用横向图片。">
|
||
<ImageUrlField />
|
||
</Form.Item>
|
||
</Col>
|
||
</Row>
|
||
</Card>
|
||
<Space direction="vertical" style={{ width: "100%", marginTop: 24 }}>
|
||
<MutationError error={save.error} />
|
||
<Button type="primary" htmlType="submit" loading={save.isPending} size="large">
|
||
保存品牌表达
|
||
</Button>
|
||
</Space>
|
||
</Form>
|
||
<PresentationEditor
|
||
templateContent={workspace.data?.templateContent}
|
||
previewWorkspace={previewWorkspace.data}
|
||
config={brand.data.config}
|
||
brand={brand.data}
|
||
loading={workspace.isLoading}
|
||
error={workspace.error}
|
||
/>
|
||
</Col>
|
||
<Col xs={24} xl={8}>
|
||
{template.data && (
|
||
<Card title="模板说明" style={{ marginTop: 24 }}>
|
||
<Typography.Paragraph>{template.data.description}</Typography.Paragraph>
|
||
<Typography.Text type="secondary">
|
||
服务分类:{template.data.serviceCategories.join("、")}
|
||
</Typography.Text>
|
||
</Card>
|
||
)}
|
||
</Col>
|
||
</Row>
|
||
</>
|
||
)}
|
||
</QueryState>
|
||
);
|
||
}
|