import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faPen, faBoxesStacked, faTrashCan, } from "@fortawesome/free-solid-svg-icons"; import { useRouter } from "next/router"; import { useEffect, useState } from "react"; import useModalStore from "@/store/modals"; import useLinkStore from "@/store/links"; import { CollectionIncludingMembersAndLinkCount, LinkIncludingShortenedCollectionAndTags, } from "@/types/global"; import { useSession } from "next-auth/react"; import useCollectionStore from "@/store/collections"; type Props = { className?: string; onClick?: Function; }; export default function SettingsSidebar({ className, onClick }: Props) { const session = useSession(); const userId = session.data?.user.id; const { setModal } = useModalStore(); const { links, removeLink } = useLinkStore(); const { collections } = useCollectionStore(); const [linkCollection, setLinkCollection] = useState(); const [link, setLink] = useState(); const router = useRouter(); useEffect(() => { if (links) setLink(links.find((e) => e.id === Number(router.query.id))); }, [links]); useEffect(() => { if (link) setLinkCollection(collections.find((e) => e.id === link?.collection.id)); }, [link]); return (
{link?.collection.ownerId === userId || linkCollection?.members.some( (e) => e.userId === userId && e.canUpdate ) ? (
{ link ? setModal({ modal: "LINK", state: true, active: link, method: "UPDATE", }) : undefined; onClick && onClick(); }} className={`hover:opacity-60 duration-100 py-2 px-2 cursor-pointer flex items-center gap-4 w-full rounded-md h-8`} >

Edit

) : undefined}
{ link ? setModal({ modal: "LINK", state: true, active: link, method: "FORMATS", }) : undefined; onClick && onClick(); }} title="Preserved Formats" className={`hover:opacity-60 duration-100 py-2 px-2 cursor-pointer flex items-center gap-4 w-full rounded-md h-8`} >

Preserved Formats

{link?.collection.ownerId === userId || linkCollection?.members.some( (e) => e.userId === userId && e.canDelete ) ? (
{ if (link?.id) { removeLink(link.id); router.back(); onClick && onClick(); } }} title="Delete" className={`hover:opacity-60 duration-100 py-2 px-2 cursor-pointer flex items-center gap-4 w-full rounded-md h-8`} >

Delete

) : undefined}
); }