import React from 'react'; import { AlertDialog, AlertDialogBody, AlertDialogContent, AlertDialogFooter, AlertDialogHeader, AlertDialogOverlay, Button } from '@chakra-ui/react'; import { useForm } from 'react-hook-form'; import { ApiError } from '../../client'; import useAuth from '../../hooks/useAuth'; import useCustomToast from '../../hooks/useCustomToast'; import { useUserStore } from '../../store/user-store'; interface DeleteProps { isOpen: boolean; onClose: () => void; } const DeleteConfirmation: React.FC = ({ isOpen, onClose }) => { const showToast = useCustomToast(); const cancelRef = React.useRef(null); const { handleSubmit, formState: { isSubmitting } } = useForm(); const { user, deleteUser } = useUserStore(); const { logout } = useAuth(); const onSubmit = async () => { try { await deleteUser(user!.id); logout(); onClose(); showToast('Success', 'Your account has been successfully deleted.', 'success'); } catch (err) { const errDetail = (err as ApiError).body.detail; showToast('Something went wrong.', `${errDetail}`, 'error'); } } return ( <> Confirmation Required All your account data will be permanently deleted. If you are sure, please click 'Confirm' to proceed. ) } export default DeleteConfirmation;