Improve user interaction for the password change

multistore
Laurent 1 year ago
parent 5dffc41026
commit 87c4b10d97
  1. 2
      PadelClub/Views/Components/PasswordField.swift
  2. 55
      PadelClub/Views/User/ChangePasswordView.swift
  3. 2
      PadelClub/Views/User/UserCreationView.swift

@ -35,8 +35,8 @@ struct PasswordField: View {
let image = self.visible ? "eye.slash" : "eye" let image = self.visible ? "eye.slash" : "eye"
Image(systemName: image) Image(systemName: image)
} }
} }
.autocorrectionDisabled(true)
} }

@ -10,32 +10,53 @@ import LeStorage
struct ChangePasswordView: View { struct ChangePasswordView: View {
@Environment(\.dismiss) var dismiss
@State var oldPassword: String = "" @State var oldPassword: String = ""
@State var password1: String = "" @State var password1: String = ""
@State var password2: String = "" @State var password2: String = ""
@State var isLoading: Bool = false @State var isLoading: Bool = false
@State var errorMessage: String = "" @State var errorMessage: String = ""
@State var showForm: Bool = true
var body: some View { var body: some View {
Form { Group {
if self.showForm {
PasswordField("Old password", text: self.$oldPassword)
PasswordField("Password", text: self.$password1) Form {
PasswordField("Password again", text: self.$password2)
PasswordField("Old password", text: self.$oldPassword)
Section { PasswordField("Password", text: self.$password1)
Button(action: { PasswordField("Password again", text: self.$password2)
self._changePassword()
}, label: { Section {
Text("Changer de mot de passe") Button(action: {
}) self._changePassword()
.frame(maxWidth: .infinity) }, label: {
} footer: { if self.isLoading {
if self.errorMessage.count > 0 { Text("Changer de mot de passe")
Text(self.errorMessage).foregroundStyle(.red) } else {
ProgressView()
}
})
.frame(maxWidth: .infinity)
} footer: {
if self.errorMessage.count > 0 {
Text(self.errorMessage).foregroundStyle(.red)
}
}
} }
} else {
VStack {
Text("Votre mot de passe a bien été changé")
RowButtonView("Ok") {
dismiss()
}
}.padding()
} }
} }
.navigationTitle("Changer de mot de passe") .navigationTitle("Changer de mot de passe")
@ -51,9 +72,11 @@ struct ChangePasswordView: View {
password1: self.password1, password1: self.password1,
password2: self.password2) password2: self.password2)
self.isLoading = false self.isLoading = false
self.showForm = false
} catch { } catch {
Logger.error(error) Logger.error(error)
self.errorMessage = ErrorUtils.message(error: error) self.errorMessage = ErrorUtils.message(error: error)
self.isLoading = false
} }
} }

@ -86,7 +86,6 @@ struct UserCreationFormView: View {
.focused($focusedField, equals: .password) .focused($focusedField, equals: .password)
.textContentType(.init(rawValue: "")) .textContentType(.init(rawValue: ""))
.keyboardType(.asciiCapable) .keyboardType(.asciiCapable)
.autocorrectionDisabled(true)
.submitLabel(.next) .submitLabel(.next)
.onSubmit(of: .text) { .onSubmit(of: .text) {
focusedField = .confirmPassword focusedField = .confirmPassword
@ -96,7 +95,6 @@ struct UserCreationFormView: View {
.focused($focusedField, equals: .confirmPassword) .focused($focusedField, equals: .confirmPassword)
.textContentType(.init(rawValue: "")) .textContentType(.init(rawValue: ""))
.keyboardType(.asciiCapable) .keyboardType(.asciiCapable)
.autocorrectionDisabled(true)
.submitLabel(.next) .submitLabel(.next)
.onSubmit(of: .text) { .onSubmit(of: .text) {
focusedField = .firstName focusedField = .firstName

Loading…
Cancel
Save