Updated flows tree
Deploy Frontend / build-and-deploy (push) Successful in 1m9s Details

This commit is contained in:
romanskijdev 2026-08-04 13:22:14 +03:00
parent 9d61e80d92
commit aa50168138
1 changed files with 42 additions and 24 deletions

View File

@ -29,6 +29,7 @@ import { useUsers } from '@/features/users/hooks/useUsers'
import { useDepartments } from '@/features/departments/hooks/useDepartments'
import { useCategories } from '@/features/categories/hooks/useCategories'
import { useTopics } from '@/features/topics/hooks/useTopics'
import { useAllSystemOptions } from '@/features/hierarchies/hooks/useSystemOptions' // 👈 ИМПОРТИРОВАЛИ ХУК
import type { ChainGroup } from '@/features/hierarchies/utils'
interface ChainDuplicateModalProps {
@ -42,6 +43,7 @@ type ScopeType = 'global' | 'category' | 'topic'
interface StepForm {
approver_id: number | null
priority: number
target_system: string | null // 👈 ДОБАВИЛИ ПОЛЕ В ИНТЕРФЕЙС
}
export default function ChainDuplicateModal({
@ -54,9 +56,9 @@ export default function ChainDuplicateModal({
const { data: departments } = useDepartments()
const { data: categories } = useCategories({ limit: 1000 })
// Полный список тем без фильтра — нужен, чтобы восстановить
// topic_category_id по topic_id, когда scopeType === 'topic'
// (см. useEffect ниже — та же логика, что в HierarchyEditModal).
// Подтягиваем доступные системы
const { options: systemOptions } = useAllSystemOptions()
const { data: allTopics } = useTopics({ limit: 1000 })
const form = useForm({
@ -97,11 +99,6 @@ export default function ChainDuplicateModal({
...(form.values.topic_category_id && { category_id: form.values.topic_category_id }),
})
// Заполняем форму данными из цепочки
// 🩹 ФИКС: раньше при scopeType === 'topic' в topic_category_id
// подставлялся group.scopeObjectId — а это ID ТЕМЫ, не категории (мусор
// в поле категории). Теперь категория корректно достаётся через
// allTopics по topic_id — та же логика, что уже чинили в HierarchyEditModal.
useEffect(() => {
if (group && opened) {
let resolvedCategoryId: number | null = null
@ -121,6 +118,7 @@ export default function ChainDuplicateModal({
steps: group.steps.map((s, idx) => ({
approver_id: s.approver_id || null,
priority: idx,
target_system: s.target_system || null, // 👈 ИНИЦИАЛИЗИРУЕМ ИЗ БД
})),
})
}
@ -141,12 +139,12 @@ export default function ChainDuplicateModal({
form.insertListItem('steps', {
approver_id: null,
priority: form.values.steps.length,
target_system: null, // 👈 ИНИЦИАЛИЗИРУЕМ ДЛЯ НОВОГО ШАГА
})
}
const removeStep = (index: number) => {
form.removeListItem('steps', index)
// Пересчитываем priority
form.values.steps.forEach((_, idx) => {
form.setFieldValue(`steps.${idx}.priority`, idx)
})
@ -187,13 +185,13 @@ export default function ChainDuplicateModal({
}
try {
// Создаём все записи последовательно
for (const step of values.steps) {
await createHierarchy.mutateAsync({
subordinate_id: values.subordinate_id!,
approver_id: step.approver_id!,
department_id: values.department_id!,
priority: step.priority,
target_system: step.target_system || null, // 👈 ОТПРАВЛЯЕМ СИСТЕМУ
topic_category_id:
values.scope_type === 'global'
? null
@ -431,20 +429,39 @@ export default function ChainDuplicateModal({
</Badge>
</Group>
<Select
placeholder="Выберите согласующего"
data={userOptions}
value={step.approver_id ? String(step.approver_id) : null}
onChange={(v) =>
form.setFieldValue(`steps.${index}.approver_id`, v ? Number(v) : null)
}
searchable
error={
Array.isArray(form.errors.steps) && form.errors.steps[index]
? (form.errors.steps[index] as any)?.approver_id
: undefined
}
/>
<Group grow gap="xs">
<Select
placeholder="Выберите согласующего"
data={userOptions}
value={step.approver_id ? String(step.approver_id) : null}
onChange={(v) =>
form.setFieldValue(`steps.${index}.approver_id`, v ? Number(v) : null)
}
searchable
error={
Array.isArray(form.errors.steps) && form.errors.steps[index]
? (form.errors.steps[index] as any)?.approver_id
: undefined
}
/>
{/* 👈 ДОБАВЛЕННЫЙ ВЫБОР СИСТЕМЫ */}
<Select
placeholder="Система: Все (по умолчанию)"
data={[
{ value: 'all', label: 'Система: Все' },
...systemOptions.map((s) => ({ value: s.value, label: `Система: ${s.label}` })),
]}
value={step.target_system || 'all'}
onChange={(v) =>
form.setFieldValue(
`steps.${index}.target_system`,
(v === 'all' || !v) ? null : v
)
}
clearable
/>
</Group>
</Stack>
<ActionIcon
@ -485,6 +502,7 @@ export default function ChainDuplicateModal({
{users?.data?.find(
(u) => u.id === step.approver_id
)?.full_name || `Шаг ${index + 1}`}
{step.target_system && ` (${step.target_system})`}
</Badge>
</Group>
))}