plane/web/lib/wrappers/instance-wrapper.tsx
2024-05-01 14:54:35 +05:30

45 lines
1.2 KiB
TypeScript

import { FC, ReactNode } from "react";
import { observer } from "mobx-react";
import useSWR from "swr";
// ui
import { Spinner } from "@plane/ui";
// components
import { InstanceNotReady } from "@/components/instance";
// hooks
import { useInstance } from "@/hooks/store";
type TInstanceWrapper = {
children: ReactNode;
};
export const InstanceWrapper: FC<TInstanceWrapper> = observer((props) => {
const { children } = props;
// store
const { isLoading, instance, error, fetchInstanceInfo } = useInstance();
useSWR("INSTANCE_INFORMATION", () => fetchInstanceInfo(), {
revalidateOnFocus: false,
});
// loading state
if (isLoading)
return (
<div className="relative flex h-screen w-full items-center justify-center">
<Spinner />
</div>
);
// something went wrong while in the request
if (error && error?.status === "error")
return (
<div className="relative flex h-screen w-screen items-center justify-center">
Something went wrong. please try again later
</div>
);
// instance is not ready and setup is not done
if (instance?.instance?.is_setup_done === false) return <InstanceNotReady />;
return <>{children}</>;
});