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

{t("delete_link")}

{t("link_deletion_confirmation_message")}

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

{t("shift_key_tip")}

); }