chore: migrate create user

This commit is contained in:
Steven 2023-11-22 22:58:04 +08:00
parent c0b5070e46
commit c0628ef95b
2 changed files with 10 additions and 12 deletions

View File

@ -1,9 +1,11 @@
import { Button, Dropdown, Input, Menu, MenuButton } from "@mui/joy"; import { Button, Dropdown, Input, Menu, MenuButton } from "@mui/joy";
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { toast } from "react-hot-toast"; import { toast } from "react-hot-toast";
import { userServiceClient } from "@/grpcweb";
import * as api from "@/helpers/api"; import * as api from "@/helpers/api";
import { useUserStore } from "@/store/module"; import { useUserStore } from "@/store/module";
import { UserNamePrefix } from "@/store/v1"; import { UserNamePrefix } from "@/store/v1";
import { User_Role } from "@/types/proto/api/v2/user_service";
import { useTranslate } from "@/utils/i18n"; import { useTranslate } from "@/utils/i18n";
import showChangeMemberPasswordDialog from "../ChangeMemberPasswordDialog"; import showChangeMemberPasswordDialog from "../ChangeMemberPasswordDialog";
import { showCommonDialog } from "../Dialog/CommonDialog"; import { showCommonDialog } from "../Dialog/CommonDialog";
@ -53,16 +55,16 @@ const MemberSection = () => {
return; return;
} }
const userCreate: UserCreate = {
username: state.createUserUsername,
password: state.createUserPassword,
role: "USER",
};
try { try {
await api.createUser(userCreate); await userServiceClient.createUser({
user: {
name: `${UserNamePrefix}${state.createUserUsername}`,
password: state.createUserPassword,
role: User_Role.USER,
},
});
} catch (error: any) { } catch (error: any) {
toast.error(error.response.data.message); toast.error(error.details);
} }
await fetchUserList(); await fetchUserList();
setState({ setState({

View File

@ -44,10 +44,6 @@ export function signout() {
return axios.post("/api/v1/auth/signout"); return axios.post("/api/v1/auth/signout");
} }
export function createUser(userCreate: UserCreate) {
return axios.post<User>("/api/v1/user", userCreate);
}
export function getMyselfUser() { export function getMyselfUser() {
return axios.get<User>("/api/v1/user/me"); return axios.get<User>("/api/v1/user/me");
} }