feat(fe/management): add reset used space button for users
This commit is contained in:
parent
21593af444
commit
097b94d1ed
7 changed files with 58 additions and 4 deletions
|
@ -28,6 +28,7 @@ export interface Preferences {
|
|||
lanPackURL: string;
|
||||
lan: string;
|
||||
}
|
||||
|
||||
export interface User {
|
||||
id: string;
|
||||
name: string;
|
||||
|
@ -121,6 +122,7 @@ export interface IUsersClient {
|
|||
listRoles: () => Promise<Response>;
|
||||
getCaptchaID: () => Promise<Response>;
|
||||
setPreferences: (prefers: Preferences) => Promise<Response>;
|
||||
resetUsedSpace: (userID: string) => Promise<Response>;
|
||||
}
|
||||
|
||||
export interface IFilesClient {
|
||||
|
|
|
@ -151,4 +151,14 @@ export class UsersClient extends BaseClient {
|
|||
},
|
||||
});
|
||||
};
|
||||
|
||||
resetUsedSpace = (userID: string): Promise<Response> => {
|
||||
return this.do({
|
||||
method: "put",
|
||||
url: `${this.url}/v1/users/used-space`,
|
||||
data: {
|
||||
userID,
|
||||
},
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ export interface UsersClientResps {
|
|||
selfMockResp?: Response;
|
||||
getCaptchaIDMockResp?: Response;
|
||||
setPreferencesMockResp?: Response;
|
||||
resetUsedSpaceMockResp?: Response;
|
||||
}
|
||||
|
||||
export const resps = {
|
||||
|
@ -107,6 +108,11 @@ export const resps = {
|
|||
statusText: "",
|
||||
data: {},
|
||||
},
|
||||
resetUsedSpaceMockResp: {
|
||||
status: 200,
|
||||
statusText: "",
|
||||
data: {}
|
||||
}
|
||||
};
|
||||
export class MockUsersClient {
|
||||
private url: string;
|
||||
|
@ -186,6 +192,10 @@ export class MockUsersClient {
|
|||
setPreferences = (prefers: Preferences): Promise<Response> => {
|
||||
return this.wrapPromise(this.resps.setPreferencesMockResp);
|
||||
};
|
||||
|
||||
resetUsedSpace = (userID: string): Promise<Response> => {
|
||||
return this.wrapPromise(this.resps.resetUsedSpaceMockResp);
|
||||
}
|
||||
}
|
||||
|
||||
export class JestUsersClient {
|
||||
|
@ -215,6 +225,9 @@ export class JestUsersClient {
|
|||
setPreferences = jest
|
||||
.fn()
|
||||
.mockReturnValue(makePromise(resps.setPreferencesMockResp));
|
||||
resetUsedSpace = jest
|
||||
.fn()
|
||||
.mockReturnValue(makePromise(resps.resetUsedSpaceMockResp));
|
||||
}
|
||||
|
||||
export const NewMockUsersClient = (url: string): IUsersClient => {
|
||||
|
|
|
@ -109,6 +109,17 @@ export class UserForm extends React.Component<
|
|||
this.props.update(updater().updateUI);
|
||||
};
|
||||
|
||||
resetUsedSpace = async (userID: string) => {
|
||||
if (!confirmMsg(this.props.msg.pkg.get("confirm.resetUsedSpace"))) {
|
||||
return;
|
||||
}
|
||||
|
||||
const status = await updater().resetUsedSpace(userID);
|
||||
if (status !== "") {
|
||||
alertMsg(this.props.msg.pkg.get("resetUsedSpace"));
|
||||
}
|
||||
}
|
||||
|
||||
setPwd = async () => {
|
||||
if (this.state.newPwd1 !== this.state.newPwd2) {
|
||||
alertMsg(this.props.msg.pkg.get("settings.pwd.notSame"));
|
||||
|
@ -190,6 +201,9 @@ export class UserForm extends React.Component<
|
|||
render() {
|
||||
const foldedClass = this.state.folded ? "hidden" : "";
|
||||
const foldIconColor = this.state.folded ? "black-font" : "cyan1-font";
|
||||
const resetUsedSpace = () => {
|
||||
this.resetUsedSpace(this.props.id);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="user-form">
|
||||
|
@ -295,9 +309,15 @@ export class UserForm extends React.Component<
|
|||
</span>
|
||||
</div>,
|
||||
|
||||
<button onClick={this.setUser}>
|
||||
{this.props.msg.pkg.get("update")}
|
||||
</button>,
|
||||
<div>
|
||||
<button onClick={this.setUser}>
|
||||
{this.props.msg.pkg.get("update")}
|
||||
</button>
|
||||
<br />
|
||||
<button onClick={resetUsedSpace}>
|
||||
{this.props.msg.pkg.get("resetUsedSpace")}
|
||||
</button>
|
||||
</div>,
|
||||
])}
|
||||
childrenStyles={List([
|
||||
{ alignItems: "flex-start", flexBasis: "70%" },
|
||||
|
@ -668,7 +688,7 @@ interface BgProps {
|
|||
update?: (updater: (prevState: ICoreState) => ICoreState) => void;
|
||||
}
|
||||
|
||||
interface BgState {}
|
||||
interface BgState { }
|
||||
export class BgCfg extends React.Component<BgProps, BgState, {}> {
|
||||
changeSiteName = (ev: React.ChangeEvent<HTMLInputElement>) => {
|
||||
updater().setClientCfg({ ...this.props.ui, siteName: ev.target.value });
|
||||
|
|
|
@ -965,6 +965,11 @@ export class Updater {
|
|||
this.updateSharings(sorted);
|
||||
};
|
||||
|
||||
resetUsedSpace = async (userID: string): Promise<string> => {
|
||||
const resp = await this.usersClient.resetUsedSpace(userID);
|
||||
return resp.status == 200 ? "" : errServer;
|
||||
};
|
||||
|
||||
updateAll = (prevState: ICoreState): ICoreState => {
|
||||
return {
|
||||
filesInfo: { ...prevState.filesInfo, ...this.props.filesInfo },
|
||||
|
|
|
@ -138,4 +138,6 @@ export const msgs: Map<string, string> = Map({
|
|||
"endpoints.home": "Home",
|
||||
"state.stopped": "Stopped",
|
||||
"state.error": "Error",
|
||||
"resetUsedSpace": "Reset Used Space",
|
||||
"confirm.resetUsedSpace": "The operation may take some time, do you confirm?"
|
||||
});
|
||||
|
|
|
@ -135,4 +135,6 @@ export const msgs: Map<string, string> = Map({
|
|||
"endpoints.home": "家",
|
||||
"state.stopped": "已停止",
|
||||
"state.error": "错误",
|
||||
"resetUsedSpace": "重置已用空间",
|
||||
"confirm.resetUsedSpace": "此操作可能会需要一些时间, 确认吗?"
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue