Refactored group validation

This commit is contained in:
Philipp Czora
2018-08-01 15:54:32 +02:00
parent 6719d12db9
commit f426c14f70
2 changed files with 23 additions and 23 deletions

View File

@@ -5,18 +5,17 @@ import InputField from "../../components/forms/InputField";
import { SubmitButton } from "../../components/buttons";
import { translate } from "react-i18next";
import type { Group } from "../types/Group";
import * as validator from "./groupValidation"
import * as validator from "./groupValidation";
type Props = {
t: string => string,
submitForm: Group => void
}
};
type State = {
group: Group,
nameValidationError: boolean,
descriptionValidationError: boolean
}
nameValidationError: boolean
};
class GroupForm extends React.Component<Props, State> {
constructor(props) {
@@ -30,10 +29,9 @@ class GroupForm extends React.Component<Props, State> {
},
_links: {},
members: [],
type: "",
type: ""
},
nameValidationError: false,
descriptionValidationError: false
nameValidationError: false
};
}
@@ -44,15 +42,15 @@ class GroupForm extends React.Component<Props, State> {
isValid = () => {
const group = this.state.group;
return !(this.state.nameValidationError || this.state.descriptionValidationError || group.name);
}
return !(this.state.nameValidationError || group.name);
};
submit = (event: Event) => {
event.preventDefault();
if (this.isValid) {
this.props.submitForm(this.state.group)
}
this.props.submitForm(this.state.group);
}
};
render() {
const { t } = this.props;
@@ -68,7 +66,7 @@ class GroupForm extends React.Component<Props, State> {
label={t("group.description")}
errorMessage=""
onChange={this.handleDescriptionChange}
validationError={this.state.descriptionValidationError}
validationError={false}
/>
<SubmitButton label={t("group-form.submit")} />
</form>

View File

@@ -13,9 +13,9 @@ type Props = {
t: string => string,
createGroup: (group: Group, callback?: () => void) => void,
history: History
}
};
type State = {}
type State = {};
class AddGroup extends React.Component<Props, State> {
render() {
@@ -30,21 +30,23 @@ class AddGroup extends React.Component<Props, State> {
}
groupCreated = () => {
console.log("pushing history")
this.props.history.push("/groups")
}
this.props.history.push("/groups");
};
createGroup = (group: Group) => {
this.props.createGroup(group, this.groupCreated)
this.props.createGroup(group, this.groupCreated);
};
}
const mapDispatchToProps = dispatch => {
return {
createGroup: (group: Group, callback?: () => void) => dispatch(createGroup(group, callback))
createGroup: (group: Group, callback?: () => void) =>
dispatch(createGroup(group, callback))
};
};
const mapStateToProps = state => {};
const mapStateToProps = state => {
return {}
};
export default connect(
mapStateToProps,