PromucFlow_constructor/app/client/src/pages/Applications/CreateApplicationForm.tsx

64 lines
2.0 KiB
TypeScript
Raw Normal View History

2019-11-21 10:52:49 +00:00
import React from "react";
import { connect } from "react-redux";
import { Form, reduxForm, InjectedFormProps, Field } from "redux-form";
2019-11-21 10:52:49 +00:00
import { CREATE_APPLICATION_FORM_NAME } from "constants/forms";
import { AppState } from "reducers";
2019-11-21 10:52:49 +00:00
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";
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";
type Props = InjectedFormProps<
CreateApplicationFormValues,
{ onCancel: () => void; orgId: string; initialValues: {} }
> & {
onCancel: () => void;
orgId: string;
initialValues: {};
};
2020-02-03 10:37:03 +00:00
// TODO(abhinav): abstract onCancel out.
export const CreateApplicationForm = (props: Props) => {
const { error, handleSubmit, pristine, submitting } = props;
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"}>
2019-12-16 08:49:10 +00:00
<TextField name="applicationName" placeholder="Name" />
<Field type="hidden" name="orgId" component="input" />
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>
);
};
const mapStateToProps = (state: AppState, props: Props): any => {
const orgId = props.orgId;
return {
2020-06-25 10:04:57 +00:00
initialValues: { orgId },
};
};
export default connect(mapStateToProps)(
reduxForm<
CreateApplicationFormValues,
{ onCancel: () => void; orgId: string; initialValues: {} }
>({
2020-02-03 10:37:03 +00:00
form: CREATE_APPLICATION_FORM_NAME,
onSubmit: createApplicationFormSubmitHandler,
})(CreateApplicationForm),
);