"use client"; import React from 'react'; import { get } from '@/api/request'; import { DashboardLayout } from "@/components/layout/dashboard-layout"; /** * Share (Invite) Page - Static UI with mocked data. * Sections: Invite Flow, My Invitation Code, Invite Records (with pagination) */ /** * 邀请记录项 */ type InviteRecord = { user_email: string; user_id: string; user_name: string; reg_time: number; purchase_status: number; reward_status: number; invite_reward: number; pay_reward: number; }; /** * 分页信息 */ type PaginationInfo = { page: number; page_size: number; total: number; total_pages: number; has_next: boolean; has_prev: boolean; }; /** * 邀请记录API响应 */ type InviteRecordsResponse = { successful: boolean; code: number; message: string; data: { invited_list: InviteRecord[]; pagination: PaginationInfo; }; }; const PAGE_SIZE = 10; /** * Format epoch ms using browser preferred language. * @param {number} epochMs - timestamp in milliseconds * @returns {string} - localized date time string */ function formatLocalTime(epochMs: number): string { try { const locale = typeof navigator !== 'undefined' ? navigator.language : 'en-US'; const dtf = new Intl.DateTimeFormat(locale, { dateStyle: 'medium', timeStyle: 'medium', }); return dtf.format(new Date(epochMs)); } catch { return new Date(epochMs).toLocaleString(); } } /** * 从后端获取邀请记录 * @returns {Promise} */ async function fetchInviteRecords(): Promise { const res = await get('/api/user_fission/query_invite_record'); return res; } export default function SharePage(): JSX.Element { // Mocked data (to be replaced by real API integration later) const [inviteCode, setInviteCode] = React.useState(''); const [invitedCount, setInvitedCount] = React.useState(0); const [totalInviteCredits, setTotalInviteCredits] = React.useState(0); const [copyState, setCopyState] = React.useState<'idle' | 'copied' | 'error'>('idle'); const [records, setRecords] = React.useState([]); const [pagination, setPagination] = React.useState({ page: 1, page_size: 20, total: 0, total_pages: 1, has_next: false, has_prev: false }); const [pageIndex, setPageIndex] = React.useState(0); const [expandedRowIds, setExpandedRowIds] = React.useState>(() => new Set()); React.useEffect(() => { let mounted = true; (async () => { try { const response = await fetchInviteRecords(); if (mounted && response.successful) { setRecords(response.data.invited_list); setPagination(response.data.pagination); } } catch { // 保持静默失败,页面仍可用 } // 获取邀请统计信息 try { const res = await get('/api/user_fission/my_invite_stats'); const stats = res?.data ?? {}; if (mounted) { if (typeof stats.total_invited === 'number') { setInvitedCount(stats.total_invited); } if (typeof stats.total_invite_credits === 'number') { setTotalInviteCredits(stats.total_invite_credits); } } } catch { // 保持静默失败 } try { const res = await get('/api/user_fission/my_invite_code'); const code = res?.data?.invite_code ?? res?.data?.inviteCode ?? ''; if (mounted && typeof code === 'string') setInviteCode(code); } catch { // 保持静默失败 } })(); return () => { mounted = false; }; }, []); const totalPages = pagination.total_pages; const pagedRecords = records; // 后端已经分页,直接使用records const handleCopy = React.useCallback(async () => { try { await navigator.clipboard.writeText(location.origin + '/signup?inviteCode=' + inviteCode); setCopyState('copied'); window.setTimeout(() => setCopyState('idle'), 1600); } catch { setCopyState('error'); window.setTimeout(() => setCopyState('idle'), 1600); } }, [inviteCode]); const toggleRow = React.useCallback((id: string) => { setExpandedRowIds((prev) => { const next = new Set(prev); if (next.has(id)) { next.delete(id); } else { next.add(id); } return next; }); }, []); return (

Invite Friends

Invite friends to join and earn rewards.

{/* Section 1: Invite Flow */}

Invitation Flow

  1. Step 1 Share

    Copy your invitation code and share it with friends.

  2. Step 2 Register

    Friends register and enter your invitation code.

  3. Step 3 Reward

    You both receive rewards after successful registration.

{/* Section 2: My Invitation Code */}

My Invitation Code

{inviteCode}

Share this code. Your friends can enter it during registration.

Total Credits {totalInviteCredits} All credits earned from invitations.
Invited Friends {invitedCount} Points detail will be available soon.
{/* Section 3: Invite Records */}

Invite Records

{pagination.page} / {pagination.total_pages}
{pagedRecords.map((r) => { const isExpanded = expandedRowIds.has(r.user_id); return ( {isExpanded && ( )} ); })}
Invited Username Registered At Reward
{r.user_name} {formatLocalTime(r.reg_time * 1000)}
{r.invite_reward + r.pay_reward}
{r.invite_reward} Register
{r.pay_reward} First Payment
); }