mirror of
https://github.com/ansible/awx.git
synced 2026-01-12 10:30:03 -03:30
handle any errors thrown in survey handleSubmit
This commit is contained in:
parent
564012b2c8
commit
56d31fec77
@ -9,15 +9,15 @@ export default function SurveyQuestionAdd({ survey, updateSurvey }) {
|
||||
const match = useRouteMatch();
|
||||
|
||||
const handleSubmit = async question => {
|
||||
if (survey.spec?.some(q => q.variable === question.variable)) {
|
||||
setFormError(
|
||||
new Error(
|
||||
`Survey already contains a question with variable named “${question.variable}”`
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (survey.spec?.some(q => q.variable === question.variable)) {
|
||||
setFormError(
|
||||
new Error(
|
||||
`Survey already contains a question with variable named “${question.variable}”`
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
const newSpec = survey.spec ? survey.spec.concat(question) : [question];
|
||||
await updateSurvey(newSpec);
|
||||
history.push(match.url.replace('/add', ''));
|
||||
|
||||
@ -21,19 +21,18 @@ export default function SurveyQuestionEdit({ survey, updateSurvey }) {
|
||||
};
|
||||
|
||||
const handleSubmit = async formData => {
|
||||
if (
|
||||
formData.variable !== question.variable &&
|
||||
survey.spec.find(q => q.variable === formData.variable)
|
||||
) {
|
||||
debugger;
|
||||
setFormError(
|
||||
new Error(
|
||||
`Survey already contains a question with variable named “${formData.variable}”`
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (
|
||||
formData.variable !== question.variable &&
|
||||
survey.spec.find(q => q.variable === formData.variable)
|
||||
) {
|
||||
setFormError(
|
||||
new Error(
|
||||
`Survey already contains a question with variable named “${formData.variable}”`
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
const questionIndex = survey.spec.findIndex(
|
||||
q => q.variable === match.params.variable
|
||||
);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user