2023-12-02 03:42:51 -06:00
|
|
|
import React, { useEffect, useState } from "react";
|
|
|
|
import { LinkIncludingShortenedCollectionAndTags } from "@/types/global";
|
|
|
|
import Modal from "../Modal";
|
2023-12-06 23:33:05 -06:00
|
|
|
import { useRouter } from "next/router";
|
2024-05-24 16:12:47 -05:00
|
|
|
import Button from "../ui/Button";
|
2024-06-09 08:27:16 -05:00
|
|
|
import { useTranslation } from "next-i18next";
|
2024-08-12 23:08:57 -05:00
|
|
|
import { useDeleteLink } from "@/hooks/store/links";
|
2023-12-02 03:42:51 -06:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
onClose: Function;
|
|
|
|
activeLink: LinkIncludingShortenedCollectionAndTags;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default function DeleteLinkModal({ onClose, activeLink }: Props) {
|
2024-06-09 08:27:16 -05:00
|
|
|
const { t } = useTranslation();
|
2023-12-02 03:42:51 -06:00
|
|
|
const [link, setLink] =
|
|
|
|
useState<LinkIncludingShortenedCollectionAndTags>(activeLink);
|
2024-08-12 23:08:57 -05:00
|
|
|
|
|
|
|
const deleteLink = useDeleteLink();
|
2023-12-06 23:33:05 -06:00
|
|
|
const router = useRouter();
|
|
|
|
|
2023-12-02 03:42:51 -06:00
|
|
|
useEffect(() => {
|
|
|
|
setLink(activeLink);
|
|
|
|
}, []);
|
|
|
|
|
2024-08-12 23:08:57 -05:00
|
|
|
const submit = async () => {
|
|
|
|
await deleteLink.mutateAsync(link.id as number, {
|
|
|
|
onSuccess: () => {
|
|
|
|
if (router.pathname.startsWith("/links/[id]")) {
|
|
|
|
router.push("/dashboard");
|
|
|
|
}
|
2023-12-06 23:33:05 -06:00
|
|
|
|
2024-08-12 23:08:57 -05:00
|
|
|
onClose();
|
|
|
|
},
|
|
|
|
});
|
2023-12-02 03:42:51 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Modal toggleModal={onClose}>
|
2024-06-09 08:27:16 -05:00
|
|
|
<p className="text-xl font-thin text-red-500">{t("delete_link")}</p>
|
2023-12-03 22:52:32 -06:00
|
|
|
|
2023-12-05 14:17:36 -06:00
|
|
|
<div className="divider mb-3 mt-1"></div>
|
2023-12-03 22:52:32 -06:00
|
|
|
|
2023-12-02 03:42:51 -06:00
|
|
|
<div className="flex flex-col gap-3">
|
2024-06-09 08:27:16 -05:00
|
|
|
<p>{t("link_deletion_confirmation_message")}</p>
|
2023-12-02 03:42:51 -06:00
|
|
|
|
|
|
|
<div role="alert" className="alert alert-warning">
|
2023-12-29 11:21:22 -06:00
|
|
|
<i className="bi-exclamation-triangle text-xl" />
|
2023-12-13 05:59:36 -06:00
|
|
|
<span>
|
2024-06-09 08:27:16 -05:00
|
|
|
<b>{t("warning")}:</b> {t("irreversible_warning")}
|
2023-12-13 05:59:36 -06:00
|
|
|
</span>
|
2023-12-02 03:42:51 -06:00
|
|
|
</div>
|
|
|
|
|
2024-06-09 08:27:16 -05:00
|
|
|
<p>{t("shift_key_tip")}</p>
|
2023-12-02 03:42:51 -06:00
|
|
|
|
2024-08-12 23:08:57 -05:00
|
|
|
<Button className="ml-auto" intent="destructive" onClick={submit}>
|
2023-12-29 11:21:22 -06:00
|
|
|
<i className="bi-trash text-xl" />
|
2024-06-09 08:27:16 -05:00
|
|
|
{t("delete")}
|
2024-05-24 16:12:47 -05:00
|
|
|
</Button>
|
2023-12-02 03:42:51 -06:00
|
|
|
</div>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|