mirror of
https://github.com/ansible/awx.git
synced 2026-05-08 01:47:35 -02:30
fix errors when adding first question to new survey
This commit is contained in:
@@ -9,7 +9,7 @@ export default function SurveyQuestionAdd({ survey, updateSurvey }) {
|
|||||||
const match = useRouteMatch();
|
const match = useRouteMatch();
|
||||||
|
|
||||||
const handleSubmit = async question => {
|
const handleSubmit = async question => {
|
||||||
if (survey.spec.find(q => q.variable === question.variable)) {
|
if (survey.spec?.some(q => q.variable === question.variable)) {
|
||||||
setFormError(
|
setFormError(
|
||||||
new Error(
|
new Error(
|
||||||
`Survey already contains a question with variable named “${question.variable}”`
|
`Survey already contains a question with variable named “${question.variable}”`
|
||||||
@@ -18,7 +18,8 @@ export default function SurveyQuestionAdd({ survey, updateSurvey }) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await updateSurvey(survey.spec.concat(question));
|
const newSpec = survey.spec ? survey.spec.concat(question) : [question];
|
||||||
|
await updateSurvey(newSpec);
|
||||||
history.push(match.url.replace('/add', ''));
|
history.push(match.url.replace('/add', ''));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setFormError(err);
|
setFormError(err);
|
||||||
|
|||||||
@@ -39,7 +39,8 @@ function TemplateSurvey({ template, i18n }) {
|
|||||||
);
|
);
|
||||||
const updateSurveySpec = spec => {
|
const updateSurveySpec = spec => {
|
||||||
updateSurvey({
|
updateSurvey({
|
||||||
...survey,
|
name: survey.name || '',
|
||||||
|
description: survey.description || '',
|
||||||
spec,
|
spec,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user