mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 14:35:45 +01:00
Use Me-type
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
//@flow
|
//@flow
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
import { Me } from "../types/Me";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
me?: string
|
me?: Me
|
||||||
};
|
};
|
||||||
|
|
||||||
class Footer extends React.Component<Props> {
|
class Footer extends React.Component<Props> {
|
||||||
@@ -14,7 +15,7 @@ class Footer extends React.Component<Props> {
|
|||||||
return (
|
return (
|
||||||
<footer className="footer">
|
<footer className="footer">
|
||||||
<div className="container is-centered">
|
<div className="container is-centered">
|
||||||
<p className="has-text-centered">{me}</p>
|
<p className="has-text-centered">{me.displayName}</p>
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -14,11 +14,10 @@ import ErrorPage from "../components/ErrorPage";
|
|||||||
import Footer from "../components/Footer";
|
import Footer from "../components/Footer";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
me: any,
|
me: Me,
|
||||||
error: Error,
|
error: Error,
|
||||||
loading: boolean,
|
loading: boolean,
|
||||||
authenticated?: boolean,
|
authenticated?: boolean,
|
||||||
displayName: string,
|
|
||||||
t: string => string,
|
t: string => string,
|
||||||
fetchMe: () => void
|
fetchMe: () => void
|
||||||
};
|
};
|
||||||
@@ -29,7 +28,7 @@ class App extends Component<Props> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { loading, error, authenticated, displayName, t } = this.props;
|
const { me, loading, error, authenticated, t } = this.props;
|
||||||
|
|
||||||
let content;
|
let content;
|
||||||
const navigation = authenticated ? <PrimaryNavigation /> : "";
|
const navigation = authenticated ? <PrimaryNavigation /> : "";
|
||||||
@@ -51,7 +50,7 @@ class App extends Component<Props> {
|
|||||||
<div className="App">
|
<div className="App">
|
||||||
<Header>{navigation}</Header>
|
<Header>{navigation}</Header>
|
||||||
{content}
|
{content}
|
||||||
<Footer me={displayName} />
|
<Footer me={me} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -65,16 +64,14 @@ const mapDispatchToProps = (dispatch: any) => {
|
|||||||
|
|
||||||
const mapStateToProps = state => {
|
const mapStateToProps = state => {
|
||||||
let mapped = state.auth.me || {};
|
let mapped = state.auth.me || {};
|
||||||
let displayName;
|
|
||||||
if (state.auth.login) {
|
if (state.auth.login) {
|
||||||
mapped.authenticated = state.auth.login.authenticated;
|
mapped.authenticated = state.auth.login.authenticated;
|
||||||
}
|
}
|
||||||
if (state.auth.me && state.auth.me.entry) {
|
|
||||||
displayName = state.auth.me.entry.displayName;
|
|
||||||
}
|
|
||||||
return {
|
return {
|
||||||
...mapped,
|
...mapped,
|
||||||
displayName
|
me: mapped.entry
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -205,7 +205,9 @@ export const fetchMe = () => {
|
|||||||
return response.json();
|
return response.json();
|
||||||
})
|
})
|
||||||
.then(me => {
|
.then(me => {
|
||||||
dispatch(fetchMeSuccess(me));
|
dispatch(
|
||||||
|
fetchMeSuccess({ userName: me.name, displayName: me.displayName })
|
||||||
|
);
|
||||||
})
|
})
|
||||||
.catch((error: Error) => {
|
.catch((error: Error) => {
|
||||||
if (error === UNAUTHORIZED_ERROR) {
|
if (error === UNAUTHORIZED_ERROR) {
|
||||||
|
|||||||
@@ -166,13 +166,16 @@ describe("auth actions", () => {
|
|||||||
|
|
||||||
it("should dispatch fetch me success", () => {
|
it("should dispatch fetch me success", () => {
|
||||||
fetchMock.getOnce("/scm/api/rest/v2/me", {
|
fetchMock.getOnce("/scm/api/rest/v2/me", {
|
||||||
body: { username: "sorbot" },
|
body: { name: "sorbot", displayName: "Sorbot" },
|
||||||
headers: { "content-type": "application/json" }
|
headers: { "content-type": "application/json" }
|
||||||
});
|
});
|
||||||
|
|
||||||
const expectedActions = [
|
const expectedActions = [
|
||||||
{ type: FETCH_ME_REQUEST },
|
{ type: FETCH_ME_REQUEST },
|
||||||
{ type: FETCH_ME_SUCCESS, payload: { username: "sorbot" } }
|
{
|
||||||
|
type: FETCH_ME_SUCCESS,
|
||||||
|
payload: { userName: "sorbot", displayName: "Sorbot" }
|
||||||
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
const store = mockStore({});
|
const store = mockStore({});
|
||||||
|
|||||||
6
scm-ui/src/types/Me.js
Normal file
6
scm-ui/src/types/Me.js
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
// @flow
|
||||||
|
|
||||||
|
export type Me = {
|
||||||
|
userName: string,
|
||||||
|
displayName: string
|
||||||
|
};
|
||||||
@@ -26,7 +26,6 @@ export const DELETE_USER_SUCCESS = "scm/users/DELETE_SUCCESS";
|
|||||||
export const DELETE_USER_FAILURE = "scm/users/DELETE_FAILURE";
|
export const DELETE_USER_FAILURE = "scm/users/DELETE_FAILURE";
|
||||||
|
|
||||||
const USERS_URL = "users";
|
const USERS_URL = "users";
|
||||||
const USER_URL = "users/";
|
|
||||||
|
|
||||||
const CONTENT_TYPE_USER = "application/vnd.scmm-user+json;v=2";
|
const CONTENT_TYPE_USER = "application/vnd.scmm-user+json;v=2";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user