Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

90 changes: 64 additions & 26 deletions Modules/Sources/WordPressUI/Views/Users/Views/UserDetailsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ struct UserDetailsView: View {
private let actionDispatcher: UserManagementActionDispatcher
let user: DisplayUser

@State private var presentPasswordAlert: Bool = false {
didSet {
newPassword = ""
newPasswordConfirmation = ""
}
}
@State private var newPassword: String = ""
@State private var newPasswordConfirmation: String = ""

@StateObject
var viewModel: UserDetailViewModel

Expand Down Expand Up @@ -46,10 +55,8 @@ struct UserDetailsView: View {

if viewModel.currentUserCanModifyUsers {
Section(Strings.accountManagementSectionTitle) {
NavigationLink {
UserChangePasswordView(viewModel: passwordChangeViewModel)
} label: {
Text(Strings.setNewPasswordActionTitle)
Button(Strings.setNewPasswordActionTitle) {
presentPasswordAlert = true
}

NavigationLink {
Expand All @@ -62,15 +69,34 @@ struct UserDetailsView: View {
}
}
}
.alert(
Strings.setNewPasswordActionTitle,
isPresented: $presentPasswordAlert,
actions: {
SecureField(Strings.newPasswordPlaceholder, text: $newPassword)
SecureField(Strings.newPasswordConfirmationPlaceholder, text: $newPasswordConfirmation)
Button(Strings.updatePasswordButton) {
Task {
try await self.actionDispatcher.setNewPassword(id: user.id, newPassword: newPassword)
}
}
.disabled(newPassword.isEmpty || newPassword != newPasswordConfirmation)
Button(role: .cancel) {
presentPasswordAlert = false
} label: {
// TODO: Replace with `SharedStrings.Button.cancel`
Text(NSLocalizedString("shared.button.cancel", value: "Cancel", comment: "A shared button title used in different contexts"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would've probably been faster to do it that to add a TODO :laugh

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to move all the "Users" code to the app target first 🥲

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right. Yeah, I'd suggest moving it until there is an idea of how to organize it better.

}
},
message: {
Text(Strings.newPasswordAlertMessage)
}
)
.task {
await viewModel.loadCurrentUserRole()
}
}

var passwordChangeViewModel: UserChangePasswordViewModel {
UserChangePasswordViewModel(user: user, actionDispatcher: actionDispatcher)
}

func makeRow(title: String, content: String, link: URL? = nil) -> some View {
VStack(alignment: .leading) {
Text(title)
Expand All @@ -85,58 +111,70 @@ struct UserDetailsView: View {

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

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

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

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

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

static let setNewPasswordActionTitle = NSLocalizedString(
"userdetail.setNewPasswordActionTitle",
"userDetails.setNewPasswordActionTitle",
value: "Set New Password",
comment: "The 'Set New Password' button on the user profile – matches what's in /wp-admin/profile.php"
)

static let sendPasswordResetEmailActionTitle = NSLocalizedString(
"userdetail.sendPasswordResetEmailActionTitle",
value: "Send Password Reset Email",
comment: "The 'Send Password Reset Email' button on the user profile – matches what's in /wp-admin/profile.php"
)

static let deleteUserActionTitle = NSLocalizedString(
"userdetail.deleteUserActionTitle",
"userDetails.deleteUserActionTitle",
value: "Delete User",
comment: "The 'Delete User' button on the user profile – matches what's in /wp-admin/profile.php"
)
}
}

private struct UserDetailLabeledContentStyle: LabeledContentStyle {
func makeBody(configuration: LabeledContentStyleConfiguration) -> some View {
LabeledContent(configuration)
static let newPasswordAlertMessage = NSLocalizedString(
"userDetails.newPasswordAlertMessage",
value: "Enter a new password for this user",
comment: "The message in the alert that appears when setting a new password on the user profile"
)

static let newPasswordPlaceholder = NSLocalizedString(
"userDetails.textField.placeholder.newPassword",
value: "New password",
comment: "The placeholder text for the 'New Password' field on the user profile"
)

static let newPasswordConfirmationPlaceholder = NSLocalizedString(
"userDetails.textField.placeholder.newPasswordConfirmation",
value: "Confirm new password",
comment: "The placeholder text for the 'Confirm New Password' field on the user profile"
)

static let updatePasswordButton = NSLocalizedString(
"userDetails.button.updatePassword",
value: "Update",
comment: "The 'Update' button to set a new password on the user profile"
)
}
}

Expand Down