feat(fe/management): add reset used space button for users

This commit is contained in:
hexxa 2022-03-10 15:19:51 +08:00 committed by Hexxa
parent 21593af444
commit 097b94d1ed
7 changed files with 58 additions and 4 deletions

View file

@ -28,6 +28,7 @@ export interface Preferences {
lanPackURL: string; lanPackURL: string;
lan: string; lan: string;
} }
export interface User { export interface User {
id: string; id: string;
name: string; name: string;
@ -121,6 +122,7 @@ export interface IUsersClient {
listRoles: () => Promise<Response>; listRoles: () => Promise<Response>;
getCaptchaID: () => Promise<Response>; getCaptchaID: () => Promise<Response>;
setPreferences: (prefers: Preferences) => Promise<Response>; setPreferences: (prefers: Preferences) => Promise<Response>;
resetUsedSpace: (userID: string) => Promise<Response>;
} }
export interface IFilesClient { export interface IFilesClient {

View file

@ -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,
},
});
};
} }

View file

@ -17,6 +17,7 @@ export interface UsersClientResps {
selfMockResp?: Response; selfMockResp?: Response;
getCaptchaIDMockResp?: Response; getCaptchaIDMockResp?: Response;
setPreferencesMockResp?: Response; setPreferencesMockResp?: Response;
resetUsedSpaceMockResp?: Response;
} }
export const resps = { export const resps = {
@ -107,6 +108,11 @@ export const resps = {
statusText: "", statusText: "",
data: {}, data: {},
}, },
resetUsedSpaceMockResp: {
status: 200,
statusText: "",
data: {}
}
}; };
export class MockUsersClient { export class MockUsersClient {
private url: string; private url: string;
@ -186,6 +192,10 @@ export class MockUsersClient {
setPreferences = (prefers: Preferences): Promise<Response> => { setPreferences = (prefers: Preferences): Promise<Response> => {
return this.wrapPromise(this.resps.setPreferencesMockResp); return this.wrapPromise(this.resps.setPreferencesMockResp);
}; };
resetUsedSpace = (userID: string): Promise<Response> => {
return this.wrapPromise(this.resps.resetUsedSpaceMockResp);
}
} }
export class JestUsersClient { export class JestUsersClient {
@ -215,6 +225,9 @@ export class JestUsersClient {
setPreferences = jest setPreferences = jest
.fn() .fn()
.mockReturnValue(makePromise(resps.setPreferencesMockResp)); .mockReturnValue(makePromise(resps.setPreferencesMockResp));
resetUsedSpace = jest
.fn()
.mockReturnValue(makePromise(resps.resetUsedSpaceMockResp));
} }
export const NewMockUsersClient = (url: string): IUsersClient => { export const NewMockUsersClient = (url: string): IUsersClient => {

View file

@ -109,6 +109,17 @@ export class UserForm extends React.Component<
this.props.update(updater().updateUI); 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 () => { setPwd = async () => {
if (this.state.newPwd1 !== this.state.newPwd2) { if (this.state.newPwd1 !== this.state.newPwd2) {
alertMsg(this.props.msg.pkg.get("settings.pwd.notSame")); alertMsg(this.props.msg.pkg.get("settings.pwd.notSame"));
@ -190,6 +201,9 @@ export class UserForm extends React.Component<
render() { render() {
const foldedClass = this.state.folded ? "hidden" : ""; const foldedClass = this.state.folded ? "hidden" : "";
const foldIconColor = this.state.folded ? "black-font" : "cyan1-font"; const foldIconColor = this.state.folded ? "black-font" : "cyan1-font";
const resetUsedSpace = () => {
this.resetUsedSpace(this.props.id);
}
return ( return (
<div className="user-form"> <div className="user-form">
@ -295,9 +309,15 @@ export class UserForm extends React.Component<
</span> </span>
</div>, </div>,
<div>
<button onClick={this.setUser}> <button onClick={this.setUser}>
{this.props.msg.pkg.get("update")} {this.props.msg.pkg.get("update")}
</button>, </button>
<br />
<button onClick={resetUsedSpace}>
{this.props.msg.pkg.get("resetUsedSpace")}
</button>
</div>,
])} ])}
childrenStyles={List([ childrenStyles={List([
{ alignItems: "flex-start", flexBasis: "70%" }, { alignItems: "flex-start", flexBasis: "70%" },

View file

@ -965,6 +965,11 @@ export class Updater {
this.updateSharings(sorted); 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 => { updateAll = (prevState: ICoreState): ICoreState => {
return { return {
filesInfo: { ...prevState.filesInfo, ...this.props.filesInfo }, filesInfo: { ...prevState.filesInfo, ...this.props.filesInfo },

View file

@ -138,4 +138,6 @@ export const msgs: Map<string, string> = Map({
"endpoints.home": "Home", "endpoints.home": "Home",
"state.stopped": "Stopped", "state.stopped": "Stopped",
"state.error": "Error", "state.error": "Error",
"resetUsedSpace": "Reset Used Space",
"confirm.resetUsedSpace": "The operation may take some time, do you confirm?"
}); });

View file

@ -135,4 +135,6 @@ export const msgs: Map<string, string> = Map({
"endpoints.home": "家", "endpoints.home": "家",
"state.stopped": "已停止", "state.stopped": "已停止",
"state.error": "错误", "state.error": "错误",
"resetUsedSpace": "重置已用空间",
"confirm.resetUsedSpace": "此操作可能会需要一些时间, 确认吗?"
}); });