2021-01-14 01:56:01 +01:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
// See LICENSE.txt for license information.
|
|
|
|
import React from 'react'
|
|
|
|
import {injectIntl, IntlShape} from 'react-intl'
|
|
|
|
|
|
|
|
import {IWorkspace} from '../blocks/workspace'
|
|
|
|
import {sendFlashMessage} from '../components/flashMessages'
|
|
|
|
import client from '../octoClient'
|
|
|
|
import {Utils} from '../utils'
|
|
|
|
import Button from '../widgets/buttons/button'
|
|
|
|
|
|
|
|
import Modal from './modal'
|
2021-03-27 10:03:44 +01:00
|
|
|
import './registrationLink.scss'
|
2021-01-14 01:56:01 +01:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
onClose: () => void
|
|
|
|
intl: IntlShape
|
|
|
|
}
|
|
|
|
|
|
|
|
type State = {
|
|
|
|
workspace?: IWorkspace
|
2021-01-14 18:15:31 +01:00
|
|
|
wasCopied: boolean
|
2021-01-14 01:56:01 +01:00
|
|
|
}
|
|
|
|
|
2021-03-27 10:03:44 +01:00
|
|
|
class RegistrationLink extends React.PureComponent<Props, State> {
|
2021-01-14 18:15:31 +01:00
|
|
|
state: State = {wasCopied: false}
|
2021-01-14 01:56:01 +01:00
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.loadData()
|
|
|
|
}
|
|
|
|
|
|
|
|
private async loadData() {
|
|
|
|
const workspace = await client.getWorkspace()
|
2021-01-14 18:15:31 +01:00
|
|
|
this.setState({workspace, wasCopied: false})
|
2021-01-14 01:56:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
render(): JSX.Element {
|
|
|
|
const {intl} = this.props
|
|
|
|
const {workspace} = this.state
|
|
|
|
|
|
|
|
const registrationUrl = window.location.origin + '/register?t=' + workspace?.signupToken
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Modal
|
2021-01-21 19:52:44 +01:00
|
|
|
position='bottom-right'
|
2021-01-14 01:56:01 +01:00
|
|
|
onClose={this.props.onClose}
|
|
|
|
>
|
2021-03-27 10:03:44 +01:00
|
|
|
<div className='RegistrationLink'>
|
2021-01-14 01:56:01 +01:00
|
|
|
{workspace && <>
|
|
|
|
<div className='row'>
|
2021-01-15 02:10:27 +01:00
|
|
|
{intl.formatMessage({id: 'RegistrationLink.description', defaultMessage: 'Share this link for others to create accounts:'})}
|
|
|
|
</div>
|
|
|
|
<div className='row'>
|
|
|
|
<a
|
2021-01-14 01:56:01 +01:00
|
|
|
className='shareUrl'
|
2021-01-15 02:10:27 +01:00
|
|
|
href={registrationUrl}
|
|
|
|
target='_blank'
|
|
|
|
rel='noreferrer'
|
|
|
|
>
|
|
|
|
{registrationUrl}
|
|
|
|
</a>
|
2021-01-14 01:56:01 +01:00
|
|
|
<Button
|
|
|
|
filled={true}
|
|
|
|
onClick={() => {
|
|
|
|
Utils.copyTextToClipboard(registrationUrl)
|
|
|
|
this.setState({wasCopied: true})
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{this.state.wasCopied ? intl.formatMessage({id: 'RegistrationLink.copiedLink', defaultMessage: 'Copied!'}) : intl.formatMessage({id: 'RegistrationLink.copyLink', defaultMessage: 'Copy link'})}
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
<div className='row'>
|
|
|
|
<Button onClick={this.onRegenerateToken}>
|
|
|
|
{intl.formatMessage({id: 'RegistrationLink.regenerateToken', defaultMessage: 'Regenerate token'})}
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</>}
|
|
|
|
</div>
|
|
|
|
</Modal>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
private onRegenerateToken = async () => {
|
|
|
|
const {intl} = this.props
|
|
|
|
// eslint-disable-next-line no-alert
|
|
|
|
const accept = window.confirm(intl.formatMessage({id: 'RegistrationLink.confirmRegenerateToken', defaultMessage: 'This will invalidate previously shared links. Continue?'}))
|
|
|
|
if (accept) {
|
|
|
|
await client.regenerateWorkspaceSignupToken()
|
|
|
|
await this.loadData()
|
|
|
|
|
|
|
|
const description = intl.formatMessage({id: 'RegistrationLink.tokenRegenerated', defaultMessage: 'Registration link regenerated'})
|
|
|
|
sendFlashMessage({content: description, severity: 'low'})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-27 10:03:44 +01:00
|
|
|
export default injectIntl(RegistrationLink)
|