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 interface ProjectCreateProps {
17 handleClose: () => void;
18 onSubmit: (data: { name: string, description: string }) => void;
21 interface DialogState {
25 isDescriptionValid: boolean;
28 class DialogProjectCreate extends React.Component<ProjectCreateProps & WithStyles<CssRules>> {
29 state: DialogState = {
33 isDescriptionValid: true
37 const { name, description } = this.state;
38 const { classes, open, handleClose } = this.props;
43 onClose={handleClose}>
44 <div className={classes.dialog}>
45 <DialogTitle id="form-dialog-title" className={classes.dialogTitle}>Create a project</DialogTitle>
46 <DialogContent className={classes.dialogContent}>
49 onChange={e => this.isNameValid(e)}
54 className={classes.textField}
56 onChange={e => this.handleProjectName(e)}
62 onChange={e => this.isDescriptionValid(e)}
67 className={classes.textField}
69 onChange={e => this.handleDescriptionValue(e)}
70 label="Description - optional"
75 <Button onClick={handleClose} className={classes.button} color="primary">CANCEL</Button>
76 <Button onClick={this.handleSubmit} className={classes.lastButton} color="primary" disabled={!this.state.isNameValid || (!this.state.isDescriptionValid && description.length > 0)} variant="raised">CREATE A PROJECT</Button>
83 handleSubmit = () => {
85 name: this.state.name,
86 description: this.state.description
90 handleProjectName(e: React.ChangeEvent<HTMLInputElement>) {
96 handleDescriptionValue(e: React.ChangeEvent<HTMLInputElement>) {
98 description: e.target.value,
102 isNameValid(value: boolean | string) {
108 isDescriptionValid(value: boolean | string) {
110 isDescriptionValid: value,
115 type CssRules = "button" | "lastButton" | "dialogContent" | "textField" | "dialog" | "dialogTitle";
117 const styles: StyleRulesCallback<CssRules> = theme => ({
119 marginLeft: theme.spacing.unit
122 marginLeft: theme.spacing.unit,
140 export default withStyles(styles)(DialogProjectCreate);