import { FC, ReactNode } from "react"; import { observer } from "mobx-react-lite"; import useSWR from "swr"; // components import { LogoSpinner } from "@/components/common"; import { InstanceSetupForm, InstanceFailureView } from "@/components/instance"; // hooks import { useInstance } from "@/hooks/store"; // layout import { DefaultLayout } from "@/layouts/default-layout"; type InstanceProviderProps = { children: ReactNode; }; export const InstanceProvider: FC = observer((props) => { const { children } = props; // store hooks const { instance, error, fetchInstanceInfo } = useInstance(); // fetching instance details useSWR("INSTANCE_DETAILS", () => fetchInstanceInfo(), { revalidateOnFocus: false, revalidateIfStale: false, errorRetryCount: 0, }); if (!instance && !error) return (
); if (error) { return (
); } if (!instance?.is_setup_done) { return (
); } return <>{children}; });