import { Event } from "@prisma/client" import { useTranslation } from "next-i18next" import { useRouter } from "next/router" import { useState } from "react" import { useAxiosRequest } from "../hooks/useAxiosRequest" import { Loading } from "./Loading" import { ErrorBlock } from "./errors/ErrorBlock" import { FestaIcon } from "./extensions/FestaIcon" import { faPlus } from "@fortawesome/free-solid-svg-icons" import { FormMonorow } from "./form/FormMonorow" export function EventCreate() { const { t } = useTranslation() const router = useRouter() const [name, setName] = useState("") const createEvent = useAxiosRequest( { method: "POST", url: "/api/events/", data: { name } }, (response) => { router.push(`/events/${response.data.slug}`) } ) if (createEvent.running) return if (createEvent.data) return return <> { e.preventDefault(); createEvent.run() }} noValidate > setName(e.target.value)} required /> {createEvent.error ? : null} }