1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import TextField from '@material-ui/core/TextField';
7 import Dialog from '@material-ui/core/Dialog';
8 import DialogActions from '@material-ui/core/DialogActions';
9 import DialogContent from '@material-ui/core/DialogContent';
10 import DialogTitle from '@material-ui/core/DialogTitle';
11 import { Button, StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core';
13 import { Validator } from '../../utils/dialog-validator';
15 type CssRules = "button" | "lastButton" | "dialogContent" | "textField" | "dialog" | "dialogTitle";
17 const styles: StyleRulesCallback<CssRules> = theme => ({
19 marginLeft: theme.spacing.unit
22 marginLeft: theme.spacing.unit,
40 interface ProjectCreateProps {
42 handleClose: () => void;
43 onSubmit: (data: { name: string, description: string }) => void;
46 interface DialogState {
50 isDescriptionValid: boolean;
53 export const DialogProjectCreate = withStyles(styles)(
54 class extends React.Component<ProjectCreateProps & WithStyles<CssRules>> {
55 state: DialogState = {
59 isDescriptionValid: true
63 const { name, description } = this.state;
64 const { classes, open, handleClose } = this.props;
69 onClose={handleClose}>
70 <div className={classes.dialog}>
71 <DialogTitle id="form-dialog-title" className={classes.dialogTitle}>Create a project</DialogTitle>
72 <DialogContent className={classes.dialogContent}>
75 onChange={e => this.isNameValid(e)}
80 className={classes.textField}
82 onChange={e => this.handleProjectName(e)}
88 onChange={e => this.isDescriptionValid(e)}
93 className={classes.textField}
95 onChange={e => this.handleDescriptionValue(e)}
96 label="Description - optional"
101 <Button onClick={handleClose} className={classes.button} color="primary">CANCEL</Button>
102 <Button onClick={this.handleSubmit} className={classes.lastButton} color="primary"
103 disabled={!this.state.isNameValid || (!this.state.isDescriptionValid && description.length > 0)}
104 variant="raised">CREATE A PROJECT</Button>
111 handleSubmit = () => {
112 this.props.onSubmit({
113 name: this.state.name,
114 description: this.state.description
118 handleProjectName(e: React.ChangeEvent<HTMLInputElement>) {
120 name: e.target.value,
124 handleDescriptionValue(e: React.ChangeEvent<HTMLInputElement>) {
126 description: e.target.value,
130 isNameValid(value: boolean | string) {
136 isDescriptionValid(value: boolean | string) {
138 isDescriptionValid: value,