2024-01-16 22:07:21 +01:00
|
|
|
import { useState } from "react";
|
2024-01-16 20:28:33 +01:00
|
|
|
import { useNavigate } from "react-router-dom";
|
2024-01-16 22:07:21 +01:00
|
|
|
import { useAsyncFn } from "react-use";
|
2024-01-16 20:28:33 +01:00
|
|
|
|
2024-01-16 22:07:21 +01:00
|
|
|
import { singularProxiedFetch } from "@/backend/helpers/fetch";
|
2024-01-16 20:28:33 +01:00
|
|
|
import { Button } from "@/components/buttons/Button";
|
|
|
|
import { Stepper } from "@/components/layout/Stepper";
|
|
|
|
import { CenterContainer } from "@/components/layout/ThinContainer";
|
2024-01-16 22:07:21 +01:00
|
|
|
import { AuthInputBox } from "@/components/text-inputs/AuthInputBox";
|
2024-01-16 20:28:33 +01:00
|
|
|
import { Heading2, Paragraph } from "@/components/utils/Text";
|
|
|
|
import { MinimalPageLayout } from "@/pages/layouts/MinimalPageLayout";
|
2024-01-16 22:07:21 +01:00
|
|
|
import { useRedirectBack } from "@/pages/onboarding/onboardingHooks";
|
2024-01-16 20:28:33 +01:00
|
|
|
import { PageTitle } from "@/pages/parts/util/PageTitle";
|
2024-01-16 22:07:21 +01:00
|
|
|
import { useAuthStore } from "@/stores/auth";
|
|
|
|
|
|
|
|
const testUrl = "https://postman-echo.com/get";
|
2024-01-16 20:28:33 +01:00
|
|
|
|
|
|
|
export function OnboardingProxyPage() {
|
|
|
|
const navigate = useNavigate();
|
2024-01-16 22:07:21 +01:00
|
|
|
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("Not a valid URL");
|
|
|
|
const res = await singularProxiedFetch(url, testUrl, {});
|
|
|
|
if (res.url !== testUrl) throw new Error("Not a proxy");
|
|
|
|
setProxySet([url]);
|
|
|
|
completeAndRedirect();
|
|
|
|
}, [url, completeAndRedirect, setProxySet]);
|
2024-01-16 20:28:33 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<MinimalPageLayout>
|
|
|
|
<PageTitle subpage k="global.pages.about" />
|
|
|
|
<CenterContainer>
|
|
|
|
<Stepper steps={2} current={2} className="mb-12" />
|
|
|
|
<Heading2 className="!mt-0">Lorem ipsum</Heading2>
|
|
|
|
<Paragraph>Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum</Paragraph>
|
2024-01-16 22:07:21 +01:00
|
|
|
<AuthInputBox value={url} onChange={setUrl} placeholder="lorem ipsum" />
|
|
|
|
{error ? <p>url invalid</p> : null}
|
|
|
|
<Button onClick={() => navigate("/onboarding")} loading={loading}>
|
|
|
|
Backagd
|
2024-01-16 20:28:33 +01:00
|
|
|
</Button>
|
2024-01-16 22:07:21 +01:00
|
|
|
<Button onClick={test}>Submit proxy</Button>
|
2024-01-16 20:28:33 +01:00
|
|
|
</CenterContainer>
|
|
|
|
</MinimalPageLayout>
|
|
|
|
);
|
|
|
|
}
|