diff --git a/ui/src/pages/Users.js b/ui/src/pages/Users.js deleted file mode 100644 index 3ea1523..0000000 --- a/ui/src/pages/Users.js +++ /dev/null @@ -1,202 +0,0 @@ -import React, {Component} from 'react'; -import Grid from 'material-ui/Grid'; -import {withStyles} from 'material-ui/styles'; -import Table, {TableBody, TableCell, TableHead, TableRow} from 'material-ui/Table'; -import Paper from 'material-ui/Paper'; -import Switch from 'material-ui/Switch'; -import Button from 'material-ui/Button'; -import IconButton from 'material-ui/IconButton'; -import Dialog, {DialogActions, DialogContent, DialogTitle} from 'material-ui/Dialog'; -import TextField from 'material-ui/TextField'; -import Tooltip from 'material-ui/Tooltip'; -import UserStore from '../stores/UserStore'; -import * as UserAction from '../actions/UserAction'; -import {FormControlLabel} from 'material-ui/Form'; -import ConfirmDialog from '../component/ConfirmDialog'; -import DefaultPage from '../component/DefaultPage'; -import Delete from 'material-ui-icons/Delete'; -import Edit from 'material-ui-icons/Edit'; -import PropTypes from 'prop-types'; - -const styles = () => ({ - wrapper: { - margin: '0 auto', - maxWidth: 700, - }, -}); - -class UserRow extends Component { - static propTypes = { - name: PropTypes.string.isRequired, - admin: PropTypes.bool.isRequired, - fDelete: PropTypes.func.isRequired, - fEdit: PropTypes.func.isRequired, - }; - - render() { - const {name, admin, fDelete, fEdit} = this.props; - return ( - - {name} - {admin ? 'Yes' : 'No'} - - - - - - ); - } -} - -class Users extends Component { - constructor() { - super(); - this.state = {users: [], createDialog: false, deleteId: -1, editId: -1}; - } - - componentWillMount() { - UserStore.on('change', this.updateUsers); - this.updateUsers(); - } - - componentWillUnmount() { - UserStore.removeListener('change', this.updateUsers); - } - - updateUsers = () => this.setState({...this.state, users: UserStore.get()}); - - showCreateDialog = () => this.setState({...this.state, createDialog: true}); - hideCreateDialog = () => this.setState({...this.state, createDialog: false}); - - showEditDialog = (editId) => this.setState({...this.state, editId}); - hideEditDialog = () => this.setState({...this.state, editId: -1}); - - showDeleteDialog = (deleteId) => this.setState({...this.state, deleteId}); - hideDeleteDialog = () => this.setState({...this.state, deleteId: -1}); - - render() { - const {users, deleteId, editId} = this.state; - return ( - - - - - - - Name - Admin - - - - - {users.map((user) => { - return ( - this.showDeleteDialog(user.id)} - fEdit={() => this.showEditDialog(user.id)}/> - ); - })} - -
-
-
- {this.state.createDialog && } - {editId !== -1 && } - {deleteId !== -1 && UserAction.deleteUser(this.state.deleteId)} - />} -
- ); - } -} - -class AddEditDialog extends Component { - static defaultProps = { - name: '', - pass: '', - admin: false, - isEdit: false, - }; - - static propTypes = { - name: PropTypes.string.isRequired, - admin: PropTypes.bool.isRequired, - fClose: PropTypes.func.isRequired, - fOnSubmit: PropTypes.func.isRequired, - isEdit: PropTypes.bool.isRequired, - }; - - constructor() { - super(); - this.state = { - name: '', - pass: '', - admin: false, - }; - } - - componentWillMount() { - const {name, admin} = this.props; - this.setState({...this.state, name, admin: admin}); - } - - - handleChange(propertyName, event) { - const state = this.state; - state[propertyName] = event.target.value; - this.setState(state); - } - - handleChecked(propertyName, event) { - const state = this.state; - state[propertyName] = event.target.checked; - this.setState(state); - } - - render() { - const {fClose, fOnSubmit, isEdit} = this.props; - const {name, pass, admin} = this.state; - const namePresent = this.state.name.length !== 0; - const passPresent = this.state.pass.length !== 0 || isEdit; - const submitAndClose = () => { - fOnSubmit(name, pass, admin); - fClose(); - }; - return ( - - {isEdit ? 'Edit ' + this.props.name : 'Add a user'} - - - - } label="has administrator rights"/> - - - - -
- -
-
-
-
- ); - } -} - -export default withStyles(styles)(Users); diff --git a/ui/src/pages/Users.tsx b/ui/src/pages/Users.tsx new file mode 100644 index 0000000..5fdec79 --- /dev/null +++ b/ui/src/pages/Users.tsx @@ -0,0 +1,114 @@ +import {WithStyles} from "material-ui"; +import Delete from 'material-ui-icons/Delete'; +import Edit from 'material-ui-icons/Edit'; +import Grid from 'material-ui/Grid'; +import IconButton from 'material-ui/IconButton'; +import Paper from 'material-ui/Paper'; +import {withStyles} from 'material-ui/styles'; +import Table, {TableBody, TableCell, TableHead, TableRow} from 'material-ui/Table'; +import React, {Component, SFC} from 'react'; +import * as UserAction from '../actions/UserAction'; +import ConfirmDialog from '../component/ConfirmDialog'; +import DefaultPage from '../component/DefaultPage'; +import UserStore from '../stores/UserStore'; +import AddEditDialog from "./dialog/AddEditUserDialog"; + +const styles = () => ({ + wrapper: { + margin: '0 auto', + maxWidth: 700, + }, +}); + +interface IRowProps { + name: string + admin: boolean + fDelete: VoidFunction + fEdit: VoidFunction +} + +const UserRow: SFC = ({name, admin, fDelete, fEdit}) => ( + + {name} + {admin ? 'Yes' : 'No'} + + + + + +); + +interface IState { + users: IUser[] + createDialog: boolean + deleteId: number + editId: number +} + +class Users extends Component, IState> { + public state = {users: [], createDialog: false, deleteId: -1, editId: -1}; + + public componentWillMount() { + UserStore.on('change', this.updateUsers); + this.updateUsers(); + } + + public componentWillUnmount() { + UserStore.removeListener('change', this.updateUsers); + } + + public render() { + const {users, deleteId, editId} = this.state; + return ( + + + + + + + Name + Admin + + + + + {users.map((user: IUser) => { + return ( + this.showDeleteDialog(user.id)} + fEdit={() => this.showEditDialog(user.id)}/> + ); + })} + +
+
+
+ {this.state.createDialog && } + {editId !== -1 && } + {deleteId !== -1 && UserAction.deleteUser(this.state.deleteId)} + />} +
+ ); + } + + private updateUsers = () => this.setState({...this.state, users: UserStore.get()}); + private showCreateDialog = () => this.setState({...this.state, createDialog: true}); + + private hideCreateDialog = () => this.setState({...this.state, createDialog: false}); + private showEditDialog = (editId: number) => this.setState({...this.state, editId}); + + private hideEditDialog = () => this.setState({...this.state, editId: -1}); + private showDeleteDialog = (deleteId: number) => this.setState({...this.state, deleteId}); + + private hideDeleteDialog = () => this.setState({...this.state, deleteId: -1}); +} + +export default withStyles(styles)(Users); diff --git a/ui/src/pages/dialog/AddEditUserDialog.tsx b/ui/src/pages/dialog/AddEditUserDialog.tsx new file mode 100644 index 0000000..f5c176c --- /dev/null +++ b/ui/src/pages/dialog/AddEditUserDialog.tsx @@ -0,0 +1,84 @@ +import Button from 'material-ui/Button'; +import Dialog, {DialogActions, DialogContent, DialogTitle} from 'material-ui/Dialog'; +import {FormControlLabel} from 'material-ui/Form'; +import Switch from 'material-ui/Switch'; +import TextField from 'material-ui/TextField'; +import Tooltip from 'material-ui/Tooltip'; +import React, {ChangeEvent, Component} from 'react'; + +interface IProps { + name?: string + admin?: boolean + fClose: VoidFunction + fOnSubmit: (name: string, pass: string, admin: boolean) => void + isEdit?: boolean +} + +interface IState { + name: string + pass: string + admin: boolean +} + +export default class AddEditDialog extends Component { + public state = { + name: '', + pass: '', + admin: false, + }; + + public render() { + const {fClose, fOnSubmit, isEdit} = this.props; + const {name, pass, admin} = this.state; + const namePresent = this.state.name.length !== 0; + const passPresent = this.state.pass.length !== 0 || isEdit; + const submitAndClose = () => { + fOnSubmit(name, pass, admin); + fClose(); + }; + return ( + + {isEdit ? 'Edit ' + this.props.name : 'Add a user'} + + + + } label="has administrator rights"/> + + + + +
+ +
+
+
+
+ ); + } + + public componentWillMount() { + const {name, admin} = this.props; + this.setState({...this.state, name: name || '', admin: admin || false}); + } + + private handleChange(propertyName: string, event: ChangeEvent) { + const state = this.state; + state[propertyName] = event.target.value; + this.setState(state); + } + + private handleChecked(propertyName: string, event: ChangeEvent) { + const state = this.state; + state[propertyName] = event.target.checked; + this.setState(state); + } +} \ No newline at end of file