mirror of
https://github.com/ansible/awx.git
synced 2026-03-20 18:37:39 -02:30
wire in SurveyQuestionAdd form to post to API
This commit is contained in:
@@ -3,13 +3,25 @@ import { useHistory, useRouteMatch } from 'react-router-dom';
|
|||||||
import { CardBody } from '@components/Card';
|
import { CardBody } from '@components/Card';
|
||||||
import SurveyQuestionForm from './SurveyQuestionForm';
|
import SurveyQuestionForm from './SurveyQuestionForm';
|
||||||
|
|
||||||
export default function SurveyQuestionAdd({ template }) {
|
export default function SurveyQuestionAdd({ survey, updateSurvey }) {
|
||||||
const [formError, setFormError] = useState(null);
|
const [formError, setFormError] = useState(null);
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const match = useRouteMatch();
|
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 = () => {
|
const handleCancel = () => {
|
||||||
@@ -21,6 +33,7 @@ export default function SurveyQuestionAdd({ template }) {
|
|||||||
<SurveyQuestionForm
|
<SurveyQuestionForm
|
||||||
handleSubmit={handleSubmit}
|
handleSubmit={handleSubmit}
|
||||||
handleCancel={handleCancel}
|
handleCancel={handleCancel}
|
||||||
|
submitError={formError}
|
||||||
/>
|
/>
|
||||||
</CardBody>
|
</CardBody>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import FormField, {
|
|||||||
import AnsibleSelect from '@components/AnsibleSelect';
|
import AnsibleSelect from '@components/AnsibleSelect';
|
||||||
import { required, noWhiteSpace, combine } from '@util/validators';
|
import { required, noWhiteSpace, combine } from '@util/validators';
|
||||||
|
|
||||||
function AnswerType({ i18n }) {
|
function AnswerTypeField({ i18n }) {
|
||||||
const [field] = useField({
|
const [field] = useField({
|
||||||
name: 'type',
|
name: 'type',
|
||||||
validate: required(i18n._(t`Select a value for this field`), i18n),
|
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.`
|
etc.). Variable names with spaces are not allowed.`
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
<AnswerType i18n={i18n} />
|
<AnswerTypeField i18n={i18n} />
|
||||||
<CheckboxField
|
<CheckboxField
|
||||||
id="question-required"
|
id="question-required"
|
||||||
name="required"
|
name="required"
|
||||||
|
|||||||
Reference in New Issue
Block a user