onChange: (isValid: boolean | string) => void;
render: (hasError: boolean) => React.ReactElement<any>;
isRequired: boolean;
- duplicatedName?: string;
+ isUniqName?: boolean;
};
interface ValidatorState {
}
render() {
- const { classes, isRequired, value, duplicatedName } = this.props;
+ const { classes, isRequired, value, isUniqName } = this.props;
const { isLengthValid } = this.state;
return (
<span>
{this.props.render(!isLengthValid && (isRequired || (!isRequired && value.length > 0)))}
{!isLengthValid ? <span className={classes.formInputError}>This field should have max 255 characters.</span> : null}
- {duplicatedName ? <span className={classes.formInputError}>Project with this name already exists</span> : null}
+ {isUniqName ? <span className={classes.formInputError}>Project with this name already exists</span> : null}
</span>
);
}
description: string;
isNameValid: boolean;
isDescriptionValid: boolean;
- duplicatedName: string;
+ isUniqName: boolean;
}
class DialogProjectCreate extends React.Component<ProjectCreateProps & WithStyles<CssRules>> {
description: '',
isNameValid: false,
isDescriptionValid: true,
- duplicatedName: ''
+ isUniqName: false
};
componentWillReceiveProps(nextProps: ProjectCreateProps) {
const { error } = nextProps;
if (this.props.error !== error) {
- this.setState({ duplicatedName: error });
+ this.setState({ isUniqName: error });
}
}
render() {
- const { name, description, isNameValid, isDescriptionValid, duplicatedName } = this.state;
+ const { name, description, isNameValid, isDescriptionValid, isUniqName } = this.state;
const { classes, open, handleClose, pending } = this.props;
return (
value={name}
onChange={e => this.isNameValid(e)}
isRequired={true}
- duplicatedName={duplicatedName}
+ isUniqName={isUniqName}
render={hasError =>
<TextField
margin="dense"
id="name"
onChange={e => this.handleProjectName(e)}
label="Project name"
- error={hasError || !!duplicatedName}
+ error={hasError || isUniqName}
fullWidth />} />
<Validator
value={description}
handleProjectName(e: any) {
this.setState({
name: e.target.value,
- duplicatedName: ''
+ isUniqName: ''
});
}