admin footer check

This commit is contained in:
Nate Kelley 2025-09-19 10:52:09 -06:00
parent 6efa72de40
commit a6680a4678
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
2 changed files with 61 additions and 51 deletions

View File

@ -1,5 +1,5 @@
import React, { useMemo } from 'react';
import { useGetUserBasicInfo } from '@/api/buster_rest/users/useGetUserInfo';
import { useGetUserBasicInfo, useIsUserAdmin } from '@/api/buster_rest/users/useGetUserInfo';
import { useSignOut } from '@/components/features/auth/useSignOut';
import { AvatarUserButton } from '@/components/ui/avatar/AvatarUserButton';
import { Button } from '@/components/ui/buttons';
@ -55,61 +55,69 @@ export const SidebarUserFooter: React.FC = React.memo(() => {
SidebarUserFooter.displayName = 'SidebarUserFooter';
const topItems: DropdownProps['items'] = [
{
label: 'Settings',
value: 'setting',
icon: <Gear />,
link: {
to: '/app/settings/profile',
},
},
{
label: 'Datasources',
value: 'datasources',
link: {
to: '/app/settings/datasources',
},
icon: <Database />,
},
{
label: 'Invite & manage members',
value: 'invite-manage-members',
icon: <UserGroup />,
link: {
to: '/app/settings/users',
},
},
{ type: 'divider' },
{
label: 'Docs',
value: 'docs',
link: BUSTER_DOCS_URL,
linkIcon: 'arrow-external',
icon: <Book2 />,
},
{
label: 'Contact support',
value: 'contact-support',
icon: <Message />,
onClick: () => toggleContactSupportModal('help'),
},
{
label: 'Leave feedback',
value: 'leave-feedback',
icon: <Flag />,
onClick: () => toggleContactSupportModal('feedback'),
},
{ type: 'divider' },
];
const topItems = ({ isAdmin }: { isAdmin: boolean }) =>
(
[
{
label: 'Settings',
value: 'setting',
icon: <Gear />,
link: {
to: '/app/settings/profile',
},
},
{
label: 'Datasources',
value: 'datasources',
link: {
to: '/app/settings/datasources',
},
icon: <Database />,
show: isAdmin,
},
{
label: 'Invite & manage members',
value: 'invite-manage-members',
icon: <UserGroup />,
link: {
to: '/app/settings/users',
},
},
{ type: 'divider' },
{
label: 'Docs',
value: 'docs',
link: BUSTER_DOCS_URL,
linkIcon: 'arrow-external',
icon: <Book2 />,
},
{
label: 'Contact support',
value: 'contact-support',
icon: <Message />,
onClick: () => toggleContactSupportModal('help'),
},
{
label: 'Leave feedback',
value: 'leave-feedback',
icon: <Flag />,
onClick: () => toggleContactSupportModal('feedback'),
},
{ type: 'divider' },
] satisfies (DropdownProps['items'][number] & { show?: boolean })[]
).reduce<DropdownProps['items']>((acc, { show, ...item }) => {
if (show ?? true) acc.push(item);
return acc;
}, []);
const SidebarUserDropdown: React.FC<{
children: React.ReactNode;
signOut: () => void;
}> = ({ children, signOut }) => {
const isAdmin = useIsUserAdmin();
const allItems: DropdownProps['items'] = useMemo(() => {
return [
...topItems,
...topItems({ isAdmin }),
{
label: 'Logout',
value: 'logout',
@ -117,7 +125,7 @@ const SidebarUserDropdown: React.FC<{
icon: <ArrowRightFromLine />,
},
];
}, []);
}, [isAdmin]);
return (
<Dropdown align="start" side="top" items={allItems}>

View File

@ -1,6 +1,8 @@
import type { UserOrganization } from '@buster/server-shared/user';
export const checkIfUserIsAdmin = (userOrganization?: UserOrganization | null): boolean => {
export const checkIfUserIsAdmin = (
userOrganization?: Pick<UserOrganization, 'role'> | null
): boolean => {
if (!userOrganization) return false;
if (!userOrganization) return false;