'use client';
import { UserDetail } from '@/app/dashboard/user/user-detail';
import { IpLink } from '@/components/ip-link';
import { ProTable } from '@/components/pro-table';
import { getUserSubscribeById } from '@/services/admin/user';
import { formatDate } from '@/utils/common';
import { useQuery } from '@tanstack/react-query';
import { Badge } from '@workspace/ui/components/badge';
import {
Sheet,
SheetContent,
SheetHeader,
SheetTitle,
SheetTrigger,
} from '@workspace/ui/components/sheet';
import { formatBytes } from '@workspace/ui/utils';
import { Users } from 'lucide-react';
import { useTranslations } from 'next-intl';
import { useState } from 'react';
function UserSubscribeInfo({
subscribeId,
open,
type,
}: {
subscribeId: number;
open: boolean;
type: 'account' | 'subscribeName' | 'subscribeId' | 'trafficUsage' | 'expireTime';
}) {
const t = useTranslations('servers');
const { data } = useQuery({
enabled: subscribeId !== 0 && open,
queryKey: ['getUserSubscribeById', subscribeId],
queryFn: async () => {
const { data } = await getUserSubscribeById({ id: subscribeId });
return data.data;
},
});
if (!data) return --;
switch (type) {
case 'account':
if (!data.user_id) return --;
return ;
case 'subscribeName':
if (!data.subscribe?.name) return --;
return {data.subscribe.name};
case 'subscribeId':
if (!data.id) return --;
return {data.id};
case 'trafficUsage': {
const usedTraffic = data.upload + data.download;
const totalTraffic = data.traffic || 0;
return (
{formatBytes(usedTraffic)} / {totalTraffic > 0 ? formatBytes(totalTraffic) : '无限制'}
);
}
case 'expireTime': {
if (!data.expire_time) return --;
const isExpired = data.expire_time < Date.now() / 1000;
return (
{formatDate(data.expire_time)}
{isExpired && (
{t('expired')}
)}
);
}
default:
return --;
}
}
export default function OnlineUsersCell({ status }: { status?: API.ServerStatus }) {
const t = useTranslations('servers');
const [open, setOpen] = useState(false);
return (
{t('onlineUsers')}
>
header={{ hidden: true }}
columns={[
{
accessorKey: 'ip',
header: t('ipAddresses'),
cell: ({ row }) => {
const ips = row.original.ip;
return (
{ips.map((item, i) => (
{item.protocol}
))}
);
},
},
{
accessorKey: 'user',
header: t('user'),
cell: ({ row }) => (
),
},
{
accessorKey: 'subscription',
header: t('subscription'),
cell: ({ row }) => (
),
},
{
accessorKey: 'subscribeId',
header: t('subscribeId'),
cell: ({ row }) => (
),
},
{
accessorKey: 'traffic',
header: t('traffic'),
cell: ({ row }) => (
),
},
{
accessorKey: 'expireTime',
header: t('expireTime'),
cell: ({ row }) => (
),
},
]}
request={async () => ({
list: status?.online || [],
total: status?.online?.length || 0,
})}
/>
);
}