import React from 'react'; import { useParams, useNavigate } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import dayjs from 'dayjs'; import { ArrowLeft } from 'lucide-react'; import { useUser } from '@/hooks/useUsers'; import { formatDisplayValue } from '@/lib/utils'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Card, CardContent } from '@/components/ui/card'; import { Skeleton } from '@/components/ui/skeleton'; import { PageHeader } from '@/components/PageHeader'; const isBadValue = (val: unknown) => val === '-' || val === 'undefined' || val === '' || val === null || val === undefined; const roleBadgeVariant = (role: string) => { if (role === 'user') return 'default' as const; if (role === 'bot') return 'secondary' as const; return 'outline' as const; }; const statusBadgeVariant = (status: string) => { if (status === 'active') return 'default' as const; if (status === 'frozen') return 'warning' as const; return 'destructive' as const; }; const DetailValue: React.FC<{ value: unknown; emptyLabel: string }> = ({ value, emptyLabel }) => { const text = formatDisplayValue(value); if (text === '-') return <>{emptyLabel}>; if (typeof value === 'object' && value !== null && !Array.isArray(value)) { return
{text};
}
return <>{text}>;
};
const UserDetailPage: React.FC = () => {
const { t } = useTranslation();
const { id } = useParams<{ id: string }>();
const navigate = useNavigate();
const { data: user, isLoading } = useUser(id || '');
const formatDate = (dateStr: string) => {
if (isBadValue(dateStr)) return t('common.emDash');
const d = dayjs(dateStr);
return d.isValid() ? d.format('DD.MM.YYYY HH:mm') : dateStr;
};
if (isLoading) {
return (
{t('users.notFound')}
; const titleName = !isBadValue(user.nickname) ? user.nickname : user.email || user.id; const emDash = t('common.emDash'); return (