import React, { useEffect, useState } from "react"; import { LinkIncludingShortenedCollectionAndTags } from "@/types/global"; import Modal from "../Modal"; import { useRouter } from "next/router"; import Button from "../ui/Button"; import { useTranslation } from "next-i18next"; import { useDeleteLink } from "@/hooks/store/links"; import toast from "react-hot-toast"; type Props = { onClose: Function; activeLink: LinkIncludingShortenedCollectionAndTags; }; export default function DeleteLinkModal({ onClose, activeLink }: Props) { const { t } = useTranslation(); const [link, setLink] = useState(activeLink); const deleteLink = useDeleteLink(); const router = useRouter(); useEffect(() => { setLink(activeLink); }, []); const submit = async () => { const load = toast.loading(t("deleting")); await deleteLink.mutateAsync(link.id as number, { onSettled: (data, error) => { toast.dismiss(load); if (error) { toast.error(error.message); } else { if (router.pathname.startsWith("/links/[id]")) { router.push("/dashboard"); } onClose(); toast.success(t("deleted")); } }, }); }; return (

{t("delete_link")}

{t("link_deletion_confirmation_message")}

{t("warning")}: {t("irreversible_warning")}

{t("shift_key_tip")}

); }