Skip to content

Commit 1898814

Browse files
authored
Present an alert for setting a new password (#23790)
* Present an alert for setting a new password * Update localizable string keys
1 parent 6d67d85 commit 1898814

File tree

3 files changed

+64
-164
lines changed

3 files changed

+64
-164
lines changed

Modules/Sources/WordPressUI/Views/Users/ViewModel/UserChangePasswordViewModel.swift

Lines changed: 0 additions & 76 deletions
This file was deleted.

Modules/Sources/WordPressUI/Views/Users/Views/UserChangePasswordView.swift

Lines changed: 0 additions & 62 deletions
This file was deleted.

Modules/Sources/WordPressUI/Views/Users/Views/UserDetailsView.swift

Lines changed: 64 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
@@ -85,58 +111,70 @@ struct UserDetailsView: View {
85111

86112
enum Strings {
87113
static let accountManagementSectionTitle = NSLocalizedString(
88-
"userdetail.accountManagementSectionTitle",
114+
"userDetails.accountManagementSectionTitle",
89115
value: "Account Management",
90116
comment: "The 'Account Management' section of the user profile – matches what's in /wp-admin/profile.php"
91117
)
92118

93119
static let roleFieldTitle = NSLocalizedString(
94-
"userdetail.roleFieldTitle",
120+
"userDetails.roleFieldTitle",
95121
value: "Role",
96122
comment: "The 'Role' field of the user profile – matches what's in /wp-admin/profile.php"
97123
)
98124

99125
static let emailAddressFieldTitle = NSLocalizedString(
100-
"userdetail.emailAddressFieldTitle",
126+
"userDetails.emailAddressFieldTitle",
101127
value: "Email Address",
102128
comment: "The 'Email' field of the user profile – matches what's in /wp-admin/profile.php"
103129
)
104130

105131
static let websiteFieldTitle = NSLocalizedString(
106-
"userdetail.websiteFieldTitle",
132+
"userDetails.websiteFieldTitle",
107133
value: "Website",
108134
comment: "The 'Website' field of the user profile – matches what's in /wp-admin/profile.php"
109135
)
110136

111137
static let bioFieldTitle = NSLocalizedString(
112-
"userdetail.bioFieldTitle",
138+
"userDetails.bioFieldTitle",
113139
value: "Biographical Info",
114140
comment: "The 'Biographical Info' field of the user profile – matches what's in /wp-admin/profile.php"
115141
)
116142

117143
static let setNewPasswordActionTitle = NSLocalizedString(
118-
"userdetail.setNewPasswordActionTitle",
144+
"userDetails.setNewPasswordActionTitle",
119145
value: "Set New Password",
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(
130-
"userdetail.deleteUserActionTitle",
150+
"userDetails.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+
"userDetails.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+
"userDetails.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+
"userDetails.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+
"userDetails.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

Comments
 (0)