import React, { useState } from "react" import { useTranslation } from "react-i18next" import useNotification from "../../hooks/use-notification" import { getErrorMessage } from "../../utils/error-messages" import Button from "../fundamentals/button" import Modal from "../molecules/modal" type DeletePromptProps = { heading?: string text?: string successText?: string | false cancelText?: string confirmText?: string handleClose: () => void onDelete: () => Promise } const DeletePrompt: React.FC = ({ heading, text = "", successText, cancelText, confirmText, handleClose, onDelete, }) => { const { t } = useTranslation() const notification = useNotification() const [isLoading, setIsLoading] = useState(false) const handleSubmit = (e) => { e.preventDefault() setIsLoading(true) onDelete() .then(() => { if (successText) { notification( t("organisms-success", "Success"), successText || t("organisms-delete-successful", "Delete successful"), "success" ) } }) .catch((err) => notification("Error", getErrorMessage(err), "error")) .finally(() => { setIsLoading(false) handleClose() }) } return (
{heading || t( "organisms-are-you-sure-you-want-to-delete", "Are you sure you want to delete?" )} {text}
) } export default DeletePrompt