'use client'; import React, { useState } from 'react'; import { api } from '@/lib/api-client'; import { useAuth } from '@/context/auth-context'; import { UserRole } from '@fileshare/shared'; import { X, Trash2, AlertTriangle, Loader2, Building2, HardDrive, FileText } from 'lucide-react'; import { formatBytes } from '@/lib/utils'; interface DeleteUserModalProps { isOpen: boolean; onClose: () => void; onSuccess: () => void; user: any | null; } export const DeleteUserModal: React.FC = ({ isOpen, onClose, onSuccess, user, }) => { const { user: currentUser } = useAuth(); const [isDeleting, setIsDeleting] = useState(false); const [error, setError] = useState(null); if (!isOpen || !user) return null; const isSuperAdmin = currentUser?.role === UserRole.SUPER_ADMIN; const isSelf = currentUser?.id === user.id; const isOtherCompany = !isSuperAdmin && (user.companyName || 'Ecohub').trim().toLowerCase() !== (currentUser?.companyName || 'Ecohub').trim().toLowerCase(); const handleDelete = async () => { if (isSelf || isOtherCompany) return; setError(null); setIsDeleting(true); try { await api.deleteUser(user.id); onSuccess(); onClose(); } catch (err: any) { setError(err.message || 'Failed to delete user'); } finally { setIsDeleting(false); } }; return (
{/* Header */}

Delete User Account

Permanent System & Storage Cleanup

{/* Content */}
{error && (
{error}
)} {/* User Info Card */}
{user.fullName} {user.role}
@{user.username} • {user.email}
{user.companyName || 'Ecohub'}
{user.fileCount || 0} Files
Storage: {formatBytes(Number(user.storageUsedBytes || 0))} used
{/* Warning Banner */}
Are you absolutely sure?

This action cannot be undone. Deleting this account will permanently erase the user profile, all their personal folders, and purge all their uploaded physical files from storage.

{isSelf && (
You are currently logged into this account. You cannot delete yourself.
)} {isOtherCompany && (
Admins cannot delete users belonging to other companies ({user.companyName || 'Other Company'}). Only Super Admin has permission to delete external company accounts.
)} {/* Actions */}
); };