Web.Client: added new prop for ConfirmRoute component

This commit is contained in:
Daniil Senkiv 2019-10-04 13:57:55 +03:00
parent 8436294a74
commit 24191334f4
3 changed files with 34 additions and 16 deletions

View File

@ -1,6 +1,6 @@
import React, { Suspense, lazy } from "react";
import { connect } from "react-redux";
import { Redirect, Route, Switch } from "react-router-dom";
import { Route, Switch } from "react-router-dom";
import { Loader } from "asc-web-components";
import ConfirmRoute from "../../../helpers/confirmRoute";
import i18n from "./i18n";
@ -31,6 +31,7 @@ const Confirm = ({ match, language }) => {
component={CreateUserForm}
/>
<ConfirmRoute
forUnauthorized
path={`${match.path}/Activation`}
component={ActivateUserForm}
/>

View File

@ -111,13 +111,14 @@ class Confirm extends React.PureComponent {
firstname: this.state.firstName,
lastname: this.state.lastName
};
logout();
activateConfirmUser(personalData, loginData, this.state.key, this.state.userId, EmployeeActivationStatus.Activated)
.then(() => window.location.href = '/')
.catch(e => {
console.error("activate error", e);
this.setState({ errorText: e.message });
this.setState({ isLoading: false });
this.setState({
errorText: e.message,
isLoading: false
});
});
});
};
@ -321,4 +322,4 @@ function mapStateToProps(state) {
};
}
export default connect(mapStateToProps, { getConfirmationInfo, activateConfirmUser,logout })(withRouter(withTranslation()(ActivateUserForm)));
export default connect(mapStateToProps, { getConfirmationInfo, activateConfirmUser, logout })(withRouter(withTranslation()(ActivateUserForm)));

View File

@ -1,11 +1,13 @@
import React from 'react';
import { Route } from 'react-router-dom';
import { Route, Redirect } from 'react-router-dom';
import { ValidationResult } from './../helpers/constants';
import { decomposeConfirmLink } from './../helpers/converters';
import { PageLayout, Loader } from "asc-web-components";
import { connect } from 'react-redux';
import { checkConfirmLink } from './../store/auth/actions';
import { withRouter } from "react-router";
import Cookies from "universal-cookie";
import { AUTH_KEY } from './constants';
class ConfirmRoute extends React.Component {
constructor(props) {
@ -56,24 +58,38 @@ class ConfirmRoute extends React.Component {
break;
}
})
.catch((e) => history.push(`${path}/error=${e}`));
.catch((e) => {
history.push(`${path}/error=${e.message}`);
})
}
render() {
const { component: Component, ...rest } = this.props;
const { component: Component, isAuthenticated, ...rest } = this.props;
let path = '';
if (!isAuthenticated) {
path = '/login';
}
const { forUnauthorized } = rest;
return (
<Route
{...rest}
render={props =>
!this.state.isLoaded ? (
<PageLayout
sectionBodyContent={
<Loader className="pageLoader" type="rombs" size={40} />
}
forUnauthorized && (new Cookies()).get(AUTH_KEY)
? <Redirect
to={{
pathname: `${path}/error=Access error`,
state: { from: props.location }
}}
/>
) : (
<Component {...props = { ...props, linkData: this.state.componentProps }} />
)
: !this.state.isLoaded ? (
<PageLayout
sectionBodyContent={
<Loader className="pageLoader" type="rombs" size={40} />
}
/>
) : (
<Component {...props = { ...props, linkData: this.state.componentProps }} />
)
}
/>
)