diff --git a/src/App.tsx b/src/App.tsx index d1d8326..c298ccb 100644 --- a/src/App.tsx +++ b/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 }) => (
@@ -48,29 +49,33 @@ function ProtectedRoute({ children }: { children: React.ReactNode }) { function App() { return ( - - } /> + + + + } /> - }> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - - + }> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + + + + ) } diff --git a/src/pages/notifications/components/SendNotificationForm.tsx b/src/pages/notifications/components/SendNotificationForm.tsx index 82e1397..c583d10 100644 --- a/src/pages/notifications/components/SendNotificationForm.tsx +++ b/src/pages/notifications/components/SendNotificationForm.tsx @@ -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: ( + + Вы уверены, что хотите отправить уведомление «{title.trim()}»? + {totalRecipients > 0 && ( + <> Получателей по выбранным критериям: ~{totalRecipients} групп. + )} + + ), + 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 ( - - + + + {/* Заголовок формы */} + + Новая рассылка + {totalRecipients > 0 && ( + + {totalRecipients} критериев выбрано + + )} + + + {/* Редактор сообщения */} - Текст сообщения - + + Текст сообщения + {!isMessageEmpty && ( + + Заполнено + + )} + + @@ -170,27 +216,44 @@ export default function SendNotificationForm() { + + + + + + + - + - Поддерживаются: жирный, курсив, подчёркнутый, зачёркнутый, код, ссылки — - остальное форматирование Telegram не отображает + Поддерживаются: жирный, курсив, подчёркнутый, зачёркнутый, код, ссылки — остальное Telegram не отображает + {/* Фото */} Фото (опционально) {photoPreviewUrl ? ( - - handlePhotoChange(null)}> - - + + + + + {photoFileName} + handlePhotoChange(null)} + > + + + ) : ( @@ -255,7 +318,12 @@ export default function SendNotificationForm() { )} - + + + + + Сообщение будет отправлено через Telegram Bot +