fixed getting data for completing a survey
This commit is contained in:
parent
88dcb63232
commit
2ec9354fc1
13 changed files with 128 additions and 55 deletions
|
|
@ -10,8 +10,8 @@ import {
|
|||
getAnswerVariants,
|
||||
updateAnswerVariant
|
||||
} from "../../api/AnswerVariantsApi.ts";
|
||||
import {useLocation} from "react-router-dom";
|
||||
import TextareaAutosize from "react-textarea-autosize";
|
||||
import {useRouteReadOnly} from "../../hooks/useRouteReadOnly.ts";
|
||||
|
||||
interface QuestionItemProps {
|
||||
questionId: number;
|
||||
|
|
@ -23,7 +23,6 @@ interface QuestionItemProps {
|
|||
onDeleteQuestion: (index: number) => Promise<void>;
|
||||
initialQuestionType: 'SingleAnswerQuestion' | 'MultipleAnswerQuestion';
|
||||
onQuestionTypeChange: (type: 'SingleAnswerQuestion' | 'MultipleAnswerQuestion') => void;
|
||||
|
||||
surveyId?: number;
|
||||
}
|
||||
|
||||
|
|
@ -45,8 +44,7 @@ const QuestionItem: React.FC<QuestionItemProps> = ({
|
|||
const [questionType, setQuestionType] = useState<'SingleAnswerQuestion' | 'MultipleAnswerQuestion'>(initialQuestionType);
|
||||
const textareaQuestionRef = useRef<HTMLTextAreaElement>(null);
|
||||
|
||||
const location = useLocation();
|
||||
const isCompleteSurveyActive = location.pathname === '/complete-survey';
|
||||
const isReadOnly = useRouteReadOnly();
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
|
|
@ -63,6 +61,8 @@ const QuestionItem: React.FC<QuestionItemProps> = ({
|
|||
};
|
||||
|
||||
const handleAddAnswer = async () => {
|
||||
if (isReadOnly) return
|
||||
|
||||
if (!surveyId) {
|
||||
onAnswerVariantsChange([...initialAnswerVariants, { text: '' }]);
|
||||
return;
|
||||
|
|
@ -167,10 +167,8 @@ const QuestionItem: React.FC<QuestionItemProps> = ({
|
|||
|
||||
const toggleSelect = (index: number) => {
|
||||
if (initialQuestionType === 'SingleAnswerQuestion') {
|
||||
// Для одиночного выбора: заменяем массив одним выбранным индексом
|
||||
setSelectedAnswers([index]);
|
||||
} else {
|
||||
// Для множественного выбора: добавляем/удаляем индекс
|
||||
setSelectedAnswers(prev =>
|
||||
prev.includes(index)
|
||||
? prev.filter(i => i !== index)
|
||||
|
|
@ -181,7 +179,7 @@ const QuestionItem: React.FC<QuestionItemProps> = ({
|
|||
|
||||
return (
|
||||
<div className={styles.questionCard}>
|
||||
{isCompleteSurveyActive ? (
|
||||
{isReadOnly ? (
|
||||
<div>
|
||||
<div className={styles.questionContainer}>
|
||||
<h2 className={styles.textQuestion}>{textQuestion || initialTextQuestion}</h2>
|
||||
|
|
@ -194,7 +192,6 @@ const QuestionItem: React.FC<QuestionItemProps> = ({
|
|||
value={answer.text}
|
||||
isSelected={selectedAnswers.includes(index)}
|
||||
toggleSelect={() => toggleSelect(index)}
|
||||
isCompleteSurveyActive={isCompleteSurveyActive}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue