2023-11-17 19:20:17 +01:00
|
|
|
import { useMemo } from "react";
|
2023-11-27 20:19:03 +01:00
|
|
|
import { Trans, useTranslation } from "react-i18next";
|
2023-12-23 06:24:43 +01:00
|
|
|
import { useNavigate } from "react-router-dom";
|
2023-11-05 01:16:45 +01:00
|
|
|
import { useAsync } from "react-use";
|
|
|
|
|
|
|
|
import { MetaResponse, getBackendMeta } from "@/backend/accounts/meta";
|
2023-11-26 16:04:23 +01:00
|
|
|
import { Button } from "@/components/buttons/Button";
|
2023-11-17 14:45:13 +01:00
|
|
|
import { Icon, Icons } from "@/components/Icon";
|
|
|
|
import {
|
|
|
|
LargeCard,
|
|
|
|
LargeCardButtons,
|
|
|
|
LargeCardText,
|
|
|
|
} from "@/components/layout/LargeCard";
|
2023-11-17 19:20:17 +01:00
|
|
|
import { Loading } from "@/components/layout/Loading";
|
2023-12-07 01:52:35 +01:00
|
|
|
import { MwLink } from "@/components/text/Link";
|
2023-11-17 19:20:17 +01:00
|
|
|
import { useBackendUrl } from "@/hooks/auth/useBackendUrl";
|
2023-11-05 01:16:45 +01:00
|
|
|
import { conf } from "@/setup/config";
|
|
|
|
|
|
|
|
interface TrustBackendPartProps {
|
|
|
|
onNext?: (meta: MetaResponse) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function TrustBackendPart(props: TrustBackendPartProps) {
|
2023-12-23 06:24:43 +01:00
|
|
|
const navigate = useNavigate();
|
2023-11-17 19:20:17 +01:00
|
|
|
const backendUrl = useBackendUrl();
|
2023-11-27 20:19:03 +01:00
|
|
|
const hostname = useMemo(() => new URL(backendUrl).hostname, [backendUrl]);
|
2023-11-17 19:20:17 +01:00
|
|
|
const result = useAsync(() => {
|
|
|
|
return getBackendMeta(conf().BACKEND_URL);
|
|
|
|
}, [backendUrl]);
|
2023-11-27 20:19:03 +01:00
|
|
|
const { t } = useTranslation();
|
2023-11-05 01:16:45 +01:00
|
|
|
|
2023-11-17 19:20:17 +01:00
|
|
|
let cardContent = (
|
|
|
|
<>
|
2023-11-27 20:19:03 +01:00
|
|
|
<h3 className="text-white font-bold text-lg">
|
|
|
|
{t("auth.trust.failed.title")}
|
|
|
|
</h3>
|
|
|
|
<p>{t("auth.trust.failed.text")}</p>
|
2023-11-17 19:20:17 +01:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
if (result.loading) cardContent = <Loading />;
|
|
|
|
if (result.value)
|
|
|
|
cardContent = (
|
|
|
|
<>
|
|
|
|
<h3 className="text-white font-bold text-lg">{result.value.name}</h3>
|
2023-12-14 21:18:02 +01:00
|
|
|
{result.value.description ? (
|
|
|
|
<p className="text-center">{result.value.description}</p>
|
|
|
|
) : null}
|
2023-11-17 19:20:17 +01:00
|
|
|
</>
|
|
|
|
);
|
2023-11-05 01:16:45 +01:00
|
|
|
|
|
|
|
return (
|
2023-11-17 14:45:13 +01:00
|
|
|
<LargeCard>
|
|
|
|
<LargeCardText
|
2023-11-27 20:19:03 +01:00
|
|
|
title={t("auth.trust.title")}
|
2023-11-17 14:45:13 +01:00
|
|
|
icon={<Icon icon={Icons.CIRCLE_EXCLAMATION} />}
|
|
|
|
>
|
2023-12-23 06:24:43 +01:00
|
|
|
<span className="text-white">
|
2023-12-24 02:58:07 +01:00
|
|
|
<Trans i18nKey="auth.trust.host">{[{ hostname }]}</Trans>
|
2023-12-23 06:24:43 +01:00
|
|
|
</span>
|
2023-11-17 14:45:13 +01:00
|
|
|
</LargeCardText>
|
|
|
|
|
|
|
|
<div className="border border-authentication-border rounded-xl px-4 py-8 flex flex-col items-center space-y-2 my-8">
|
2023-11-17 19:20:17 +01:00
|
|
|
{cardContent}
|
2023-11-05 01:16:45 +01:00
|
|
|
</div>
|
2023-11-17 14:45:13 +01:00
|
|
|
<LargeCardButtons>
|
2023-12-23 06:24:43 +01:00
|
|
|
<Button theme="secondary" onClick={() => navigate("/")}>
|
2023-12-07 01:52:35 +01:00
|
|
|
{t("auth.trust.no")}
|
|
|
|
</Button>
|
2023-11-17 14:45:13 +01:00
|
|
|
<Button
|
|
|
|
theme="purple"
|
2023-11-17 19:20:17 +01:00
|
|
|
onClick={() => result.value && props.onNext?.(result.value)}
|
2023-11-17 14:45:13 +01:00
|
|
|
>
|
2023-11-27 20:19:03 +01:00
|
|
|
{t("auth.trust.yes")}
|
2023-11-17 14:45:13 +01:00
|
|
|
</Button>
|
|
|
|
</LargeCardButtons>
|
2023-12-07 01:52:35 +01:00
|
|
|
<p className="text-center mt-6">
|
|
|
|
<Trans i18nKey="auth.hasAccount">
|
|
|
|
<MwLink to="/login">.</MwLink>
|
|
|
|
</Trans>
|
|
|
|
</p>
|
2023-11-17 14:45:13 +01:00
|
|
|
</LargeCard>
|
2023-11-05 01:16:45 +01:00
|
|
|
);
|
|
|
|
}
|