// @flow import React from "react"; import { connect } from "react-redux"; import { translate } from "react-i18next"; import type { History } from "history"; import queryString from "query-string"; import type { User, PagedCollection } from "@scm-manager/ui-types"; import { fetchUsersByPage, fetchUsersByLink, getUsersFromState, selectListAsCollection, isPermittedToCreateUsers, isFetchUsersPending, getFetchUsersFailure } from "../modules/users"; import { Page, PageActions, Button, CreateButton, LinkPaginator, getPageFromMatch } from "@scm-manager/ui-components"; import { UserTable } from "./../components/table"; import { getUsersLink } from "../../modules/indexResource"; type Props = { users: User[], loading: boolean, error: Error, canAddUsers: boolean, list: PagedCollection, page: number, usersLink: string, // context objects t: string => string, history: History, location: any, // dispatch functions fetchUsersByPage: (link: string, page: number, filter?: any) => void, fetchUsersByLink: (link: string) => void }; type State = { page: number }; class Users extends React.Component { constructor(props: Props) { super(props); this.state = { page: -1 }; } componentDidMount() { const { fetchUsersByPage, usersLink, page } = this.props; fetchUsersByPage(usersLink, page, this.getQueryString()); this.setState({ page: page }); } componentDidUpdate = (prevProps: Props) => { const { list, page, location, fetchUsersByPage, usersLink } = this.props; if (list && page) { if ( page !== this.state.page || prevProps.location.search !== location.search ) { fetchUsersByPage(usersLink, page, this.getQueryString()); this.setState({ page: page }); } } }; render() { const { users, loading, error, history, t } = this.props; return ( { history.push("/users/?q=" + filter); }} > {this.renderPaginator()} {this.renderCreateButton()} {this.renderPageActionCreateButton()} ); } renderPaginator = () => { const { list, page } = this.props; if (list) { return ( ); } return null; }; renderCreateButton() { const { canAddUsers, t } = this.props; if (canAddUsers) { return ; } return null; } renderPageActionCreateButton() { const { canAddUsers, t } = this.props; if (canAddUsers) { return (