97 lines
4.5 KiB
TypeScript
97 lines
4.5 KiB
TypeScript
import { useNotification } from '@/features/notifications/hooks/useNotifications'
|
||
import { Drawer, Stack, Text, Badge, Skeleton, Box, Group } from '@mantine/core'
|
||
import { DataTable, type Column } from '@/components/ui/DataTable'
|
||
import classes from '@/components/UserDrawer.module.css'
|
||
|
||
interface Props {
|
||
notificationId: number | null
|
||
opened: boolean
|
||
onClose: () => void
|
||
}
|
||
|
||
const RECIPIENT_STATUS_LABELS: Record<string, { label: string; color: string }> = {
|
||
pending: { label: 'В очереди', color: 'gray' },
|
||
sent: { label: 'Доставлено', color: 'green' },
|
||
failed: { label: 'Ошибка', color: 'red' },
|
||
}
|
||
|
||
export default function NotificationDetailsDrawer({ notificationId, opened, onClose }: Props) {
|
||
const { data: notification, isLoading } = useNotification(notificationId)
|
||
|
||
const columns: Column<any>[] = [
|
||
{
|
||
key: 'user',
|
||
header: 'Пользователь',
|
||
cell: (r) => <Text size="sm" fw={500}>{r.user?.full_name || `ID ${r.user_id}`}</Text>
|
||
},
|
||
{
|
||
key: 'status',
|
||
header: 'Статус',
|
||
width: 120,
|
||
cell: (r) => {
|
||
const statusInfo = RECIPIENT_STATUS_LABELS[r.status || ''] || { label: r.status || '—', color: 'gray' }
|
||
return <Badge color={statusInfo.color} variant="light" size="sm">{statusInfo.label}</Badge>
|
||
}
|
||
},
|
||
{
|
||
key: 'error',
|
||
header: 'Лог ошибки',
|
||
cell: (r) => <Text size="xs" c="red" lineClamp={2}>{r.error_message || '—'}</Text>
|
||
}
|
||
]
|
||
|
||
return (
|
||
<Drawer.Root opened={opened} onClose={onClose} position="right" size="min(640px, 100vw)">
|
||
<Drawer.Overlay backgroundOpacity={0.25} />
|
||
<Drawer.Content>
|
||
<Drawer.Header>
|
||
<Box style={{ minWidth: 0 }}>
|
||
<Group gap="sm" wrap="nowrap">
|
||
<Text fw={600}>Детали уведомления</Text>
|
||
{notification && <Badge variant="light" color="gray">ID {notification.id}</Badge>}
|
||
</Group>
|
||
</Box>
|
||
<Drawer.CloseButton />
|
||
</Drawer.Header>
|
||
|
||
<Drawer.Body className={classes.body} pb="xl">
|
||
{isLoading ? (
|
||
<Stack className={classes.section} gap="md">
|
||
<Skeleton h={40} />
|
||
<Skeleton h={120} />
|
||
<Skeleton h={200} mt="lg" />
|
||
</Stack>
|
||
) : !notification ? (
|
||
<Text size="sm" c="dimmed">Уведомление не найдено</Text>
|
||
) : (
|
||
<Stack gap="xl" mt="sm">
|
||
<Box>
|
||
<Text size="sm" fw={600} mb="xs">Содержимое</Text>
|
||
<Box p="md" style={{ border: '1px solid var(--mantine-color-default-border)', borderRadius: 'var(--mantine-radius-md)', backgroundColor: 'var(--mantine-color-gray-0)' }}>
|
||
<Text fw={600} mb="sm">{notification.title}</Text>
|
||
<div
|
||
style={{ fontSize: 14 }}
|
||
dangerouslySetInnerHTML={{ __html: notification.message_html }}
|
||
/>
|
||
</Box>
|
||
</Box>
|
||
|
||
<Box>
|
||
<Text size="sm" fw={600} mb="xs">Получатели ({notification.recipients?.length || 0})</Text>
|
||
<Box style={{ border: '1px solid var(--mantine-color-default-border)', borderRadius: 'var(--mantine-radius-md)' }}>
|
||
<DataTable
|
||
columns={columns}
|
||
rows={notification.recipients || []}
|
||
getRowId={(r) => r.id!}
|
||
minWidth={400}
|
||
empty={{ title: 'Нет получателей' }}
|
||
/>
|
||
</Box>
|
||
</Box>
|
||
</Stack>
|
||
)}
|
||
</Drawer.Body>
|
||
</Drawer.Content>
|
||
</Drawer.Root>
|
||
)
|
||
} |