@ -29,21 +29,15 @@ struct ChangePasswordView: View {
Form {
Form {
PasswordField ( " Old password " , text : self . $ oldPassword )
PasswordField ( " Ancien mot de passe " , text : self . $ oldPassword )
PasswordField ( " Password " , text : self . $ password1 )
PasswordField ( " Nouveau mot de passe " , text : self . $ password1 )
PasswordField ( " Password again " , text : self . $ password2 )
PasswordField ( " Confirmer du nouveau mot de passe " , text : self . $ password2 )
Section {
Section {
Button ( action : {
RowButtonView ( " Changer de mot de passe " , role : . destructive ) {
self . _changePassword ( )
await self . _changePassword ( )
} , label : {
}
if self . isLoading {
. disabled ( isLoading )
Text ( " Changer de mot de passe " )
} else {
ProgressView ( )
}
} )
. frame ( maxWidth : . infinity )
} footer : {
} footer : {
if self . errorMessage . count > 0 {
if self . errorMessage . count > 0 {
Text ( self . errorMessage ) . foregroundStyle ( . logoRed )
Text ( self . errorMessage ) . foregroundStyle ( . logoRed )
@ -60,26 +54,25 @@ struct ChangePasswordView: View {
}
}
}
}
. navigationTitle ( " Changer de mot de passe " )
. navigationTitle ( " Changer de mot de passe " )
. navigationBarTitleDisplayMode ( . inline )
. toolbarBackground ( . visible , for : . navigationBar )
}
}
fileprivate func _changePassword ( ) {
fileprivate func _changePassword ( ) async {
Task {
do {
do {
self . isLoading = true
self . isLoading = true
let service = try StoreCenter . main . service ( )
let service = try StoreCenter . main . service ( )
_ = try await service . changePassword (
_ = try await service . changePassword (
oldPassword : self . oldPassword ,
oldPassword : self . oldPassword ,
password1 : self . password1 ,
password1 : self . password1 ,
password2 : self . password2 )
password2 : self . password2 )
self . isLoading = false
self . isLoading = false
self . showForm = 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
self . isLoading = false
}
}
}
}
}
}
}