/* eslint-disable react/no-danger */ import React from 'react'; import PropTypes from 'prop-types'; import { withTranslation } from 'react-i18next'; import { createSubscribedElement } from '../../UnstatedUtils'; import { toastSuccess, toastError } from '../../../util/apiNotification'; import AppContainer from '../../../services/AppContainer'; import AdminGeneralSecurityContainer from '../../../services/AdminGeneralSecurityContainer'; import AdminGoogleSecurityContainer from '../../../services/AdminGoogleSecurityContainer'; class GoogleSecurityManagement extends React.Component { constructor(props) { super(props); this.state = { isRetrieving: true, }; this.onClickSubmit = this.onClickSubmit.bind(this); } async componentDidMount() { const { adminGoogleSecurityContainer } = this.props; try { await adminGoogleSecurityContainer.retrieveSecurityData(); } catch (err) { toastError(err); } this.setState({ isRetrieving: false }); } async onClickSubmit() { const { t, adminGoogleSecurityContainer, adminGeneralSecurityContainer } = this.props; try { await adminGoogleSecurityContainer.updateGoogleSetting(); await adminGeneralSecurityContainer.retrieveSetupStratedies(); toastSuccess(t('security_setting.OAuth.Google.updated_google')); } catch (err) { toastError(err); } } render() { const { t, adminGeneralSecurityContainer, adminGoogleSecurityContainer } = this.props; const { isGoogleEnabled } = adminGeneralSecurityContainer.state; if (this.state.isRetrieving) { return null; } return (

{t('security_setting.OAuth.Google.name')}

{this.state.retrieveError != null && (

{t('Error occurred')} : {this.state.err}

)}
{ adminGeneralSecurityContainer.switchIsGoogleOAuthEnabled() }} />
{(!adminGeneralSecurityContainer.state.setupStrategies.includes('google') && isGoogleEnabled) &&
{t('security_setting.setup_is_not_yet_complete')}
}

{t('security_setting.desc_of_callback_URL', { AuthName: 'OAuth' })}

{!adminGeneralSecurityContainer.state.appSiteUrl && (
${t('App settings')}` }) }} />
)}
{isGoogleEnabled && (

{t('security_setting.configuration')}

adminGoogleSecurityContainer.changeGoogleClientId(e.target.value)} />

adminGoogleSecurityContainer.changeGoogleClientSecret(e.target.value)} />

{ adminGoogleSecurityContainer.switchIsSameUsernameTreatedAsIdenticalUser() }} />

)}

{t('security_setting.OAuth.how_to.google')}

    {/* eslint-disable-next-line max-len */}
  1. Google Cloud Platform API Manager' }) }} />
); } } GoogleSecurityManagement.propTypes = { t: PropTypes.func.isRequired, // i18next appContainer: PropTypes.instanceOf(AppContainer).isRequired, adminGeneralSecurityContainer: PropTypes.instanceOf(AdminGeneralSecurityContainer).isRequired, adminGoogleSecurityContainer: PropTypes.instanceOf(AdminGoogleSecurityContainer).isRequired, }; const GoogleSecurityManagementWrapper = (props) => { return createSubscribedElement(GoogleSecurityManagement, props, [AppContainer, AdminGeneralSecurityContainer, AdminGoogleSecurityContainer]); }; export default withTranslation()(GoogleSecurityManagementWrapper);