-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
clients/web/docs: fix user menu not loading on static pages
- Loading branch information
1 parent
60ba4fc
commit f2c5901
Showing
4 changed files
with
99 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
clients/apps/web/src/components/Documentation/UserMenu.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
'use client' | ||
|
||
import { PolarMenu } from '@/app/[organization]/(sidebar)/LayoutPolarMenu' | ||
import { useListAdminOrganizations } from '@/hooks/queries' | ||
import { api } from '@/utils/api' | ||
import { UserRead } from '@polar-sh/sdk' | ||
import { Skeleton } from 'polarkit/components/ui/skeleton' | ||
import { useCallback, useEffect, useState } from 'react' | ||
|
||
const UserMenu = () => { | ||
const [loaded, setLoaded] = useState(false) | ||
const [currentUser, setCurrentUser] = useState<UserRead | undefined>() | ||
const { data: organizations, refetch } = useListAdminOrganizations(false) | ||
|
||
const reload = useCallback(async (): Promise<undefined> => { | ||
try { | ||
const user = await api.users.getAuthenticated() | ||
setCurrentUser(user) | ||
await refetch() | ||
} catch { | ||
} finally { | ||
setLoaded(true) | ||
} | ||
}, [refetch]) | ||
|
||
useEffect(() => { | ||
reload() | ||
}, [reload]) | ||
|
||
if (!loaded) { | ||
return ( | ||
<div className="flex h-9 flex-row items-center gap-x-6"> | ||
<div className="relative flex w-max flex-shrink-0 flex-row items-center justify-between gap-x-6"> | ||
<Skeleton className="h-8 w-40 rounded-full" /> | ||
<Skeleton className="h-10 w-10 rounded-full" /> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
return ( | ||
<PolarMenu | ||
authenticatedUser={currentUser} | ||
userAdminOrganizations={organizations?.items ?? []} | ||
/> | ||
) | ||
} | ||
|
||
export default UserMenu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters