import { FC, ReactNode } from "react"; import { observer } from "mobx-react"; import useSWR from "swr"; // components import { LogoSpinner } from "@/components/common"; import { InstanceNotReady } from "@/components/instance"; // hooks import { useInstance } from "@/hooks/store"; type TInstanceWrapper = { children: ReactNode; }; export const InstanceWrapper: FC = observer((props) => { const { children } = props; // store const { isLoading, instance, error, fetchInstanceInfo } = useInstance(); const { isLoading: isInstanceSWRLoading } = useSWR("INSTANCE_INFORMATION", () => fetchInstanceInfo(), { revalidateOnFocus: false, }); // loading state if ((isLoading || isInstanceSWRLoading) && !instance) return (
); // something went wrong while in the request if (error && error?.status === "error") return <>{children}; // instance is not ready and setup is not done if (instance?.is_setup_done === false) return ; return <>{children}; });