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