crm/frontend/src/components/Layouts/AppSidebar.vue
2024-01-29 22:53:49 +05:30

199 lines
5.2 KiB
Vue

<template>
<div
class="flex h-full flex-col justify-between transition-all duration-300 ease-in-out"
:class="isSidebarCollapsed ? 'w-12' : 'w-56'"
>
<div>
<UserDropdown class="p-2" :isCollapsed="isSidebarCollapsed" />
</div>
<div class="flex-1 overflow-y-auto">
<div class="mb-3 flex flex-col">
<SidebarLink
label="Notifications"
:icon="NotificationsIcon"
:isCollapsed="isSidebarCollapsed"
@click="() => toggleNotificationPanel()"
class="mx-2 my-0.5"
/>
</div>
<div v-for="view in allViews" :key="view.label">
<div
v-if="!view.hideLabel && isSidebarCollapsed && view.views?.length"
class="mx-2 my-2 h-1 border-b"
/>
<Section
:label="view.name"
:hideLabel="view.hideLabel"
:isOpened="view.opened"
>
<template #header="{ opened, hide, toggle }">
<div
v-if="!hide"
class="flex cursor-pointer gap-1.5 px-1 text-sm font-medium text-gray-600 transition-all duration-300 ease-in-out"
:class="
isSidebarCollapsed
? 'ml-0 h-0 overflow-hidden opacity-0'
: 'ml-2 mt-4 h-7 w-auto opacity-100'
"
@click="toggle()"
>
<FeatherIcon
name="chevron-right"
class="h-4 text-gray-900 transition-all duration-300 ease-in-out"
:class="{ 'rotate-90': opened }"
/>
<span class="uppercase">
{{ view.name }}
</span>
</div>
</template>
<nav class="flex flex-col">
<SidebarLink
v-for="link in view.views"
:icon="link.icon"
:label="link.label"
:to="link.to"
:isCollapsed="isSidebarCollapsed"
class="mx-2 my-0.5"
/>
</nav>
</Section>
</div>
</div>
<SidebarLink
:label="isSidebarCollapsed ? 'Expand' : 'Collapse'"
:isCollapsed="isSidebarCollapsed"
@click="isSidebarCollapsed = !isSidebarCollapsed"
class="m-2"
>
<template #icon>
<span class="grid h-5 w-6 flex-shrink-0 place-items-center">
<CollapseSidebar
class="h-4.5 w-4.5 text-gray-700 duration-300 ease-in-out"
:class="{ '[transform:rotateY(180deg)]': isSidebarCollapsed }"
/>
</span>
</template>
</SidebarLink>
</div>
</template>
<script setup>
import Section from '@/components/Section.vue'
import EmailIcon from '@/components/Icons/EmailIcon.vue'
import PinIcon from '@/components/Icons/PinIcon.vue'
import UserDropdown from '@/components/UserDropdown.vue'
import LeadsIcon from '@/components/Icons/LeadsIcon.vue'
import DealsIcon from '@/components/Icons/DealsIcon.vue'
import ContactsIcon from '@/components/Icons/ContactsIcon.vue'
import OrganizationsIcon from '@/components/Icons/OrganizationsIcon.vue'
import NoteIcon from '@/components/Icons/NoteIcon.vue'
import PhoneIcon from '@/components/Icons/PhoneIcon.vue'
import CollapseSidebar from '@/components/Icons/CollapseSidebar.vue'
import NotificationsIcon from '@/components/Icons/NotificationsIcon.vue'
import SidebarLink from '@/components/SidebarLink.vue'
import { viewsStore } from '@/stores/views'
import { notificationsStore } from '@/stores/notifications'
import { globalStore } from '@/stores/global'
import { computed } from 'vue'
const { getPinnedViews, getPublicViews } = viewsStore()
const { toggle: toggleNotificationPanel } = notificationsStore()
const isSidebarCollapsed = computed({
get: () => globalStore().isSidebarCollapsed,
set: (value) => globalStore().setIsSidebarCollapsed(value),
})
const links = [
{
label: 'Leads',
icon: LeadsIcon,
to: 'Leads',
},
{
label: 'Deals',
icon: DealsIcon,
to: 'Deals',
},
{
label: 'Contacts',
icon: ContactsIcon,
to: 'Contacts',
},
{
label: 'Organizations',
icon: OrganizationsIcon,
to: 'Organizations',
},
{
label: 'Notes',
icon: NoteIcon,
to: 'Notes',
},
{
label: 'Call Logs',
icon: PhoneIcon,
to: 'Call Logs',
},
{
label: 'Email Templates',
icon: EmailIcon,
to: 'Email Templates',
},
]
const allViews = computed(() => {
return [
{
name: 'All Views',
hideLabel: true,
opened: true,
views: links,
},
{
name: 'Public views',
opened: true,
views: parseView(getPublicViews()),
},
{
name: 'Pinned views',
opened: true,
views: parseView(getPinnedViews()),
},
]
})
function parseView(views) {
return views.map((view) => {
return {
label: view.label,
icon: getIcon(view.route_name),
to: {
name: view.route_name,
query: { view: view.name },
},
}
})
}
function getIcon(routeName) {
switch (routeName) {
case 'Leads':
return LeadsIcon
case 'Deals':
return DealsIcon
case 'Contacts':
return ContactsIcon
case 'Organizations':
return OrganizationsIcon
case 'Notes':
return NoteIcon
case 'Call Logs':
return PhoneIcon
default:
return PinIcon
}
}
</script>