import React from 'react'; import { pathUtils } from '@growi/core'; import { useTranslation } from 'next-i18next'; import PropTypes from 'prop-types'; import urljoin from 'url-join'; import AdminGeneralSecurityContainer from '~/client/services/AdminGeneralSecurityContainer'; import AdminGoogleSecurityContainer from '~/client/services/AdminGoogleSecurityContainer'; import { toastSuccess, toastError } from '~/client/util/apiNotification'; import { useSiteUrl } from '~/stores/context'; import { withUnstatedContainers } from '../../UnstatedUtils'; class GoogleSecurityManagementContents extends React.Component { constructor(props) { super(props); this.onClickSubmit = this.onClickSubmit.bind(this); } async onClickSubmit() { const { t, adminGoogleSecurityContainer, adminGeneralSecurityContainer } = this.props; try { await adminGoogleSecurityContainer.updateGoogleSetting(); await adminGeneralSecurityContainer.retrieveSetupStratedies(); toastSuccess(t('security_settings.OAuth.Google.updated_google')); } catch (err) { toastError(err); } } render() { const { t, adminGeneralSecurityContainer, adminGoogleSecurityContainer, siteUrl, } = this.props; const { isGoogleEnabled } = adminGeneralSecurityContainer.state; const googleCallbackUrl = urljoin(pathUtils.removeTrailingSlash(siteUrl), '/passport/google/callback'); return ( {t('security_settings.OAuth.Google.name')} {adminGoogleSecurityContainer.state.retrieveError != null && ( {t('Error occurred')} : {adminGoogleSecurityContainer.state.retrieveError} )} { adminGeneralSecurityContainer.switchIsGoogleOAuthEnabled() }} /> {t('security_settings.OAuth.Google.enable_google')} {(!adminGeneralSecurityContainer.state.setupStrategies.includes('google') && isGoogleEnabled) && {t('security_settings.setup_is_not_yet_complete')}} {t('security_settings.callback_URL')} {t('security_settings.desc_of_callback_URL', { AuthName: 'OAuth' })} {(siteUrl == null || siteUrl === '') && ( ${t('app_settings')}` }) }} /> )} {isGoogleEnabled && ( {t('security_settings.configuration')} {t('security_settings.clientID')} adminGoogleSecurityContainer.changeGoogleClientId(e.target.value)} /> {t('security_settings.client_secret')} adminGoogleSecurityContainer.changeGoogleClientSecret(e.target.value)} /> { adminGoogleSecurityContainer.switchIsSameEmailTreatedAsIdenticalUser() }} /> {t('Update')} )} {t('security_settings.OAuth.how_to.google')} {/* eslint-disable-next-line max-len */} Google Cloud Platform API Manager' }) }} /> ); } } const GoogleSecurityManagementContentsFc = (props) => { const { t } = useTranslation('admin'); const { data: siteUrl } = useSiteUrl(); return ; }; GoogleSecurityManagementContents.propTypes = { t: PropTypes.func.isRequired, // i18next adminGeneralSecurityContainer: PropTypes.instanceOf(AdminGeneralSecurityContainer).isRequired, adminGoogleSecurityContainer: PropTypes.instanceOf(AdminGoogleSecurityContainer).isRequired, siteUrl: PropTypes.string, }; const GoogleSecurityManagementContentsWrapper = withUnstatedContainers(GoogleSecurityManagementContentsFc, [ AdminGeneralSecurityContainer, AdminGoogleSecurityContainer, ]); export default GoogleSecurityManagementContentsWrapper;
{t('Error occurred')} : {adminGoogleSecurityContainer.state.retrieveError}
{t('security_settings.desc_of_callback_URL', { AuthName: 'OAuth' })}