1
Fork 0
mirror of https://github.com/Steffo99/festa.git synced 2024-12-23 07:04:22 +00:00
festa/components/ActionEventList.tsx

62 lines
1.5 KiB
TypeScript
Raw Normal View History

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
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-06-01 03:04:15 +00:00
let contents: JSX.Element
if(error) {
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) {
contents = <>
<p>
{t("eventListCreateFirst")}
</p>
2022-06-01 16:54:59 +00:00
<EventCreate/>
</>
2022-06-01 03:04:15 +00:00
}
else {
contents = <>
<p>
{t("eventListDescription")}
</p>
2022-06-01 16:54:59 +00:00
<EventList data={data}/>
<p>
{t("eventListCreateAnother")}
</p>
2022-06-01 16:54:59 +00:00
<EventCreate/>
</>
2022-06-01 03:04:15 +00:00
}
}
return (
<div className={newClassName}>
2022-06-01 03:04:15 +00:00
{contents}
</div>
2022-06-01 03:04:15 +00:00
)
}