import { useEffect, useState } from 'react'; import { Link, Outlet, useLocation, useNavigate, useParams } from 'react-router-dom'; import { Breadcrumb, Button, Space, Spin, Tabs, Tag, Typography } from 'antd'; import { ArrowLeftOutlined } from '@ant-design/icons'; import { PROMO_CODE_STATUS_LABELS, type PromoCodeItem, type PromoCodeStats, } from '@dukang/shared-types'; import { request } from '../../lib/api'; export type PromoCodeDetailContext = { detail: PromoCodeItem & { stats?: PromoCodeStats }; reload: () => Promise; }; export default function PromoCodeDetailLayout() { const { id = '' } = useParams(); const navigate = useNavigate(); const location = useLocation(); const [detail, setDetail] = useState<(PromoCodeItem & { stats?: PromoCodeStats }) | null>(null); const [loading, setLoading] = useState(true); async function loadDetail() { setLoading(true); try { const res = await request(`/admin/promo-codes/${id}`); setDetail(res); } catch { setDetail(null); } finally { setLoading(false); } } useEffect(() => { void loadDetail(); }, [id]); const tabKey = location.pathname.endsWith('/users') ? 'users' : 'overview'; if (loading) { return ; } if (!detail) { return (
推广码不存在或加载失败
); } return (
推广码管理 }, { title: detail.name }, ]} />
{ if (key === 'users') navigate(`/promo-codes/${id}/users`); else navigate(`/promo-codes/${id}`); }} items={[ { key: 'overview', label: '概览' }, { key: 'users', label: `关联用户${detail.stats?.sourceMarkedCount != null ? ` (${detail.stats.sourceMarkedCount})` : ''}`, }, ]} style={{ marginBottom: 16 }} />
); }