chore: use user v2 api in frontend

This commit is contained in:
Steven
2023-09-10 22:03:12 +08:00
parent 93f062d0b9
commit 3ad0832516
11 changed files with 205 additions and 168 deletions

View File

@ -1,6 +1,7 @@
import { useEffect, useState } from "react";
import { toast } from "react-hot-toast";
import { useGlobalStore, useUserStore } from "@/store/module";
import { useUserV1Store } from "@/store/v1";
import { useTranslate } from "@/utils/i18n";
import { generateDialog } from "./Dialog";
import Icon from "./Icon";
@ -10,6 +11,7 @@ type Props = DialogProps;
const ChangePasswordDialog: React.FC<Props> = ({ destroy }: Props) => {
const t = useTranslate();
const userStore = useUserStore();
const userV1Store = useUserV1Store();
const globalStore = useGlobalStore();
const profile = globalStore.state.systemStatus.profile;
const [newPassword, setNewPassword] = useState("");
@ -50,10 +52,13 @@ const ChangePasswordDialog: React.FC<Props> = ({ destroy }: Props) => {
try {
const user = userStore.getState().user as User;
await userStore.patchUser({
id: user.id,
password: newPassword,
});
await userV1Store.updateUser(
{
username: user.username,
password: newPassword,
},
["password"]
);
toast.success(t("message.password-changed"));
handleCloseBtnClick();
} catch (error: any) {

View File

@ -1,5 +1,6 @@
import { Button, Input, Textarea } from "@mui/joy";
import { useUserStore } from "@/store/module";
import useCurrentUser from "@/hooks/useCurrentUser";
import { useUserV1Store } from "@/store/v1";
import { useTranslate } from "@/utils/i18n";
import showChangePasswordDialog from "../ChangePasswordDialog";
import { showCommonDialog } from "../Dialog/CommonDialog";
@ -9,8 +10,8 @@ import UserAvatar from "../UserAvatar";
const MyAccountSection = () => {
const t = useTranslate();
const userStore = useUserStore();
const user = userStore.state.user as User;
const userV1Store = useUserV1Store();
const user = useCurrentUser();
const openAPIRoute = `${window.location.origin}/api/v1/memo?openId=${user.openId}`;
const handleResetOpenIdBtnClick = async () => {
@ -20,10 +21,12 @@ const MyAccountSection = () => {
style: "warning",
dialogName: "reset-openid-dialog",
onConfirm: async () => {
await userStore.patchUser({
id: user.id,
resetOpenId: true,
});
await userV1Store.updateUser(
{
username: user.username,
},
["reset_open_id"]
);
},
});
};