Added notification center to header
Deploy Frontend / build-and-deploy (push) Successful in 33s
Details
Deploy Frontend / build-and-deploy (push) Successful in 33s
Details
This commit is contained in:
parent
ca9736af21
commit
f1e21f2112
|
|
@ -1,14 +1,89 @@
|
|||
import {
|
||||
Group, Burger, Text, Avatar, Menu, ActionIcon, Button, Kbd, Breadcrumbs, Box, UnstyledButton,
|
||||
useMantineColorScheme, useComputedColorScheme,
|
||||
Popover, Indicator, ThemeIcon, Stack, ScrollArea,
|
||||
} from '@mantine/core'
|
||||
import { spotlight } from '@mantine/spotlight'
|
||||
import { IconLogout, IconSearch, IconSun, IconMoon, IconUser } from '@tabler/icons-react'
|
||||
import {
|
||||
IconLogout, IconSearch, IconBell, IconBriefcase, IconCheck, IconX, type Icon
|
||||
} from '@tabler/icons-react'
|
||||
import { useLocation } from 'react-router-dom'
|
||||
import { useAuth } from '@/hooks/useAuth'
|
||||
import { findTrail } from './navigation'
|
||||
import { ColorSchemeToggle } from '@/components/ui/ColorSchemeToggle'
|
||||
|
||||
// Заглушки для Центра уведомлений
|
||||
const MOCK_NOTIFICATIONS = [
|
||||
{
|
||||
id: 1,
|
||||
title: 'Новая задача',
|
||||
text: 'Вам назначена задача по заявке #1024: «Подготовить договор»',
|
||||
time: '10 мин назад',
|
||||
icon: IconBriefcase,
|
||||
color: 'blue',
|
||||
unread: true,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
title: 'Заявка согласована',
|
||||
text: 'Заявка #980 успешно согласована всеми участниками',
|
||||
time: '1 час назад',
|
||||
icon: IconCheck,
|
||||
color: 'green',
|
||||
unread: true,
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
title: 'Заявка отклонена',
|
||||
text: 'Иван Иванов отклонил вашу заявку #975',
|
||||
time: 'Вчера, 15:30',
|
||||
icon: IconX,
|
||||
color: 'red',
|
||||
unread: false,
|
||||
},
|
||||
]
|
||||
|
||||
function NotificationItem({
|
||||
title, text, time, icon: IconCmp, color, unread
|
||||
}: {
|
||||
title: string; text: string; time: string; icon: Icon; color: string; unread: boolean
|
||||
}) {
|
||||
return (
|
||||
<UnstyledButton
|
||||
p="sm"
|
||||
style={(theme) => ({
|
||||
borderBottom: '1px solid var(--mantine-color-default-border)',
|
||||
width: '100%',
|
||||
backgroundColor: unread ? 'var(--mantine-color-default-hover)' : 'transparent',
|
||||
transition: 'background-color 150ms',
|
||||
'&:hover': { backgroundColor: 'var(--mantine-color-default-hover)' },
|
||||
})}
|
||||
>
|
||||
<Group wrap="nowrap" align="flex-start">
|
||||
<ThemeIcon variant="light" color={color} size={32} radius="xl">
|
||||
<IconCmp size={16} stroke={2} />
|
||||
</ThemeIcon>
|
||||
<Box style={{ flex: 1, minWidth: 0 }}>
|
||||
<Group justify="space-between" wrap="nowrap" align="flex-start">
|
||||
<Text size="sm" fw={600} truncate>{title}</Text>
|
||||
{unread && (
|
||||
<Box
|
||||
w={8} h={8} mt={6}
|
||||
style={{
|
||||
borderRadius: '50%',
|
||||
background: 'var(--mantine-primary-color-filled)',
|
||||
flexShrink: 0
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</Group>
|
||||
<Text size="xs" c="dimmed" lineClamp={2} mt={2}>{text}</Text>
|
||||
<Text size="xs" c="dimmed" mt={4}>{time}</Text>
|
||||
</Box>
|
||||
</Group>
|
||||
</UnstyledButton>
|
||||
)
|
||||
}
|
||||
|
||||
interface HeaderProps {
|
||||
toggleMobile: () => void
|
||||
toggleDesktop: () => void
|
||||
|
|
@ -22,6 +97,8 @@ export default function Header({ toggleMobile, toggleDesktop, mobileOpened, desk
|
|||
const trail = findTrail(pathname)
|
||||
const role = user?.is_root ? 'Суперадмин' : user?.is_observer ? 'Наблюдатель' : 'Администратор'
|
||||
|
||||
const unreadCount = MOCK_NOTIFICATIONS.filter((n) => n.unread).length
|
||||
|
||||
return (
|
||||
<Group h="100%" px="md" justify="space-between" wrap="nowrap">
|
||||
<Group gap="sm" wrap="nowrap">
|
||||
|
|
@ -72,6 +149,43 @@ export default function Header({ toggleMobile, toggleDesktop, mobileOpened, desk
|
|||
<IconSearch size={18} stroke={1.6} />
|
||||
</ActionIcon>
|
||||
|
||||
{/* Центр уведомлений */}
|
||||
<Popover width={320} position="bottom-end" shadow="md">
|
||||
<Popover.Target>
|
||||
<Indicator
|
||||
color="brand"
|
||||
size={9}
|
||||
offset={5}
|
||||
disabled={unreadCount === 0}
|
||||
withBorder
|
||||
>
|
||||
<ActionIcon size="lg" aria-label="Уведомления" variant="subtle" color="gray">
|
||||
<IconBell size={20} stroke={1.6} />
|
||||
</ActionIcon>
|
||||
</Indicator>
|
||||
</Popover.Target>
|
||||
<Popover.Dropdown p={0}>
|
||||
<Group justify="space-between" px="md" py="xs" style={{ borderBottom: '1px solid var(--mantine-color-default-border)' }}>
|
||||
<Text size="sm" fw={600}>Уведомления</Text>
|
||||
{unreadCount > 0 && (
|
||||
<Button variant="subtle" size="compact-xs">Прочитать все</Button>
|
||||
)}
|
||||
</Group>
|
||||
|
||||
<ScrollArea.Autosize mah={360} type="auto">
|
||||
{MOCK_NOTIFICATIONS.length > 0 ? (
|
||||
<Stack gap={0}>
|
||||
{MOCK_NOTIFICATIONS.map((notif) => (
|
||||
<NotificationItem key={notif.id} {...notif} />
|
||||
))}
|
||||
</Stack>
|
||||
) : (
|
||||
<Text size="sm" c="dimmed" ta="center" py="xl">Нет новых уведомлений</Text>
|
||||
)}
|
||||
</ScrollArea.Autosize>
|
||||
</Popover.Dropdown>
|
||||
</Popover>
|
||||
|
||||
<ColorSchemeToggle />
|
||||
|
||||
<Menu width={220} position="bottom-end">
|
||||
|
|
|
|||
Loading…
Reference in New Issue