1
Fork 0
mirror of https://github.com/Steffo99/festa.git synced 2024-10-16 15:07:27 +00:00
festa/components/ActionEventList.tsx

61 lines
1.5 KiB
TypeScript
Raw Normal View History

2022-06-03 01:56:43 +00:00
import { default as classNames } from "classnames";
2022-06-01 03:04:15 +00:00
import { useTranslation } from "next-i18next";
import { HTMLProps } from "react";
2022-06-03 02:10:51 +00:00
import { useMyEventsSWR } from "../hooks/swr/useMyEventsSWR";
2022-06-01 03:04:15 +00:00
import { Loading } from "./Loading";
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-03 01:56:43 +00:00
const { t } = useTranslation()
2022-06-03 02:10:51 +00:00
const { data, error } = useMyEventsSWR()
2022-06-01 03:04:15 +00:00
const newClassName = classNames(props.className, {
"negative": error,
})
2022-06-03 01:56:43 +00:00
2022-06-01 03:04:15 +00:00
let contents: JSX.Element
2022-06-03 01:56:43 +00:00
if (error) {
contents = <>
<p>
{t("eventListError")}
</p>
<code>
{JSON.stringify(error)}
</code>
</>
2022-06-01 03:04:15 +00:00
}
2022-06-03 01:56:43 +00:00
else if (!data) {
contents = <Loading text={t("eventListLoading")} />
2022-06-01 03:04:15 +00:00
}
else {
2022-06-03 01:56:43 +00:00
if (data.length === 0) {
contents = <>
<p>
{t("eventListCreateFirst")}
</p>
2022-06-03 01:56:43 +00:00
<EventCreate />
</>
2022-06-01 03:04:15 +00:00
}
else {
contents = <>
<p>
{t("eventListDescription")}
</p>
2022-06-03 01:56:43 +00:00
<EventList data={data} />
<p>
{t("eventListCreateAnother")}
</p>
2022-06-03 01:56:43 +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
)
}