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-04 03:13:19 +00:00
|
|
|
import { ListEvents } from "./ListEvents";
|
2022-06-01 16:54:59 +00:00
|
|
|
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-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) {
|
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
|
|
|
}
|
2022-06-03 01:56:43 +00:00
|
|
|
else if (!data) {
|
2022-06-10 03:21:02 +00:00
|
|
|
contents = <>
|
|
|
|
<p>
|
|
|
|
<Loading text={t("eventListLoading")} />
|
|
|
|
</p>
|
|
|
|
</>
|
2022-06-01 03:04:15 +00:00
|
|
|
}
|
|
|
|
else {
|
2022-06-03 01:56:43 +00:00
|
|
|
if (data.length === 0) {
|
2022-06-01 14:57:19 +00:00
|
|
|
contents = <>
|
|
|
|
<p>
|
|
|
|
{t("eventListCreateFirst")}
|
|
|
|
</p>
|
2022-06-03 01:56:43 +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-04 03:13:19 +00:00
|
|
|
<ListEvents data={data} />
|
2022-06-01 14:57:19 +00:00
|
|
|
<p>
|
|
|
|
{t("eventListCreateAnother")}
|
|
|
|
</p>
|
2022-06-03 01:56:43 +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
|
|
|
}
|