Groups can now be added via the UI

This commit is contained in:
Philipp Czora
2018-07-31 18:44:01 +02:00
parent c12040d8d0
commit d532c36204
5 changed files with 121 additions and 20 deletions

View File

@@ -22,5 +22,11 @@
"add-group": { "add-group": {
"title": "Create Group", "title": "Create Group",
"subtitle": "Create a new group" "subtitle": "Create a new group"
},
"create-group-button": {
"label": "Create group"
},
"group-form": {
"submit": "Submit"
} }
} }

View File

@@ -0,0 +1,30 @@
//@flow
import React from "react";
import injectSheet from "react-jss";
import { translate } from "react-i18next";
import { AddButton } from "../../../components/buttons";
import classNames from "classnames";
const styles = {
spacing: {
margin: "1em 0 0 1em"
}
};
type Props = {
t: string => string,
classes: any
};
class CreateGroupButton extends React.Component<Props> {
render() {
const { classes, t } = this.props;
return (
<div className={classNames("is-pulled-right", classes.spacing)}>
<AddButton label={t("create-group-button.label")} link="/groups/add" />
</div>
);
}
}
export default translate("groups")(injectSheet(styles)(CreateGroupButton));

View File

@@ -1,24 +1,44 @@
//@flow //@flow
import React from 'react'; import React from "react";
import Page from "../../components/layout/Page" import Page from "../../components/layout/Page";
import { translate } from "react-i18next"; import { translate } from "react-i18next";
import GroupForm from './GroupForm'; import GroupForm from "./GroupForm";
import { connect } from "react-redux";
import { createGroup } from "../modules/groups";
export interface Props { export interface Props {
t: string => string t: string => string;
} }
export interface State { export interface State {}
}
class AddGroup extends React.Component<Props, State> { class AddGroup extends React.Component<Props, State> {
render() { render() {
const { t } = this.props; const { t } = this.props;
return <Page title={t("add-group.title")} subtitle={t("add-group.subtitle")}><div><GroupForm /></div></Page> return (
<Page title={t("add-group.title")} subtitle={t("add-group.subtitle")}>
<div>
<GroupForm submitForm={group => this.createGroup(group)} />
</div>
</Page>
);
} }
createGroup = (group: Group) => {
this.props.createGroup(group);
};
} }
export default translate("groups")(AddGroup); const mapDispatchToProps = dispatch => {
return {
createGroup: (group: Group) => dispatch(createGroup(group))
};
};
const mapStateToProps = state => {};
export default connect(
mapStateToProps,
mapDispatchToProps
)(translate("groups")(AddGroup));

View File

@@ -1,23 +1,68 @@
//@flow //@flow
import React from 'react'; import React from "react";
import InputField from "../../components/forms/InputField";
import { SubmitButton } from "../../components/buttons";
import { translate } from "react-i18next";
import type { Group } from "../types/Group";
import InputField from "../../components/forms/InputField"
export interface Props { export interface Props {
t: string => string;
submitForm: Group => void;
} }
export interface State { export interface State {
group: Group;
} }
class GroupForm extends React.Component<Props, State> { class GroupForm extends React.Component<Props, State> {
constructor(props) {
super(props);
this.state = {};
}
onSubmit = (event: Event) => {
event.preventDefault();
this.props.submitForm(this.state.group);
};
render() { render() {
const { t } = this.props;
return ( return (
<form> <form onSubmit={this.onSubmit}>
<InputField label="Name" errorMessage="" onChange={()=>{}} validationError={false}/> <InputField
label={t("group.name")}
errorMessage=""
onChange={this.handleGroupNameChange}
validationError={false}
/>
<InputField
label={t("group.description")}
errorMessage=""
onChange={this.handleDescriptionChange}
validationError={false}
/>
<SubmitButton label={t("group-form.submit")} />
</form> </form>
) );
} }
handleGroupNameChange = (name: string) => {
this.setState({
group: {
...this.state.group,
name
}
});
};
handleDescriptionChange = (description: string) => {
this.setState({
group: {
...this.state.group,
description
}
});
};
} }
export default GroupForm; export default translate("groups")(GroupForm);

View File

@@ -8,6 +8,7 @@ import type { History } from "history";
import { Page } from "../../components/layout"; import { Page } from "../../components/layout";
import { GroupTable } from "./../components/table"; import { GroupTable } from "./../components/table";
import Paginator from "../../components/Paginator"; import Paginator from "../../components/Paginator";
import CreateGroupButton from "../components/buttons/CreateGroupButton";
import { import {
fetchGroupsByPage, fetchGroupsByPage,
@@ -37,7 +38,6 @@ type Props = {
}; };
class Groups extends React.Component<Props> { class Groups extends React.Component<Props> {
componentDidMount() { componentDidMount() {
this.props.fetchGroupsByPage(this.props.page); this.props.fetchGroupsByPage(this.props.page);
} }
@@ -85,11 +85,11 @@ class Groups extends React.Component<Props> {
} }
renderCreateButton() { renderCreateButton() {
/* if (this.props.canAddGroups) { if (this.props.canAddGroups) {
return <CreateGroupButton />; return <CreateGroupButton />;
} else { } else {
return; return;
}*/ }
} }
} }
@@ -122,7 +122,7 @@ const mapStateToProps = (state, ownProps) => {
}; };
}; };
const mapDispatchToProps = (dispatch) => { const mapDispatchToProps = dispatch => {
return { return {
fetchGroupsByPage: (page: number) => { fetchGroupsByPage: (page: number) => {
dispatch(fetchGroupsByPage(page)); dispatch(fetchGroupsByPage(page));