import { useState } from "react"; import { CollectionIncludingMembersAndLinkCount, LinkIncludingShortenedCollectionAndTags, } from "@/types/global"; import usePermissions from "@/hooks/usePermissions"; import EditLinkModal from "@/components/ModalContent/EditLinkModal"; import DeleteLinkModal from "@/components/ModalContent/DeleteLinkModal"; import PreservedFormatsModal from "@/components/ModalContent/PreservedFormatsModal"; import useLinkStore from "@/store/links"; import { toast } from "react-hot-toast"; import useAccountStore from "@/store/account"; import { dropdownTriggerer } from "@/lib/client/utils"; import { useTranslation } from "next-i18next"; type Props = { link: LinkIncludingShortenedCollectionAndTags; collection: CollectionIncludingMembersAndLinkCount; position?: string; toggleShowInfo?: () => void; linkInfo?: boolean; alignToTop?: boolean; flipDropdown?: boolean; }; export default function LinkActions({ link, toggleShowInfo, position, linkInfo, alignToTop, flipDropdown, }: Props) { const { t } = useTranslation(); const permissions = usePermissions(link.collection.id as number); const [editLinkModal, setEditLinkModal] = useState(false); const [deleteLinkModal, setDeleteLinkModal] = useState(false); const [preservedFormatsModal, setPreservedFormatsModal] = useState(false); const { account } = useAccountStore(); const { removeLink, updateLink } = useLinkStore(); const pinLink = async () => { const isAlreadyPinned = link?.pinnedBy && link.pinnedBy[0]; const load = toast.loading(t("applying")); const response = await updateLink({ ...link, pinnedBy: isAlreadyPinned ? undefined : [{ id: account.id }], }); toast.dismiss(load); if (response.ok) { toast.success(isAlreadyPinned ? t("link_unpinned") : t("link_unpinned")); } else { toast.error(response.data as string); } }; const deleteLink = async () => { const load = toast.loading(t("deleting")); const response = await removeLink(link.id as number); toast.dismiss(load); if (response.ok) { toast.success(t("deleted")); } else { toast.error(response.data as string); } }; return ( <>