mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 06:55:47 +01:00
use me link of index resource
This commit is contained in:
@@ -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<Props> {
|
||||
componentDidMount() {
|
||||
//this.props.fetchIndexResources();
|
||||
if (this.props.meLink) this.props.fetchMe(this.props.meLink);
|
||||
}
|
||||
|
||||
@@ -110,8 +108,7 @@ class App extends Component<Props> {
|
||||
|
||||
const mapDispatchToProps = (dispatch: any) => {
|
||||
return {
|
||||
fetchMe: (link: string) => dispatch(fetchMe(link)),
|
||||
fetchIndexResources: () => dispatch(fetchIndexResources())
|
||||
fetchMe: (link: string) => dispatch(fetchMe(link))
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -98,6 +98,7 @@ class Login extends React.Component<Props, State> {
|
||||
}
|
||||
|
||||
renderRedirect = () => {
|
||||
this.props.fetchIndexResources();
|
||||
const { from } = this.props.location.state || { from: { pathname: "/" } };
|
||||
return <Redirect to={from} />;
|
||||
};
|
||||
@@ -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())
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -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<Me> => {
|
||||
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));
|
||||
|
||||
@@ -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 }
|
||||
|
||||
@@ -21,12 +21,16 @@ export const FETCH_INDEXRESOURCES_FAILURE = `${FETCH_INDEXRESOURCES}_${
|
||||
|
||||
const INDEX_RESOURCES_LINK = "/";
|
||||
|
||||
export const callFetchIndexResources = (): Promise<IndexResources> => {
|
||||
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));
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user