import { useEffect, useState } from "react"; import { faFolder } from "@fortawesome/free-solid-svg-icons"; import useCollectionStore from "@/store/collections"; import { HexColorPicker } from "react-colorful"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { toast } from "react-hot-toast"; import TextInput from "@/components/TextInput"; import { useRouter } from "next/router"; import { Collection } from "@prisma/client"; type Props = { isOpen: boolean; modalId: string; }; export default function NewCollection({ isOpen, modalId }: Props) { const router = useRouter(); const initial = { name: "", description: "", color: "#0ea5e9", }; const [collection, setCollection] = useState>(initial); useEffect(() => { setCollection(initial); }, [isOpen]); const [submitLoader, setSubmitLoader] = useState(false); const { addCollection } = useCollectionStore(); const submit = async () => { if (!submitLoader) { setSubmitLoader(true); if (!collection) return null; setSubmitLoader(true); const load = toast.loading("Creating..."); let response; response = await addCollection(collection as any); toast.dismiss(load); if (response.ok) { toast.success(`Collection "Created!"`); (document.getElementById(modalId) as any).close(); } else toast.error(response.data as string); setSubmitLoader(false); } }; return (

Name

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

Color

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

Description