fix survey id
This commit is contained in:
parent
5a1cc7c43c
commit
8622f9e9db
4 changed files with 40 additions and 30 deletions
|
|
@ -11,7 +11,7 @@ const Survey: React.FC = () => {
|
|||
const navigate = useNavigate();
|
||||
const [descriptionSurvey, setDescriptionSurvey] = useState('');
|
||||
const [titleSurvey, setTitleSurvey] = useState('Название опроса');
|
||||
const [survey, setSurvey] = useState<ISurvey | null>(null);
|
||||
const [survey] = useState<ISurvey | null>(null);
|
||||
|
||||
const [questions, setQuestions] = useState<Question[]>([
|
||||
{ id: 1, text: '', questionType: 'singleanswerquestion'},
|
||||
|
|
@ -34,22 +34,26 @@ const Survey: React.FC = () => {
|
|||
|
||||
|
||||
const handleSave = async () => {
|
||||
const savedSurvey = await postNewSurvey({title: titleSurvey, description: descriptionSurvey});
|
||||
setSurvey(savedSurvey);
|
||||
|
||||
try {
|
||||
const savedSurvey = await postNewSurvey({
|
||||
title: titleSurvey,
|
||||
description: descriptionSurvey
|
||||
});
|
||||
|
||||
await Promise.all(
|
||||
questions.map(question =>
|
||||
addNewQuestion(savedSurvey.id, {title: question.text, questionType: question.questionType})
|
||||
))
|
||||
addNewQuestion(savedSurvey.id, {
|
||||
title: question.text,
|
||||
questionType: question.questionType
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
// Сбрасываем состояние после сохранения
|
||||
setQuestions([{ id: 1, text: '', questionType: 'singleanswerquestion' }]);
|
||||
setTitleSurvey('Новый опрос');
|
||||
setDescriptionSurvey('');
|
||||
navigate('/my-surveys');
|
||||
|
||||
} catch (error) {
|
||||
console.error('Ошибка при сохранении:', error);
|
||||
alert('Не удалось сохранить опрос');
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue