mirror of
https://github.com/ansible/awx.git
synced 2026-02-15 02:00:01 -03:30
handle any errors thrown in survey handleSubmit
This commit is contained in:
@@ -9,15 +9,15 @@ export default function SurveyQuestionAdd({ survey, updateSurvey }) {
|
|||||||
const match = useRouteMatch();
|
const match = useRouteMatch();
|
||||||
|
|
||||||
const handleSubmit = async question => {
|
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 {
|
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];
|
const newSpec = survey.spec ? survey.spec.concat(question) : [question];
|
||||||
await updateSurvey(newSpec);
|
await updateSurvey(newSpec);
|
||||||
history.push(match.url.replace('/add', ''));
|
history.push(match.url.replace('/add', ''));
|
||||||
|
|||||||
@@ -21,19 +21,18 @@ export default function SurveyQuestionEdit({ survey, updateSurvey }) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmit = async formData => {
|
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 {
|
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(
|
const questionIndex = survey.spec.findIndex(
|
||||||
q => q.variable === match.params.variable
|
q => q.variable === match.params.variable
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user