import { BlockImageUploader } from "./imageUploader"; import { Dialog, Transition } from "@headlessui/react"; import { CancelIcon, PlusIcon } from "@shared/icons"; import { Image } from "@shared/image"; import { useActiveAccount } from "@stores/accounts"; import { DEFAULT_AVATAR } from "@stores/constants"; import { createBlock } from "@utils/storage"; import { Fragment, useEffect, useState } from "react"; import { useForm } from "react-hook-form"; export function CreateBlockModal() { const account = useActiveAccount((state: any) => state.account); const { register, handleSubmit, reset, watch, setValue } = useForm(); const [image, setImage] = useState(DEFAULT_AVATAR); const [isOpen, setIsOpen] = useState(false); const [loading, setLoading] = useState(false); const kind = watch("kind"); const closeModal = () => { setIsOpen(false); }; const openModal = () => { setIsOpen(true); }; const onSubmit = (data: any) => { setLoading(true); createBlock(account.id, data.kind, data.title, data.content).then(() => { // reset form reset(); // close modal setIsOpen(false); // stop loading setLoading(false); }); }; useEffect(() => { setValue("content", image); }, [setValue, image]); return ( <>
Create block
Personalize your space by adding a new block.
{kind === "1" ? (