2019-11-21 10:52:49 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import { Form, reduxForm, InjectedFormProps } from "redux-form";
|
|
|
|
|
import { CREATE_APPLICATION_FORM_NAME } from "constants/forms";
|
|
|
|
|
import {
|
|
|
|
|
CreateApplicationFormValues,
|
|
|
|
|
createApplicationFormSubmitHandler,
|
2019-12-16 08:49:10 +00:00
|
|
|
} from "./helpers";
|
2019-11-25 09:15:11 +00:00
|
|
|
import TextField from "components/editorComponents/form/fields/TextField";
|
2019-12-23 12:16:33 +00:00
|
|
|
import FormGroup from "components/editorComponents/form/FormGroup";
|
2020-02-03 10:37:03 +00:00
|
|
|
import FormFooter from "components/editorComponents/form/FormFooter";
|
|
|
|
|
import FormMessage from "components/editorComponents/form/FormMessage";
|
2019-11-07 04:59:40 +00:00
|
|
|
|
2020-02-03 10:37:03 +00:00
|
|
|
// TODO(abhinav): abstract onCancel out.
|
2019-11-21 10:52:49 +00:00
|
|
|
export const CreateApplicationForm = (
|
2020-02-03 10:37:03 +00:00
|
|
|
props: InjectedFormProps<
|
|
|
|
|
CreateApplicationFormValues,
|
|
|
|
|
{ onCancel: () => void }
|
|
|
|
|
> & {
|
|
|
|
|
onCancel: () => void;
|
|
|
|
|
},
|
2019-11-21 10:52:49 +00:00
|
|
|
) => {
|
2020-02-03 10:37:03 +00:00
|
|
|
const { error, handleSubmit, pristine, submitting } = props;
|
2019-11-07 04:59:40 +00:00
|
|
|
return (
|
2019-11-21 10:52:49 +00:00
|
|
|
<Form onSubmit={handleSubmit(createApplicationFormSubmitHandler)}>
|
2020-02-03 10:37:03 +00:00
|
|
|
{error && !pristine && <FormMessage intent="danger" message={error} />}
|
|
|
|
|
<FormGroup intent={error ? "danger" : "none"} helperText={error}>
|
2019-12-16 08:49:10 +00:00
|
|
|
<TextField name="applicationName" placeholder="Name" />
|
2019-11-21 10:52:49 +00:00
|
|
|
</FormGroup>
|
2020-02-03 10:37:03 +00:00
|
|
|
<FormFooter
|
|
|
|
|
onCancel={props.onCancel}
|
|
|
|
|
onSubmit={handleSubmit(createApplicationFormSubmitHandler)}
|
|
|
|
|
divider
|
|
|
|
|
submitOnEnter
|
|
|
|
|
submitText="Submit"
|
|
|
|
|
size="small"
|
|
|
|
|
submitting={submitting && !error}
|
|
|
|
|
/>
|
2019-11-21 10:52:49 +00:00
|
|
|
</Form>
|
2019-11-07 04:59:40 +00:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2020-02-03 10:37:03 +00:00
|
|
|
export default reduxForm<CreateApplicationFormValues, { onCancel: () => void }>(
|
|
|
|
|
{
|
|
|
|
|
form: CREATE_APPLICATION_FORM_NAME,
|
|
|
|
|
onSubmit: createApplicationFormSubmitHandler,
|
|
|
|
|
},
|
|
|
|
|
)(CreateApplicationForm);
|