mirror of
https://github.com/ansible/awx.git
synced 2026-05-17 06:17:36 -02:30
add submit error support to Project form
This commit is contained in:
@@ -9,7 +9,7 @@ const ErrorMessage = styled('div')`
|
|||||||
ErrorMessage.displayName = 'ErrorMessage';
|
ErrorMessage.displayName = 'ErrorMessage';
|
||||||
|
|
||||||
function FormSubmitError({ error }) {
|
function FormSubmitError({ error }) {
|
||||||
const [formError, setFormError] = useState(null);
|
const [errorMessage, setErrorMessage] = useState(null);
|
||||||
const { setErrors } = useFormikContext();
|
const { setErrors } = useFormikContext();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -21,22 +21,22 @@ function FormSubmitError({ error }) {
|
|||||||
const errorMessages = error.response.data;
|
const errorMessages = error.response.data;
|
||||||
setErrors(errorMessages);
|
setErrors(errorMessages);
|
||||||
if (errorMessages.__all__) {
|
if (errorMessages.__all__) {
|
||||||
setFormError({ message: errorMessages.__all__ });
|
setErrorMessage(errorMessages.__all__);
|
||||||
} else {
|
} else {
|
||||||
setFormError(null);
|
setErrorMessage(null);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* eslint-disable-next-line no-console */
|
/* eslint-disable-next-line no-console */
|
||||||
console.error(error);
|
console.error(error);
|
||||||
setFormError(error);
|
setErrorMessage(error.message);
|
||||||
}
|
}
|
||||||
}, [error, setErrors]);
|
}, [error, setErrors]);
|
||||||
|
|
||||||
if (!formError) {
|
if (!errorMessage) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return <ErrorMessage>{formError.message}</ErrorMessage>;
|
return <ErrorMessage>{errorMessage}</ErrorMessage>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default FormSubmitError;
|
export default FormSubmitError;
|
||||||
|
|||||||
@@ -41,13 +41,9 @@ function ProjectAdd() {
|
|||||||
<ProjectForm
|
<ProjectForm
|
||||||
handleCancel={handleCancel}
|
handleCancel={handleCancel}
|
||||||
handleSubmit={handleSubmit}
|
handleSubmit={handleSubmit}
|
||||||
|
submitError={formSubmitError}
|
||||||
/>
|
/>
|
||||||
</CardBody>
|
</CardBody>
|
||||||
{formSubmitError ? (
|
|
||||||
<div className="formSubmitError">formSubmitError</div>
|
|
||||||
) : (
|
|
||||||
''
|
|
||||||
)}
|
|
||||||
</Card>
|
</Card>
|
||||||
</PageSection>
|
</PageSection>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -42,13 +42,9 @@ function ProjectEdit({ project }) {
|
|||||||
project={project}
|
project={project}
|
||||||
handleCancel={handleCancel}
|
handleCancel={handleCancel}
|
||||||
handleSubmit={handleSubmit}
|
handleSubmit={handleSubmit}
|
||||||
|
submitError={formSubmitError}
|
||||||
/>
|
/>
|
||||||
</CardBody>
|
</CardBody>
|
||||||
{formSubmitError ? (
|
|
||||||
<div className="formSubmitError">formSubmitError</div>
|
|
||||||
) : (
|
|
||||||
''
|
|
||||||
)}
|
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,10 @@ import AnsibleSelect from '@components/AnsibleSelect';
|
|||||||
import ContentError from '@components/ContentError';
|
import ContentError from '@components/ContentError';
|
||||||
import ContentLoading from '@components/ContentLoading';
|
import ContentLoading from '@components/ContentLoading';
|
||||||
import FormActionGroup from '@components/FormActionGroup/FormActionGroup';
|
import FormActionGroup from '@components/FormActionGroup/FormActionGroup';
|
||||||
import FormField, { FieldTooltip } from '@components/FormField';
|
import FormField, {
|
||||||
|
FieldTooltip,
|
||||||
|
FormSubmitError,
|
||||||
|
} from '@components/FormField';
|
||||||
import FormRow from '@components/FormRow';
|
import FormRow from '@components/FormRow';
|
||||||
import OrganizationLookup from '@components/Lookup/OrganizationLookup';
|
import OrganizationLookup from '@components/Lookup/OrganizationLookup';
|
||||||
import { CredentialTypesAPI, ProjectsAPI } from '@api';
|
import { CredentialTypesAPI, ProjectsAPI } from '@api';
|
||||||
@@ -70,7 +73,7 @@ const fetchCredentials = async credential => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
function ProjectForm({ project, ...props }) {
|
function ProjectForm({ project, submitError, ...props }) {
|
||||||
const { i18n, handleCancel, handleSubmit } = props;
|
const { i18n, handleCancel, handleSubmit } = props;
|
||||||
const { summary_fields = {} } = project;
|
const { summary_fields = {} } = project;
|
||||||
const [contentError, setContentError] = useState(null);
|
const [contentError, setContentError] = useState(null);
|
||||||
@@ -388,6 +391,7 @@ function ProjectForm({ project, ...props }) {
|
|||||||
<FormActionGroup
|
<FormActionGroup
|
||||||
onCancel={handleCancel}
|
onCancel={handleCancel}
|
||||||
onSubmit={formik.handleSubmit}
|
onSubmit={formik.handleSubmit}
|
||||||
|
errorMessage={<FormSubmitError error={submitError} />}
|
||||||
/>
|
/>
|
||||||
</Form>
|
</Form>
|
||||||
)}
|
)}
|
||||||
@@ -401,10 +405,12 @@ ProjectForm.propTypes = {
|
|||||||
handleCancel: PropTypes.func.isRequired,
|
handleCancel: PropTypes.func.isRequired,
|
||||||
handleSubmit: PropTypes.func.isRequired,
|
handleSubmit: PropTypes.func.isRequired,
|
||||||
project: PropTypes.shape({}),
|
project: PropTypes.shape({}),
|
||||||
|
submitError: PropTypes.shape({}),
|
||||||
};
|
};
|
||||||
|
|
||||||
ProjectForm.defaultProps = {
|
ProjectForm.defaultProps = {
|
||||||
project: {},
|
project: {},
|
||||||
|
submitError: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default withI18n()(ProjectForm);
|
export default withI18n()(ProjectForm);
|
||||||
|
|||||||
Reference in New Issue
Block a user