Fix issue with window creation

multistore
Laurent 1 year ago
parent 6f4398ee8c
commit 2bd79445c5
  1. 45
      PadelClub/Views/Navigation/Umpire/UmpireView.swift
  2. 21
      PadelClub/Views/User/LoginView.swift
  3. 1
      PadelClub/Views/User/MainUserView.swift
  4. 115
      PadelClub/Views/User/UserCreationView.swift

@ -17,6 +17,8 @@ struct UmpireView: View {
@State private var presentSearchView: Bool = false @State private var presentSearchView: Bool = false
@State private var showSubscriptions: Bool = false @State private var showSubscriptions: Bool = false
// @State var isConnected: Bool = false
var lastDataSource: String? { var lastDataSource: String? {
dataStore.appSettings.lastDataSource dataStore.appSettings.lastDataSource
} }
@ -47,18 +49,17 @@ struct UmpireView: View {
} }
} }
NavigationLink { if self._isConnected() {
MainUserView() NavigationLink {
} label: { AccountView(user: dataStore.user) { }
LabeledContent {
if Store.main.hasToken() {
Text(dataStore.user.username)
} else {
Image(systemName: "xmark.circle.fill")
.foregroundStyle(.logoRed)
}
} label: { } label: {
Label("Mon compte", systemImage: "person.fill") AccountRowView(userName: dataStore.user.username)
}
} else {
NavigationLink {
LoginView {_ in }
} label: {
AccountRowView(userName: dataStore.user.username)
} }
} }
@ -211,6 +212,28 @@ struct UmpireView: View {
} }
} }
} }
fileprivate func _isConnected() -> Bool {
return dataStore.user.username.count > 0 && Store.main.hasToken()
}
}
struct AccountRowView: View {
var userName: String
var body: some View {
LabeledContent {
if Store.main.hasToken() {
Text(self.userName)
} else {
Image(systemName: "xmark.circle.fill")
.foregroundStyle(.logoRed)
}
} label: {
Label("Mon compte", systemImage: "person.fill")
}
}
} }
#Preview { #Preview {

@ -18,11 +18,12 @@ struct LoginView: View {
@State var isLoading: Bool = false @State var isLoading: Bool = false
@State var showEmailPopup: Bool = false @State var showEmailPopup: Bool = false
@State var showUserCreationForm: Bool = false
@State var showEmailValidationMessage: Bool = false
@State var showSubscriptionView: Bool = false
@State var errorText: String? = nil @State var errorText: String? = nil
@State var showSubscriptionView: Bool = false
var loginFailed: Binding<Bool> { var loginFailed: Binding<Bool> {
Binding { Binding {
errorText != nil errorText != nil
@ -33,8 +34,6 @@ struct LoginView: View {
} }
} }
var showEmailValidationMessage: Bool = false
var handler: (User) -> () var handler: (User) -> ()
var body: some View { var body: some View {
@ -64,9 +63,19 @@ struct LoginView: View {
if !self.showEmailValidationMessage { if !self.showEmailValidationMessage {
Section { Section {
NavigationLink("Créer un compte") { Button(action: {
UserCreationView() self.showUserCreationForm = true
}, label: {
Text("Créer un compte")
})
.sheet(isPresented: self.$showUserCreationForm) {
UserCreationFormView(isPresented: self.$showUserCreationForm, showEmailValidationMessage: self.$showEmailValidationMessage)
} }
// NavigationLink("Créer un compte") {
// UserCreationView()
// }
Button(action: { Button(action: {
self.showEmailPopup = true self.showEmailPopup = true
}, label: { }, label: {

@ -31,6 +31,7 @@ struct MainUserView: View {
} }
fileprivate func _checkConnection() { fileprivate func _checkConnection() {
Logger.log("_checkConnection")
self.isConnected = dataStore.user.username.count > 0 && Store.main.hasToken() self.isConnected = dataStore.user.username.count > 0 && Store.main.hasToken()
} }

@ -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 { Section {
TextField("Nom d'utilisateur", text: self.$username) TextField("Nom d'utilisateur", text: self.$username)
.autocorrectionDisabled() .autocorrectionDisabled()
.textInputAutocapitalization(.never) .textInputAutocapitalization(.never)
TextField("Email", text: self.$email) TextField("Email", text: self.$email)
.keyboardType(.emailAddress) .keyboardType(.emailAddress)
.textInputAutocapitalization(.never) .textInputAutocapitalization(.never)
} }
Section { Section {
SecureField("Mot de passe", text: self.$password1) SecureField("Mot de passe", text: self.$password1)
SecureField("Confirmez le mot de passe", text: self.$password2) SecureField("Confirmez le mot de passe", text: self.$password2)
} }
Section { Section {
TextField("Prénom", text: self.$firstName) TextField("Prénom", text: self.$firstName)
.autocorrectionDisabled() .autocorrectionDisabled()
TextField("Nom", text: self.$lastName) TextField("Nom", text: self.$lastName)
.autocorrectionDisabled() .autocorrectionDisabled()
TextField("Téléphone", text: self.$phone) TextField("Téléphone", text: self.$phone)
.autocorrectionDisabled() .autocorrectionDisabled()
Picker("Pays", selection: $selectedCountryIndex) { Picker("Pays", selection: $selectedCountryIndex) {
ForEach(0..<self.countries.count, id: \.self) { index in ForEach(0..<self.countries.count, id: \.self) { index in
Text(self.countries[index]).tag(index) Text(self.countries[index]).tag(index)
}
} }
.pickerStyle(DefaultPickerStyle())
.padding()
} }
.pickerStyle(DefaultPickerStyle())
.padding()
}
Section { Section {
Toggle(isOn: self.$dataCollectAuthorized) { 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) 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 {
Button(action: { Button(action: {
self._create() self._create()
}, label: { }, label: {
if self.isLoading { if self.isLoading {
ProgressView() ProgressView()
} else { } else {
Text("Créer") Text("Créer")
} }
}).disabled(!self.dataCollectAuthorized) }).disabled(!self.dataCollectAuthorized)
.frame(maxWidth: .infinity) .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))
} }

Loading…
Cancel
Save