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

74 lines
2.0 KiB
TypeScript
Raw Normal View History

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";
2023-12-06 23:33:05 -06:00
import { useRouter } from "next/router";
type Props = {
onClose: Function;
activeLink: LinkIncludingShortenedCollectionAndTags;
};
export default function DeleteLinkModal({ onClose, activeLink }: Props) {
const [link, setLink] =
useState<LinkIncludingShortenedCollectionAndTags>(activeLink);
const { removeLink } = useLinkStore();
const [submitLoader, setSubmitLoader] = useState(false);
2023-12-06 23:33:05 -06:00
const router = useRouter();
useEffect(() => {
setLink(activeLink);
}, []);
const deleteLink = async () => {
const load = toast.loading("Deleting...");
const response = await removeLink(link.id as number);
toast.dismiss(load);
response.ok && toast.success(`Link Deleted.`);
2023-12-06 23:33:05 -06:00
if (router.pathname.startsWith("/links/[id]")) {
router.push("/dashboard");
}
onClose();
};
return (
<Modal toggleModal={onClose}>
<p className="text-xl font-thin text-red-500">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">
<p>Are you sure you want to delete this Link?</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>
<b>Warning:</b> This action is irreversible!
</span>
</div>
<p>
Hold the <kbd className="kbd kbd-sm">Shift</kbd> key while clicking
2023-12-08 10:01:47 -06:00
&apos;Delete&apos; to bypass this confirmation in the future.
</p>
<button
className={`ml-auto btn w-fit text-white flex items-center gap-2 duration-100 bg-red-500 hover:bg-red-400 hover:dark:bg-red-600 cursor-pointer`}
onClick={deleteLink}
>
2023-12-29 11:21:22 -06:00
<i className="bi-trash text-xl" />
Delete
</button>
</div>
</Modal>
);
}