update users table with unique tag

This commit is contained in:
steven
2021-12-12 14:00:25 +08:00
parent 9db1f57307
commit b20741cca8
8 changed files with 103 additions and 20 deletions

View File

@@ -6,7 +6,7 @@ type ResponseType<T = unknown> = {
data: T;
};
async function request<T>(method: string, url: string, data?: BasicType): Promise<ResponseType<T>> {
async function request<T>(method: string, url: string, data?: any): Promise<ResponseType<T>> {
const requestConfig: RequestInit = {
method,
};
@@ -55,13 +55,15 @@ namespace api {
return request<boolean>("POST", "/api/user/validpassword", { password });
}
export function updateUserinfo(username?: string, password?: string, githubName?: string, wxOpenId?: string) {
return request("PATCH", "/api/user/me", {
username,
password,
githubName,
wxOpenId,
});
interface UserInfoPatch {
username?: string;
password?: string;
githubName?: string;
wxOpenId?: string;
}
export function updateUserinfo(userinfo: UserInfoPatch) {
return request("PATCH", "/api/user/me", userinfo);
}
export function getMyMemos() {

View File

@@ -4,7 +4,6 @@ import { validate, ValidatorConfig } from "../helpers/validator";
import useLoading from "../hooks/useLoading";
import { locationService, userService } from "../services";
import Only from "../components/common/OnlyWhen";
import showAboutSiteDialog from "../components/AboutSiteDialog";
import toastHelper from "../components/Toast";
import "../less/signin.less";
@@ -50,8 +49,8 @@ const Signin: React.FC<Props> = () => {
setPassword(text);
};
const handleAboutBtnClick = () => {
showAboutSiteDialog();
const handleSignUpBtnClick = async () => {
toastHelper.info("注册已关闭");
};
const handleSignInBtnClick = async () => {
@@ -186,7 +185,7 @@ const Signin: React.FC<Props> = () => {
</button>
<span className="split-text">/</span>
<button className="btn signup-btn disabled" onClick={() => toastHelper.info("注册已关闭")}>
<button className="btn signup-btn" onClick={handleSignUpBtnClick}>
</button>
<span className="split-text">/</span>

View File

@@ -35,11 +35,15 @@ class UserService {
}
public async updateUsername(username: string): Promise<void> {
await api.updateUserinfo(username);
await api.updateUserinfo({
username,
});
}
public async removeGithubName(): Promise<void> {
await api.updateUserinfo(undefined, undefined, "");
await api.updateUserinfo({
githubName: "",
});
}
public async checkPasswordValid(password: string): Promise<boolean> {
@@ -48,11 +52,15 @@ class UserService {
}
public async updatePassword(password: string): Promise<void> {
await api.updateUserinfo(undefined, password);
await api.updateUserinfo({
password,
});
}
public async updateWxOpenId(wxOpenId: string): Promise<void> {
await api.updateUserinfo(undefined, undefined, undefined, wxOpenId);
await api.updateUserinfo({
wxOpenId,
});
}
}