Files
persionalBrand/apps/admin/src/features/brands/BrandsPage.tsx
T
que01 06619a191f
CI / Static checks (push) Has been cancelled
CI / Production build (push) Has been cancelled
CI / API integration (push) Has been cancelled
CI / Taro builds (acheng-campus-food) (push) Has been cancelled
CI / Taro builds (atelier-solopreneur) (push) Has been cancelled
CI / Taro builds (linjing-editorial) (push) Has been cancelled
CI / Browser regression (push) Has been cancelled
refactor: 提示与确认框改用 App 上下文实例
2026-10-21 10:34:34 +08:00

130 lines
4.6 KiB
TypeScript

import { Alert, App, Button, Card, Col, Row, Space } from "antd";
import { PlusOutlined } from "@ant-design/icons";
import { useQuery } from "@tanstack/react-query";
import { useNavigate } from "react-router-dom";
import { createApiClient } from "../../lib/api.js";
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
import { EmptyState } from "../../components/EmptyState.js";
import { QueryState } from "../../components/QueryState.js";
import { StatusTag } from "../../components/StatusTag.js";
const client = createApiClient();
export function BrandsPage({ canCreate }: { canCreate: boolean }) {
const { message } = App.useApp();
const navigate = useNavigate();
const brands = useQuery({
queryKey: ["admin-brand-memberships"],
queryFn: () => client.listAdminBrands(),
});
const current = useQuery({
queryKey: ["admin-shell-brand"],
queryFn: () => client.getAdminBrand(),
});
const switchBrand = async (brandId: string) => {
try {
await client.switchAdminBrand(brandId);
window.location.assign("/admin/overview");
} catch (error) {
message.error(error instanceof Error ? error.message : "品牌切换失败,请重试");
}
};
return (
<QueryState
loading={brands.isLoading || current.isLoading}
error={brands.error || current.error}
onRetry={() => {
void brands.refetch();
void current.refetch();
}}
>
<AdminPageHeader
title="品牌管理"
description="每个品牌拥有独立的业务类型、页面方案、内容与发布记录。"
extra={
canCreate ? (
<Button
type="primary"
icon={<PlusOutlined />}
onClick={() => navigate("/admin/brands/new")}
>
创建品牌
</Button>
) : null
}
/>
<Alert
className="admin-offset-bottom"
type="info"
showIcon
title="切换品牌会进入对应品牌的工作区"
description="品牌之间的业务内容、成员、发布记录和页面方案相互隔离。"
/>
{brands.data?.length ? (
<Row gutter={[16, 16]} className="admin-equal-height">
{brands.data.map((membership) => {
const isCurrent = membership.brand.id === current.data?.id;
return (
<Col key={membership.brand.id} xs={24} lg={12}>
<Card
title={membership.brand.name}
extra={
<StatusTag
tone={isCurrent ? "success" : "neutral"}
label={
isCurrent ? "当前品牌" : membership.role === "owner" ? "负责人" : "编辑"
}
/>
}
actions={[
<Button
key="switch"
type={isCurrent ? "default" : "primary"}
disabled={isCurrent}
onClick={() => void switchBrand(membership.brand.id)}
>
{isCurrent ? "正在使用" : "进入此品牌"}
</Button>,
]}
>
<Space orientation="vertical" size={8}>
<span className="admin-section-description">
小程序地址标识:{membership.brand.slug}
</span>
{membership.role === "owner" ? (
<span className="admin-section-description">
你可以在该品牌中管理页面方案、成员和发布。
</span>
) : (
<span className="admin-section-description">
你在该品牌中的角色是内容编辑,不能管理页面方案或成员。
</span>
)}
</Space>
</Card>
</Col>
);
})}
</Row>
) : (
<Card>
<EmptyState
title="还没有可管理的品牌"
description={
canCreate ? "创建第一个品牌后即可开始配置内容。" : "请联系品牌负责人邀请你加入。"
}
action={
canCreate ? (
<Button type="primary" onClick={() => navigate("/admin/brands/new")}>
创建品牌
</Button>
) : undefined
}
/>
</Card>
)}
</QueryState>
);
}