Files
classroomio/apps/dashboard/src/lib/components/Org/SideBar.svelte
T

181 lines
6.9 KiB
Svelte
Raw Normal View History

2023-09-11 11:47:30 +01:00
<script lang="ts">
2025-11-01 15:49:29 +01:00
import { page } from '$app/state';
import Avatar from '$lib/components/Avatar/index.svelte';
2025-11-01 15:49:29 +01:00
import LayoutDashboardIcon from '@lucide/svelte/icons/layout-dashboard';
import LibraryBigIcon from '@lucide/svelte/icons/library-big';
import UsersIcon from '@lucide/svelte/icons/users';
import ChevronRightIcon from '@lucide/svelte/icons/chevron-right';
2025-11-01 16:18:29 +01:00
import Settings2 from '@lucide/svelte/icons/settings-2';
2025-11-01 15:49:29 +01:00
import MessageSquareMoreIcon from '@lucide/svelte/icons/message-square-more';
import BadgeHelpIcon from '@lucide/svelte/icons/badge-help';
import Dice6Icon from '@lucide/svelte/icons/dice-6';
import LayoutTemplateIcon from '@lucide/svelte/icons/layout-template';
import OrgSelector from '$lib/components/OrgSelector/OrgSelector.svelte';
import PrimaryButton from '$lib/components/PrimaryButton/index.svelte';
2024-09-30 01:36:12 +01:00
import { currentOrgPath, isFreePlan } from '$lib/utils/store/org';
2024-04-07 06:08:34 +01:00
import { goto } from '$app/navigation';
2024-09-30 01:36:12 +01:00
import ProfileMenu from '$lib/components/Org/ProfileMenu/index.svelte';
import { NavClasses } from '$lib/utils/constants/reusableClass';
import { t } from '$lib/utils/functions/translations';
import { isOrgAdmin } from '$lib/utils/store/org';
import { profile } from '$lib/utils/store/user';
import { profileMenu, sideBar } from './store';
2025-11-01 15:49:29 +01:00
interface MenuItems {
2024-04-07 06:08:34 +01:00
label: string;
2024-04-19 05:45:48 +01:00
path: string;
2024-04-07 06:08:34 +01:00
show: boolean;
isActive: boolean;
2024-04-19 05:45:48 +01:00
}
2023-09-11 11:47:30 +01:00
function isActive(pagePath: string, itemPath: string) {
const pageLinkItems = pagePath.split('/');
const itemLinkItems = itemPath.split('/');
if (itemLinkItems.length !== pageLinkItems.length) {
return false;
}
return pagePath.includes(itemPath);
}
const toggleSidebar = () => {
2023-11-01 09:45:40 +00:00
$sideBar.hidden = !$sideBar.hidden;
};
2024-04-07 06:08:34 +01:00
const openModal = () => {
goto(window.location.pathname + '?upgrade=true');
};
2025-11-01 15:49:29 +01:00
const menuItems: MenuItems[] = $derived.by(() => [
2024-04-19 05:45:48 +01:00
{
path: '',
label: $t('org_navigation.dashboard'),
2025-11-01 15:49:29 +01:00
isActive: isActive(page.url.pathname, `${$currentOrgPath}`),
2024-04-19 05:45:48 +01:00
show: true
},
{
path: '/courses',
label: $t('org_navigation.courses'),
2025-11-01 15:49:29 +01:00
isActive: page.url.pathname.includes(`${$currentOrgPath}/courses`),
2024-04-19 05:45:48 +01:00
show: true
},
{
path: '/community',
label: $t('org_navigation.community'),
2025-11-01 15:49:29 +01:00
isActive: page.url.pathname.includes(`${$currentOrgPath}/community`),
2024-04-19 05:45:48 +01:00
show: true
},
{
path: '/audience',
label: $t('org_navigation.audience'),
2025-11-01 15:49:29 +01:00
isActive: page.url.pathname.includes(`${$currentOrgPath}/audience`),
2024-04-19 05:45:48 +01:00
show: true
},
{
path: '/setup',
label: $t('org_navigation.setup'),
2025-11-01 15:49:29 +01:00
isActive: page.url.pathname.includes(`${$currentOrgPath}/setup`),
show: !!$isOrgAdmin
2024-04-19 05:45:48 +01:00
}
2025-11-01 15:49:29 +01:00
]);
</script>
2024-09-30 01:36:12 +01:00
<div bind:this={$profileMenu.ref} class="static md:relative">
<aside
class={`${
$sideBar.hidden
? 'absolute top-[48px] z-40 -translate-x-[100%] md:relative md:top-0 md:translate-x-0'
: 'absolute top-[48px] z-40 translate-x-0 md:relative md:top-0'
} border-r-1 h-[calc(100vh-48px)] w-[250px] min-w-[250px] overflow-y-auto border border-b-0 border-l-0 border-t-0 border-gray-100 bg-gray-100 transition dark:border-neutral-600 dark:bg-neutral-900`}
2024-09-30 01:36:12 +01:00
>
<div class="flex h-full flex-col">
<div class="">
<OrgSelector />
<ul class="my-2 mt-4 px-4">
2024-09-30 01:36:12 +01:00
{#each menuItems as menuItem}
{#if menuItem.show}
2025-11-01 15:49:29 +01:00
<a href="{$currentOrgPath}{menuItem.path}" class="text-black no-underline" onclick={toggleSidebar}>
2024-09-30 01:36:12 +01:00
<li
2025-11-01 16:18:29 +01:00
class="group mb-1 flex items-center gap-2.5 px-2.5 py-2 {NavClasses.item} {menuItem.isActive
2024-09-30 01:36:12 +01:00
? NavClasses.active
: 'dark:text-white'}"
>
{#if menuItem.path === ''}
2025-11-01 16:18:29 +01:00
<LayoutDashboardIcon size={16} class="group-hover:animate-gather" />
2024-09-30 01:36:12 +01:00
{:else if menuItem.path === '/courses'}
2025-11-01 16:18:29 +01:00
<LibraryBigIcon size={16} class="group-hover:animate-library-expand" />
2024-09-30 01:36:12 +01:00
{:else if menuItem.path === '/site'}
2025-11-01 16:18:29 +01:00
<LayoutTemplateIcon size={16} class="group-hover:animate-template-morph" />
2024-09-30 01:36:12 +01:00
{:else if menuItem.path === '/community'}
2025-11-01 16:18:29 +01:00
<MessageSquareMoreIcon size={16} class="group-hover:animate-ripple" />
2024-09-30 01:36:12 +01:00
{:else if menuItem.path === '/quiz'}
2025-11-01 16:18:29 +01:00
<Dice6Icon size={16} class="group-hover:animate-roll" />
2024-09-30 01:36:12 +01:00
{:else if menuItem.path === '/audience'}
2025-11-01 16:18:29 +01:00
<UsersIcon size={16} class="group-hover:animate-gather" />
2024-09-30 01:36:12 +01:00
{:else if menuItem.path === '/setup'}
2025-11-01 16:18:29 +01:00
<Settings2 size={16} class="group-hover:animate-setup-configure" />
2024-09-30 01:36:12 +01:00
{/if}
<p class="text-sm font-medium">{menuItem.label}</p>
</li>
</a>
{/if}
{/each}
</ul>
</div>
2025-11-01 15:49:29 +01:00
<span class="flex-grow"></span>
2024-09-30 01:36:12 +01:00
{#if $isFreePlan}
<div
class="border-primary-700 mx-4 flex flex-col items-center justify-center gap-4 rounded-md border px-2 py-6 text-center transition-all ease-in-out hover:scale-95"
2024-09-30 01:36:12 +01:00
>
<img src="/upgrade.png" alt="upgrade" class="h-16 w-16" />
<span class="flex flex-col gap-1">
<p class="text-base font-semibold">{$t('org_navigation.early_adopter')}</p>
<p class="text-xs">{$t('org_navigation.unlock')}</p>
</span>
2025-11-01 15:49:29 +01:00
<PrimaryButton label={$t('org_navigation.upgrade')} onClick={openModal} className="font-normal" />
2024-09-30 01:36:12 +01:00
</div>
{/if}
<ul class="my-5 px-4 pb-5">
2025-11-01 15:49:29 +01:00
<a href={$currentOrgPath} class="text-black no-underline" onclick={toggleSidebar}>
2024-09-30 01:36:12 +01:00
<li class="mb-2 flex items-center rounded px-2.5 py-1.5">
2025-11-01 15:49:29 +01:00
<BadgeHelpIcon size={16} />
<p class="ml-2.5 text-sm font-medium dark:text-white">{$t('org_navigation.help')}</p>
2024-09-30 01:36:12 +01:00
</li>
</a>
<button
class="w-full"
2025-11-01 15:49:29 +01:00
onclick={() => {
2024-09-30 01:36:12 +01:00
$profileMenu.open = !$profileMenu.open;
$sideBar.hidden = true;
}}
>
<div
2025-11-01 15:49:29 +01:00
class="mb-2 flex cursor-pointer items-center justify-between gap-2.5 px-2.5 py-2 text-black no-underline {NavClasses.item} {page.url.pathname.includes(
2024-10-08 22:17:05 +01:00
'settings'
)
? NavClasses.active
: 'dark:text-white'}"
2024-09-30 01:36:12 +01:00
>
<div class="flex w-full items-center justify-start space-x-1 text-start">
2025-11-01 15:49:29 +01:00
<Avatar src={$profile.avatar_url} name={$profile.username} width="w-[1.2rem]" height="h-[1.2rem]" />
<p class="max-w-full truncate text-sm font-medium dark:text-white">
{$profile.fullname}
</p>
2024-09-30 01:36:12 +01:00
</div>
<div>
2025-11-01 15:49:29 +01:00
<ChevronRightIcon size={16} />
2024-09-30 01:36:12 +01:00
</div>
</div>
</button>
</ul>
</div>
2024-09-30 01:36:12 +01:00
</aside>
2024-04-07 06:08:34 +01:00
2024-09-30 01:36:12 +01:00
<ProfileMenu />
</div>