mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-03-21 18:04:39 -05:00
57 lines
1.3 KiB
TypeScript
57 lines
1.3 KiB
TypeScript
import { createPortal } from "react-dom";
|
|
import { useTranslation } from "react-i18next";
|
|
import { useSearchParams } from "react-router";
|
|
import { SendouDialog } from "~/components/elements/Dialog";
|
|
import { useIsMounted } from "~/hooks/useIsMounted";
|
|
import { LOG_IN_URL, SENDOU_INK_DISCORD_URL } from "~/utils/urls";
|
|
|
|
export function LogInButtonContainer({
|
|
children,
|
|
}: {
|
|
children: React.ReactNode;
|
|
}) {
|
|
const { t } = useTranslation();
|
|
const isMounted = useIsMounted();
|
|
const [searchParams] = useSearchParams();
|
|
const authError = searchParams.get("authError");
|
|
|
|
return (
|
|
<>
|
|
<form action={LOG_IN_URL} method="post">
|
|
{children}
|
|
</form>
|
|
{authError != null &&
|
|
isMounted &&
|
|
createPortal(
|
|
<SendouDialog
|
|
isDismissable
|
|
onCloseTo="/"
|
|
heading={
|
|
authError === "aborted"
|
|
? t("auth.errors.aborted")
|
|
: t("auth.errors.failed")
|
|
}
|
|
>
|
|
<div className="stack md layout__user-item">
|
|
{authError === "aborted" ? (
|
|
t("auth.errors.discordPermissions")
|
|
) : (
|
|
<>
|
|
{t("auth.errors.unknown")}{" "}
|
|
<a
|
|
href={SENDOU_INK_DISCORD_URL}
|
|
target="_blank"
|
|
rel="noreferrer"
|
|
>
|
|
{SENDOU_INK_DISCORD_URL}
|
|
</a>
|
|
</>
|
|
)}
|
|
</div>
|
|
</SendouDialog>,
|
|
document.body,
|
|
)}
|
|
</>
|
|
);
|
|
}
|