Browse Source

SignIn: Update redirect on reroute (#18360)

* Connect SignIn with redux and get url

* Update test snapshot
Tobias Skarhed 6 years ago
parent
commit
b62ab25c41

+ 2 - 2
public/app/core/components/sidemenu/SignIn.test.tsx

@@ -1,10 +1,10 @@
 import React from 'react';
 import { shallow } from 'enzyme';
-import SignIn from './SignIn';
+import { SignIn } from './SignIn';
 
 describe('Render', () => {
   it('should render component', () => {
-    const wrapper = shallow(<SignIn />);
+    const wrapper = shallow(<SignIn url="/" />);
 
     expect(wrapper).toMatchSnapshot();
   });

+ 9 - 3
public/app/core/components/sidemenu/SignIn.tsx

@@ -1,7 +1,9 @@
 import React, { FC } from 'react';
+import { connectWithStore } from 'app/core/utils/connectWithReduxStore';
+import { StoreState } from 'app/types';
 
-const SignIn: FC<any> = () => {
-  const loginUrl = `login?redirect=${encodeURIComponent(window.location.pathname)}`;
+export const SignIn: FC<any> = ({ url }) => {
+  const loginUrl = `login?redirect=${encodeURIComponent(url)}`;
   return (
     <div className="sidemenu-item">
       <a href={loginUrl} className="sidemenu-link" target="_self">
@@ -20,4 +22,8 @@ const SignIn: FC<any> = () => {
   );
 };
 
-export default SignIn;
+const mapStateToProps = (state: StoreState) => ({
+  url: state.location.url,
+});
+
+export default connectWithStore(SignIn, mapStateToProps);

+ 1 - 1
public/app/core/components/sidemenu/__snapshots__/BottomSection.test.tsx.snap

@@ -4,7 +4,7 @@ exports[`Render should render component 1`] = `
 <div
   className="sidemenu__bottom"
 >
-  <SignIn />
+  <Component />
   <BottomNavLinks
     key="undefined-0"
     link={