import * as React from 'react'; import I18n from 'i18n-js'; import UserEditable from './UserEditable'; import Box from '../../common/Box'; import SiteSettingsInfoBox from '../../common/SiteSettingsInfoBox'; import { UsersState } from '../../../reducers/usersReducer'; import { UserRoles, USER_STATUS_ACTIVE, USER_STATUS_BLOCKED } from '../../../interfaces/IUser'; import HttpStatus from '../../../constants/http_status'; import Spinner from '../../common/Spinner'; interface Props { users: UsersState; settingsAreUpdating: boolean; settingsError: string; requestUsers(): void; updateUserRole( id: number, role: UserRoles, authenticityToken: string, ): Promise; updateUserStatus( id: number, status: typeof USER_STATUS_ACTIVE | typeof USER_STATUS_BLOCKED, authenticityToken: string, ): void; currentUserEmail: string; currentUserRole: UserRoles; authenticityToken: string; } class UsersSiteSettingsP extends React.Component { constructor(props: Props) { super(props); this._handleUpdateUserRole = this._handleUpdateUserRole.bind(this); this._handleUpdateUserStatus = this._handleUpdateUserStatus.bind(this); } componentDidMount() { this.props.requestUsers(); } _handleUpdateUserRole(id: number, role: UserRoles, closeEditMode: Function) { this.props.updateUserRole( id, role, this.props.authenticityToken, ).then(res => { if (res?.status !== HttpStatus.OK) return; closeEditMode(); }); } _handleUpdateUserStatus(id: number, status: typeof USER_STATUS_ACTIVE | typeof USER_STATUS_BLOCKED) { this.props.updateUserStatus( id, status, this.props.authenticityToken, ); } render() { const { users, settingsAreUpdating, settingsError, currentUserRole, currentUserEmail, } = this.props; return ( <>

{ I18n.t('site_settings.users.title') }

    { users.areLoading === false ? users.items.map((user, i) => ( )) : }
); } } export default UsersSiteSettingsP;