import React from 'react'; import PropTypes from 'prop-types'; import { withTranslation } from 'react-i18next'; import { withUnstatedContainers } from '../../UnstatedUtils'; import AppContainer from '~/client/services/AppContainer'; import { toastSuccess, toastError } from '~/client/util/apiNotification'; class UserGroupCreateForm extends React.Component { constructor(props) { super(props); this.state = { name: '', }; this.xss = window.xss; this.handleChange = this.handleChange.bind(this); this.handleSubmit = this.handleSubmit.bind(this); this.validateForm = this.validateForm.bind(this); } handleChange(event) { const target = event.target; const value = target.type === 'checkbox' ? target.checked : target.value; const name = target.name; this.setState({ [name]: value, }); } async handleSubmit(e) { e.preventDefault(); try { const res = await this.props.appContainer.apiv3.post('/user-groups', { name: this.state.name, }); const userGroup = res.data.userGroup; const userGroupId = userGroup._id; const res2 = await this.props.appContainer.apiv3.get(`/user-groups/${userGroupId}/users`); const { users } = res2.data; this.props.onCreate(userGroup, users); this.setState({ name: '' }); toastSuccess(`Created a user group "${this.xss.process(userGroup.name)}"`); } catch (err) { toastError(err); } } validateForm() { return this.state.name !== ''; } render() { const { t } = this.props; return (
{this.props.isAclEnabled ? ( ) : ( t('admin:user_group_management.deny_create_group') ) }