import { Menu, Transition } from "@headlessui/react"; import { DocumentAddIcon, PlusIcon, TerminalIcon, ViewGridAddIcon, } from "@heroicons/react/outline"; import { DotsHorizontalIcon, TrashIcon } from "@heroicons/react/solid"; import Link from "next/link"; import { Fragment, useState } from "react"; import { useForms } from "../lib/forms"; import { classNames } from "../lib/utils"; import NewFormModal from "./form/NewFormModal"; import EmptyPageFiller from "./layout/EmptyPageFiller"; export default function FormList() { const { forms, mutateForms } = useForms(); const [openNewFormModal, setOpenNewFormModal] = useState(false); const newForm = async () => { setOpenNewFormModal(true); }; const deleteForm = async (form, formIdx) => { try { await fetch(`/api/forms/${form.id}`, { method: "DELETE", }); // remove locally const updatedForms = [...forms]; updatedForms.splice(formIdx, 1); mutateForms(updatedForms); } catch (error) { console.error(error); } }; return ( <>
{forms && (forms.length === 0 ? (
newForm()} alertText="You don't have any forms yet." hintText="Start by creating a form." buttonText="create form" borderStyles="border-4 border-dotted border-red" hasButton={true} >
) : ( ))}
); }