'use client';
import { Display } from '@/components/display';
import { getUserDetail, getUserSubscribeById } from '@/services/admin/user';
import { formatDate } from '@/utils/common';
import { useQuery } from '@tanstack/react-query';
import { Button } from '@workspace/ui/components/button';
import { HoverCard, HoverCardContent, HoverCardTrigger } from '@workspace/ui/components/hover-card';
import { formatBytes } from '@workspace/ui/utils';
import { useTranslations } from 'next-intl';
import Link from 'next/link';
export function UserSubscribeDetail({
id,
enabled,
hoverCard = false,
}: {
id: number;
enabled: boolean;
hoverCard?: boolean;
}) {
const t = useTranslations('user');
const { data } = useQuery({
enabled: id !== 0 && enabled,
queryKey: ['getUserSubscribeById', id],
queryFn: async () => {
const { data } = await getUserSubscribeById({ id });
return data.data;
},
});
if (!id) return '--';
const usedTraffic = data ? data.upload + data.download : 0;
const totalTraffic = data?.traffic || 0;
const subscribeContent = (
{t('subscriptionInfo')}
-
{t('subscriptionId')}
{data?.id || '--'}
-
{t('subscriptionName')}
{data?.subscribe?.name || '--'}
-
{t('token')}
{data?.token || '--'}
-
{t('trafficUsage')}
{data
? totalTraffic === 0
? `${formatBytes(usedTraffic)} / ${t('unlimited')}`
: `${formatBytes(usedTraffic)} / ${formatBytes(totalTraffic)}`
: '--'}
-
{t('startTime')}
{data?.start_time ? formatDate(data.start_time) : '--'}
-
{t('expireTime')}
{data?.expire_time ? formatDate(data.expire_time) : '--'}
{!hoverCard && (
{t('userInfo')}
{/* Removed link to legacy user detail page */}
-
{t('userId')}
{data?.user_id}
-
{t('balance')}
-
{t('giftAmount')}
-
{t('commission')}
-
{t('createdAt')}
{data?.user?.created_at && formatDate(data?.user?.created_at)}
)}
);
if (hoverCard) {
return (
{subscribeContent}
);
}
return subscribeContent;
}
export function UserDetail({ id }: { id: number }) {
const t = useTranslations('user');
const { data } = useQuery({
enabled: id !== 0,
queryKey: ['getUserDetail', id],
queryFn: async () => {
const { data } = await getUserDetail({ id });
return data.data;
},
});
if (!id) return '--';
const identifier =
data?.auth_methods.find((m) => m.auth_type === 'email')?.auth_identifier ||
data?.auth_methods[0]?.auth_identifier;
return (
-
ID
{data?.id}
-
{t('balance')}
-
{t('giftAmount')}
-
{t('commission')}
-
{t('createdAt')}
{data?.created_at && formatDate(data?.created_at)}
);
}