diff --git a/scm-ui/src/containers/App.js b/scm-ui/src/containers/App.js index fb579acc3f..a5349f0814 100644 --- a/scm-ui/src/containers/App.js +++ b/scm-ui/src/containers/App.js @@ -46,7 +46,6 @@ type Props = { // dispatcher functions fetchMe: (link: string) => void, - fetchIndexResources: () => void, // context props t: string => string @@ -54,7 +53,6 @@ type Props = { class App extends Component { componentDidMount() { - //this.props.fetchIndexResources(); if (this.props.meLink) this.props.fetchMe(this.props.meLink); } @@ -110,8 +108,7 @@ class App extends Component { const mapDispatchToProps = (dispatch: any) => { return { - fetchMe: (link: string) => dispatch(fetchMe(link)), - fetchIndexResources: () => dispatch(fetchIndexResources()) + fetchMe: (link: string) => dispatch(fetchMe(link)) }; }; diff --git a/scm-ui/src/containers/Login.js b/scm-ui/src/containers/Login.js index df4484a539..a5c9d2964c 100644 --- a/scm-ui/src/containers/Login.js +++ b/scm-ui/src/containers/Login.js @@ -98,6 +98,7 @@ class Login extends React.Component { } renderRedirect = () => { + this.props.fetchIndexResources(); const { from } = this.props.location.state || { from: { pathname: "/" } }; return ; }; @@ -167,8 +168,13 @@ const mapStateToProps = state => { const mapDispatchToProps = dispatch => { return { - login: (link: string, username: string, password: string) => - dispatch(login(link, username, password)) + login: ( + loginLink: string, + meLink: string, + username: string, + password: string + ) => dispatch(login(loginLink, meLink, username, password)), + fetchIndexResources: () => dispatch(fetchIndexResources()) }; }; diff --git a/scm-ui/src/modules/auth.js b/scm-ui/src/modules/auth.js index dd7971ba74..0723d8bf41 100644 --- a/scm-ui/src/modules/auth.js +++ b/scm-ui/src/modules/auth.js @@ -5,7 +5,7 @@ import * as types from "./types"; import { apiClient, UNAUTHORIZED_ERROR } from "@scm-manager/ui-components"; import { isPending } from "./pending"; import { getFailure } from "./failure"; -import { fetchIndexResources, getMeLink } from "./indexResource"; +import { callFetchIndexResources } from "./indexResource"; // Action @@ -122,14 +122,9 @@ export const fetchMeFailure = (error: Error) => { }; }; -// urls - -const ME_URL = "/me"; - // side effects const callFetchMe = (link: string): Promise => { - console.log(link); return apiClient .get(link) .then(response => { @@ -156,11 +151,11 @@ export const login = ( return apiClient .post(loginLink, login_data) .then(response => { - return dispatch(fetchIndexResources()); + return callFetchIndexResources(); }) .then(response => { const meLink = response._links.me.href; - return dispatch(callFetchMe(meLink)); + return callFetchMe(meLink); }) .then(me => { dispatch(loginSuccess(me)); diff --git a/scm-ui/src/modules/auth.test.js b/scm-ui/src/modules/auth.test.js index 848e64d7c7..1f5efb31a7 100644 --- a/scm-ui/src/modules/auth.test.js +++ b/scm-ui/src/modules/auth.test.js @@ -93,6 +93,14 @@ describe("auth actions", () => { headers: { "content-type": "application/json" } }); + fetchMock.getOnce("/api/v2/", { + _links: { + me: { + href: "/me" + } + } + }); + const expectedActions = [ { type: LOGIN_PENDING }, { type: LOGIN_SUCCESS, payload: me } diff --git a/scm-ui/src/modules/indexResource.js b/scm-ui/src/modules/indexResource.js index c511c4668e..2e429a2cb1 100644 --- a/scm-ui/src/modules/indexResource.js +++ b/scm-ui/src/modules/indexResource.js @@ -21,12 +21,16 @@ export const FETCH_INDEXRESOURCES_FAILURE = `${FETCH_INDEXRESOURCES}_${ const INDEX_RESOURCES_LINK = "/"; +export const callFetchIndexResources = (): Promise => { + return apiClient.get(INDEX_RESOURCES_LINK).then(response => { + return response.json(); + }); +}; + export function fetchIndexResources() { return function(dispatch: any) { dispatch(fetchIndexResourcesPending()); - return apiClient - .get(INDEX_RESOURCES_LINK) - .then(response => response.json()) + return callFetchIndexResources() .then(resources => { dispatch(fetchIndexResourcesSuccess(resources)); })