import React, { useEffect, useState } from "react"; import TextInput from "@/components/TextInput"; import useCollectionStore from "@/store/collections"; import toast, { Toaster } from "react-hot-toast"; import { faFolder } from "@fortawesome/free-solid-svg-icons"; import { HexColorPicker } from "react-colorful"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { CollectionIncludingMembersAndLinkCount } from "@/types/global"; type Props = { modalId: string; isOpen: boolean; onClose: Function; activeCollection: CollectionIncludingMembersAndLinkCount; }; export default function EditCollectionModal({ modalId, isOpen, onClose, activeCollection, }: Props) { const modal = document.getElementById(modalId); useEffect(() => { modal?.addEventListener("close", () => { onClose(); }); return () => { modal?.addEventListener("close", () => { onClose(); }); }; }, [isOpen]); const [collection, setCollection] = useState(activeCollection); useEffect(() => { setCollection(activeCollection); }, [isOpen]); const [submitLoader, setSubmitLoader] = useState(false); const { updateCollection } = useCollectionStore(); const submit = async () => { if (!submitLoader) { setSubmitLoader(true); if (!collection) return null; setSubmitLoader(true); const load = toast.loading("Updating..."); let response; response = await updateCollection(collection as any); toast.dismiss(load); if (response.ok) { toast.success(`Updated!`); (document.getElementById(modalId) as any).close(); } else toast.error(response.data as string); setSubmitLoader(false); } }; return (

Edit Collection Info

Name

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

Color

setCollection({ ...collection, color: "#0ea5e9" }) } > Reset
setCollection({ ...collection, color: e }) } />

Description