2022-06-01 03:04:15 +00:00
|
|
|
import classNames from "classnames";
|
|
|
|
import { useTranslation } from "next-i18next";
|
|
|
|
import { HTMLProps } from "react";
|
|
|
|
import { useMyEvents } from "../hooks/useMyEvents";
|
|
|
|
import { Loading } from "./Loading";
|
|
|
|
import { Event } from "@prisma/client";
|
2022-06-01 16:54:59 +00:00
|
|
|
import { EventList } from "./EventList";
|
|
|
|
import { EventCreate } from "./EventCreate";
|
2022-06-01 03:04:15 +00:00
|
|
|
|
|
|
|
|
2022-06-01 14:58:19 +00:00
|
|
|
export function ActionEventList(props: HTMLProps<HTMLFormElement>) {
|
2022-06-01 03:04:15 +00:00
|
|
|
const {t} = useTranslation()
|
|
|
|
const { data, error } = useMyEvents()
|
|
|
|
|
|
|
|
const newClassName = classNames(props.className, {
|
|
|
|
"negative": error,
|
|
|
|
})
|
2022-05-31 14:35:54 +00:00
|
|
|
|
2022-06-01 03:04:15 +00:00
|
|
|
let contents: JSX.Element
|
|
|
|
|
|
|
|
if(error) {
|
2022-06-01 14:57:19 +00:00
|
|
|
contents = <>
|
|
|
|
<p>
|
|
|
|
{t("eventListError")}
|
|
|
|
</p>
|
|
|
|
<code>
|
|
|
|
{JSON.stringify(error)}
|
|
|
|
</code>
|
|
|
|
</>
|
2022-06-01 03:04:15 +00:00
|
|
|
}
|
|
|
|
else if(!data) {
|
2022-06-01 16:54:59 +00:00
|
|
|
contents = <Loading text={t("eventListLoading")}/>
|
2022-06-01 03:04:15 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(data.length === 0) {
|
2022-06-01 14:57:19 +00:00
|
|
|
contents = <>
|
|
|
|
<p>
|
|
|
|
{t("eventListCreateFirst")}
|
|
|
|
</p>
|
2022-06-01 16:54:59 +00:00
|
|
|
<EventCreate/>
|
2022-06-01 14:57:19 +00:00
|
|
|
</>
|
2022-06-01 03:04:15 +00:00
|
|
|
}
|
|
|
|
else {
|
2022-06-01 14:57:19 +00:00
|
|
|
contents = <>
|
|
|
|
<p>
|
|
|
|
{t("eventListDescription")}
|
|
|
|
</p>
|
2022-06-01 16:54:59 +00:00
|
|
|
<EventList data={data}/>
|
2022-06-01 14:57:19 +00:00
|
|
|
<p>
|
|
|
|
{t("eventListCreateAnother")}
|
|
|
|
</p>
|
2022-06-01 16:54:59 +00:00
|
|
|
<EventCreate/>
|
2022-06-01 14:57:19 +00:00
|
|
|
</>
|
2022-06-01 03:04:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2022-06-01 14:57:19 +00:00
|
|
|
<div className={newClassName}>
|
2022-06-01 03:04:15 +00:00
|
|
|
{contents}
|
2022-06-01 14:57:19 +00:00
|
|
|
</div>
|
2022-06-01 03:04:15 +00:00
|
|
|
)
|
2022-05-31 14:35:54 +00:00
|
|
|
}
|