import React, { useState } from "react"; import CollectionSelection from "@/components/InputSelect/CollectionSelection"; import TagSelection from "@/components/InputSelect/TagSelection"; import useLinkStore from "@/store/links"; import { LinkIncludingShortenedCollectionAndTags } from "@/types/global"; import toast from "react-hot-toast"; import Modal from "../Modal"; import { useTranslation } from "next-i18next"; type Props = { onClose: Function; }; export default function BulkEditLinksModal({ onClose }: Props) { const { t } = useTranslation(); const { updateLinks, selectedLinks, setSelectedLinks } = useLinkStore(); const [submitLoader, setSubmitLoader] = useState(false); const [removePreviousTags, setRemovePreviousTags] = useState(false); const [updatedValues, setUpdatedValues] = useState< Pick >({ tags: [] }); const setCollection = (e: any) => { const collectionId = e?.value || null; setUpdatedValues((prevValues) => ({ ...prevValues, collectionId })); }; const setTags = (e: any) => { const tags = e.map((tag: any) => ({ name: tag.label })); setUpdatedValues((prevValues) => ({ ...prevValues, tags })); }; const submit = async () => { if (!submitLoader) { setSubmitLoader(true); const load = toast.loading(t("updating")); const response = await updateLinks( selectedLinks, removePreviousTags, updatedValues ); toast.dismiss(load); if (response.ok) { toast.success(t("updated")); setSelectedLinks([]); onClose(); } else toast.error(response.data as string); setSubmitLoader(false); return response; } }; return (

{selectedLinks.length === 1 ? t("edit_link") : t("edit_links", { count: selectedLinks.length })}

{t("move_to_collection")}

{t("add_tags")}

); }