'use client' import { Modal, ModalContent, ModalHeader, ModalBody, ModalFooter, useDisclosure, } from '@nextui-org/modal' import { Dropdown, DropdownTrigger, DropdownMenu, DropdownItem, } from '@nextui-org/dropdown' import { Button } from '@nextui-org/button' import { Input } from '@nextui-org/input' import { Icon } from '@iconify/react' import { ChevronDownIcon } from './ChevronDownIcon' import { useRouter } from 'next/navigation' import { useState } from 'react' export default function NewBookmarkForm() { const { isOpen, onOpen, onOpenChange } = useDisclosure() const router = useRouter() const onSubmit = async () => { const body = { name, link, description, url, category_id: selectedKey === 'Other' ? 2 : 1, } await fetch('/api/bookmark', { method: 'POST', body: JSON.stringify(body), }) onOpenChange() router.refresh() } const [name, setName] = useState('') const [link, setLink] = useState('') const [description, setDescription] = useState('') const [url, setUrl] = useState('') const [selectedKey, setSelectedKey] = useState('Other') return ( <> { if (e.key === 'Enter') onSubmit() }}> {(onClose) => ( <> New Bookmark { setName(event.target.value) }} /> { setLink(event.target.value) }} /> { setDescription(event.target.value) }} /> { setSelectedKey('Coding') }} className='capitalize'> Coding { setSelectedKey('Other') }} className='capitalize'> Other { setUrl(event.target.value) }} /> )} ) }