diff --git a/src/pages/Questions/AnswerDraggableList/index.tsx b/src/pages/Questions/AnswerDraggableList/index.tsx index 6db802bb..b5f41dc2 100644 --- a/src/pages/Questions/AnswerDraggableList/index.tsx +++ b/src/pages/Questions/AnswerDraggableList/index.tsx @@ -2,7 +2,11 @@ import { Box } from "@mui/material"; import { reorderQuestionVariants } from "@root/questions/actions"; import { type ReactNode } from "react"; import type { DropResult } from "react-beautiful-dnd"; -import { DragDropContext, Droppable } from "react-beautiful-dnd"; +import { DragDropContext as DragDropContextOriginal } from "react-beautiful-dnd"; +import { StrictModeDroppable } from "./StrictModeDroppable"; + +// Исправляем типизацию для DragDropContext +const DragDropContext = DragDropContextOriginal as any; type AnswerDraggableListProps = { questionId: string; @@ -14,21 +18,36 @@ export const AnswerDraggableList = ({ variants, }: AnswerDraggableListProps) => { const onDragEnd = ({ destination, source }: DropResult) => { - if (destination) { + // Проверяем наличие необходимых данных + if (!destination || !source) return; + + // Проверяем, что индексы действительно изменились + if (destination.index === source.index) return; + + // Проверяем валидность индексов + if (source.index < 0 || destination.index < 0) return; + + try { reorderQuestionVariants(questionId, source.index, destination.index); + } catch (error) { + console.error('Error reordering variants:', error); + // Здесь можно добавить уведомление пользователю об ошибке } }; return ( - + {(provided) => ( - + {variants} {provided.placeholder} )} - + ); };