1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-30 13:55:31 +03:00

fix errors when adding first question to new survey

This commit is contained in:
Keith Grant 2020-03-20 09:41:28 -07:00
parent cfe0607b6a
commit 564012b2c8
2 changed files with 5 additions and 3 deletions

View File

@ -9,7 +9,7 @@ export default function SurveyQuestionAdd({ survey, updateSurvey }) {
const match = useRouteMatch();
const handleSubmit = async question => {
if (survey.spec.find(q => q.variable === question.variable)) {
if (survey.spec?.some(q => q.variable === question.variable)) {
setFormError(
new Error(
`Survey already contains a question with variable named “${question.variable}`
@ -18,7 +18,8 @@ export default function SurveyQuestionAdd({ survey, updateSurvey }) {
return;
}
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', ''));
} catch (err) {
setFormError(err);

View File

@ -39,7 +39,8 @@ function TemplateSurvey({ template, i18n }) {
);
const updateSurveySpec = spec => {
updateSurvey({
...survey,
name: survey.name || '',
description: survey.description || '',
spec,
});
};