import React, { useState } from "react"; import { LinkIncludingShortenedCollectionAndTags } from "@/types/global"; import { useTranslation } from "next-i18next"; import { useDeleteLink } from "@/hooks/store/links"; import Drawer from "../Drawer"; import LinkDetails from "../LinkDetails"; import Link from "next/link"; import usePermissions from "@/hooks/usePermissions"; import { useRouter } from "next/router"; import { dropdownTriggerer } from "@/lib/client/utils"; import toast from "react-hot-toast"; import clsx from "clsx"; type Props = { onClose: Function; onDelete: Function; onUpdateArchive: Function; onPin: Function; link: LinkIncludingShortenedCollectionAndTags; activeMode?: "view" | "edit"; }; export default function LinkModal({ onClose, onDelete, onUpdateArchive, onPin, link, activeMode, }: Props) { const { t } = useTranslation(); const permissions = usePermissions(link.collection.id as number); const router = useRouter(); const isPublicRoute = router.pathname.startsWith("/public") ? true : false; const deleteLink = useDeleteLink(); const [mode, setMode] = useState<"view" | "edit">(activeMode || "view"); return (
onClose()} >
{(permissions === true || permissions?.canUpdate) && (
{ setMode("view"); }} > View
{ setMode("edit"); }} > Edit
)}
    {
  • { (document?.activeElement as HTMLElement)?.blur(); onPin(); }} className="whitespace-nowrap" > {link?.pinnedBy && link.pinnedBy[0] ? t("unpin") : t("pin_to_dashboard")}
  • } {link.type === "url" && (permissions === true || permissions?.canUpdate) && (
  • { (document?.activeElement as HTMLElement)?.blur(); onUpdateArchive(); }} className="whitespace-nowrap" > {t("refresh_preserved_formats")}
  • )} {(permissions === true || permissions?.canDelete) && (
  • { (document?.activeElement as HTMLElement)?.blur(); console.log(e.shiftKey); if (e.shiftKey) { const load = toast.loading(t("deleting")); await deleteLink.mutateAsync(link.id as number, { onSettled: (data, error) => { toast.dismiss(load); if (error) { toast.error(error.message); } else { toast.success(t("deleted")); } }, }); onClose(); } else { onDelete(); onClose(); } }} className="whitespace-nowrap" > {t("delete")}
  • )}
{link.url && ( )}
setMode(mode)} />
); }