fix: prevent new workspace modal from getting stuck in an open state (#173)

This commit is contained in:
Henry
2025-09-11 22:29:48 +01:00
committed by GitHub
parent 2f88366418
commit 4ee1d6f2d5
3 changed files with 47 additions and 42 deletions

View File

@@ -47,12 +47,16 @@ export const WorkspaceProvider: React.FC<{ children: ReactNode }> = ({
const [hasLoaded, setHasLoaded] = useState(false);
const { data, isLoading } = api.workspace.all.useQuery();
const utils = api.useUtils();
const switchWorkspace = (_workspace: Workspace) => {
localStorage.setItem("workspacePublicId", _workspace.publicId);
setWorkspace(_workspace);
// Refetch workspace data to ensure availableWorkspaces is up to date
void utils.workspace.all.refetch();
router.push(`/boards`);
};
@@ -66,21 +70,15 @@ export const WorkspaceProvider: React.FC<{ children: ReactNode }> = ({
localStorage.getItem("workspacePublicId");
if (data.length) {
const workspaces = data
.map(({ workspace, role }) => {
if (!workspace) return;
return {
role,
publicId: workspace.publicId,
name: workspace.name,
slug: workspace.slug,
description: workspace.description,
plan: workspace.plan,
hasLoaded: true,
};
})
.filter((workspace) => workspace !== null) as Workspace[];
const workspaces = data.map(({ workspace, role }) => ({
role,
publicId: workspace.publicId,
name: workspace.name,
slug: workspace.slug,
description: workspace.description,
plan: workspace.plan,
hasLoaded: true,
})) as Workspace[];
if (workspaces.length) setAvailableWorkspaces(workspaces);
}
@@ -116,7 +114,7 @@ export const WorkspaceProvider: React.FC<{ children: ReactNode }> = ({
role: primaryWorkspaceRole,
});
}
}, [data]);
}, [data, isLoading]);
return (
<WorkspaceContext.Provider