From 384a9a4a84939f3c9eaee6339ea9372a423e3790 Mon Sep 17 00:00:00 2001 From: Daniil Senkiv Date: Tue, 1 Oct 2019 12:16:02 +0300 Subject: [PATCH] Web.Client: applied confirmRoute to activateUser sub-component, fixed decomposeConfirmLink helper --- .../src/components/pages/Confirm/index.js | 2 +- .../Confirm/sub-components/activateUser.js | 38 ++++++------------- .../src/helpers/decomposeConfirmLink.js | 7 ++-- web/ASC.Web.Client/src/store/auth/actions.js | 4 +- 4 files changed, 19 insertions(+), 32 deletions(-) diff --git a/web/ASC.Web.Client/src/components/pages/Confirm/index.js b/web/ASC.Web.Client/src/components/pages/Confirm/index.js index ecaef1c0b1..86a9ee4548 100644 --- a/web/ASC.Web.Client/src/components/pages/Confirm/index.js +++ b/web/ASC.Web.Client/src/components/pages/Confirm/index.js @@ -28,7 +28,7 @@ const Confirm = ({ match }) => { path={`${match.path}/LinkInvite`} component={CreateUserForm} /> - diff --git a/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/activateUser.js b/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/activateUser.js index 44f69cce06..489687e155 100644 --- a/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/activateUser.js +++ b/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/activateUser.js @@ -44,35 +44,25 @@ const ConfirmContainer = styled.div` `; -const emailInputName = 'email'; -const passwordInputName = 'password'; - class Confirm extends React.PureComponent { constructor(props) { super(props); - const queryParams = props.location.search.slice(1).split('&'); - const arrayOfQueryParams = queryParams.map(queryParam => queryParam.split('=')); - const linkParams = Object.fromEntries(arrayOfQueryParams); - const indexOfSlash = this.props.match.path.lastIndexOf('/'); - const typeLink = this.props.match.path.slice(indexOfSlash + 1); - this.state = { - email: decodeURIComponent(linkParams.email), - emailValid: true, - firstName: decodeURIComponent(linkParams.firstname), + email: props.linkData.email, + firstName: props.linkData.firstname, firstNameValid: true, - lastName: decodeURIComponent(linkParams.lastname), + lastName: props.linkData.lastname, lastNameValid: true, password: '', passwordValid: true, errorText: '', isLoading: false, passwordEmpty: false, - queryString: `type=${typeLink}&${props.location.search.slice(1)}`, - type: typeLink, - userId: linkParams.uid + key: props.linkData.confirmHeader, + linkType: props.linkData.type, + userId: props.linkData.uid }; } @@ -110,22 +100,19 @@ class Confirm extends React.PureComponent { userName: this.state.email, password: this.state.password }; + const personalData = { firstname: this.state.firstName, - lastname: this.state.lastName, - email: this.state.email + lastname: this.state.lastName }; - activateConfirmUser(personalData, loginData, this.state.queryString, this.state.userId, EmployeeActivationStatus.Activated) + activateConfirmUser(personalData, loginData, this.state.key, this.state.userId, EmployeeActivationStatus.Activated) .then(() => history.push('/')) .catch(e => { console.error("activate error", e); this.setState({ errorText: e.message }); this.setState({ isLoading: false }); }); - - - }); }; @@ -141,7 +128,7 @@ class Confirm extends React.PureComponent { componentDidMount() { const { getConfirmationInfo, history } = this.props; - getConfirmationInfo(this.state.queryString) + getConfirmationInfo(this.state.key, this.state.linkType) .then( function () { console.log("get settings success"); @@ -173,7 +160,6 @@ class Confirm extends React.PureComponent { this.state.errorText && this.setState({ errorText: "" });; } - onChangePassword = event => { this.setState({ password: event.target.value }); !this.state.passwordValid && this.setState({ passwordValid: true }); @@ -244,8 +230,8 @@ class Confirm extends React.PureComponent { { - const queryString = querySearch.slice(1).split('&'); +const decomposeConfirmLink = (url, querySearch) => { + const decodedString = decodeURIComponent(querySearch); + const queryString = decodedString.slice(1).split('&'); const arrayOfQueryString = queryString.map(queryParam => queryParam.split('=')); const queryParams = Object.fromEntries(arrayOfQueryString); const posSeparator = url.lastIndexOf('/'); @@ -8,4 +9,4 @@ const decomposeLink = (url, querySearch) => { return data; } -export default decomposeLink; \ No newline at end of file +export default decomposeConfirmLink; \ No newline at end of file diff --git a/web/ASC.Web.Client/src/store/auth/actions.js b/web/ASC.Web.Client/src/store/auth/actions.js index 25ec10ff62..1578b691f8 100644 --- a/web/ASC.Web.Client/src/store/auth/actions.js +++ b/web/ASC.Web.Client/src/store/auth/actions.js @@ -164,14 +164,14 @@ export function changeEmail(userId, email, key) { } export function activateConfirmUser(personalData, loginData, key, userId, activationStatus) { - const data = Object.assign({}, personalData, loginData); const changedData = { id: userId, FirstName: personalData.firstname, LastName: personalData.lastname } + return dispatch => { - return api.changePassword(userId, data, key) + return api.changePassword(userId, { password: loginData.password }, key) .then(res => { checkResponseError(res); console.log('set password success:', res.data.response);