import React from 'react';
import PropTypes from 'prop-types';
import { useTranslation } from 'react-i18next';
import {
Modal,
ModalHeader,
ModalBody,
ModalFooter,
} from 'reactstrap';
import AppContainer from '~/client/services/AppContainer';
import PersonalContainer from '~/client/services/PersonalContainer';
import { toastSuccess, toastError } from '~/client/util/apiNotification';
import LdapAuthTest from '../Admin/Security/LdapAuthTest';
import { withUnstatedContainers } from '../UnstatedUtils';
class AssociateModal extends React.Component {
constructor(props) {
super(props);
this.state = {
username: '',
password: '',
};
this.onChangeUsername = this.onChangeUsername.bind(this);
this.onChangePassword = this.onChangePassword.bind(this);
this.onClickAddBtn = this.onClickAddBtn.bind(this);
}
/**
* Change username
*/
onChangeUsername(username) {
this.setState({ username });
}
/**
* Change password
*/
onChangePassword(password) {
this.setState({ password });
}
async onClickAddBtn() {
const { t, personalContainer } = this.props;
const { username, password } = this.state;
try {
await personalContainer.associateLdapAccount({ username, password });
this.props.onClose();
toastSuccess(t('security_setting.updated_general_security_setting'));
}
catch (err) {
toastError(err);
}
try {
await personalContainer.retrieveExternalAccounts();
}
catch (err) {
toastError(err);
}
}
render() {
const { t } = this.props;
return (
{ t('admin:user_management.create_external_account') }
);
}
}
AssociateModal.propTypes = {
t: PropTypes.func.isRequired, // i18next
appContainer: PropTypes.instanceOf(AppContainer).isRequired,
personalContainer: PropTypes.instanceOf(PersonalContainer).isRequired,
isOpen: PropTypes.bool.isRequired,
onClose: PropTypes.func.isRequired,
};
const AssociateModalWrapperFC = (props) => {
const { t } = useTranslation();
return ;
};
/**
* Wrapper component for using unstated
*/
const AssociateModalWrapper = withUnstatedContainers(AssociateModalWrapperFC, [AppContainer, PersonalContainer]);
export default AssociateModalWrapper;