mirror of
https://github.com/ansible/awx.git
synced 2026-01-12 18:40:01 -03:30
wire in SurveyQuestionAdd form to post to API
This commit is contained in:
parent
1412bf6232
commit
782d465c78
@ -3,13 +3,25 @@ import { useHistory, useRouteMatch } from 'react-router-dom';
|
||||
import { CardBody } from '@components/Card';
|
||||
import SurveyQuestionForm from './SurveyQuestionForm';
|
||||
|
||||
export default function SurveyQuestionAdd({ template }) {
|
||||
export default function SurveyQuestionAdd({ survey, updateSurvey }) {
|
||||
const [formError, setFormError] = useState(null);
|
||||
const history = useHistory();
|
||||
const match = useRouteMatch();
|
||||
|
||||
const handleSubmit = async formData => {
|
||||
//
|
||||
const handleSubmit = async question => {
|
||||
if (survey.spec.find(q => q.variable === question.variable)) {
|
||||
setFormError(
|
||||
new Error(`Survey already contains a question with variable named
|
||||
“${question.variable}”`)
|
||||
);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await updateSurvey(survey.spec.concat(question));
|
||||
history.push(match.url.replace('/add', ''));
|
||||
} catch (err) {
|
||||
setFormError(err);
|
||||
}
|
||||
};
|
||||
|
||||
const handleCancel = () => {
|
||||
@ -21,6 +33,7 @@ export default function SurveyQuestionAdd({ template }) {
|
||||
<SurveyQuestionForm
|
||||
handleSubmit={handleSubmit}
|
||||
handleCancel={handleCancel}
|
||||
submitError={formError}
|
||||
/>
|
||||
</CardBody>
|
||||
);
|
||||
|
||||
@ -15,7 +15,7 @@ import FormField, {
|
||||
import AnsibleSelect from '@components/AnsibleSelect';
|
||||
import { required, noWhiteSpace, combine } from '@util/validators';
|
||||
|
||||
function AnswerType({ i18n }) {
|
||||
function AnswerTypeField({ i18n }) {
|
||||
const [field] = useField({
|
||||
name: 'type',
|
||||
validate: required(i18n._(t`Select a value for this field`), i18n),
|
||||
@ -112,7 +112,7 @@ function SurveyQuestionForm({
|
||||
etc.). Variable names with spaces are not allowed.`
|
||||
)}
|
||||
/>
|
||||
<AnswerType i18n={i18n} />
|
||||
<AnswerTypeField i18n={i18n} />
|
||||
<CheckboxField
|
||||
id="question-required"
|
||||
name="required"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user