mirror of
https://github.com/ansible/awx.git
synced 2026-02-26 23:46:05 -03:30
Avoid prop reference error when recreating survey
The survey object is undefined when recreating a survey after deleting it. Add optional chaining on survey fields to avoid prop reference error.
This commit is contained in:
@@ -11,7 +11,7 @@ export default function SurveyQuestionAdd({ survey, updateSurvey }) {
|
|||||||
const handleSubmit = async question => {
|
const handleSubmit = async question => {
|
||||||
const formData = { ...question };
|
const formData = { ...question };
|
||||||
try {
|
try {
|
||||||
if (survey.spec?.some(q => q.variable === formData.variable)) {
|
if (survey?.spec?.some(q => q.variable === formData.variable)) {
|
||||||
setFormError(
|
setFormError(
|
||||||
new Error(
|
new Error(
|
||||||
`Survey already contains a question with variable named “${formData.variable}”`
|
`Survey already contains a question with variable named “${formData.variable}”`
|
||||||
@@ -41,9 +41,7 @@ export default function SurveyQuestionAdd({ survey, updateSurvey }) {
|
|||||||
formData.choices = choices.trim();
|
formData.choices = choices.trim();
|
||||||
}
|
}
|
||||||
delete formData.formattedChoices;
|
delete formData.formattedChoices;
|
||||||
|
const newSpec = survey?.spec ? survey.spec.concat(formData) : [formData];
|
||||||
const newSpec = survey.spec ? survey.spec.concat(formData) : [formData];
|
|
||||||
|
|
||||||
await updateSurvey(newSpec);
|
await updateSurvey(newSpec);
|
||||||
history.push(match.url.replace('/add', ''));
|
history.push(match.url.replace('/add', ''));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@@ -53,8 +53,8 @@ function TemplateSurvey({ template, canEdit }) {
|
|||||||
);
|
);
|
||||||
const updateSurveySpec = spec => {
|
const updateSurveySpec = spec => {
|
||||||
updateSurvey({
|
updateSurvey({
|
||||||
name: survey.name || '',
|
name: survey?.name || '',
|
||||||
description: survey.description || '',
|
description: survey?.description || '',
|
||||||
spec,
|
spec,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user