import React from 'react'; import PropTypes from 'prop-types'; import { withTranslation } from 'react-i18next'; import loggerFactory from '@alias/logger'; import { TabContent, TabPane, Nav, NavItem, NavLink, } from 'reactstrap'; import { withUnstatedContainers } from '../../UnstatedUtils'; import { toastSuccess, toastError } from '../../../util/apiNotification'; import AppContainer from '../../../services/AppContainer'; import AdminAppContainer from '../../../services/AdminAppContainer'; import SmtpSetting from './SmtpSetting'; import SesSetting from './SesSetting'; const logger = loggerFactory('growi:mailSettings'); class MailSetting extends React.Component { constructor(props) { super(props); this.state = { activeTab: 'smtp-setting', // Prevent unnecessary rendering activeComponents: new Set(['smtp-setting']), }; this.emailInput = React.createRef(); this.hostInput = React.createRef(); this.portInput = React.createRef(); this.userInput = React.createRef(); this.passwordInput = React.createRef(); this.submitFromAdressHandler = this.submitFromAdressHandler.bind(this); } toggleActiveTab(activeTab) { this.setState({ activeTab, activeComponents: this.state.activeComponents.add(activeTab), }); } async submitFromAdressHandler() { const { t, adminAppContainer } = this.props; try { await adminAppContainer.updateFromAdressHandler(); toastSuccess(t('toaster.update_successed', { target: t('admin:app_setting.mail_settings') })); } catch (err) { toastError(err); logger.error(err); } } render() { const { t, adminAppContainer } = this.props; const { activeTab, activeComponents } = this.state; return ( {!adminAppContainer.state.isMailerSetup && (

{t('admin:app_setting.mailer_is_not_set_up')}

)}
{ adminAppContainer.changeFromAddress(e.target.value) }} />
{activeComponents.has('smtp-setting') && } {activeComponents.has('ses-setting') && }
); } } /** * Wrapper component for using unstated */ const MailSettingWrapper = withUnstatedContainers(MailSetting, [AppContainer, AdminAppContainer]); MailSetting.propTypes = { t: PropTypes.func.isRequired, // i18next appContainer: PropTypes.instanceOf(AppContainer).isRequired, adminAppContainer: PropTypes.instanceOf(AdminAppContainer).isRequired, }; export default withTranslation()(MailSettingWrapper);