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 {
19 handleClose: () => void;
20 onSubmit: (data: { name: string, description: string }) => void;
23 interface DialogState {
27 isDescriptionValid: boolean;
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) {
44 this.setState({ isUniqName: error });
49 const { name, description, isNameValid, isDescriptionValid, isUniqName } = this.state;
50 const { classes, open, handleClose, pending } = this.props;
55 onClose={handleClose}>
56 <div className={classes.dialog}>
57 <DialogTitle id="form-dialog-title" className={classes.dialogTitle}>Create a project</DialogTitle>
58 <DialogContent className={classes.dialogContent}>
61 onChange={e => this.isNameValid(e)}
63 isUniqName={isUniqName}
67 className={classes.textField}
69 onChange={e => this.handleProjectName(e)}
71 error={hasError || isUniqName}
75 onChange={e => this.isDescriptionValid(e)}
80 className={classes.textField}
82 onChange={e => this.handleDescriptionValue(e)}
83 label="Description - optional"
88 <Button onClick={handleClose} className={classes.button} color="primary" disabled={pending}>CANCEL</Button>
89 <Button onClick={this.handleSubmit}
90 className={classes.lastButton}
92 disabled={!isNameValid || (!isDescriptionValid && description.length > 0) || pending}
96 {pending && <CircularProgress size={20} className={classes.createProgress} />}
103 handleSubmit = () => {
104 this.props.onSubmit({
105 name: this.state.name,
106 description: this.state.description
110 handleProjectName(e: any) {
112 name: e.target.value,
117 handleDescriptionValue(e: any) {
119 description: e.target.value,
123 isNameValid(value: boolean | string) {
129 isDescriptionValid(value: boolean | string) {
131 isDescriptionValid: value,
136 type CssRules = "button" | "lastButton" | "dialogContent" | "textField" | "dialog" | "dialogTitle" | "createProgress";
138 const styles: StyleRulesCallback<CssRules> = theme => ({
140 marginLeft: theme.spacing.unit
143 marginLeft: theme.spacing.unit,
160 position: "absolute",
166 export default withStyles(styles)(DialogProjectCreate);