import { faPlus } from "@fortawesome/free-solid-svg-icons" import { Event } from "@prisma/client" import classNames from "classnames" import { useTranslation } from "next-i18next" import Link from "next/link" import { useRouter } from "next/router" import { useEffect, useState } from "react" import { default as useSWR } from "swr" import { useAxiosRequest } from "../../auth/requests" import { ErrorBlock } from "../../generic/errors/renderers" import { promiseMultiplexer, UsePromiseStatus } from "../../generic/loading/promise" import { swrMultiplexer } from "../../generic/loading/swr" import { LoadingInline } from "../../generic/loading/renderers" import { FestaIcon } from "../../generic/renderers/fontawesome" import style from "./events.module.css" import mood from "../../../styles/mood.module.css" /** * Displayed if the user has never created an event on Festa. */ const LandingActionEventsFirst = () => { const { t } = useTranslation() return (

) } /** * Displayed if the user has one or more events created on Festa. */ const LandingActionEventsList = ({ data }: { data: Event[] }) => { const { t } = useTranslation() return ( <>

{t("landingEventsDescription")}

) } /** * One-line form to create a new event on Festa. */ const LandingActionEventsFormCreate = () => { const { t } = useTranslation() const router = useRouter() const [name, setName] = useState("") const createHook = useAxiosRequest>({ method: "POST", url: "/api/events/" }) useEffect( () => { if (createHook.status === UsePromiseStatus.FULFILLED) { console.debug(`[LandingActionEventsFormCreate] Moving you to /events/${createHook.data!.slug}`) router.push(`/events/${createHook.data!.slug}`) } }, [router] ) return promiseMultiplexer({ hook: createHook, ready: ({ run }) => (
setName(e.target.value)} required id="festa-landing-action-events-form-create-name" className={style.landingActionEventsFormCreateName} />
), pending: ({ }) => (

), rejected: ({ error }) => (

), fulfilled: ({ result }) => (

) }) } export const LandingActionEvents = () => { const { t } = useTranslation() const apiHook = useSWR("/api/events/mine") return swrMultiplexer({ hook: apiHook, loading: () => (

), ready: (data) => (<> {data.length === 0 ? : } ), error: (error) => (

) }) }