import React from "react"; import { connect } from "react-redux"; import { Form, reduxForm, InjectedFormProps, Field } from "redux-form"; import { CREATE_APPLICATION_FORM_NAME } from "@appsmith/constants/forms"; import { createMessage, ERROR_MESSAGE_NAME_EMPTY, NAME_SPACE_ERROR, } from "@appsmith/constants/messages"; import { AppState } from "@appsmith/reducers"; import { CreateApplicationFormValues, createApplicationFormSubmitHandler, CREATE_APPLICATION_FORM_NAME_FIELD, } from "./helpers"; import TextField from "components/editorComponents/form/fields/TextField"; import FormGroup from "components/editorComponents/form/FormGroup"; import FormFooter from "components/editorComponents/form/FormFooter"; import FormMessage from "components/editorComponents/form/FormMessage"; type Props = InjectedFormProps< CreateApplicationFormValues, { onCancel: () => void; workspaceId: string; initialValues: Record; } > & { onCancel: () => void; workspaceId: string; initialValues: Record; }; const validate = (values: CreateApplicationFormValues) => { if (!values[CREATE_APPLICATION_FORM_NAME_FIELD]) { return { [CREATE_APPLICATION_FORM_NAME_FIELD]: createMessage( ERROR_MESSAGE_NAME_EMPTY, ), }; } else if (!values[CREATE_APPLICATION_FORM_NAME_FIELD].trim()) { return { [CREATE_APPLICATION_FORM_NAME_FIELD]: createMessage(NAME_SPACE_ERROR), }; } return {}; }; // TODO(abhinav): abstract onCancel out. function CreateApplicationForm(props: Props) { const { error, handleSubmit, invalid, pristine, submitting } = props; return (
{error && !pristine && } ); } const mapStateToProps = (state: AppState, props: Props): any => { const workspaceId = props.workspaceId; return { initialValues: { workspaceId }, }; }; export default connect(mapStateToProps)( reduxForm< CreateApplicationFormValues, { onCancel: () => void; workspaceId: string; initialValues: Record; } >({ validate, form: CREATE_APPLICATION_FORM_NAME, onSubmit: createApplicationFormSubmitHandler, })(CreateApplicationForm), );