fix(topbar): display user name

This commit is contained in:
hexxa 2021-08-26 22:07:59 +08:00 committed by Hexxa
parent 01d38786ec
commit 565c7324ef
8 changed files with 25 additions and 11 deletions

View file

@ -666,3 +666,7 @@ div.hr {
border: solid 1px #95a5a6; border: solid 1px #95a5a6;
border-radius: 0.5rem; border-radius: 0.5rem;
} }
.user {
font-weight: bold;
}

View file

@ -73,7 +73,7 @@ export const resps = {
status: 200, status: 200,
statusText: "", statusText: "",
data: { data: {
id: 0, id: "0",
name: "mockUser", name: "mockUser",
role: "admin", role: "admin",
usedSpace: "256", usedSpace: "256",

View file

@ -32,6 +32,8 @@ describe("Login", () => {
// login // login
expect(updater().props.login).toEqual({ expect(updater().props.login).toEqual({
userID: "0",
userName: "mockUser",
userRole: "admin", userRole: "admin",
authed: true, authed: true,
captchaID: "", captchaID: "",

View file

@ -49,6 +49,8 @@ describe("State Manager", () => {
// login // login
expect(coreState.login).toEqual({ expect(coreState.login).toEqual({
userID: "0",
userName: "mockUser",
userRole: "admin", userRole: "admin",
authed: true, authed: true,
captchaID: "mockCaptchaID", captchaID: "mockCaptchaID",

View file

@ -81,6 +81,7 @@ export class AuthPane extends React.Component<Props, State, {}> {
}) })
.then(() => { .then(() => {
this.update(updater().updateBrowser); this.update(updater().updateBrowser);
this.update(updater().updateLogin);
}); });
}; };

View file

@ -101,6 +101,7 @@ export class StateMgr extends React.Component<Props, State, {}> {
} }
}) })
.then(() => { .then(() => {
this.update(updater().updateLogin);
this.update(updater().updatePanes); this.update(updater().updatePanes);
this.update(updater().updateAdmin); this.update(updater().updateAdmin);
}); });

View file

@ -205,6 +205,8 @@ export class Updater {
self = async (): Promise<boolean> => { self = async (): Promise<boolean> => {
const resp = await this.usersClient.self(); const resp = await this.usersClient.self();
if (resp.status === 200) { if (resp.status === 200) {
this.props.login.userID = resp.data.id;
this.props.login.userName = resp.data.name;
this.props.login.userRole = resp.data.role; this.props.login.userRole = resp.data.role;
return true; return true;
} }

View file

@ -26,10 +26,7 @@ export class TopBar extends React.Component<Props, State, {}> {
.self() .self()
.then(() => { .then(() => {
// TODO: remove hardcode role // TODO: remove hardcode role
if ( if (this.props.login.authed && this.props.login.userRole === "admin") {
this.props.login.authed &&
this.props.login.userRole === "admin"
) {
return Promise.all([updater().listRoles(), updater().listUsers()]); return Promise.all([updater().listRoles(), updater().listUsers()]);
} }
}) })
@ -41,6 +38,15 @@ export class TopBar extends React.Component<Props, State, {}> {
}; };
render() { render() {
const adminBtn =
this.props.login.userRole === "admin" ? (
<button
onClick={this.showAdmin}
className="grey1-bg white-font margin-r-m"
>
{this.props.msg.pkg.get("admin")}
</button>
) : null;
return ( return (
<div <div
id="top-bar" id="top-bar"
@ -54,18 +60,14 @@ export class TopBar extends React.Component<Props, State, {}> {
Quickshare Quickshare
</a> </a>
<span className="flex-23col text-right"> <span className="flex-23col text-right">
<span className="user margin-r-m">{this.props.login.userName}</span>
<button <button
onClick={this.showSettings} onClick={this.showSettings}
className="grey1-bg white-font margin-r-m" className="grey1-bg white-font margin-r-m"
> >
{this.props.msg.pkg.get("settings")} {this.props.msg.pkg.get("settings")}
</button> </button>
<button {adminBtn}
onClick={this.showAdmin}
className="grey1-bg white-font margin-r-m"
>
{this.props.msg.pkg.get("admin")}
</button>
</span> </span>
</div> </div>
</div> </div>