el.xwx.moe/components/ModalContent/DeleteLinkModal.tsx

64 lines
1.7 KiB
TypeScript
Raw Normal View History

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";
import Button from "../ui/Button";
2024-06-09 08:27:16 -05:00
import { useTranslation } from "next-i18next";
import { useDeleteLink } from "@/hooks/store/links";
type Props = {
onClose: Function;
activeLink: LinkIncludingShortenedCollectionAndTags;
};
export default function DeleteLinkModal({ onClose, activeLink }: Props) {
2024-06-09 08:27:16 -05:00
const { t } = useTranslation();
const [link, setLink] =
useState<LinkIncludingShortenedCollectionAndTags>(activeLink);
const deleteLink = useDeleteLink();
2023-12-06 23:33:05 -06:00
const router = useRouter();
useEffect(() => {
setLink(activeLink);
}, []);
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
onClose();
},
});
};
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-05 14:17:36 -06:00
<div className="divider mb-3 mt-1"></div>
<div className="flex flex-col gap-3">
2024-06-09 08:27:16 -05:00
<p>{t("link_deletion_confirmation_message")}</p>
<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>
</div>
2024-06-09 08:27:16 -05:00
<p>{t("shift_key_tip")}</p>
<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")}
</Button>
</div>
</Modal>
);
}