import { Alert, Button, Col, Form, Input, Row, Select, Segmented, Space, Tag, Typography, message, } from "antd"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { useState } from "react"; import { Link, useLocation } from "react-router-dom"; 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"; import type { PreviewSelection } from "./preview-selection.js"; import "./BrandPage.css"; import { useEditorDraft } from "./use-editor-draft.js"; export function BrandPage() { const location = useLocation(); const initialSelection = location.state as PreviewSelection | undefined; const [panel, setPanel] = useState("pages"); const [dirty, setDirty] = useState(false); useEditorDraft(dirty); const client = createApiClient(); const queryClient = useQueryClient(); const [form] = Form.useForm(); 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 templateCatalog = useQuery({ queryKey: ["template-catalog"], queryFn: () => client.listPublicTemplates(), }); const save = useMutation({ mutationFn: (values: Partial) => client.updateAdminBrand(values), onSuccess: () => { setDirty(false); message.success("品牌表达已保存"); void queryClient.invalidateQueries({ queryKey: ["admin-brand"] }); void queryClient.invalidateQueries({ queryKey: ["admin-preview-workspace"] }); }, }); return ( void brand.refetch()}> {!brand.data ? null : ( <> {template.data?.name ?? "当前模板"}} />
setPanel(String(value))} options={[ { value: "pages", label: "页面编辑" }, { value: "brand", label: "品牌资料" }, ]} /> {dirty ? "品牌资料有未保存修改" : "草稿工作区"} 检查与发布 →