X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/35df2cdddc36985bdca21547d7c12332ea032b1c..a1310aae9f24935feae463542e9bfde298a5d9e4:/src/views-components/dialog-create/dialog-project-create.tsx

diff --git a/src/views-components/dialog-create/dialog-project-create.tsx b/src/views-components/dialog-create/dialog-project-create.tsx
index 8c690c09..e77114b3 100644
--- a/src/views-components/dialog-create/dialog-project-create.tsx
+++ b/src/views-components/dialog-create/dialog-project-create.tsx
@@ -5,16 +5,13 @@
 import * as React from 'react';
 import { reduxForm, Field } from 'redux-form';
 import { compose } from 'redux';
-import TextField from '@material-ui/core/TextField';
-import Dialog from '@material-ui/core/Dialog';
-import DialogActions from '@material-ui/core/DialogActions';
-import DialogContent from '@material-ui/core/DialogContent';
-import DialogTitle from '@material-ui/core/DialogTitle';
+import { TextField } from '~/components/text-field/text-field';
+import { Dialog, DialogActions, DialogContent, DialogTitle } from '@material-ui/core/';
 import { Button, StyleRulesCallback, WithStyles, withStyles, CircularProgress } from '@material-ui/core';
 
-import { NAME, DESCRIPTION } from '../../validators/create-project/create-project-validator';
+import { PROJECT_NAME_VALIDATION, PROJECT_DESCRIPTION_VALIDATION } from '~/validators/validators';
 
-type CssRules = "button" | "lastButton" | "formContainer" | "textField" | "dialog" | "dialogTitle" | "createProgress" | "dialogActions";
+type CssRules = "button" | "lastButton" | "formContainer" | "dialog" | "dialogTitle" | "createProgress" | "dialogActions";
 
 const styles: StyleRulesCallback<CssRules> = theme => ({
     button: {
@@ -32,9 +29,6 @@ const styles: StyleRulesCallback<CssRules> = theme => ({
     dialogTitle: {
         paddingBottom: "0"
     },
-    textField: {
-        marginTop: "32px",
-    },
     dialog: {
         minWidth: "600px",
         minHeight: "320px"
@@ -54,74 +48,55 @@ interface DialogProjectProps {
     onSubmit: (data: { name: string, description: string }) => void;
     handleSubmit: any;
     submitting: boolean;
+    invalid: boolean;
+    pristine: boolean;
 }
 
-interface TextFieldProps {
-    label: string;
-    floatinglabeltext: string;
-    className?: string;
-    input?: string;
-    meta?: any;
-}
+export const PROJECT_CREATE_DIALOG = "projectCreateDialog";
 
-class DialogProjectCreate extends React.Component<DialogProjectProps & WithStyles<CssRules>> {
-    render() {
-        const { classes, open, handleClose, handleSubmit, onSubmit, submitting } = this.props;
+export const DialogProjectCreate = compose(
+    reduxForm({ form: PROJECT_CREATE_DIALOG }),
+    withStyles(styles))(
+    class DialogProjectCreate extends React.Component<DialogProjectProps & WithStyles<CssRules>> {
+        render() {
+            const { classes, open, handleClose, handleSubmit, onSubmit, submitting, invalid, pristine } = this.props;
 
-        return (
-            <Dialog
-                open={open}
-                onClose={handleClose}
-                disableBackdropClick={true}
-                disableEscapeKeyDown={true}>
-                <div className={classes.dialog}>
-                    <form onSubmit={handleSubmit((data: any) => onSubmit(data))}>
-                        <DialogTitle id="form-dialog-title" className={classes.dialogTitle}>Create a project</DialogTitle>
-                        <DialogContent className={classes.formContainer}>
-                            <Field name="name"
-                                component={this.renderTextField}
-                                floatinglabeltext="Project Name"
-                                validate={NAME}
-                                className={classes.textField}
-                                label="Project Name" />
-                            <Field name="description"
-                                component={this.renderTextField}
-                                floatinglabeltext="Description - optional"
-                                validate={DESCRIPTION}
-                                className={classes.textField}
-                                label="Description - optional" />
-                        </DialogContent>
-                        <DialogActions className={classes.dialogActions}>
-                            <Button onClick={handleClose} className={classes.button} color="primary" disabled={submitting}>CANCEL</Button>
-                            <Button type="submit"
-                                className={classes.lastButton}
-                                color="primary"
-                                disabled={submitting}
-                                variant="contained">
-                                CREATE A PROJECT
-                            </Button>
-                            {submitting && <CircularProgress size={20} className={classes.createProgress} />}
-                        </DialogActions>
-                    </form>
-                </div>
-            </Dialog>
-        );
+            return (
+                <Dialog
+                    open={open}
+                    onClose={handleClose}
+                    disableBackdropClick={true}
+                    disableEscapeKeyDown={true}>
+                    <div className={classes.dialog}>
+                        <form onSubmit={handleSubmit((data: any) => onSubmit(data))}>
+                            <DialogTitle id="form-dialog-title" className={classes.dialogTitle}>Create a
+                                project</DialogTitle>
+                            <DialogContent className={classes.formContainer}>
+                                <Field name="name"
+                                       component={TextField}
+                                       validate={PROJECT_NAME_VALIDATION}
+                                       label="Project Name"/>
+                                <Field name="description"
+                                       component={TextField}
+                                       validate={PROJECT_DESCRIPTION_VALIDATION}
+                                       label="Description - optional"/>
+                            </DialogContent>
+                            <DialogActions className={classes.dialogActions}>
+                                <Button onClick={handleClose} className={classes.button} color="primary"
+                                        disabled={submitting}>CANCEL</Button>
+                                <Button type="submit"
+                                        className={classes.lastButton}
+                                        color="primary"
+                                        disabled={invalid || submitting || pristine}
+                                        variant="contained">
+                                    CREATE A PROJECT
+                                </Button>
+                                {submitting && <CircularProgress size={20} className={classes.createProgress}/>}
+                            </DialogActions>
+                        </form>
+                    </div>
+                </Dialog>
+            );
+        }
     }
-
-    renderTextField = ({ input, label, meta: { touched, error }, ...custom }: TextFieldProps) => (
-        <TextField
-            helperText={touched && error}
-            label={label}
-            className={this.props.classes.textField}
-            error={touched && !!error}
-            autoComplete='off'
-            {...input}
-            {...custom}
-        />
-    )
-}
-
-export default compose(
-    reduxForm({ form: 'projectCreateDialog' }),
-    withStyles(styles)
-)(DialogProjectCreate);
+);
