Updated notification page design
Deploy Frontend / build-and-deploy (push) Successful in 27s
Details
Deploy Frontend / build-and-deploy (push) Successful in 27s
Details
This commit is contained in:
parent
30789b2642
commit
b181d9a4be
51
src/App.tsx
51
src/App.tsx
|
|
@ -6,7 +6,7 @@ import UsersPage from './pages/users/UsersPage'
|
|||
import RolesPage from './pages/roles/RolesPage'
|
||||
import ApprovalsPage from './pages/approvals/ApprovalsPage'
|
||||
import { useAuth } from './hooks/useAuth'
|
||||
import { Loader, Center, Text } from '@mantine/core'
|
||||
import { Loader, Center, Text, MantineProvider } from '@mantine/core'
|
||||
import DepartmentsPage from "@/pages/DepartmentsPage.tsx";
|
||||
import PermissionsPage from './pages/permissions/PermissionsPage'
|
||||
import HierarchiesPage from './pages/hierarchies/HierarchiesPage'
|
||||
|
|
@ -20,6 +20,7 @@ import ApprovalTasksPage from './pages/approvalTasks/ApprovalTasksPage'
|
|||
import FlowTreePage from "@/pages/flowNodes/FlowTreePage.tsx";
|
||||
import FlowTreeGuidePage from './pages/flowNodes/FlowTreeGuidePage'
|
||||
import NotificationsPage from "@/pages/notifications/NotificationsPage.tsx";
|
||||
import {ModalsProvider} from "@mantine/modals";
|
||||
|
||||
const Placeholder = ({ title }: { title: string }) => (
|
||||
<div style={{ padding: 40 }}>
|
||||
|
|
@ -48,29 +49,33 @@ function ProtectedRoute({ children }: { children: React.ReactNode }) {
|
|||
|
||||
function App() {
|
||||
return (
|
||||
<Routes>
|
||||
<Route path="/login" element={<Login />} />
|
||||
<MantineProvider>
|
||||
<ModalsProvider>
|
||||
<Routes>
|
||||
<Route path="/login" element={<Login />} />
|
||||
|
||||
<Route element={<ProtectedRoute><MainLayout /></ProtectedRoute>}>
|
||||
<Route path="/" element={<Placeholder title="Главная" /> } />
|
||||
<Route path="/notifications" element={<NotificationsPage />} />
|
||||
<Route path="/approval-dash" element={<Dashboard />} />
|
||||
<Route path="/nodes" element={<FlowTreePage/>} />
|
||||
<Route path="/users" element={<UsersPage />} />
|
||||
<Route path="/departments" element={<DepartmentsPage />} />
|
||||
<Route path="/roles" element={<RolesPage />} />
|
||||
<Route path="/approvals" element={<ApprovalsPage />} />
|
||||
<Route path="/permissions" element={<PermissionsPage />} />
|
||||
<Route path="/categories" element={<CategoriesPage />} />
|
||||
<Route path="/topics" element={<TopicsPage />} />
|
||||
<Route path="/executors" element={<TopicExecutorsPage />} />
|
||||
<Route path="/hierarchies" element={<HierarchiesPage />} />
|
||||
<Route path="/settings" element={<SettingsPage />} />
|
||||
<Route path="/admins" element={<AdminsPage />} />
|
||||
<Route path="/approval-tasks" element={<ApprovalTasksPage />} />
|
||||
<Route path="/guide/flow-trees" element={<FlowTreeGuidePage />} />
|
||||
</Route>
|
||||
</Routes>
|
||||
<Route element={<ProtectedRoute><MainLayout /></ProtectedRoute>}>
|
||||
<Route path="/" element={<Placeholder title="Главная" /> } />
|
||||
<Route path="/notifications" element={<NotificationsPage />} />
|
||||
<Route path="/approval-dash" element={<Dashboard />} />
|
||||
<Route path="/nodes" element={<FlowTreePage/>} />
|
||||
<Route path="/users" element={<UsersPage />} />
|
||||
<Route path="/departments" element={<DepartmentsPage />} />
|
||||
<Route path="/roles" element={<RolesPage />} />
|
||||
<Route path="/approvals" element={<ApprovalsPage />} />
|
||||
<Route path="/permissions" element={<PermissionsPage />} />
|
||||
<Route path="/categories" element={<CategoriesPage />} />
|
||||
<Route path="/topics" element={<TopicsPage />} />
|
||||
<Route path="/executors" element={<TopicExecutorsPage />} />
|
||||
<Route path="/hierarchies" element={<HierarchiesPage />} />
|
||||
<Route path="/settings" element={<SettingsPage />} />
|
||||
<Route path="/admins" element={<AdminsPage />} />
|
||||
<Route path="/approval-tasks" element={<ApprovalTasksPage />} />
|
||||
<Route path="/guide/flow-trees" element={<FlowTreeGuidePage />} />
|
||||
</Route>
|
||||
</Routes>
|
||||
</ModalsProvider>
|
||||
</MantineProvider>
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { useState, useMemo } from 'react'
|
||||
import {
|
||||
Paper, Stack, TextInput, Button, Group, MultiSelect, Checkbox,
|
||||
Text, FileButton, Image, ActionIcon, Divider, Alert,
|
||||
Text, FileButton, Image, ActionIcon, Divider, Alert, Badge,
|
||||
} from '@mantine/core'
|
||||
import { IconPhoto, IconX, IconSend, IconAlertCircle } from '@tabler/icons-react'
|
||||
import { IconPhoto, IconX, IconSend, IconAlertCircle, IconMessage, IconUsers } from '@tabler/icons-react'
|
||||
import { RichTextEditor, Link } from '@mantine/tiptap'
|
||||
import { useEditor } from '@tiptap/react'
|
||||
import StarterKit from '@tiptap/starter-kit'
|
||||
|
|
@ -12,9 +12,11 @@ import { useDebouncedValue } from '@mantine/hooks'
|
|||
import { useUsers } from '@/features/users/hooks/useUsers'
|
||||
import { useDepartments } from '@/features/departments/hooks/useDepartments'
|
||||
import { useAllRoles } from '@/features/roles/hooks/useAllRoles'
|
||||
import {useCreateNotification} from "@/features/notifications/hooks/useNotifications.ts";
|
||||
import {convertHtmlToTelegram} from "@/features/notifications/utils/telegramHtml.ts";
|
||||
import {notifications} from "@mantine/notifications";
|
||||
import { useCreateNotification } from '@/features/notifications/hooks/useNotifications.ts'
|
||||
import { convertHtmlToTelegram } from '@/features/notifications/utils/telegramHtml.ts'
|
||||
import { notifications } from '@mantine/notifications'
|
||||
import { modals } from '@mantine/modals'
|
||||
import '@mantine/tiptap/styles.css'
|
||||
|
||||
const ROLE_TYPE_OPTIONS = [
|
||||
{ value: 'director', label: 'Директора' },
|
||||
|
|
@ -71,7 +73,7 @@ export default function SendNotificationForm() {
|
|||
[departments],
|
||||
)
|
||||
|
||||
const MAX_ASPECT_RATIO = 20 // Telegram Bot API ограничение
|
||||
const MAX_ASPECT_RATIO = 20
|
||||
|
||||
const handlePhotoChange = (file: File | null) => {
|
||||
if (!file) {
|
||||
|
|
@ -118,39 +120,75 @@ export default function SendNotificationForm() {
|
|||
|
||||
const canSubmit = title.trim().length > 0 && !isMessageEmpty && hasAnyTarget
|
||||
|
||||
const totalRecipients =
|
||||
selectedUserIds.length +
|
||||
selectedRoleIds.length +
|
||||
selectedRoleFlags.length +
|
||||
selectedDepartmentIds.length
|
||||
|
||||
const handleSubmit = () => {
|
||||
if (!canSubmit) return
|
||||
|
||||
createNotification.mutate(
|
||||
{
|
||||
title: title.trim(),
|
||||
message_html: convertHtmlToTelegram(messageHtml),
|
||||
photo_base64: photoBase64 || undefined,
|
||||
photo_file_name: photoFileName || undefined,
|
||||
targets: {
|
||||
user_ids: selectedUserIds.map(Number),
|
||||
role_ids: selectedRoleIds.map(Number),
|
||||
role_type_flags: selectedRoleFlags,
|
||||
department_ids: selectedDepartmentIds.map(Number),
|
||||
},
|
||||
modals.openConfirmModal({
|
||||
title: 'Подтверждение отправки',
|
||||
children: (
|
||||
<Text size="sm">
|
||||
Вы уверены, что хотите отправить уведомление <b>«{title.trim()}»</b>?
|
||||
{totalRecipients > 0 && (
|
||||
<> Получателей по выбранным критериям: ~<b>{totalRecipients}</b> групп.</>
|
||||
)}
|
||||
</Text>
|
||||
),
|
||||
labels: { confirm: 'Отправить', cancel: 'Отмена' },
|
||||
confirmProps: { color: 'blue' },
|
||||
onConfirm: () => {
|
||||
createNotification.mutate(
|
||||
{
|
||||
title: title.trim(),
|
||||
message_html: convertHtmlToTelegram(messageHtml),
|
||||
photo_base64: photoBase64 || undefined,
|
||||
photo_file_name: photoFileName || undefined,
|
||||
targets: {
|
||||
user_ids: selectedUserIds.map(Number),
|
||||
role_ids: selectedRoleIds.map(Number),
|
||||
role_type_flags: selectedRoleFlags,
|
||||
department_ids: selectedDepartmentIds.map(Number),
|
||||
},
|
||||
},
|
||||
{
|
||||
onSuccess: () => {
|
||||
setTitle('')
|
||||
editor?.commands.clearContent()
|
||||
setSelectedUserIds([])
|
||||
setSelectedRoleIds([])
|
||||
setSelectedRoleFlags([])
|
||||
setSelectedDepartmentIds([])
|
||||
handlePhotoChange(null)
|
||||
notifications.show({
|
||||
title: 'Успешно',
|
||||
message: 'Уведомление отправлено',
|
||||
color: 'green',
|
||||
})
|
||||
},
|
||||
},
|
||||
)
|
||||
},
|
||||
{
|
||||
onSuccess: () => {
|
||||
setTitle('')
|
||||
editor?.commands.clearContent()
|
||||
setSelectedUserIds([])
|
||||
setSelectedRoleIds([])
|
||||
setSelectedRoleFlags([])
|
||||
setSelectedDepartmentIds([])
|
||||
handlePhotoChange(null)
|
||||
},
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<Paper withBorder p="md">
|
||||
<Stack gap="md">
|
||||
<Paper withBorder p="md" radius="md">
|
||||
<Stack gap="lg">
|
||||
{/* Заголовок формы */}
|
||||
<Group justify="space-between" align="center">
|
||||
<Text size="xl" fw={700}>Новая рассылка</Text>
|
||||
{totalRecipients > 0 && (
|
||||
<Badge size="lg" variant="light" color="blue">
|
||||
{totalRecipients} критериев выбрано
|
||||
</Badge>
|
||||
)}
|
||||
</Group>
|
||||
|
||||
<TextInput
|
||||
label="Заголовок рассылки"
|
||||
description="Только для админки, в Telegram не отправляется"
|
||||
|
|
@ -160,9 +198,17 @@ export default function SendNotificationForm() {
|
|||
required
|
||||
/>
|
||||
|
||||
{/* Редактор сообщения */}
|
||||
<Stack gap={4}>
|
||||
<Text size="sm" fw={500}>Текст сообщения</Text>
|
||||
<RichTextEditor editor={editor}>
|
||||
<Group justify="space-between" align="center">
|
||||
<Text size="sm" fw={500}>Текст сообщения</Text>
|
||||
{!isMessageEmpty && (
|
||||
<Badge size="xs" variant="light" color="green">
|
||||
Заполнено
|
||||
</Badge>
|
||||
)}
|
||||
</Group>
|
||||
<RichTextEditor editor={editor} style={{ minHeight: 220 }}>
|
||||
<RichTextEditor.Toolbar sticky stickyOffset={0}>
|
||||
<RichTextEditor.ControlsGroup>
|
||||
<RichTextEditor.Bold />
|
||||
|
|
@ -170,27 +216,44 @@ export default function SendNotificationForm() {
|
|||
<RichTextEditor.Underline />
|
||||
<RichTextEditor.Strikethrough />
|
||||
<RichTextEditor.ClearFormatting />
|
||||
</RichTextEditor.ControlsGroup>
|
||||
|
||||
<RichTextEditor.ControlsGroup>
|
||||
<RichTextEditor.Code />
|
||||
<RichTextEditor.CodeBlock />
|
||||
</RichTextEditor.ControlsGroup>
|
||||
|
||||
<RichTextEditor.ControlsGroup>
|
||||
<RichTextEditor.Link />
|
||||
<RichTextEditor.Unlink />
|
||||
</RichTextEditor.ControlsGroup>
|
||||
</RichTextEditor.Toolbar>
|
||||
<RichTextEditor.Content />
|
||||
<RichTextEditor.Content style={{ minHeight: 160 }} />
|
||||
</RichTextEditor>
|
||||
<Text size="xs" c="dimmed">
|
||||
Поддерживаются: жирный, курсив, подчёркнутый, зачёркнутый, код, ссылки —
|
||||
остальное форматирование Telegram не отображает
|
||||
Поддерживаются: <b>жирный</b>, <i>курсив</i>, <u>подчёркнутый</u>, <s>зачёркнутый</s>, <code>код</code>, ссылки — остальное Telegram не отображает
|
||||
</Text>
|
||||
</Stack>
|
||||
|
||||
{/* Фото */}
|
||||
<Stack gap={4}>
|
||||
<Text size="sm" fw={500}>Фото (опционально)</Text>
|
||||
{photoPreviewUrl ? (
|
||||
<Group gap="xs">
|
||||
<Image src={photoPreviewUrl} h={80} w={80} radius="sm" fit="cover" />
|
||||
<ActionIcon color="red" variant="light" onClick={() => handlePhotoChange(null)}>
|
||||
<IconX size={16} />
|
||||
</ActionIcon>
|
||||
<Paper withBorder p={4} radius="sm">
|
||||
<Image src={photoPreviewUrl} h={80} w={80} radius="sm" fit="cover" />
|
||||
</Paper>
|
||||
<Stack gap={2}>
|
||||
<Text size="xs" lineClamp={1}>{photoFileName}</Text>
|
||||
<ActionIcon
|
||||
color="red"
|
||||
variant="light"
|
||||
size="sm"
|
||||
onClick={() => handlePhotoChange(null)}
|
||||
>
|
||||
<IconX size={14} />
|
||||
</ActionIcon>
|
||||
</Stack>
|
||||
</Group>
|
||||
) : (
|
||||
<FileButton onChange={handlePhotoChange} accept="image/png,image/jpeg,image/webp">
|
||||
|
|
@ -255,7 +318,12 @@ export default function SendNotificationForm() {
|
|||
</Alert>
|
||||
)}
|
||||
|
||||
<Group justify="flex-end">
|
||||
<Divider />
|
||||
|
||||
<Group justify="space-between" align="center">
|
||||
<Text size="xs" c="dimmed">
|
||||
Сообщение будет отправлено через Telegram Bot
|
||||
</Text>
|
||||
<Button
|
||||
leftSection={<IconSend size={16} />}
|
||||
onClick={handleSubmit}
|
||||
|
|
|
|||
Loading…
Reference in New Issue