import React, { useEffect, useState } from 'react'; import { useParams, useNavigate } from 'react-router-dom'; import api from '../../utils/api'; import { Card } from '../../components/ui/card'; import { Button } from '../../components/ui/button'; import { Badge } from '../../components/ui/badge'; import { ArrowLeft, Mail, Phone, MapPin, Calendar, Lock, AlertTriangle } from 'lucide-react'; import { toast } from 'sonner'; const AdminUserView = () => { const { userId } = useParams(); const navigate = useNavigate(); const [user, setUser] = useState(null); const [loading, setLoading] = useState(true); const [resetPasswordLoading, setResetPasswordLoading] = useState(false); const [resendVerificationLoading, setResendVerificationLoading] = useState(false); useEffect(() => { fetchUserProfile(); }, [userId]); const fetchUserProfile = async () => { try { const response = await api.get(`/admin/users/${userId}`); setUser(response.data); } catch (error) { toast.error('Failed to load user profile'); navigate('/admin/members'); } finally { setLoading(false); } }; const handleResetPassword = async () => { const confirmed = window.confirm( `Reset password for ${user.first_name} ${user.last_name}?\n\n` + `A temporary password will be emailed to ${user.email}.\n` + `They will be required to change it on next login.` ); if (!confirmed) return; setResetPasswordLoading(true); try { await api.put(`/admin/users/${userId}/reset-password`, { force_change: true }); toast.success(`Password reset email sent to ${user.email}`); } catch (error) { const errorMessage = error.response?.data?.detail || 'Failed to reset password'; toast.error(errorMessage); } finally { setResetPasswordLoading(false); } }; const handleResendVerification = async () => { const confirmed = window.confirm( `Resend verification email to ${user.email}?` ); if (!confirmed) return; setResendVerificationLoading(true); try { await api.post(`/admin/users/${userId}/resend-verification`); toast.success(`Verification email sent to ${user.email}`); // Refresh user data to get updated email_verified status if changed await fetchUserProfile(); } catch (error) { const errorMessage = error.response?.data?.detail || 'Failed to send verification email'; toast.error(errorMessage); } finally { setResendVerificationLoading(false); } }; if (loading) return
{user.address}
{new Date(user.date_of_birth).toLocaleDateString()}
{user.partner_first_name} {user.partner_last_name}
{user.referred_by_member_name}
Subscription details coming soon...