Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
e5f660a0
Commit
e5f660a0
authored
Nov 22, 2023
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: migrate update user
parent
c0628ef9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
21 deletions
+34
-21
MemberSection.tsx
web/src/components/Settings/MemberSection.tsx
+13
-6
UpdateAccountDialog.tsx
web/src/components/UpdateAccountDialog.tsx
+17
-8
api.ts
web/src/helpers/api.ts
+0
-4
user.ts
web/src/store/module/user.ts
+4
-3
No files found.
web/src/components/Settings/MemberSection.tsx
View file @
e5f660a0
...
@@ -5,6 +5,7 @@ import { userServiceClient } from "@/grpcweb";
...
@@ -5,6 +5,7 @@ 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
{
RowStatus
}
from
"@/types/proto/api/v2/common"
;
import
{
User_Role
}
from
"@/types/proto/api/v2/user_service"
;
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"
;
...
@@ -84,9 +85,12 @@ const MemberSection = () => {
...
@@ -84,9 +85,12 @@ const MemberSection = () => {
style
:
"danger"
,
style
:
"danger"
,
dialogName
:
"archive-user-dialog"
,
dialogName
:
"archive-user-dialog"
,
onConfirm
:
async
()
=>
{
onConfirm
:
async
()
=>
{
await
userStore
.
patchUser
({
await
userServiceClient
.
updateUser
({
id
:
user
.
id
,
user
:
{
rowStatus
:
"ARCHIVED"
,
name
:
`
${
UserNamePrefix
}${
user
.
username
}
`
,
rowStatus
:
RowStatus
.
ARCHIVED
,
},
updateMask
:
[
"row_status"
],
});
});
fetchUserList
();
fetchUserList
();
},
},
...
@@ -94,9 +98,12 @@ const MemberSection = () => {
...
@@ -94,9 +98,12 @@ const MemberSection = () => {
};
};
const
handleRestoreUserClick
=
async
(
user
:
User
)
=>
{
const
handleRestoreUserClick
=
async
(
user
:
User
)
=>
{
await
userStore
.
patchUser
({
await
userServiceClient
.
updateUser
({
id
:
user
.
id
,
user
:
{
rowStatus
:
"NORMAL"
,
name
:
`
${
UserNamePrefix
}${
user
.
username
}
`
,
rowStatus
:
RowStatus
.
ACTIVE
,
},
updateMask
:
[
"row_status"
],
});
});
fetchUserList
();
fetchUserList
();
};
};
...
...
web/src/components/UpdateAccountDialog.tsx
View file @
e5f660a0
...
@@ -3,6 +3,8 @@ import { useEffect, useState } from "react";
...
@@ -3,6 +3,8 @@ import { useEffect, useState } from "react";
import
{
toast
}
from
"react-hot-toast"
;
import
{
toast
}
from
"react-hot-toast"
;
import
{
convertFileToBase64
}
from
"@/helpers/utils"
;
import
{
convertFileToBase64
}
from
"@/helpers/utils"
;
import
{
useUserStore
}
from
"@/store/module"
;
import
{
useUserStore
}
from
"@/store/module"
;
import
{
UserNamePrefix
}
from
"@/store/v1"
;
import
{
User
as
UserPb
}
from
"@/types/proto/api/v2/user_service"
;
import
{
useTranslate
}
from
"@/utils/i18n"
;
import
{
useTranslate
}
from
"@/utils/i18n"
;
import
{
generateDialog
}
from
"./Dialog"
;
import
{
generateDialog
}
from
"./Dialog"
;
import
Icon
from
"./Icon"
;
import
Icon
from
"./Icon"
;
...
@@ -94,22 +96,29 @@ const UpdateAccountDialog: React.FC<Props> = ({ destroy }: Props) => {
...
@@ -94,22 +96,29 @@ const UpdateAccountDialog: React.FC<Props> = ({ destroy }: Props) => {
try
{
try
{
const
user
=
userStore
.
getState
().
user
as
User
;
const
user
=
userStore
.
getState
().
user
as
User
;
const
userPatch
:
UserPatch
=
{
const
updateMask
=
[];
id
:
user
.
id
,
};
if
(
!
isEqual
(
user
.
avatarUrl
,
state
.
avatarUrl
))
{
if
(
!
isEqual
(
user
.
avatarUrl
,
state
.
avatarUrl
))
{
u
serPatch
.
avatarUrl
=
state
.
avatarUrl
;
u
pdateMask
.
push
(
"avatar_url"
)
;
}
}
if
(
!
isEqual
(
user
.
nickname
,
state
.
nickname
))
{
if
(
!
isEqual
(
user
.
nickname
,
state
.
nickname
))
{
u
serPatch
.
nickname
=
state
.
nickname
;
u
pdateMask
.
push
(
"nickname"
)
;
}
}
if
(
!
isEqual
(
user
.
username
,
state
.
username
))
{
if
(
!
isEqual
(
user
.
username
,
state
.
username
))
{
u
serPatch
.
username
=
state
.
username
;
u
pdateMask
.
push
(
"username"
)
;
}
}
if
(
!
isEqual
(
user
.
email
,
state
.
email
))
{
if
(
!
isEqual
(
user
.
email
,
state
.
email
))
{
u
serPatch
.
email
=
state
.
email
;
u
pdateMask
.
push
(
"email"
)
;
}
}
await
userStore
.
patchUser
(
userPatch
);
await
userStore
.
patchUser
(
UserPb
.
fromPartial
({
name
:
`
${
UserNamePrefix
}${
state
.
username
}
`
,
id
:
user
.
id
,
nickname
:
state
.
nickname
,
email
:
state
.
email
,
avatarUrl
:
state
.
avatarUrl
,
}),
updateMask
);
toast
.
success
(
t
(
"message.update-succeed"
));
toast
.
success
(
t
(
"message.update-succeed"
));
handleCloseBtnClick
();
handleCloseBtnClick
();
}
catch
(
error
:
any
)
{
}
catch
(
error
:
any
)
{
...
...
web/src/helpers/api.ts
View file @
e5f660a0
...
@@ -56,10 +56,6 @@ export function upsertUserSetting(upsert: UserSettingUpsert) {
...
@@ -56,10 +56,6 @@ export function upsertUserSetting(upsert: UserSettingUpsert) {
return
axios
.
post
<
UserSetting
>
(
`/api/v1/user/setting`
,
upsert
);
return
axios
.
post
<
UserSetting
>
(
`/api/v1/user/setting`
,
upsert
);
}
}
export
function
patchUser
(
userPatch
:
UserPatch
)
{
return
axios
.
patch
<
User
>
(
`/api/v1/user/
${
userPatch
.
id
}
`
,
userPatch
);
}
export
function
getAllMemos
(
memoFind
?:
MemoFind
)
{
export
function
getAllMemos
(
memoFind
?:
MemoFind
)
{
const
queryList
=
[];
const
queryList
=
[];
if
(
memoFind
?.
offset
)
{
if
(
memoFind
?.
offset
)
{
...
...
web/src/store/module/user.ts
View file @
e5f660a0
...
@@ -3,6 +3,7 @@ import { userServiceClient } from "@/grpcweb";
...
@@ -3,6 +3,7 @@ import { userServiceClient } from "@/grpcweb";
import
*
as
api
from
"@/helpers/api"
;
import
*
as
api
from
"@/helpers/api"
;
import
storage
from
"@/helpers/storage"
;
import
storage
from
"@/helpers/storage"
;
import
{
getSystemColorScheme
}
from
"@/helpers/utils"
;
import
{
getSystemColorScheme
}
from
"@/helpers/utils"
;
import
{
User
as
UserPb
}
from
"@/types/proto/api/v2/user_service"
;
import
store
,
{
useAppSelector
}
from
".."
;
import
store
,
{
useAppSelector
}
from
".."
;
import
{
setAppearance
,
setLocale
}
from
"../reducer/global"
;
import
{
setAppearance
,
setLocale
}
from
"../reducer/global"
;
import
{
patchUser
,
setHost
,
setUser
}
from
"../reducer/user"
;
import
{
patchUser
,
setHost
,
setUser
}
from
"../reducer/user"
;
...
@@ -106,10 +107,10 @@ export const useUserStore = () => {
...
@@ -106,10 +107,10 @@ export const useUserStore = () => {
storage
.
set
({
localSetting
});
storage
.
set
({
localSetting
});
store
.
dispatch
(
patchUser
({
localSetting
}));
store
.
dispatch
(
patchUser
({
localSetting
}));
},
},
patchUser
:
async
(
user
Patch
:
UserPatch
):
Promise
<
void
>
=>
{
patchUser
:
async
(
user
:
UserPb
,
updateMask
:
string
[]
):
Promise
<
void
>
=>
{
await
api
.
patchUser
(
userPatch
);
await
userServiceClient
.
updateUser
({
user
,
updateMask
}
);
// If the user is the current user and the username is changed, reload the page.
// If the user is the current user and the username is changed, reload the page.
if
(
user
Patch
.
id
===
store
.
getState
().
user
.
user
?.
id
&&
userPatch
.
username
)
{
if
(
user
.
id
===
store
.
getState
().
user
.
user
?.
id
)
{
window
.
location
.
reload
();
window
.
location
.
reload
();
}
}
},
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment