import React, { useEffect, useState } from "react"; import TextInput from "@/components/TextInput"; import useCollectionStore from "@/store/collections"; import toast from "react-hot-toast"; import { HexColorPicker } from "react-colorful"; import { Collection } from "@prisma/client"; import Modal from "../Modal"; import { CollectionIncludingMembersAndLinkCount } from "@/types/global"; type Props = { onClose: Function; parent?: CollectionIncludingMembersAndLinkCount; }; export default function NewCollectionModal({ onClose, parent }: Props) { const initial = { parentId: parent?.id, name: "", description: "", color: "#0ea5e9", } as Partial; const [collection, setCollection] = useState>(initial); useEffect(() => { setCollection(initial); }, []); const [submitLoader, setSubmitLoader] = useState(false); const { addCollection } = useCollectionStore(); const submit = async () => { if (submitLoader) return; if (!collection) return null; setSubmitLoader(true); const load = toast.loading("Creating..."); let response = await addCollection(collection as any); toast.dismiss(load); if (response.ok) { toast.success("Created!"); onClose(); } else toast.error(response.data as string); setSubmitLoader(false); }; return ( {parent?.id ? ( <>

New Sub-Collection

For {parent.name}

) : (

Create a New Collection

)}

Name

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

Color

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

Description