fix(frontend): use workspaceInfo API to get full workspace data for sidebar
This commit is contained in:
parent
a1ebe47564
commit
2afad11cb6
@ -1,7 +1,8 @@
|
||||
import {Outlet} from 'react-router-dom';
|
||||
import {WorkspaceSidebar} from '@/components/layout/workspace-sidebar';
|
||||
import {useQuery} from '@tanstack/react-query';
|
||||
import {workspaceList, type WorkspaceInfoResponse} from '@/client';
|
||||
import {workspaceList, workspaceInfo} from '@/client';
|
||||
import type {WorkspaceInfoResponse} from '@/client';
|
||||
import {WorkspaceSidebar} from '@/components/layout/workspace-sidebar';
|
||||
import {Spinner} from '@/components/ui/spinner';
|
||||
|
||||
export default function HomePageLayout() {
|
||||
@ -13,7 +14,20 @@ export default function HomePageLayout() {
|
||||
},
|
||||
});
|
||||
|
||||
if (isLoading) {
|
||||
const first = data?.workspaces?.[0];
|
||||
const slug = first?.slug;
|
||||
|
||||
const {data: workspaceInfoData, isLoading: infoLoading} = useQuery({
|
||||
queryKey: ['workspaceInfo', slug],
|
||||
queryFn: async (): Promise<WorkspaceInfoResponse> => {
|
||||
if (!slug) throw new Error('no slug');
|
||||
const resp = await workspaceInfo({path: {slug}});
|
||||
return resp.data!.data!;
|
||||
},
|
||||
enabled: !!slug,
|
||||
});
|
||||
|
||||
if (isLoading || infoLoading) {
|
||||
return (
|
||||
<div className="flex h-screen w-full items-center justify-center bg-background">
|
||||
<Spinner/>
|
||||
@ -21,8 +35,7 @@ export default function HomePageLayout() {
|
||||
);
|
||||
}
|
||||
|
||||
const first = data?.workspaces?.[0];
|
||||
if (!first) {
|
||||
if (!workspaceInfoData) {
|
||||
return (
|
||||
<div className="flex h-screen w-full items-center justify-center bg-background">
|
||||
<div className="text-muted-foreground">Loading workspace...</div>
|
||||
@ -30,21 +43,9 @@ export default function HomePageLayout() {
|
||||
);
|
||||
}
|
||||
|
||||
const workspace: WorkspaceInfoResponse = {
|
||||
slug: first.slug,
|
||||
name: first.name,
|
||||
description: first.description ?? null,
|
||||
my_role: first.my_role,
|
||||
avatar_url: first.avatar_url ?? null,
|
||||
member_count: data?.member_count ?? 0,
|
||||
project_count: data?.project_count ?? 0,
|
||||
created_at: first.created_at,
|
||||
updated_at: first.updated_at ?? first.created_at,
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex h-screen w-full bg-background">
|
||||
<WorkspaceSidebar workspace={workspace}/>
|
||||
<WorkspaceSidebar workspace={workspaceInfoData}/>
|
||||
<main className="flex-1 overflow-y-auto">
|
||||
<Outlet/>
|
||||
</main>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user