@@ -6,6 +6,15 @@ struct UserDetailsView: View {
66 private let actionDispatcher : UserManagementActionDispatcher
77 let user : DisplayUser
88
9+ @State private var presentPasswordAlert : Bool = false {
10+ didSet {
11+ newPassword = " "
12+ newPasswordConfirmation = " "
13+ }
14+ }
15+ @State private var newPassword : String = " "
16+ @State private var newPasswordConfirmation : String = " "
17+
918 @StateObject
1019 var viewModel : UserDetailViewModel
1120
@@ -46,10 +55,8 @@ struct UserDetailsView: View {
4655
4756 if viewModel. currentUserCanModifyUsers {
4857 Section ( Strings . accountManagementSectionTitle) {
49- NavigationLink {
50- UserChangePasswordView ( viewModel: passwordChangeViewModel)
51- } label: {
52- Text ( Strings . setNewPasswordActionTitle)
58+ Button ( Strings . setNewPasswordActionTitle) {
59+ presentPasswordAlert = true
5360 }
5461
5562 NavigationLink {
@@ -62,15 +69,34 @@ struct UserDetailsView: View {
6269 }
6370 }
6471 }
72+ . alert (
73+ Strings . setNewPasswordActionTitle,
74+ isPresented: $presentPasswordAlert,
75+ actions: {
76+ SecureField ( Strings . newPasswordPlaceholder, text: $newPassword)
77+ SecureField ( Strings . newPasswordConfirmationPlaceholder, text: $newPasswordConfirmation)
78+ Button ( Strings . updatePasswordButton) {
79+ Task {
80+ try await self . actionDispatcher. setNewPassword ( id: user. id, newPassword: newPassword)
81+ }
82+ }
83+ . disabled ( newPassword. isEmpty || newPassword != newPasswordConfirmation)
84+ Button ( role: . cancel) {
85+ presentPasswordAlert = false
86+ } label: {
87+ // TODO: Replace with `SharedStrings.Button.cancel`
88+ Text ( NSLocalizedString ( " shared.button.cancel " , value: " Cancel " , comment: " A shared button title used in different contexts " ) )
89+ }
90+ } ,
91+ message: {
92+ Text ( Strings . newPasswordAlertMessage)
93+ }
94+ )
6595 . task {
6696 await viewModel. loadCurrentUserRole ( )
6797 }
6898 }
6999
70- var passwordChangeViewModel : UserChangePasswordViewModel {
71- UserChangePasswordViewModel ( user: user, actionDispatcher: actionDispatcher)
72- }
73-
74100 func makeRow( title: String , content: String , link: URL ? = nil ) -> some View {
75101 VStack ( alignment: . leading) {
76102 Text ( title)
@@ -120,23 +146,35 @@ struct UserDetailsView: View {
120146 comment: " The 'Set New Password' button on the user profile – matches what's in /wp-admin/profile.php "
121147 )
122148
123- static let sendPasswordResetEmailActionTitle = NSLocalizedString (
124- " userdetail.sendPasswordResetEmailActionTitle " ,
125- value: " Send Password Reset Email " ,
126- comment: " The 'Send Password Reset Email' button on the user profile – matches what's in /wp-admin/profile.php "
127- )
128-
129149 static let deleteUserActionTitle = NSLocalizedString (
130150 " userdetail.deleteUserActionTitle " ,
131151 value: " Delete User " ,
132152 comment: " The 'Delete User' button on the user profile – matches what's in /wp-admin/profile.php "
133153 )
134- }
135- }
136154
137- private struct UserDetailLabeledContentStyle : LabeledContentStyle {
138- func makeBody( configuration: LabeledContentStyleConfiguration ) -> some View {
139- LabeledContent ( configuration)
155+ static let newPasswordAlertMessage = NSLocalizedString (
156+ " userdetail.newPasswordAlertMessage " ,
157+ value: " Enter a new password for this user " ,
158+ comment: " The message in the alert that appears when setting a new password on the user profile "
159+ )
160+
161+ static let newPasswordPlaceholder = NSLocalizedString (
162+ " userdetail.textField.placeholder.newPassword " ,
163+ value: " New password " ,
164+ comment: " The placeholder text for the 'New Password' field on the user profile "
165+ )
166+
167+ static let newPasswordConfirmationPlaceholder = NSLocalizedString (
168+ " userdetail.textField.placeholder.newPasswordConfirmation " ,
169+ value: " Confirm new password " ,
170+ comment: " The placeholder text for the 'Confirm New Password' field on the user profile "
171+ )
172+
173+ static let updatePasswordButton = NSLocalizedString (
174+ " userdetail.button.updatePassword " ,
175+ value: " Update " ,
176+ comment: " The 'Update' button to set a new password on the user profile "
177+ )
140178 }
141179}
142180
0 commit comments