Skip to content

Commit

Permalink
Merge pull request #1402 from flanksource/stabalize-ui
Browse files Browse the repository at this point in the history
fix: make UI consistent as user waits for backend creation
  • Loading branch information
moshloop authored Sep 18, 2023
2 parents 7370807 + e7e2f8d commit a6fe0da
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/components/Authentication/Clerk/ClerkAuthContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export default function ClerkAuthContextProvider({
// when organization is switched, we need to re-fetch the user and the UI
const { organization } = useOrganization();

const backendURL = organization?.publicMetadata.backend_url;

const {
data: payload,
isLoading,
Expand All @@ -25,17 +27,21 @@ export default function ClerkAuthContextProvider({
["user", "whoami", organization],
() => whoami(),
{
enabled: !!backendURL,
refetchOnWindowFocus: false,
refetchInterval: 0,
refetchOnReconnect: false
}
);

if (isLoading && !payload) {
return <FullPageSkeletonLoader />;
// if the organization backend is not yet created, we need to wait for it to
// be created before showing the UI
if (!backendURL) {
return <InstanceCreationInProgress />;
}

// if the organization backend is not yet created, we need to wait for it to
// if the organization backend returns a 404 or a 5xx error, we need to wait
// for it to be created before showing the UI
if (
error &&
(error.response?.status?.toString().startsWith("5") ||
Expand All @@ -44,6 +50,10 @@ export default function ClerkAuthContextProvider({
return <InstanceCreationInProgress />;
}

if (isLoading && !payload) {
return <FullPageSkeletonLoader />;
}

if (error && !payload) {
return <ErrorPage error={error} />;
}
Expand Down

0 comments on commit a6fe0da

Please sign in to comment.