// @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, Notification, 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 }; class Users extends React.Component { componentDidMount() { const { fetchUsersByPage, usersLink, page } = this.props; fetchUsersByPage(usersLink, page, this.getQueryString()); } componentDidUpdate = (prevProps: Props) => { const { list, page, loading, location, fetchUsersByPage, usersLink } = this.props; if (list && page && !loading) { const statePage: number = list.page + 1; if ( page !== statePage || prevProps.location.search !== location.search ) { fetchUsersByPage(usersLink, page, this.getQueryString()); } } }; render() { const { users, loading, error, history, t } = this.props; return ( { history.push("/users/?q=" + filter); }} > {this.renderUserTable()} {this.renderCreateButton()} {this.renderPageActionCreateButton()} ); } renderUserTable() { const { users, t } = this.props; if (users && users.length > 0) { return ( <> {this.renderPaginator()} ); } return {t("users.noUsers")}; } 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 (