@ -10,7 +10,8 @@ import LeStorage
struct UserCreationFormView : View {
struct UserCreationFormView : View {
@ Binding var showLoginScreen : Bool
@ Binding var isPresented : Bool
@ Binding var showEmailValidationMessage : Bool
@ State var username : String = " "
@ State var username : String = " "
@ State var password1 : String = " "
@ State var password1 : String = " "
@ -39,56 +40,58 @@ struct UserCreationFormView: View {
var body : some View {
var body : some View {
Form {
NavigationStack {
Form {
Section {
TextField ( " Nom d'utilisateur " , text : self . $ username )
Section {
. autocorrectionDisabled ( )
TextField ( " Nom d'utilisateur " , text : self . $ username )
. textInputAutocapitalization ( . never )
. autocorrectionDisabled ( )
TextField ( " Email " , text : self . $ email )
. textInputAutocapitalization ( . never )
. keyboardType ( . emailAddress )
TextField ( " Email " , text : self . $ email )
. textInputAutocapitalization ( . never )
. keyboardType ( . emailAddress )
}
. textInputAutocapitalization ( . never )
Section {
SecureField ( " Mot de passe " , text : self . $ password1 )
SecureField ( " Confirmez le mot de passe " , text : self . $ password2 )
}
Section {
TextField ( " Prénom " , text : self . $ firstName )
. autocorrectionDisabled ( )
TextField ( " Nom " , text : self . $ lastName )
. autocorrectionDisabled ( )
TextField ( " Téléphone " , text : self . $ phone )
. autocorrectionDisabled ( )
Picker ( " Pays " , selection : $ selectedCountryIndex ) {
ForEach ( 0. . < self . countries . count , id : \ . self ) { index in
Text ( self . countries [ index ] ) . tag ( index )
}
}
}
. pickerStyle ( DefaultPickerStyle ( ) )
. padding ( )
Section {
}
SecureField ( " Mot de passe " , text : self . $ password1 )
SecureField ( " Confirmez le mot de passe " , text : self . $ password2 )
Section {
Toggle ( isOn : self . $ dataCollectAuthorized ) {
Text ( " J'autorise XLR Sport, éditeur de Padel Club, à sauvegarder les données ci-dessus. XLR Sport s'engage à ne pas partager ces données. " ) . font ( . footnote )
}
}
}
Section {
Section {
TextField ( " Prénom " , text : self . $ firstName )
Button ( action : {
. autocorrectionDisabled ( )
self . _create ( )
TextField ( " Nom " , text : self . $ lastName )
} , label : {
. autocorrectionDisabled ( )
if self . isLoading {
TextField ( " Téléphone " , text : self . $ phone )
ProgressView ( )
. autocorrectionDisabled ( )
} else {
Picker ( " Pays " , selection : $ selectedCountryIndex ) {
Text ( " Créer " )
ForEach ( 0. . < self . countries . count , id : \ . self ) { index in
Text ( self . countries [ index ] ) . tag ( index )
}
}
}
} ) . disabled ( ! self . dataCollectAuthorized )
. pickerStyle ( DefaultPickerStyle ( ) )
. frame ( maxWidth : . infinity )
. padding ( )
}
}
Section {
Toggle ( isOn : self . $ dataCollectAuthorized ) {
Text ( " J'autorise XLR Sport, éditeur de Padel Club, à sauvegarder les données ci-dessus. XLR Sport s'engage à ne pas partager ces données. " ) . font ( . footnote )
}
}
Section {
Button ( action : {
self . _create ( )
} , label : {
if self . isLoading {
ProgressView ( )
} else {
Text ( " Créer " )
}
} ) . disabled ( ! self . dataCollectAuthorized )
. frame ( maxWidth : . infinity )
}
} . navigationTitle ( " Créez votre compte " )
}
}
. onAppear {
. onAppear {
self . _selectCountry ( )
self . _selectCountry ( )
@ -152,12 +155,12 @@ struct UserCreationFormView: View {
country : self . countries [ self . selectedCountryIndex ] )
country : self . countries [ self . selectedCountryIndex ] )
let service = try Store . main . service ( )
let service = try Store . main . service ( )
let user : User = try await service . createAccount ( user : userCreationForm )
let _ : User = try await service . createAccount ( user : userCreationForm )
DispatchQueue . main . async {
DispatchQueue . main . async {
DataStore . shared . user = user
self . isLoading = false
self . isLoading = false
self . showLoginScreen = true
self . showEmailValidationMessage = true
self . isPresented = false
}
}
} catch {
} catch {
@ -169,24 +172,6 @@ struct UserCreationFormView: View {
}
}
struct UserCreationView : View {
@ State var showLoginScreen : Bool = false
var body : some View {
Group {
if self . showLoginScreen {
LoginView ( showEmailValidationMessage : true ) { _ in }
} else {
UserCreationFormView ( showLoginScreen : self . $ showLoginScreen )
}
}
. navigationTitle ( " Créez votre compte " )
}
}
# Preview {
# Preview {
UserCreationView ( )
UserCreationFormView ( isPresented : . constant ( true ) , showEmailValidationMessage : . constant ( true ) )
}
}