add admin permission
This commit is contained in:
parent
3388eca2fe
commit
7ea73543b7
19 changed files with 1567 additions and 5 deletions
|
|
@ -10,16 +10,19 @@
|
|||
CherryIcon,
|
||||
DiamondIcon,
|
||||
BugIcon,
|
||||
CupSodaIcon
|
||||
CupSodaIcon,
|
||||
Shield
|
||||
} from '@lucide/svelte/icons';
|
||||
import TaobinLogo from '$lib/assets/logo.svelte';
|
||||
import { goto } from '$app/navigation';
|
||||
import Button from '$lib/components/ui/button/button.svelte';
|
||||
import { get } from 'svelte/store';
|
||||
import { sidebarStore } from '$lib/core/stores/sidebar';
|
||||
import { auth } from '$lib/core/stores/auth';
|
||||
import { isUserAdmin } from '$lib/core/admin/adminService';
|
||||
|
||||
let sideBar: HTMLElement | null = $state(null);
|
||||
let isSideBarOpen: boolean = $state(true);
|
||||
let isAdmin: boolean = $state(false);
|
||||
|
||||
const data = {
|
||||
navMain: [
|
||||
|
|
@ -68,10 +71,36 @@
|
|||
}
|
||||
]
|
||||
}
|
||||
// more to add here
|
||||
]
|
||||
};
|
||||
|
||||
const adminNav = {
|
||||
title: 'Admin',
|
||||
items: [
|
||||
{
|
||||
title: 'Permissions',
|
||||
url: '/admin/users',
|
||||
icon: Shield
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
$effect(() => {
|
||||
const currentUser = $auth;
|
||||
if (currentUser) {
|
||||
isUserAdmin(currentUser.uid)
|
||||
.then((result) => {
|
||||
isAdmin = result;
|
||||
})
|
||||
.catch((e) => {
|
||||
console.error('Error checking admin status:', e);
|
||||
isAdmin = false;
|
||||
});
|
||||
} else {
|
||||
isAdmin = false;
|
||||
}
|
||||
});
|
||||
|
||||
function onClickLogoIcon() {
|
||||
goto('/departments');
|
||||
}
|
||||
|
|
@ -123,6 +152,30 @@
|
|||
</Sidebar.GroupContent>
|
||||
</Sidebar.Group>
|
||||
{/each}
|
||||
|
||||
{#if isAdmin}
|
||||
<Sidebar.Group>
|
||||
<Sidebar.GroupLabel>{adminNav.title}</Sidebar.GroupLabel>
|
||||
<Sidebar.GroupContent>
|
||||
<Sidebar.Menu>
|
||||
{#each adminNav.items as sub}
|
||||
<Sidebar.MenuItem>
|
||||
<Sidebar.MenuButton>
|
||||
{#snippet child({ props })}
|
||||
<a href={sub.url} {...props}>
|
||||
{#if sub.icon}
|
||||
<sub.icon />
|
||||
{/if}
|
||||
<span>{sub.title}</span>
|
||||
</a>
|
||||
{/snippet}
|
||||
</Sidebar.MenuButton>
|
||||
</Sidebar.MenuItem>
|
||||
{/each}
|
||||
</Sidebar.Menu>
|
||||
</Sidebar.GroupContent>
|
||||
</Sidebar.Group>
|
||||
{/if}
|
||||
</Sidebar.Content>
|
||||
<Sidebar.Footer>
|
||||
<AppAccountSelect />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue