diff --git a/client/api/ApiDeclare.ts b/client/api/ApiDeclare.ts index b01b66d..0e739d0 100644 --- a/client/api/ApiDeclare.ts +++ b/client/api/ApiDeclare.ts @@ -3,11 +3,14 @@ export type CallMethod = "User.register" | "User.login" | - "User.setNickName" | - "User.setUserName" | "User.setAvatar" | + "User.updateProfile" | "User.getMyInfo" | + "User.getMyContacts" | + "User.addContact" | + "User.removeContacts" | + "Chat.getInfo" | "Chat.sendMessage" | "Chat.getMessageHistory" diff --git a/client/ui/dialog/UserProfileDialog.tsx b/client/ui/dialog/UserProfileDialog.tsx index 840ddb0..45ae519 100644 --- a/client/ui/dialog/UserProfileDialog.tsx +++ b/client/ui/dialog/UserProfileDialog.tsx @@ -39,20 +39,20 @@ export default function UserProfileDialog({ }) }) - return ( - -
- -
+ const userProfileEditDialogRef = React.useRef(null) + const editNickNameRef = React.useRef(null) + const editUserNameRef = React.useRef(null) + return (<> + { + // 公用 - 資料卡 + } +
- @@ -70,12 +70,58 @@ export default function UserProfileDialog({ {!isMySelf && 編輯聯絡人訊息} { isMySelf && <> - 編輯資料 + userProfileEditDialogRef.current!.open = true}>編輯資料 賬號設定 隱私設定 } - ) + { + // 個人資料編輯 + } + +
+ +
+ +
+ + +
+ + + + + userProfileEditDialogRef.current!.open = false}>取消 + { + const re = await Client.invoke("User.updateProfile", { + token: data.access_token, + nickname: editNickNameRef.current?.value, + username: editUserNameRef.current?.value, + }) + + if (checkApiSuccessOrSncakbar(re, "修改失敗")) return + snackbar({ + message: "修改成功 (刷新頁面以更新)", + placement: "top", + }) + userProfileEditDialogRef.current!.open = false + }}>更新 +
+ ) } \ No newline at end of file diff --git a/server/api/ApiDeclare.ts b/server/api/ApiDeclare.ts index c69e2cb..0e739d0 100644 --- a/server/api/ApiDeclare.ts +++ b/server/api/ApiDeclare.ts @@ -3,9 +3,8 @@ export type CallMethod = "User.register" | "User.login" | - "User.setNickName" | - "User.setUserName" | "User.setAvatar" | + "User.updateProfile" | "User.getMyInfo" | "User.getMyContacts" | diff --git a/server/api/UserApi.ts b/server/api/UserApi.ts index b760d84..f1e810f 100644 --- a/server/api/UserApi.ts +++ b/server/api/UserApi.ts @@ -129,9 +129,9 @@ export default class UserApi extends BaseApi { code: 200, } }) - // 更新昵稱 - this.registerEvent("User.setNickName", (args) => { - if (this.checkArgsMissing(args, ['nickname', 'token'])) return { + // 更新資料 + this.registerEvent("User.updateProfile", (args) => { + if (this.checkArgsMissing(args, ['token'])) return { msg: "參數缺失", code: 400, } @@ -143,27 +143,9 @@ export default class UserApi extends BaseApi { } const user = User.findById(token.author) + if (args.nickname != null) user!.setNickName(args.nickname as string) - - return { - msg: "成功", - code: 200, - } - }) - // 更新用戶名 - this.registerEvent("User.setUserName", (args) => { - if (this.checkArgsMissing(args, ['username', 'token'])) return { - msg: "參數缺失", - code: 400, - } - - const token = TokenManager.decode(args.token as string) - if (!this.checkToken(token)) return { - code: 401, - msg: "令牌無效", - } - - const user = User.findById(token.author) + if (args.username != null) user!.setUserName(args.username as string) return {