'use client'; import { AffiliateDialog, AffiliateDialogRef, } from '@/components/affiliate/components/AffiliateDialog'; import { Display } from '@/components/display'; import { Empty } from '@/components/empty'; import SvgIcon from '@/components/SvgIcon'; import useGlobalStore from '@/config/use-global'; import { queryUserAffiliate, queryUserAffiliateList } from '@/services/user/user'; import { useQuery } from '@tanstack/react-query'; import { Button } from '@workspace/ui/components/button'; import { Card, CardContent } from '@workspace/ui/components/card'; import { Input } from '@workspace/ui/components/input'; import { formatDate } from '@workspace/ui/utils'; import { useTranslations } from 'next-intl'; import { useRef, useState } from 'react'; import { CopyToClipboard } from 'react-copy-to-clipboard'; import { toast } from 'sonner'; export default function Affiliate() { const t = useTranslations('affiliate'); const { user, common } = useGlobalStore(); const [sum, setSum] = useState(); const { data } = useQuery({ queryKey: ['queryUserAffiliate'], queryFn: async () => { const response = await queryUserAffiliate(); return response.data.data; }, }); const { data: inviteList = [] } = useQuery({ queryKey: ['queryUserAffiliateList'], queryFn: async () => { const response = await queryUserAffiliateList({ page: 1, size: 3, }); return response.data.data?.list || []; }, }); const dialogRef = useRef(null); return (
{t('totalCommission')}
{t('commissionInfo')}
{t('historicalRecommendedUsers')}

{t('totalCommission')}

{t('commissionInviteCode')} { if (result) { toast.success(t('copySuccess')); } }} >

{user?.refer_code} { if (result) { toast.success(t('copySuccess')); } }} >

{t('inviteRecords')}

dialogRef.current?.open()} > {t('more')}
{inviteList?.length ? (
{inviteList?.map((invite) => { return (
{t('userIdentifier')}
{invite.identifier}
{t('time')}
{formatDate(invite.registered_at)}
); })}
) : ( )}

{t('commissionCalculation')}

{t('commissionCalculationInfo')}
{(() => { // Pro plan: $60/month, $576/year const MONTHLY_PRICE = 60; const YEARLY_PRICE = 576; const [count, setCount] = useState(10); const clamp = (n: number) => Math.max(0, Math.min(10000, Math.floor(n))); const firstMonth = count * MONTHLY_PRICE * 0.5; // 50% const firstYear = count * YEARLY_PRICE * 0.3; // 30% const recurMonth = count * MONTHLY_PRICE * 0.2; // 20% const recurYear = count * YEARLY_PRICE * 0.2; // 20% return (
{/* Calculator panel container */}
{/* Left: row headers (Monthly Plan / Yearly Plan) */}
{t('monthlyPackage')}
{t('annualPackage')}
{/* Middle: First-time top-up users (double rounded corners + three rows) */}
{t('firstTimeTopUpUser')}
50%
up to{' '}
30%
up to{' '}
{/* Blue shadow block */}
{/* Right: Repeat top-up users (gray card + three rows) */}
{t('repeatTopUpUser')}
20%
up to{' '} {' '} {t('perMonth')}
20%
up to{' '} {' '} {t('perYear')}
{/* User count adjustment */}
setCount(clamp(Number(e.target.value) || 0))} className='h-6 border-0 p-0 text-center text-sm focus-visible:ring-0 sm:h-8' style={{ width: `${Math.max(3, String(count).length + 1)}ch` }} /> {t('users')}
); })()}
); }