mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 16:05:44 +01:00
Refactored group validation
This commit is contained in:
@@ -5,18 +5,17 @@ import InputField from "../../components/forms/InputField";
|
|||||||
import { SubmitButton } from "../../components/buttons";
|
import { SubmitButton } from "../../components/buttons";
|
||||||
import { translate } from "react-i18next";
|
import { translate } from "react-i18next";
|
||||||
import type { Group } from "../types/Group";
|
import type { Group } from "../types/Group";
|
||||||
import * as validator from "./groupValidation"
|
import * as validator from "./groupValidation";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
t: string => string,
|
t: string => string,
|
||||||
submitForm: Group => void
|
submitForm: Group => void
|
||||||
}
|
};
|
||||||
|
|
||||||
type State = {
|
type State = {
|
||||||
group: Group,
|
group: Group,
|
||||||
nameValidationError: boolean,
|
nameValidationError: boolean
|
||||||
descriptionValidationError: boolean
|
};
|
||||||
}
|
|
||||||
|
|
||||||
class GroupForm extends React.Component<Props, State> {
|
class GroupForm extends React.Component<Props, State> {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@@ -30,10 +29,9 @@ class GroupForm extends React.Component<Props, State> {
|
|||||||
},
|
},
|
||||||
_links: {},
|
_links: {},
|
||||||
members: [],
|
members: [],
|
||||||
type: "",
|
type: ""
|
||||||
},
|
},
|
||||||
nameValidationError: false,
|
nameValidationError: false
|
||||||
descriptionValidationError: false
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,15 +42,15 @@ class GroupForm extends React.Component<Props, State> {
|
|||||||
|
|
||||||
isValid = () => {
|
isValid = () => {
|
||||||
const group = this.state.group;
|
const group = this.state.group;
|
||||||
return !(this.state.nameValidationError || this.state.descriptionValidationError || group.name);
|
return !(this.state.nameValidationError || group.name);
|
||||||
}
|
};
|
||||||
|
|
||||||
submit = (event: Event) => {
|
submit = (event: Event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if (this.isValid) {
|
if (this.isValid) {
|
||||||
this.props.submitForm(this.state.group)
|
this.props.submitForm(this.state.group);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { t } = this.props;
|
const { t } = this.props;
|
||||||
@@ -68,7 +66,7 @@ class GroupForm extends React.Component<Props, State> {
|
|||||||
label={t("group.description")}
|
label={t("group.description")}
|
||||||
errorMessage=""
|
errorMessage=""
|
||||||
onChange={this.handleDescriptionChange}
|
onChange={this.handleDescriptionChange}
|
||||||
validationError={this.state.descriptionValidationError}
|
validationError={false}
|
||||||
/>
|
/>
|
||||||
<SubmitButton label={t("group-form.submit")} />
|
<SubmitButton label={t("group-form.submit")} />
|
||||||
</form>
|
</form>
|
||||||
@@ -78,13 +76,13 @@ class GroupForm extends React.Component<Props, State> {
|
|||||||
handleGroupNameChange = (name: string) => {
|
handleGroupNameChange = (name: string) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
nameValidationError: !validator.isNameValid(name),
|
nameValidationError: !validator.isNameValid(name),
|
||||||
group: {...this.state.group, name}
|
group: { ...this.state.group, name }
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
handleDescriptionChange = (description: string) => {
|
handleDescriptionChange = (description: string) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
group: {...this.state.group, description }
|
group: { ...this.state.group, description }
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ type Props = {
|
|||||||
t: string => string,
|
t: string => string,
|
||||||
createGroup: (group: Group, callback?: () => void) => void,
|
createGroup: (group: Group, callback?: () => void) => void,
|
||||||
history: History
|
history: History
|
||||||
}
|
};
|
||||||
|
|
||||||
type State = {}
|
type State = {};
|
||||||
|
|
||||||
class AddGroup extends React.Component<Props, State> {
|
class AddGroup extends React.Component<Props, State> {
|
||||||
render() {
|
render() {
|
||||||
@@ -30,21 +30,23 @@ class AddGroup extends React.Component<Props, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
groupCreated = () => {
|
groupCreated = () => {
|
||||||
console.log("pushing history")
|
this.props.history.push("/groups");
|
||||||
this.props.history.push("/groups")
|
};
|
||||||
}
|
|
||||||
createGroup = (group: Group) => {
|
createGroup = (group: Group) => {
|
||||||
this.props.createGroup(group, this.groupCreated)
|
this.props.createGroup(group, this.groupCreated);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapDispatchToProps = dispatch => {
|
const mapDispatchToProps = dispatch => {
|
||||||
return {
|
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(
|
export default connect(
|
||||||
mapStateToProps,
|
mapStateToProps,
|
||||||
|
|||||||
Reference in New Issue
Block a user