import { useState } from "react"; import { useTranslation } from "react-i18next"; import { useNavigate } from "react-router-dom"; import { useAsyncFn } from "react-use"; import { singularProxiedFetch } from "@/backend/helpers/fetch"; import { Button } from "@/components/buttons/Button"; import { Stepper } from "@/components/layout/Stepper"; import { CenterContainer } from "@/components/layout/ThinContainer"; import { AuthInputBox } from "@/components/text-inputs/AuthInputBox"; import { Divider } from "@/components/utils/Divider"; import { ErrorLine } from "@/components/utils/ErrorLine"; import { Heading2, Paragraph } from "@/components/utils/Text"; import { MinimalPageLayout } from "@/pages/layouts/MinimalPageLayout"; import { useRedirectBack } from "@/pages/onboarding/onboardingHooks"; import { Link } from "@/pages/onboarding/utils"; import { PageTitle } from "@/pages/parts/util/PageTitle"; import { useAuthStore } from "@/stores/auth"; const testUrl = "https://postman-echo.com/get"; export function OnboardingProxyPage() { const { t } = useTranslation(); const navigate = useNavigate(); const { completeAndRedirect } = useRedirectBack(); const [url, setUrl] = useState(""); const setProxySet = useAuthStore((s) => s.setProxySet); const [{ loading, error }, test] = useAsyncFn(async () => { if (!url.startsWith("http")) throw new Error("onboarding.proxy.input.errorInvalidUrl"); try { const res = await singularProxiedFetch(url, testUrl, {}); if (res.url !== testUrl) throw new Error("onboarding.proxy.input.errorNotProxy"); setProxySet([url]); completeAndRedirect(); } catch (e) { throw new Error("onboarding.proxy.input.errorConnection"); } }, [url, completeAndRedirect, setProxySet]); // TODO proper link to proxy deployment docs return ( {t("onboarding.proxy.title")} {t("onboarding.proxy.explainer")} {t("onboarding.proxy.link")}
{error ? {t(error.message)} : null}
); }