diff --git a/src/pages/hierarchies/HierarchiesPage.tsx b/src/pages/hierarchies/HierarchiesPage.tsx index 1a443aa..6c5744a 100644 --- a/src/pages/hierarchies/HierarchiesPage.tsx +++ b/src/pages/hierarchies/HierarchiesPage.tsx @@ -25,13 +25,12 @@ import { IconPlus, IconInfoCircle, IconCheck, - IconCopy, } from '@tabler/icons-react' import { modals } from '@mantine/modals' import { notifications } from '@mantine/notifications' import { useHierarchies, - useDeleteHierarchy + useDeleteHierarchy, } from '@/features/hierarchies/hooks/useHierarchies' import { useUsers } from '@/features/users/hooks/useUsers' import { useDepartments } from '@/features/departments/hooks/useDepartments' @@ -44,6 +43,7 @@ import { type ChainGroup, } from '@/features/hierarchies/utils' import ChainVisualization from './components/ChainVisualization' +import ChainDuplicateModal from './components/ChainDuplicateModal' import HierarchyEditModal from './components/HierarchyEditModal' import type { UserHierarchy } from '@/types/api' @@ -65,26 +65,18 @@ export default function HierarchiesPage() { const [selectedIds, setSelectedIds] = useState([]) const [isDeleting, setIsDeleting] = useState(false) + // Модалки const [editHierarchy, setEditHierarchy] = useState(null) const [createModalOpened, setCreateModalOpened] = useState(false) const [presetGroup, setPresetGroup] = useState(null) + const [duplicateGroup, setDuplicateGroup] = useState(null) // 🆕 + const [duplicateModalOpened, setDuplicateModalOpened] = useState(false) // 🆕 - // Добавляем состояние для дублирования - const [duplicateGroup, setDuplicateGroup] = useState(null) - - // Обработчик дублирования - const handleDuplicateChain = (group: ChainGroup) => { - setDuplicateGroup(group) - setCreateModalOpened(true) - } - - // Загружаем темы только для выбранной категории (если она выбрана) const { data: categoryTopics } = useTopics({ limit: 1000, ...(categoryFilter && { category_id: Number(categoryFilter) }), }) - // Основной запрос с пагинацией и фильтрами const { data, isLoading, isFetching } = useHierarchies({ offset: (page - 1) * LIMIT, limit: LIMIT, @@ -103,13 +95,11 @@ export default function HierarchiesPage() { const totalPages = data?.total_count ? Math.ceil(data.total_count / LIMIT) : 1 - // Группируем в цепочки const chains = useMemo(() => { if (!data?.data) return [] return groupHierarchiesIntoChains(data.data) }, [data]) - // Обогатим цепочки названиями объектов const enrichedChains = useMemo(() => { return chains.map((chain) => { let scopeObjectName = 'Все темы' @@ -124,29 +114,30 @@ export default function HierarchiesPage() { }) }, [chains, categories, topics]) - // Опции для фильтров - const userOptions = users?.data?.map((u) => ({ - value: String(u.id), - label: u.full_name || `Пользователь #${u.id}`, - })) || [] + const userOptions = + users?.data?.map((u) => ({ + value: String(u.id), + label: u.full_name || `Пользователь #${u.id}`, + })) || [] - const departmentOptions = departments?.data?.map((d) => ({ - value: String(d.id), - label: d.name || '', - })) || [] + const departmentOptions = + departments?.data?.map((d) => ({ + value: String(d.id), + label: d.name || '', + })) || [] - const categoryOptions = categories?.data?.map((c) => ({ - value: String(c.id), - label: c.name || '', - })) || [] + const categoryOptions = + categories?.data?.map((c) => ({ + value: String(c.id), + label: c.name || '', + })) || [] - // Если выбрана категория, показываем только её темы, иначе все темы - const topicOptions = (categoryFilter ? categoryTopics?.data : topics?.data)?.map((t) => ({ - value: String(t.id), - label: t.name || '', - })) || [] + const topicOptions = + (categoryFilter ? categoryTopics?.data : topics?.data)?.map((t) => ({ + value: String(t.id), + label: t.name || '', + })) || [] - // Обработка выбора записей const handleSelectAll = () => { if (selectedIds.length === data?.data?.length) { setSelectedIds([]) @@ -161,21 +152,20 @@ export default function HierarchiesPage() { ) } - // Сброс выбора при изменении страницы или фильтров - const handleFilterChange = (setter: (value: string | null) => void) => (value: string | null) => { - setter(value) - setPage(1) - setSelectedIds([]) - } + const handleFilterChange = + (setter: (value: string | null) => void) => (value: string | null) => { + setter(value) + setPage(1) + setSelectedIds([]) + } - // Массовое удаление const handleBulkDelete = () => { modals.openConfirmModal({ title: 'Подтвердите массовое удаление', children: ( - Вы уверены, что хотите удалить {selectedIds.length} записей? - Это действие необратимо и может повлиять на процессы согласования. + Вы уверены, что хотите удалить {selectedIds.length}{' '} + записей? Это действие необратимо. ), labels: { confirm: 'Удалить все', cancel: 'Отмена' }, @@ -184,14 +174,12 @@ export default function HierarchiesPage() { setIsDeleting(true) try { await Promise.all(selectedIds.map((id) => deleteHierarchy.mutateAsync(id))) - notifications.show({ title: 'Успешно', message: `Удалено записей: ${selectedIds.length}`, color: 'green', icon: , }) - setSelectedIds([]) } catch (error) { notifications.show({ @@ -211,7 +199,7 @@ export default function HierarchiesPage() { title: 'Подтвердите удаление', children: ( - Вы уверены, что хотите удалить эту связь? Это может повлиять на процесс согласования. + Вы уверены, что хотите удалить эту связь? ), labels: { confirm: 'Удалить', cancel: 'Отмена' }, @@ -232,15 +220,26 @@ export default function HierarchiesPage() { setCreateModalOpened(true) } + const handleDuplicateChain = (group: ChainGroup) => { + setDuplicateGroup(group) + setDuplicateModalOpened(true) + } + const handleCloseModal = () => { setEditHierarchy(null) setCreateModalOpened(false) setPresetGroup(null) - setDuplicateGroup(null) // 🆕 } - const isAllSelected = (data?.data?.length ?? 0) > 0 && selectedIds.length === (data?.data?.length ?? 0) - const isIndeterminate = selectedIds.length > 0 && selectedIds.length < (data?.data?.length || 0) + const handleCloseDuplicateModal = () => { + setDuplicateGroup(null) + setDuplicateModalOpened(false) + } + + const isAllSelected = + (data?.data?.length ?? 0) > 0 && selectedIds.length === (data?.data?.length ?? 0) + const isIndeterminate = + selectedIds.length > 0 && selectedIds.length < (data?.data?.length || 0) return ( @@ -259,7 +258,7 @@ export default function HierarchiesPage() { }} data={[ { value: 'chains', label: 'Цепочки' }, - { value: 'table', label: 'Таблица'}, + { value: 'table', label: 'Таблица' }, ]} /> + + + + + + ) +} \ No newline at end of file diff --git a/src/pages/hierarchies/components/ChainVisualization.tsx b/src/pages/hierarchies/components/ChainVisualization.tsx index 249cf81..275b4b4 100644 --- a/src/pages/hierarchies/components/ChainVisualization.tsx +++ b/src/pages/hierarchies/components/ChainVisualization.tsx @@ -7,12 +7,11 @@ import { ActionIcon, Avatar, Box, - ThemeIcon, - Tooltip, Divider, + Tooltip, } from '@mantine/core' import { - IconArrowRight, + IconChevronRight, IconPencil, IconTrash, IconUser, @@ -20,8 +19,7 @@ import { IconCategory, IconFileText, IconCopy, - IconShield, - IconCheck, + IconPlus, } from '@tabler/icons-react' import type { ChainGroup } from '@/features/hierarchies/utils' import { SCOPE_COLORS, SCOPE_LABELS } from '@/features/hierarchies/utils' @@ -36,10 +34,14 @@ interface ChainVisualizationProps { const ScopeIcon = ({ type }: { type: string }) => { switch (type) { - case 'global': return - case 'category': return - case 'topic': return - default: return + case 'global': + return + case 'category': + return + case 'topic': + return + default: + return } } @@ -53,60 +55,56 @@ export default function ChainVisualization({ return ( {/* Заголовок группы */} - + - - {group.subordinateName.charAt(0)} + + {group.subordinateName.charAt(0).toUpperCase()} - - {group.subordinateName} - {group.departmentName} + + + + {group.subordinateName} + + + {group.departmentName} + } - size="lg" + size="sm" + tt="none" > {SCOPE_LABELS[group.scopeType]}: {group.scopeObjectName} - + onAddStep(group)} > - + - + onDuplicateChain(group)} > @@ -116,39 +114,35 @@ export default function ChainVisualization({ - + - - + {/* Цепочка согласования */} + + {/* Карточка инициатора */} - - } + + - ИНИЦИАТОР - - - {group.subordinateName.charAt(0)} + Инициатор + + + {group.subordinateName.charAt(0).toUpperCase()} - + {group.subordinateName} @@ -156,15 +150,21 @@ export default function ChainVisualization({ {/* Шаги согласования */} {group.steps.map((step, index) => ( - - {/* Стрелка с номером */} - - + + {/* Разделитель со стрелкой */} + + {index + 1} @@ -175,48 +175,67 @@ export default function ChainVisualization({ withBorder p="md" style={{ - minWidth: 160, + minWidth: 180, + borderColor: 'var(--mantine-color-gray-3)', + backgroundColor: 'var(--mantine-color-white)', cursor: 'pointer', - transition: 'all 0.2s ease', - borderColor: '#4caf50', - background: 'linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%)', - boxShadow: '0 2px 8px rgba(76, 175, 80, 0.2)', + transition: 'border-color 0.15s ease', + position: 'relative', }} onClick={() => onEditStep(step.id!)} - className="approver-card" + onMouseEnter={(e) => { + e.currentTarget.style.borderColor = + 'var(--mantine-color-blue-5)' + }} + onMouseLeave={(e) => { + e.currentTarget.style.borderColor = + 'var(--mantine-color-gray-3)' + }} > - - - } + + + + Шаг {index + 1} + + - ШАГ {index + 1} - - #{step.priority} + - {step.approver?.full_name?.charAt(0) || '?'} + {step.approver?.full_name?.charAt(0).toUpperCase() || '?'} - + + {step.approver?.full_name || '—'} + + {/* Кнопки действий */} - - + + { e.stopPropagation() @@ -226,9 +245,9 @@ export default function ChainVisualization({ - + { @@ -246,17 +265,6 @@ export default function ChainVisualization({ ))} - - ) } \ No newline at end of file