import React, { useState } from "react"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faRightFromBracket, faTrashCan, } from "@fortawesome/free-solid-svg-icons"; import { CollectionIncludingMembersAndLinkCount } from "@/types/global"; import useCollectionStore from "@/store/collections"; import { useRouter } from "next/router"; import usePermissions from "@/hooks/usePermissions"; import { toast } from "react-hot-toast"; type Props = { toggleDeleteCollectionModal: Function; collection: CollectionIncludingMembersAndLinkCount; }; export default function DeleteCollection({ toggleDeleteCollectionModal, collection, }: Props) { const [inputField, setInputField] = useState(""); const { removeCollection } = useCollectionStore(); const router = useRouter(); const submit = async () => { if (permissions === true) if (collection.name !== inputField) return null; const load = toast.loading("Deleting..."); const response = await removeCollection(collection.id as number); toast.dismiss(load); if (response.ok) { toast.success("Collection Deleted."); toggleDeleteCollectionModal(); router.push("/collections"); } }; const permissions = usePermissions(collection.id as number); return (
{permissions === true ? ( <>

Warning!

Please note that deleting the collection will permanently remove all its contents, including the following:

  • Links: All links within the collection will be permanently deleted.
  • Tags: All tags associated with the collection will be removed.
  • Screenshots/PDFs: Any screenshots or PDFs attached to links within this collection will be permanently deleted.
  • Members: Any members who have been granted access to the collection will lose their permissions and no longer be able to view or interact with the content.
  • Please double-check that you have backed up any essential data and have informed the relevant members about this action.

    To confirm, type " {collection.name} " in the box below:

    setInputField(e.target.value)} type="text" placeholder={`Type "${collection.name}" Here.`} className="w-72 sm:w-96 rounded-md p-3 mx-auto border-sky-100 border-solid border outline-none focus:border-sky-700 duration-100" />
    ) : (

    Click the button below to leave the current collection:

    )}
    {permissions === true ? "Delete" : "Leave"} Collection
    ); }