import React, { useEffect, useState } from 'react'; import { useParams, useNavigate } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { useForm, Controller } from 'react-hook-form'; import dayjs from 'dayjs'; import { ArrowLeft, Pencil } from 'lucide-react'; import { useAdmin, useUpdateAdmin } from '@/hooks/useAdmins'; import { formatDisplayValue } from '@/lib/utils'; import { PageHeader } from '@/components/PageHeader'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Card, CardContent } from '@/components/ui/card'; import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@/components/ui/select'; import { Skeleton } from '@/components/ui/skeleton'; const isBadValue = (val: unknown) => val === '-' || val === 'undefined' || val === '' || val === null || val === undefined; const clean = (val: unknown) => (val === '-' || val === 'undefined' ? undefined : val); const roleBadgeVariant = (role: string) => { if (role === 'superadmin') return 'destructive' as const; if (role === 'admin') return 'default' as const; if (role === 'moderator') return 'secondary' as const; return 'outline' as const; }; interface AdminFormValues { nickname?: string; email?: string; role?: string; status?: string; timezone?: string; language?: string; phone?: string; } 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 AdminDetailPage: React.FC = () => {
const { t } = useTranslation();
const { id } = useParams<{ id: string }>();
const navigate = useNavigate();
const { data: admin, isLoading } = useAdmin(id || '');
const updateAdmin = useUpdateAdmin();
const [editModal, setEditModal] = useState(false);
const form = useForm{t('admins.notFound')}
; const titleName = !isBadValue(admin.nickname) ? admin.nickname : admin.email || admin.id; return (