1
1
import { LockOutlined } from "@ant-design/icons" ;
2
- import { Alert , Button , Col , Descriptions , Form , Input , Row , Space } from "antd" ;
2
+ import { Alert , Button , Descriptions , Form , Input , List , Space } from "antd" ;
3
3
import Request from "libs/request" ;
4
4
import Toast from "libs/toast" ;
5
5
import messages from "messages" ;
6
+ import { useState } from "react" ;
6
7
import { type RouteComponentProps , withRouter } from "react-router-dom" ;
7
8
import { logoutUserAction } from "viewer/model/actions/user_actions" ;
8
9
import Store from "viewer/store" ;
@@ -18,6 +19,7 @@ const MIN_PASSWORD_LENGTH = 8;
18
19
19
20
function ChangePasswordView ( { history } : Props ) {
20
21
const [ form ] = Form . useForm ( ) ;
22
+ const [ isResetPasswordVisible , setResetPasswordVisible ] = useState ( false ) ;
21
23
22
24
function onFinish ( formValues : Record < string , any > ) {
23
25
Request . sendJSONReceiveJSON ( "/api/auth/changePassword" , {
@@ -45,145 +47,160 @@ function ChangePasswordView({ history }: Props) {
45
47
return Promise . resolve ( ) ;
46
48
}
47
49
48
- const items = [
50
+ function getPasswordComponent ( ) {
51
+ return isResetPasswordVisible ? (
52
+ < Form onFinish = { onFinish } form = { form } >
53
+ < FormItem
54
+ name = "oldPassword"
55
+ rules = { [
56
+ {
57
+ required : true ,
58
+ message : messages [ "auth.reset_old_password" ] ,
59
+ } ,
60
+ ] }
61
+ >
62
+ < Password
63
+ prefix = {
64
+ < LockOutlined
65
+ style = { {
66
+ fontSize : 13 ,
67
+ } }
68
+ />
69
+ }
70
+ placeholder = "Old Password"
71
+ />
72
+ </ FormItem >
73
+ < FormItem
74
+ hasFeedback
75
+ name = { [ "password" , "password1" ] }
76
+ rules = { [
77
+ {
78
+ required : true ,
79
+ message : messages [ "auth.reset_new_password" ] ,
80
+ } ,
81
+ {
82
+ min : MIN_PASSWORD_LENGTH ,
83
+ message : messages [ "auth.registration_password_length" ] ,
84
+ } ,
85
+ {
86
+ validator : ( _ , value : string ) =>
87
+ checkPasswordsAreMatching ( value , [ "password" , "password2" ] ) ,
88
+ } ,
89
+ ] }
90
+ >
91
+ < Password
92
+ prefix = {
93
+ < LockOutlined
94
+ style = { {
95
+ fontSize : 13 ,
96
+ } }
97
+ />
98
+ }
99
+ placeholder = "New Password"
100
+ />
101
+ </ FormItem >
102
+ < FormItem
103
+ hasFeedback
104
+ name = { [ "password" , "password2" ] }
105
+ rules = { [
106
+ {
107
+ required : true ,
108
+ message : messages [ "auth.reset_new_password2" ] ,
109
+ } ,
110
+ {
111
+ min : MIN_PASSWORD_LENGTH ,
112
+ message : messages [ "auth.registration_password_length" ] ,
113
+ } ,
114
+ {
115
+ validator : ( _ , value : string ) =>
116
+ checkPasswordsAreMatching ( value , [ "password" , "password1" ] ) ,
117
+ } ,
118
+ ] }
119
+ >
120
+ < Password
121
+ prefix = {
122
+ < LockOutlined
123
+ style = { {
124
+ fontSize : 13 ,
125
+ } }
126
+ />
127
+ }
128
+ placeholder = "Confirm New Password"
129
+ />
130
+ </ FormItem >
131
+ < Alert
132
+ type = "info"
133
+ message = { messages [ "auth.reset_logout" ] }
134
+ showIcon
135
+ style = { {
136
+ marginBottom : 24 ,
137
+ } }
138
+ />
139
+ < FormItem >
140
+ < Space >
141
+ < Button onClick = { ( ) => setResetPasswordVisible ( false ) } > Cancel</ Button >
142
+ < Button type = "primary" htmlType = "submit" >
143
+ Update Password
144
+ </ Button >
145
+ </ Space >
146
+ </ FormItem >
147
+ </ Form >
148
+ ) : (
149
+ < >
150
+ < Space . Compact >
151
+ < Input . Password visibilityToggle = { false } readOnly value = "******************" />
152
+ < Button type = "primary" onClick = { handleResetPassword } >
153
+ Reset Password
154
+ </ Button >
155
+ </ Space . Compact >
156
+ </ >
157
+ ) ;
158
+ }
159
+
160
+ function handleResetPassword ( ) {
161
+ setResetPasswordVisible ( true ) ;
162
+ }
163
+
164
+ const passwordItems = [
49
165
{
50
166
label : "Password" ,
51
- children : (
52
- < >
53
- < Space . Compact >
54
- < Input . Password
55
- prefix = {
56
- < LockOutlined
57
- style = { {
58
- fontSize : 13 ,
59
- } }
60
- />
61
- }
62
- value = "***************"
63
- />
64
- < Button
65
- type = "primary"
66
- htmlType = "submit"
67
- style = { {
68
- width : "100%" ,
69
- } }
70
- >
71
- Change Password
72
- </ Button >
73
- </ Space . Compact >
74
- </ >
75
- ) ,
167
+ children : getPasswordComponent ( ) ,
168
+ } ,
169
+ ] ;
170
+
171
+ const passKeyList = [
172
+ {
173
+ name : "passkey1" ,
174
+ details : "2024-05-01" ,
175
+ } ,
176
+ {
177
+ name : "passkey2" ,
178
+ details : "2025-05-01" ,
76
179
} ,
77
180
] ;
78
181
79
182
return (
80
183
< div >
81
184
< AccountSettingTitle title = "Password" description = "Manage and update your password" />
82
- < Descriptions column = { 2 } layout = "vertical" colon = { false } items = { items } />
83
- < Row >
84
- < Col span = { 8 } >
85
- < Form onFinish = { onFinish } form = { form } >
86
- < FormItem
87
- name = "oldPassword"
88
- rules = { [
89
- {
90
- required : true ,
91
- message : messages [ "auth.reset_old_password" ] ,
92
- } ,
93
- ] }
94
- >
95
- < Password
96
- prefix = {
97
- < LockOutlined
98
- style = { {
99
- fontSize : 13 ,
100
- } }
101
- />
102
- }
103
- placeholder = "Old Password"
104
- />
105
- </ FormItem >
106
- < FormItem
107
- hasFeedback
108
- name = { [ "password" , "password1" ] }
109
- rules = { [
110
- {
111
- required : true ,
112
- message : messages [ "auth.reset_new_password" ] ,
113
- } ,
114
- {
115
- min : MIN_PASSWORD_LENGTH ,
116
- message : messages [ "auth.registration_password_length" ] ,
117
- } ,
118
- {
119
- validator : ( _ , value : string ) =>
120
- checkPasswordsAreMatching ( value , [ "password" , "password2" ] ) ,
121
- } ,
122
- ] }
123
- >
124
- < Password
125
- prefix = {
126
- < LockOutlined
127
- style = { {
128
- fontSize : 13 ,
129
- } }
130
- />
131
- }
132
- placeholder = "New Password"
133
- />
134
- </ FormItem >
135
- < FormItem
136
- hasFeedback
137
- name = { [ "password" , "password2" ] }
138
- rules = { [
139
- {
140
- required : true ,
141
- message : messages [ "auth.reset_new_password2" ] ,
142
- } ,
143
- {
144
- min : MIN_PASSWORD_LENGTH ,
145
- message : messages [ "auth.registration_password_length" ] ,
146
- } ,
147
- {
148
- validator : ( _ , value : string ) =>
149
- checkPasswordsAreMatching ( value , [ "password" , "password1" ] ) ,
150
- } ,
151
- ] }
152
- >
153
- < Password
154
- prefix = {
155
- < LockOutlined
156
- style = { {
157
- fontSize : 13 ,
158
- } }
159
- />
160
- }
161
- placeholder = "Confirm New Password"
162
- />
163
- </ FormItem >
164
- < Alert
165
- type = "info"
166
- message = { messages [ "auth.reset_logout" ] }
167
- showIcon
168
- style = { {
169
- marginBottom : 24 ,
170
- } }
171
- />
172
- < FormItem >
173
- < Button
174
- type = "primary"
175
- htmlType = "submit"
176
- style = { {
177
- width : "100%" ,
178
- } }
179
- >
180
- Update Password
181
- </ Button >
182
- </ FormItem >
183
- </ Form >
184
- </ Col >
185
- </ Row >
185
+ < Descriptions
186
+ column = { 2 }
187
+ layout = "vertical"
188
+ colon = { false }
189
+ items = { passwordItems }
190
+ style = { { marginBottom : "3rem" } }
191
+ />
192
+
186
193
< AccountSettingTitle title = "Passkeys" description = "Login passwordless with Passkeys" />
194
+ < List
195
+ className = "demo-loadmore-list"
196
+ itemLayout = "horizontal"
197
+ dataSource = { passKeyList }
198
+ renderItem = { ( item ) => (
199
+ < List . Item actions = { [ < a key = "list-delete" > Delete</ a > ] } >
200
+ < List . Item . Meta title = { item . name } description = { item . details } />
201
+ </ List . Item >
202
+ ) }
203
+ />
187
204
</ div >
188
205
) ;
189
206
}
0 commit comments