fix(ui/admin): fix SetUser related issues

This commit is contained in:
hexxa 2021-08-25 14:51:12 +08:00 committed by Hexxa
parent d3bac9a47d
commit cff7ce6af4
5 changed files with 22 additions and 16 deletions

View file

@ -4,7 +4,7 @@ export const defaultTimeout = 10000;
export const userIDParam = "uid";
export interface Quota {
spaceLimit: number;
spaceLimit: string;
uploadSpeedLimit: number;
downloadSpeedLimit: number;
}

View file

@ -63,7 +63,7 @@ export class UserForm extends React.Component<
changeSpaceLimit = (ev: React.ChangeEvent<HTMLInputElement>) => {
this.setState({
quota: {
spaceLimit: parseInt(ev.target.value, 10),
spaceLimit: ev.target.value,
uploadSpeedLimit: this.state.quota.uploadSpeedLimit,
downloadSpeedLimit: this.state.quota.downloadSpeedLimit,
},
@ -111,10 +111,12 @@ export class UserForm extends React.Component<
setUser = async () => {
return updater()
.setUser(this.props.id, this.props.role, this.props.quota)
.setUser(this.props.id, this.state.role, this.state.quota)
.then((ok: boolean) => {
if (!ok) {
alert("failed to set user");
} else {
alert("user is updated");
}
return updater().listUsers();
})

View file

@ -26,8 +26,6 @@ export class AuthPane extends React.Component<Props, State, {}> {
pwd: "",
captchaInput: "",
};
this.initIsAuthed();
}
changeUser = (ev: React.ChangeEvent<HTMLInputElement>) => {
@ -42,14 +40,6 @@ export class AuthPane extends React.Component<Props, State, {}> {
this.setState({ captchaInput: ev.target.value });
};
initIsAuthed = () => {
updater()
.initIsAuthed()
.then(() => {
this.update(updater().updateLogin);
});
};
login = async () => {
return updater()
.login(

View file

@ -18,6 +18,7 @@ export class StateMgr extends React.Component<Props, State, {}> {
constructor(p: Props) {
super(p);
this.state = newState();
this.initUpdater(this.state); // don't await
}
setUsersClient = (client: IUsersClient) => {
@ -28,7 +29,7 @@ export class StateMgr extends React.Component<Props, State, {}> {
this.filesClient = client;
};
initUpdater = (state: ICoreState): Promise<void> => {
initUpdater = async (state: ICoreState): Promise<void> => {
updater().init(state);
if (this.usersClient == null || this.filesClient == null) {
console.error("updater's clients are not inited");
@ -38,7 +39,20 @@ export class StateMgr extends React.Component<Props, State, {}> {
const params = new URLSearchParams(document.location.search.substring(1));
return updater()
.getCaptchaID()
.initIsAuthed()
.then(() => {
this.update(updater().updateLogin);
})
.then(() => {
if (updater().props.login.authed) {
updater().displayPane("");
} else {
updater().displayPane("login");
}
})
.then(() => {
return updater().getCaptchaID();
})
.then((ok: boolean) => {
if (!ok) {
alert("failed to get captcha id");

View file

@ -305,7 +305,7 @@ export class Updater {
};
initIsAuthed = async (): Promise<void> => {
return updater()
return this
.isAuthed()
.then((isAuthed) => {
updater().setAuthed(isAuthed);