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, Typography } from '@material-ui/core';
13 import Validator from '../../utils/dialog-validator';
15 interface ProjectCreateProps {
19 handleClose: () => void;
20 onSubmit: (data: { name: string, description: string }) => void;
23 interface DialogState {
27 isDescriptionValid: boolean;
28 duplicatedName: string;
31 class DialogProjectCreate extends React.Component<ProjectCreateProps & WithStyles<CssRules>> {
32 state: DialogState = {
36 isDescriptionValid: true,
40 componentWillReceiveProps(nextProps: ProjectCreateProps) {
41 const { error } = nextProps;
43 if (this.props.error !== error) {
51 const { name, description, isNameValid, isDescriptionValid, duplicatedName } = this.state;
52 const { classes, open, handleClose, pending } = this.props;
57 onClose={handleClose}>
58 <div className={classes.dialog}>
59 <DialogTitle id="form-dialog-title" className={classes.dialogTitle}>Create a project</DialogTitle>
60 <DialogContent className={classes.dialogContent}>
63 onChange={e => this.isNameValid(e)}
65 duplicatedName={duplicatedName}
69 className={classes.textField}
71 onChange={e => this.handleProjectName(e)}
73 error={hasError || !!duplicatedName}
77 onChange={e => this.isDescriptionValid(e)}
82 className={classes.textField}
84 onChange={e => this.handleDescriptionValue(e)}
85 label="Description - optional"
90 <Button onClick={handleClose} className={classes.button} color="primary" disabled={pending}>CANCEL</Button>
91 <Button onClick={this.handleSubmit}
92 className={classes.lastButton}
94 disabled={!isNameValid || (!isDescriptionValid && description.length > 0) || pending}
98 {pending && <CircularProgress size={20} className={classes.createProgress} />}
105 handleSubmit = () => {
106 this.props.onSubmit({
107 name: this.state.name,
108 description: this.state.description
112 handleProjectName(e: any) {
114 name: e.target.value,
119 handleDescriptionValue(e: any) {
121 description: e.target.value,
125 isNameValid(value: boolean | string) {
131 isDescriptionValid(value: boolean | string) {
133 isDescriptionValid: value,
138 type CssRules = "button" | "lastButton" | "dialogContent" | "textField" | "dialog" | "dialogTitle" | "createProgress";
140 const styles: StyleRulesCallback<CssRules> = theme => ({
142 marginLeft: theme.spacing.unit
145 marginLeft: theme.spacing.unit,
162 position: "absolute",
168 export default withStyles(styles)(DialogProjectCreate);