import { useState } from "react"; import { useAsyncFn } from "react-use"; import { MetaResponse, getBackendMeta } from "@/backend/accounts/meta"; import { Button } from "@/components/buttons/Button"; import { Icon, Icons } from "@/components/Icon"; import { Box } from "@/components/layout/Box"; import { Divider } from "@/components/utils/Divider"; import { Heading2 } from "@/components/utils/Text"; import { conf } from "@/setup/config"; export function BackendTestPart() { const backendUrl = conf().BACKEND_URL; const [status, setStatus] = useState<{ hasTested: boolean; success: boolean; errorText: string; value: MetaResponse | null; }>({ hasTested: false, success: false, errorText: "", value: null, }); const [testState, runTests] = useAsyncFn(async () => { setStatus({ hasTested: false, success: false, errorText: "", value: null, }); try { const backendData = await getBackendMeta(backendUrl); return setStatus({ hasTested: true, success: true, errorText: "Failed to call backend, double check the URL key and your internet connection", value: backendData, }); } catch (err) { return setStatus({ hasTested: true, success: false, errorText: "Failed to call backend, double check the URL key and your internet connection", value: null, }); } }, [setStatus]); return ( <> Backend API test
{status.hasTested && status.success ? ( <>

Version: {status.value?.version}

Backend name: {status.value?.name}

Description: {status.value?.description ?? "Not set"}

Captcha enabled: {status.value?.hasCaptcha ? "Yes" : "No"}

) : null}
{!status.hasTested ? (

Run the test to validate backend

) : status.success ? (

Backend is working as expected

) : (

Backend is not working

{status.errorText}

)}
); }