From 564012b2c824258f5869cc4681dc8497732ffcb6 Mon Sep 17 00:00:00 2001 From: Keith Grant Date: Fri, 20 Mar 2020 09:41:28 -0700 Subject: [PATCH] fix errors when adding first question to new survey --- .../src/screens/Template/Survey/SurveyQuestionAdd.jsx | 5 +++-- awx/ui_next/src/screens/Template/TemplateSurvey.jsx | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/awx/ui_next/src/screens/Template/Survey/SurveyQuestionAdd.jsx b/awx/ui_next/src/screens/Template/Survey/SurveyQuestionAdd.jsx index 29304f3069..9889f824cf 100644 --- a/awx/ui_next/src/screens/Template/Survey/SurveyQuestionAdd.jsx +++ b/awx/ui_next/src/screens/Template/Survey/SurveyQuestionAdd.jsx @@ -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); diff --git a/awx/ui_next/src/screens/Template/TemplateSurvey.jsx b/awx/ui_next/src/screens/Template/TemplateSurvey.jsx index daa672fe0f..aeef6eaf52 100644 --- a/awx/ui_next/src/screens/Template/TemplateSurvey.jsx +++ b/awx/ui_next/src/screens/Template/TemplateSurvey.jsx @@ -39,7 +39,8 @@ function TemplateSurvey({ template, i18n }) { ); const updateSurveySpec = spec => { updateSurvey({ - ...survey, + name: survey.name || '', + description: survey.description || '', spec, }); };