import React, { useState } from "react"; import TextInput from "@/components/TextInput"; import { CollectionIncludingMembersAndLinkCount } from "@/types/global"; import Modal from "../Modal"; import { useTranslation } from "next-i18next"; import { useUpdateCollection } from "@/hooks/store/collections"; import toast from "react-hot-toast"; import IconPicker from "../IconPicker"; import { IconWeight } from "@phosphor-icons/react"; type Props = { onClose: Function; activeCollection: CollectionIncludingMembersAndLinkCount; }; export default function EditCollectionModal({ onClose, activeCollection, }: Props) { const { t } = useTranslation(); const [collection, setCollection] = useState(activeCollection); const [submitLoader, setSubmitLoader] = useState(false); const updateCollection = useUpdateCollection(); const submit = async () => { if (!submitLoader) { setSubmitLoader(true); if (!collection) return null; setSubmitLoader(true); const load = toast.loading(t("updating_collection")); await updateCollection.mutateAsync(collection, { onSettled: (data, error) => { setSubmitLoader(false); toast.dismiss(load); if (error) { toast.error(error.message); } else { onClose(); toast.success(t("updated")); } }, }); } }; return (

{t("edit_collection_info")}

setCollection({ ...collection, color }) } weight={(collection.iconWeight || "regular") as IconWeight} setWeight={(iconWeight: string) => setCollection({ ...collection, iconWeight }) } iconName={collection.icon as string} setIconName={(icon: string) => setCollection({ ...collection, icon }) } reset={() => setCollection({ ...collection, color: "#0ea5e9", icon: "", iconWeight: "", }) } />

{t("name")}

setCollection({ ...collection, name: e.target.value }) } />

{t("description")}