import { Copy } from 'lucide-react'; import type { ReactNode } from 'react'; import communityQqQrImage from '../../../media/social-media-group/qq.png'; import communityWechatQrImage from '../../../media/social-media-group/wechat.png'; import type { ProfileReferralInviteCenterResponse } from '../../../packages/shared/src/contracts/runtime'; import { PlatformAsyncStatePanel } from '../common/PlatformAsyncStatePanel'; import { CopyFeedbackButton } from '../common/CopyFeedbackButton'; import { PlatformActionButton } from '../common/PlatformActionButton'; import { PlatformEmptyState } from '../common/PlatformEmptyState'; import { PlatformFieldLabel } from '../common/PlatformFieldLabel'; import { PlatformProfileContentRow } from '../common/PlatformProfileContentRow'; import { PlatformProfileSkeletonList } from '../common/PlatformProfileSkeletonList'; import { PlatformStatusMessage } from '../common/PlatformStatusMessage'; import { PlatformSubpanel } from '../common/PlatformSubpanel'; import { PlatformTextField } from '../common/PlatformTextField'; import type { CopyFeedbackState } from '../common/useCopyFeedback'; import { PlatformProfileSecondaryModalShell } from './PlatformProfileModalShell'; import type { ProfileReferralPanel } from './usePlatformProfileCenterController'; type PlatformProfileReferralModalProps = { panel: ProfileReferralPanel; center: ProfileReferralInviteCenterResponse | null; isLoading: boolean; isSubmittingRedeem: boolean; redeemCode: string; copyInviteState: CopyFeedbackState; error: string | null; success: string | null; onClose: () => void; onCopyInvite: () => void; onRedeemCodeChange: (value: string) => void; onSubmitRedeemCode: () => void; }; const COMMUNITY_QR_CODES = [ { label: '微信群', src: communityWechatQrImage, alt: '玩家社区微信群二维码', }, { label: 'QQ群', src: communityQqQrImage, alt: '玩家社区 QQ 群二维码', }, ] as const; function ProfileReferralUserAvatar({ name, avatarUrl, }: { name: string; avatarUrl: string | null; }) { const avatarLabel = (name.trim() || '玩').slice(0, 1).toUpperCase(); return ( {avatarUrl ? ( ) : ( avatarLabel )} ); } function resolvePanelTitle(panel: ProfileReferralPanel) { if (panel === 'invite') { return '邀请好友'; } if (panel === 'redeem') { return '填邀请码'; } return '玩家社区'; } /** * 个人中心邀请能力统一弹层。 * 承接邀请码、填码和社区二维码三种 profile panel,避免首页继续内联重复白底浮层实现。 */ export function PlatformProfileReferralModal({ panel, center, isLoading, isSubmittingRedeem, redeemCode, copyInviteState, error, success, onClose, onCopyInvite, onRedeemCodeChange, onSubmitRedeemCode, }: PlatformProfileReferralModalProps) { const title = resolvePanelTitle(panel); const normalizedRedeemCode = redeemCode .trim() .replace(/[^0-9a-z]/gi, '') .toUpperCase(); let content: ReactNode; if (panel === 'community') { content = (
{COMMUNITY_QR_CODES.map((qrCode) => (
{qrCode.alt}
{qrCode.label}
))}
); } else if (panel === 'redeem') { content = ( } isEmpty={Boolean(center?.hasRedeemedCode)} emptyState={ 已填写邀请码 } >
{ event.preventDefault(); onSubmitRedeemCode(); }} > onRedeemCodeChange(event.target.value)} size="lg" density="roomy" tone="rose" className="rounded-xl text-center font-black uppercase tracking-[0.16em]" placeholder="邀请码" aria-label="邀请码" autoComplete="off" autoFocus /> {isSubmittingRedeem ? '提交中' : '提交'}
); } else { content = ( } >
邀请码
{center?.inviteCode ?? '--------'}
{`邀请一个用户注册,双方都可以获得${center?.rewardPoints ?? 30}泥点。`}
每日最多获得十次邀请奖励。
} actionSurface="profile" actionSize="md" actionFullWidth className="gap-2 rounded-xl" /> 成功邀请 {center?.invitedUsers?.length ? (
{center.invitedUsers.map((user) => (
{user.displayName || '玩家'}
))}
) : ( 暂无成功邀请 )}
); } return (
{title}
{content} {error ? ( {error} ) : null} {success ? ( {success} ) : null}
); }