2023-11-17 19:20:17 +01:00
|
|
|
import { useMemo } from "react";
|
|
|
|
import { useHistory } 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";
|
|
|
|
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-11-17 19:20:17 +01:00
|
|
|
const history = useHistory();
|
|
|
|
const backendUrl = useBackendUrl();
|
|
|
|
const backendHostname = useMemo(
|
|
|
|
() => new URL(backendUrl).hostname,
|
|
|
|
[backendUrl]
|
|
|
|
);
|
|
|
|
const result = useAsync(() => {
|
|
|
|
return getBackendMeta(conf().BACKEND_URL);
|
|
|
|
}, [backendUrl]);
|
2023-11-05 01:16:45 +01:00
|
|
|
|
2023-11-17 19:20:17 +01:00
|
|
|
let cardContent = (
|
|
|
|
<>
|
|
|
|
<h3 className="text-white font-bold text-lg">Failed to reach backend</h3>
|
|
|
|
<p>Did you configure it correctly?</p>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
if (result.loading) cardContent = <Loading />;
|
|
|
|
if (result.value)
|
|
|
|
cardContent = (
|
|
|
|
<>
|
|
|
|
<h3 className="text-white font-bold text-lg">{result.value.name}</h3>
|
|
|
|
{result.value.description ? <p>{result.value.description}</p> : null}
|
|
|
|
</>
|
|
|
|
);
|
2023-11-05 01:16:45 +01:00
|
|
|
|
|
|
|
return (
|
2023-11-17 14:45:13 +01:00
|
|
|
<LargeCard>
|
|
|
|
<LargeCardText
|
|
|
|
title="Do you trust this host?"
|
|
|
|
icon={<Icon icon={Icons.CIRCLE_EXCLAMATION} />}
|
|
|
|
>
|
2023-11-17 19:20:17 +01:00
|
|
|
Do you trust <span className="text-white">{backendHostname}</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>
|
|
|
|
<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
|
|
|
>
|
|
|
|
I pledge my life to the United States
|
|
|
|
</Button>
|
2023-11-17 19:20:17 +01:00
|
|
|
<Button theme="secondary" onClick={() => history.push("/")}>
|
2023-11-17 14:45:13 +01:00
|
|
|
I WILL NEVER SUCCUMB!
|
|
|
|
</Button>
|
|
|
|
</LargeCardButtons>
|
|
|
|
</LargeCard>
|
2023-11-05 01:16:45 +01:00
|
|
|
);
|
|
|
|
}
|