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

104 lines
3.4 KiB
TypeScript
Raw Normal View History

2022-05-29 02:01:56 +00:00
import { NextPageContext } from 'next'
2022-05-25 14:20:22 +00:00
import { useTranslation } from 'next-i18next'
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
2022-05-29 02:01:56 +00:00
import { useState } from 'react';
2022-05-28 03:45:05 +00:00
import { LoginContext } from '../contexts/login';
import { useDefinedContext } from '../utils/definedContext';
2022-05-29 02:01:56 +00:00
import { ApiError } from '../types/api';
import { TelegramLoginButton } from "../components/TelegramLoginButton"
import { useTelegramToFestaCallback } from '../hooks/useTelegramToFestaCallback';
2022-05-25 14:20:22 +00:00
export async function getStaticProps(context: NextPageContext) {
2022-05-28 03:45:05 +00:00
return {
props: {
...(await serverSideTranslations(context.locale ?? "it-IT", ["common"]))
}
}
2022-05-25 14:20:22 +00:00
}
2022-05-20 11:59:24 +00:00
2022-05-29 02:01:56 +00:00
export default function PageIndex() {
2022-05-28 03:45:05 +00:00
const { t } = useTranslation("common")
const [login, setLogin] = useDefinedContext(LoginContext)
2022-05-29 03:00:48 +00:00
const [working, setWorking] = useState<boolean>(false)
2022-05-29 02:01:56 +00:00
const [error, setError] = useState<ApiError | null | undefined>(null)
2022-05-29 03:00:48 +00:00
const onLogin = useTelegramToFestaCallback(setLogin, setError, setWorking)
if(!login) return (
<main id="page-index" className="page">
<hgroup className="hero-titles">
2022-05-29 02:01:56 +00:00
<h1>
{t("siteTitle")}
</h1>
2022-05-29 03:00:48 +00:00
<h2>
{t("siteSubtitle")}
</h2>
</hgroup>
{error ?
<div className="hero-action negative">
<p>
{t("telegramLoginError")}
</p>
<p>
<code>
{JSON.stringify(error)}
</code>
</p>
</div>
:
working ?
<div>
2022-05-29 02:01:56 +00:00
<p>
2022-05-29 03:00:48 +00:00
{t("telegramLoginWorking")}
2022-05-29 02:01:56 +00:00
</p>
</div>
:
2022-05-29 03:00:48 +00:00
<div className="hero-action">
2022-05-29 02:01:56 +00:00
<p>
{t("telegramLoginDescription")}
</p>
<TelegramLoginButton
dataOnauth={onLogin}
botName={process.env.NEXT_PUBLIC_TELEGRAM_USERNAME}
/>
</div>
2022-05-29 03:00:48 +00:00
}
</main>
)
return (
<main id="page-index" className="page">
<hgroup className="hero-titles">
<h1>
{t("siteTitle")}
</h1>
<h2>
{t("eventsSubtitleFirst")}
</h2>
</hgroup>
<div className="hero-action">
<label htmlFor="input-name">
<p>
{t("eventsInputDescriptionFirst")}
</p>
</label>
<form className="form-event-create">
<input
id="input-name"
placeholder={t("eventsInputName")}
type="text"
/>
<input
id="input-submit"
type="submit"
aria-label={t("eventsInputSubmitLabel")}
value="→"
className="square-40 positive"
/>
</form>
</div>
</main>
2022-05-20 22:46:39 +00:00
)
2022-05-20 11:59:24 +00:00
}