import { LockIcon, Trash } from 'lucide-react'; import React, { useState, useCallback } from 'react'; import { Label, Input, Button, Spinner, OGDialog, OGDialogContent, OGDialogTrigger, OGDialogHeader, OGDialogTitle, } from '@librechat/client'; import { useDeleteUserMutation } from '~/data-provider'; import { useAuthContext } from '~/hooks/AuthContext'; import { LocalizeFunction } from '~/common'; import { useLocalize } from '~/hooks'; import { cn } from '~/utils'; const DeleteAccount = ({ disabled = false }: { title?: string; disabled?: boolean }) => { const localize = useLocalize(); const { user, logout } = useAuthContext(); const { mutate: deleteUser, isLoading: isDeleting } = useDeleteUserMutation({ onMutate: () => logout(), }); const [isDialogOpen, setDialogOpen] = useState(false); const [isLocked, setIsLocked] = useState(true); const handleDeleteUser = () => { if (!isLocked) { deleteUser(undefined); } }; const handleInputChange = useCallback( (newEmailInput: string) => { const isEmailCorrect = newEmailInput.trim().toLowerCase() === user?.email.trim().toLowerCase(); setIsLocked(!isEmailCorrect); }, [user?.email], ); return ( <>
{localize('com_nav_delete_account_confirm')}
  • {localize('com_nav_delete_warning')}
  • {localize('com_nav_delete_data_info')}
{renderInput( localize('com_nav_delete_account_email_placeholder'), 'email-confirm-input', user?.email ?? '', (e) => handleInputChange(e.target.value), )}
{renderDeleteButton(handleDeleteUser, isDeleting, isLocked, localize)}
); }; const renderInput = ( label: string, id: string, value: string, onChange: (e: React.ChangeEvent) => void, ) => (
); const renderDeleteButton = ( handleDeleteUser: () => void, isDeleting: boolean, isLocked: boolean, localize: LocalizeFunction, ) => ( ); export default DeleteAccount;