Activate.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import React from 'react'
  2. import { compose } from 'redux'
  3. import injectReducer from 'utils/injectReducer'
  4. import injectSaga from 'utils/injectSaga'
  5. import reducer from './reducer'
  6. import saga from './sagas'
  7. import { connect } from 'react-redux'
  8. import { active } from '../App/actions'
  9. import { createStructuredSelector } from 'reselect'
  10. import { makeSelectSignupLoading } from './selectors'
  11. import { Spin } from 'antd'
  12. const styles = require('./register.less')
  13. interface IActivateProps {
  14. onActiveUser: (token: string, resolve: (err?: string) => any) => any
  15. }
  16. export class Activate extends React.PureComponent <IActivateProps, {}> {
  17. private activeUser = () => {
  18. const { onActiveUser } = this.props
  19. const token = this.getParamsByLocation('token')
  20. onActiveUser(token, (res) => {
  21. const path = `${window.location.protocol}//${window.location.host}/#projects`
  22. location.replace(path)
  23. })
  24. }
  25. private isEmptyOrNull = (str) => str == null || str === undefined || str === '' || str === 'null' || typeof str === 'undefined'
  26. private getParamsByLocation = (name) => {
  27. let values = decodeURIComponent((window.location.search.match(RegExp(`[?|&|/]${name}=([^\\&|?&]+)`)) || [void 0, null])[1])
  28. if (this.isEmptyOrNull(values)) {
  29. values = decodeURIComponent((window.location.hash.match(RegExp(`[?|&|/]${name}=([^\&|?&]+)`)) || [void 0, null])[1])
  30. }
  31. return this.isEmptyOrNull(values) || values === 'null' ? '' : values
  32. }
  33. public componentWillMount () {
  34. this.activeUser()
  35. }
  36. public render () {
  37. return (
  38. <div className={styles.activeWrapper}>
  39. <Spin size="large"/>
  40. </div>
  41. )
  42. }
  43. }
  44. const mapStateToProps = createStructuredSelector({
  45. activeLoading: makeSelectSignupLoading()
  46. })
  47. export function mapDispatchToProps (dispatch) {
  48. return {
  49. onActiveUser: (token, resolve) => dispatch(active(token, resolve))
  50. }
  51. }
  52. const withConnect = connect<{}, {}, IActivateProps>(mapStateToProps, mapDispatchToProps)
  53. const withReducer = injectReducer({ key: 'register', reducer })
  54. const withSaga = injectSaga({ key: 'register', saga })
  55. export default compose(
  56. withReducer,
  57. withSaga,
  58. withConnect
  59. )(Activate)