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, CircularProgress } from '@material-ui/core';
13 import Validator from '../../utils/dialog-validator';
15 interface ProjectCreateProps {
18 handleClose: () => void;
19 onSubmit: (data: { name: string, description: string }) => void;
22 interface DialogState {
26 isDescriptionValid: boolean;
29 class DialogProjectCreate extends React.Component<ProjectCreateProps & WithStyles<CssRules>> {
30 state: DialogState = {
34 isDescriptionValid: true
38 const { name, description, isNameValid, isDescriptionValid } = this.state;
39 const { classes, open, handleClose, pending } = this.props;
44 onClose={handleClose}>
45 <div className={classes.dialog}>
46 <DialogTitle id="form-dialog-title" className={classes.dialogTitle}>Create a project</DialogTitle>
47 <DialogContent className={classes.dialogContent}>
50 onChange={e => this.isNameValid(e)}
55 className={classes.textField}
57 onChange={e => this.handleProjectName(e)}
63 onChange={e => this.isDescriptionValid(e)}
68 className={classes.textField}
70 onChange={e => this.handleDescriptionValue(e)}
71 label="Description - optional"
76 <Button onClick={handleClose} className={classes.button} color="primary">CANCEL</Button>
77 <Button onClick={this.handleSubmit}
78 className={classes.lastButton}
80 disabled={!isNameValid || (!isDescriptionValid && description.length > 0) || pending}
84 {pending && <CircularProgress size={20} className={classes.createProgress} />}
91 handleSubmit = () => {
93 name: this.state.name,
94 description: this.state.description
98 handleProjectName(e: any) {
100 name: e.target.value,
104 handleDescriptionValue(e: any) {
106 description: e.target.value,
110 isNameValid(value: boolean | string) {
116 isDescriptionValid(value: boolean | string) {
118 isDescriptionValid: value,
123 type CssRules = "button" | "lastButton" | "dialogContent" | "textField" | "dialog" | "dialogTitle" | "createProgress";
125 const styles: StyleRulesCallback<CssRules> = theme => ({
127 marginLeft: theme.spacing.unit
130 marginLeft: theme.spacing.unit,
147 position: "absolute",
153 export default withStyles(styles)(DialogProjectCreate);